From 3d8e00eca876ca03b7800407d75c048bd7b7645e Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 29 Jun 2014 16:15:05 +0900 Subject: [PATCH 01/44] Introduce new architecture --- c3.js | 10207 +++++++++++++++++++++++++++------------------------- c3.old.js | 5537 ++++++++++++++++++++++++++++ 2 files changed, 10824 insertions(+), 4920 deletions(-) create mode 100644 c3.old.js diff --git a/c3.js b/c3.js index dca10f5..21876ab 100644 --- a/c3.js +++ b/c3.js @@ -1,5354 +1,5720 @@ +/** + * c3.core.js + */ (function (window) { 'use strict'; /*global define, module, exports, require */ - var c3 = { - version: "0.2.4" - }; + var c3 = { version: "0.3.0" }; - var CLASS = { - target: 'c3-target', - chart : 'c3-chart', - chartLine: 'c3-chart-line', - chartLines: 'c3-chart-lines', - chartBar: 'c3-chart-bar', - chartBars: 'c3-chart-bars', - chartText: 'c3-chart-text', - chartTexts: 'c3-chart-texts', - chartArc: 'c3-chart-arc', - chartArcs: 'c3-chart-arcs', - chartArcsTitle: 'c3-chart-arcs-title', - chartArcsBackground: 'c3-chart-arcs-background', - chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', - chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', - chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', - selectedCircle: 'c3-selected-circle', - selectedCircles: 'c3-selected-circles', - eventRect: 'c3-event-rect', - eventRects: 'c3-event-rects', - eventRectsSingle: 'c3-event-rects-single', - eventRectsMultiple: 'c3-event-rects-multiple', - zoomRect: 'c3-zoom-rect', - brush: 'c3-brush', - focused: 'c3-focused', - region: 'c3-region', - regions: 'c3-regions', - tooltip: 'c3-tooltip', - tooltipName: 'c3-tooltip-name', - shape: 'c3-shape', - shapes: 'c3-shapes', - line: 'c3-line', - lines: 'c3-lines', - bar: 'c3-bar', - bars: 'c3-bars', - circle: 'c3-circle', - circles: 'c3-circles', - arc: 'c3-arc', - arcs: 'c3-arcs', - area: 'c3-area', - areas: 'c3-areas', - empty: 'c3-empty', - text: 'c3-text', - texts: 'c3-texts', - gaugeValue: 'c3-gauge-value', - grid: 'c3-grid', - xgrid: 'c3-xgrid', - xgrids: 'c3-xgrids', - xgridLine: 'c3-xgrid-line', - xgridLines: 'c3-xgrid-lines', - xgridFocus: 'c3-xgrid-focus', - ygrid: 'c3-ygrid', - ygrids: 'c3-ygrids', - ygridLine: 'c3-ygrid-line', - ygridLines: 'c3-ygrid-lines', - axis: 'c3-axis', - axisX: 'c3-axis-x', - axisXLabel: 'c3-axis-x-label', - axisY: 'c3-axis-y', - axisYLabel: 'c3-axis-y-label', - axisY2: 'c3-axis-y2', - axisY2Label: 'c3-axis-y2-label', - legendBackground: 'c3-legend-background', - legendItem: 'c3-legend-item', - legendItemEvent: 'c3-legend-item-event', - legendItemTile: 'c3-legend-item-tile', - legendItemHidden: 'c3-legend-item-hidden', - legendItemFocused: 'c3-legend-item-focused', - dragarea: 'c3-dragarea', - EXPANDED: '_expanded_', - SELECTED: '_selected_', - INCLUDED: '_included_', + // will be called to generate c3 chart object + c3.generate = function (config) { + return new c3_chart(config); }; - /* - * Generate chart according to config - */ - c3.generate = function (config) { + // c3.fn.$$ and c3.fn.chart will be defined as prototype interface + c3.fn = {}; + + /*-- HIDDEN VARS AND FUNCTIONS --*/ + + // Define solid chart for hiding its functions from chart object scope + var chart = function () {}; - var d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + // Wrap solid chart object and call functions defined through c3.fn.$$ and c3.fn.chart + var c3_chart = function (config) { - var c3 = { data : {}, axis: {}, legend: {} }, - cache = {}; + var $$ = this.$$ = new chart(), + d3 = $$.d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + + $$.this = this; + $$.config = config; + $$.data = {}; + $$.cache = {}; /*-- Handle Config --*/ - function checkConfig(key, message) { - if (! (key in config)) { throw Error(message); } + $$.updateConfig(); + + // TODO: this should be an API + this.config = config; + + /*-- Set Variables --*/ + + // TODO: some of these should be a function and defined in prototype + + // MEMO: clipId needs to be unique because it conflicts when multiple charts exist + $$.clipId = "c3-" + (+new Date()) + '-clip', + $$.clipIdForXAxis = $$.clipId + '-xaxis', + $$.clipIdForYAxis = $$.clipId + '-yaxis', + $$.clipPath = $$.getClipPath($$.clipId), + $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), + $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); + + $$.isTimeSeries = ($$.__axis_x_type === 'timeseries'); + $$.isCategorized = ($$.__axis_x_type.indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && ($$.__data_x || $$.notEmpty($$.__data_xs)); }; + + $$.dragStart = null; + $$.dragging = false; + $$.cancelClick = false; + $$.mouseover = false; + $$.transiting = false; + + $$.defaultColorPattern = d3.scale.category10().range(); + $$.color = $$.generateColor($$.__data_colors, $$.notEmpty($$.__color_pattern) ? $$.__color_pattern : $$.defaultColorPattern, $$.__data_color); + $$.levelColor = $$.notEmpty($$.__color_threshold) ? $$.generateLevelColor($$.__color_pattern, $$.__color_threshold) : null; + + $$.dataTimeFormat = $$.__data_x_localtime ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = $$.__axis_x_localtime ? d3.time.format : d3.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 = []; + + $$.axes = {}; + + $$.xOrient = $$.__axis_rotated ? "left" : "bottom"; + $$.yOrient = $$.__axis_rotated ? ($$.__axis_y_inner ? "top" : "bottom") : ($$.__axis_y_inner ? "right" : "left"); + $$.y2Orient = $$.__axis_rotated ? ($$.__axis_y2_inner ? "bottom" : "top") : ($$.__axis_y2_inner ? "left" : "right"); + $$.subXOrient = $$.__axis_rotated ? "left" : "bottom"; + + $$.translate = { + main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, + context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, + legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, + x : function () { return "translate(0," + ($$.__axis_rotated ? 0 : $$.height) + ")"; }, + y : function () { return "translate(0," + ($$.__axis_rotated ? $$.height : 0) + ")"; }, + y2 : function () { return "translate(" + ($$.__axis_rotated ? 0 : $$.width) + "," + ($$.__axis_rotated ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + ($$.__axis_rotated ? 0 : $$.height2) + ")"; }, + arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } + }; + + $$.isLegendRight = $$.__legend_position === 'right'; + $$.isLegendInset = $$.__legend_position === 'inset'; + $$.isLegendTop = $$.__legend_inset_anchor === 'top-left' || $$.__legend_inset_anchor === 'top-right'; + $$.isLegendLeft = $$.__legend_inset_anchor === 'top-left' || $$.__legend_inset_anchor === 'bottom-left'; + $$.legendStep = 0; + $$.legendItemWidth = 0; + $$.legendItemHeight = 0; + $$.legendOpacityForHidden = 0.15; + + $$.currentMaxTickWidth = 0; + + $$.rotated_padding_left = 30; + $$.rotated_padding_right = $$.__axis_rotated && !$$.__axis_x_show ? 0 : 30; + $$.rotated_padding_top = 5; + + $$.withoutFadeIn = {}; + + // TODO: this should be pluggable + $$.pie = d3.layout.pie().value(function (d) { + return d.values.reduce(function (a, b) { return a + b.value; }, 0); + }); + if (!$$.__pie_sort || !$$.__donut_sort) { // TODO: this needs to be called by each type + $$.pie.sort(null); } - function getConfig(keys, defaultValue) { - var target = config, i, isLast, nextTarget; - for (i = 0; i < keys.length; i++) { - // return default if key not found - if (typeof target === 'object' && !(keys[i] in target)) { return defaultValue; } - // Check next key's value - isLast = (i === keys.length - 1); - nextTarget = target[keys[i]]; - if (!isLast && typeof nextTarget !== 'object') { - return defaultValue; - } - target = nextTarget; - } - return target; - } - - // bindto - id to bind the chart - var __bindto = getConfig(['bindto'], '#chart'); - - var __size_width = getConfig(['size', 'width']), - __size_height = getConfig(['size', 'height']); - - var __padding_left = getConfig(['padding', 'left']), - __padding_right = getConfig(['padding', 'right']), - __padding_top = getConfig(['padding', 'top']), - __padding_bottom = getConfig(['padding', 'bottom']); - - var __zoom_enabled = getConfig(['zoom', 'enabled'], false), - __zoom_extent = getConfig(['zoom', 'extent']), - __zoom_privileged = getConfig(['zoom', 'privileged'], false), - __zoom_onzoom = getConfig(['zoom', 'onzoom'], function () {}); - - var __interaction_enabled = getConfig(['interaction', 'enabled'], true); - - var __onmouseover = getConfig(['onmouseover'], function () {}), - __onmouseout = getConfig(['onmouseout'], function () {}), - __onresize = getConfig(['onresize'], function () {}), - __onresized = getConfig(['onresized'], function () {}); - - var __transition_duration = getConfig(['transition', 'duration'], 350); - - // data - data configuration - checkConfig('data', 'data is required in config'); - - var __data_x = getConfig(['data', 'x']), - __data_xs = getConfig(['data', 'xs'], {}), - __data_x_format = getConfig(['data', 'x_format'], '%Y-%m-%d'), - __data_x_localtime = getConfig(['data', 'x_localtime'], true), - __data_id_converter = getConfig(['data', 'id_converter'], function (id) { return id; }), - __data_names = getConfig(['data', 'names'], {}), - __data_classes = getConfig(['data', 'classes'], {}), - __data_groups = getConfig(['data', 'groups'], []), - __data_axes = getConfig(['data', 'axes'], {}), - __data_type = getConfig(['data', 'type']), - __data_types = getConfig(['data', 'types'], {}), - __data_labels = getConfig(['data', 'labels'], {}), - __data_order = getConfig(['data', 'order']), - __data_regions = getConfig(['data', 'regions'], {}), - __data_color = getConfig(['data', 'color']), - __data_colors = getConfig(['data', 'colors'], {}), - __data_hide = getConfig(['data', 'hide'], false), - __data_filter = getConfig(['data', 'filter']), - __data_selection_enabled = getConfig(['data', 'selection', 'enabled'], false), - __data_selection_grouped = getConfig(['data', 'selection', 'grouped'], false), - __data_selection_isselectable = getConfig(['data', 'selection', 'isselectable'], function () { return true; }), - __data_selection_multiple = getConfig(['data', 'selection', 'multiple'], true), - __data_onclick = getConfig(['data', 'onclick'], function () {}), - __data_onmouseover = getConfig(['data', 'onmouseover'], function () {}), - __data_onmouseout = getConfig(['data', 'onmouseout'], function () {}), - __data_onselected = getConfig(['data', 'onselected'], function () {}), - __data_onunselected = getConfig(['data', 'onunselected'], function () {}), - __data_ondragstart = getConfig(['data', 'ondragstart'], function () {}), - __data_ondragend = getConfig(['data', 'ondragend'], function () {}); + // TODO: this should be pluggable + $$.brush = d3.svg.brush().on("brush", $$.redrawForBrush); + $$.brush.update = function () { + if ($$.context) { $$.context.select('.' + this.CLASS.brush).call(this); } + return this; + }; + $$.brush.scale = function (scale) { + return $$.__axis_rotated ? this.y(scale) : this.x(scale); + }; + + // TODO: this should be pluggable + $$.zoom = d3.behavior.zoom() + .on("zoomstart", function () { + $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; + }) + .on("zoom", $$.redrawForZoom); + $$.zoom.scale = function (scale) { + return $$.__axis_rotated ? this.y(scale) : this.x(scale); + }; + $$.zoom.orgScaleExtent = function () { + var extent = $$.__zoom_extent ? $$.__zoom_extent : [1, 10]; + return [extent[0], Math.max(this.getMaxDataCount() / extent[1], extent[1])]; + }; + $$.zoom.updateScaleExtent = function () { + var ratio = this.diffDomain($$.x.orgDomain()) / this.diffDomain(this.orgXDomain), extent = this.orgScaleExtent(); + this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + return this; + }; + + /*-- Load data and init chart with defined functions --*/ + + if (config.data.url) { + $$.convertUrlToData(config.data.url, config.data.mimeType, config.data.keys, $$.init); + } + else if (config.data.json) { + $$.init($$.convertJsonToData(config.data.json, config.data.keys)); + } + else if (config.data.rows) { + $$.init($$.convertRowsToData(config.data.rows)); + } + else if (config.data.columns) { + $$.init($$.convertColumnsToData(config.data.columns)); + } + else { + throw Error('url or json or rows or columns is required.'); + } + }; + + // Open interface for each prototype + c3.fn.chart = c3_chart.prototype = {}; + c3.fn.$$ = chart.prototype = {}; + + if (typeof define === "function" && define.amd) { + define("c3", ["d3"], c3); + } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { + module.exports = c3; + } else { + window.c3 = c3; + } + +})(window); + + + +// TODO: these should be separated into each file +(function (c3) { + 'use strict'; + + /** + * c3.config.js + */ + c3.fn.$$.getConfig = function (keys, defaultValue) { + var target = this.config, i, isLast, nextTarget; + for (i = 0; i < keys.length; i++) { + // return default if key not found + if (typeof target === 'object' && !(keys[i] in target)) { return defaultValue; } + // Check next key's value + isLast = (i === keys.length - 1); + nextTarget = target[keys[i]]; + if (!isLast && typeof nextTarget !== 'object') { + return defaultValue; + } + target = nextTarget; + } + return target; + }; + c3.fn.$$.updateConfig = function () { + var $$ = this; + + $$.__bindto = $$.getConfig(['bindto'], '#chart'); + + $$.__size_width = $$.getConfig(['size', 'width']); + $$.__size_height = $$.getConfig(['size', 'height']); + + $$.__padding_left = $$.getConfig(['padding', 'left']); + $$.__padding_right = $$.getConfig(['padding', 'right']); + $$.__padding_top = $$.getConfig(['padding', 'top']); + $$.__padding_bottom = $$.getConfig(['padding', 'bottom']); + + $$.__zoom_enabled = $$.getConfig(['zoom', 'enabled'], false); + $$.__zoom_extent = $$.getConfig(['zoom', 'extent']); + $$.__zoom_privileged = $$.getConfig(['zoom', 'privileged'], false); + $$.__zoom_onzoom = $$.getConfig(['zoom', 'onzoom'], function () {}); + + $$.__interaction_enabled = $$.getConfig(['interaction', 'enabled'], true); + + $$.__onmouseover = $$.getConfig(['onmouseover'], function () {}); + $$.__onmouseout = $$.getConfig(['onmouseout'], function () {}); + $$.__onresize = $$.getConfig(['onresize'], function () {}); + $$.__onresized = $$.getConfig(['onresized'], function () {}); + + $$.__transition_duration = $$.getConfig(['transition', 'duration'], 350); + + $$.__data_x = $$.getConfig(['data', 'x']); + $$.__data_xs = $$.getConfig(['data', 'xs'], {}); + $$.__data_x_format = $$.getConfig(['data', 'x_format'], '%Y-%m-%d'); + $$.__data_x_localtime = $$.getConfig(['data', 'x_localtime'], true); + $$.__data_id_converter = $$.getConfig(['data', 'id_converter'], function (id) { return id; }); + $$.__data_names = $$.getConfig(['data', 'names'], {}); + $$.__data_classes = $$.getConfig(['data', 'classes'], {}); + $$.__data_groups = $$.getConfig(['data', 'groups'], []); + $$.__data_axes = $$.getConfig(['data', 'axes'], {}); + $$.__data_type = $$.getConfig(['data', 'type']); + $$.__data_types = $$.getConfig(['data', 'types'], {}); + $$.__data_labels = $$.getConfig(['data', 'labels'], {}); + $$.__data_order = $$.getConfig(['data', 'order']); + $$.__data_regions = $$.getConfig(['data', 'regions'], {}); + $$.__data_color = $$.getConfig(['data', 'color']); + $$.__data_colors = $$.getConfig(['data', 'colors'], {}); + $$.__data_hide = $$.getConfig(['data', 'hide'], false); + $$.__data_filter = $$.getConfig(['data', 'filter']); + $$.__data_selection_enabled = $$.getConfig(['data', 'selection', 'enabled'], false); + $$.__data_selection_grouped = $$.getConfig(['data', 'selection', 'grouped'], false); + $$.__data_selection_isselectable = $$.getConfig(['data', 'selection', 'isselectable'], function () { return true; }); + $$.__data_selection_multiple = $$.getConfig(['data', 'selection', 'multiple'], true); + $$.__data_onclick = $$.getConfig(['data', 'onclick'], function () {}); + $$.__data_onmouseover = $$.getConfig(['data', 'onmouseover'], function () {}); + $$.__data_onmouseout = $$.getConfig(['data', 'onmouseout'], function () {}); + $$.__data_onselected = $$.getConfig(['data', 'onselected'], function () {}); + $$.__data_onunselected = $$.getConfig(['data', 'onunselected'], function () {}); + $$.__data_ondragstart = $$.getConfig(['data', 'ondragstart'], function () {}); + $$.__data_ondragend = $$.getConfig(['data', 'ondragend'], function () {}); // configuration for no plot-able data supplied. - var __data_empty_label_text = getConfig(['data', 'empty', 'label', 'text'], ""); + $$.__data_empty_label_text = $$.getConfig(['data', 'empty', 'label', 'text'], ""); // subchart - var __subchart_show = getConfig(['subchart', 'show'], false), - __subchart_size_height = getConfig(['subchart', 'size', 'height'], 60), - __subchart_onbrush = getConfig(['subchart', 'onbrush'], function () {}); + $$.__subchart_show = $$.getConfig(['subchart', 'show'], false); + $$.__subchart_size_height = $$.getConfig(['subchart', 'size', 'height'], 60); + $$.__subchart_onbrush = $$.getConfig(['subchart', 'onbrush'], function () {}); // color - var __color_pattern = getConfig(['color', 'pattern'], []), - __color_threshold = getConfig(['color', 'threshold'], {}); + $$.__color_pattern = $$.getConfig(['color', 'pattern'], []); + $$.__color_threshold = $$.getConfig(['color', 'threshold'], {}); // legend - var __legend_show = getConfig(['legend', 'show'], true), - __legend_position = getConfig(['legend', 'position'], 'bottom'), - __legend_inset_anchor = getConfig(['legend', 'inset', 'anchor'], 'top-left'), - __legend_inset_x = getConfig(['legend', 'inset', 'x'], 10), - __legend_inset_y = getConfig(['legend', 'inset', 'y'], 0), - __legend_inset_step = getConfig(['legend', 'inset', 'step']), - __legend_item_onclick = getConfig(['legend', 'item', 'onclick']), - __legend_item_onmouseover = getConfig(['legend', 'item', 'onmouseover']), - __legend_item_onmouseout = getConfig(['legend', 'item', 'onmouseout']), - __legend_equally = getConfig(['legend', 'equally'], false); + $$.__legend_show = $$.getConfig(['legend', 'show'], true); + $$.__legend_position = $$.getConfig(['legend', 'position'], 'bottom'); + $$.__legend_inset_anchor = $$.getConfig(['legend', 'inset', 'anchor'], 'top-left'); + $$.__legend_inset_x = $$.getConfig(['legend', 'inset', 'x'], 10); + $$.__legend_inset_y = $$.getConfig(['legend', 'inset', 'y'], 0); + $$.__legend_inset_step = $$.getConfig(['legend', 'inset', 'step']); + $$.__legend_item_onclick = $$.getConfig(['legend', 'item', 'onclick']); + $$.__legend_item_onmouseover = $$.getConfig(['legend', 'item', 'onmouseover']); + $$.__legend_item_onmouseout = $$.getConfig(['legend', 'item', 'onmouseout']); + $$.__legend_equally = $$.getConfig(['legend', 'equally'], false); // axis - var __axis_rotated = getConfig(['axis', 'rotated'], false), - __axis_x_show = getConfig(['axis', 'x', 'show'], true), - __axis_x_type = getConfig(['axis', 'x', 'type'], 'indexed'), - __axis_x_localtime = getConfig(['axis', 'x', 'localtime'], true), - __axis_x_categories = getConfig(['axis', 'x', 'categories'], []), - __axis_x_tick_centered = getConfig(['axis', 'x', 'tick', 'centered'], false), - __axis_x_tick_format = getConfig(['axis', 'x', 'tick', 'format']), - __axis_x_tick_culling = getConfig(['axis', 'x', 'tick', 'culling'], {}), - __axis_x_tick_culling_max = getConfig(['axis', 'x', 'tick', 'culling', 'max'], 10), - __axis_x_tick_count = getConfig(['axis', 'x', 'tick', 'count']), - __axis_x_tick_fit = getConfig(['axis', 'x', 'tick', 'fit'], true), - __axis_x_tick_values = getConfig(['axis', 'x', 'tick', 'values'], null), - __axis_x_tick_rotate = getConfig(['axis', 'x', 'tick', 'rotate']), - __axis_x_max = getConfig(['axis', 'x', 'max'], null), - __axis_x_min = getConfig(['axis', 'x', 'min'], null), - __axis_x_padding = getConfig(['axis', 'x', 'padding'], {}), - __axis_x_height = getConfig(['axis', 'x', 'height']), - __axis_x_default = getConfig(['axis', 'x', 'default']), - __axis_x_label = getConfig(['axis', 'x', 'label'], {}), - __axis_y_show = getConfig(['axis', 'y', 'show'], true), - __axis_y_max = getConfig(['axis', 'y', 'max']), - __axis_y_min = getConfig(['axis', 'y', 'min']), - __axis_y_center = getConfig(['axis', 'y', 'center']), - __axis_y_label = getConfig(['axis', 'y', 'label'], {}), - __axis_y_inner = getConfig(['axis', 'y', 'inner'], false), - __axis_y_tick_format = getConfig(['axis', 'y', 'tick', 'format']), - __axis_y_padding = getConfig(['axis', 'y', 'padding']), - __axis_y_ticks = getConfig(['axis', 'y', 'ticks'], 10), - __axis_y2_show = getConfig(['axis', 'y2', 'show'], false), - __axis_y2_max = getConfig(['axis', 'y2', 'max']), - __axis_y2_min = getConfig(['axis', 'y2', 'min']), - __axis_y2_center = getConfig(['axis', 'y2', 'center']), - __axis_y2_label = getConfig(['axis', 'y2', 'label'], {}), - __axis_y2_inner = getConfig(['axis', 'y2', 'inner'], false), - __axis_y2_tick_format = getConfig(['axis', 'y2', 'tick', 'format']), - __axis_y2_padding = getConfig(['axis', 'y2', 'padding']), - __axis_y2_ticks = getConfig(['axis', 'y2', 'ticks'], 10); + $$.__axis_rotated = $$.getConfig(['axis', 'rotated'], false); + $$.__axis_x_show = $$.getConfig(['axis', 'x', 'show'], true); + $$.__axis_x_type = $$.getConfig(['axis', 'x', 'type'], 'indexed'); + $$.__axis_x_localtime = $$.getConfig(['axis', 'x', 'localtime'], true); + $$.__axis_x_categories = $$.getConfig(['axis', 'x', 'categories'], []); + $$.__axis_x_tick_centered = $$.getConfig(['axis', 'x', 'tick', 'centered'], false); + $$.__axis_x_tick_format = $$.getConfig(['axis', 'x', 'tick', 'format']); + $$.__axis_x_tick_culling = $$.getConfig(['axis', 'x', 'tick', 'culling'], {}); + $$.__axis_x_tick_culling_max = $$.getConfig(['axis', 'x', 'tick', 'culling', 'max'], 10); + $$.__axis_x_tick_count = $$.getConfig(['axis', 'x', 'tick', 'count']); + $$.__axis_x_tick_fit = $$.getConfig(['axis', 'x', 'tick', 'fit'], true); + $$.__axis_x_tick_values = $$.getConfig(['axis', 'x', 'tick', 'values'], null); + $$.__axis_x_tick_rotate = $$.getConfig(['axis', 'x', 'tick', 'rotate']); + $$.__axis_x_max = $$.getConfig(['axis', 'x', 'max'], null); + $$.__axis_x_min = $$.getConfig(['axis', 'x', 'min'], null); + $$.__axis_x_padding = $$.getConfig(['axis', 'x', 'padding'], {}); + $$.__axis_x_height = $$.getConfig(['axis', 'x', 'height']); + $$.__axis_x_default = $$.getConfig(['axis', 'x', 'default']); + $$.__axis_x_label = $$.getConfig(['axis', 'x', 'label'], {}); + $$.__axis_y_show = $$.getConfig(['axis', 'y', 'show'], true); + $$.__axis_y_max = $$.getConfig(['axis', 'y', 'max']); + $$.__axis_y_min = $$.getConfig(['axis', 'y', 'min']); + $$.__axis_y_center = $$.getConfig(['axis', 'y', 'center']); + $$.__axis_y_label = $$.getConfig(['axis', 'y', 'label'], {}); + $$.__axis_y_inner = $$.getConfig(['axis', 'y', 'inner'], false); + $$.__axis_y_tick_format = $$.getConfig(['axis', 'y', 'tick', 'format']); + $$.__axis_y_padding = $$.getConfig(['axis', 'y', 'padding']); + $$.__axis_y_ticks = $$.getConfig(['axis', 'y', 'ticks'], 10); + $$.__axis_y2_show = $$.getConfig(['axis', 'y2', 'show'], false); + $$.__axis_y2_max = $$.getConfig(['axis', 'y2', 'max']); + $$.__axis_y2_min = $$.getConfig(['axis', 'y2', 'min']); + $$.__axis_y2_center = $$.getConfig(['axis', 'y2', 'center']); + $$.__axis_y2_label = $$.getConfig(['axis', 'y2', 'label'], {}); + $$.__axis_y2_inner = $$.getConfig(['axis', 'y2', 'inner'], false); + $$.__axis_y2_tick_format = $$.getConfig(['axis', 'y2', 'tick', 'format']); + $$.__axis_y2_padding = $$.getConfig(['axis', 'y2', 'padding']); + $$.__axis_y2_ticks = $$.getConfig(['axis', 'y2', 'ticks'], 10); // grid - var __grid_x_show = getConfig(['grid', 'x', 'show'], false), - __grid_x_type = getConfig(['grid', 'x', 'type'], 'tick'), - __grid_x_lines = getConfig(['grid', 'x', 'lines'], []), - __grid_y_show = getConfig(['grid', 'y', 'show'], false), - // not used - // __grid_y_type = getConfig(['grid', 'y', 'type'], 'tick'), - __grid_y_lines = getConfig(['grid', 'y', 'lines'], []), - __grid_y_ticks = getConfig(['grid', 'y', 'ticks'], 10), - __grid_focus_show = getConfig(['grid', 'focus', 'show'], true); + $$.__grid_x_show = $$.getConfig(['grid', 'x', 'show'], false); + $$.__grid_x_type = $$.getConfig(['grid', 'x', 'type'], 'tick'); + $$.__grid_x_lines = $$.getConfig(['grid', 'x', 'lines'], []); + $$.__grid_y_show = $$.getConfig(['grid', 'y', 'show'], false); + // not used + // __grid_y_type = $$.getConfig(['grid', 'y', 'type'], 'tick'), + $$.__grid_y_lines = $$.getConfig(['grid', 'y', 'lines'], []); + $$.__grid_y_ticks = $$.getConfig(['grid', 'y', 'ticks'], 10); + $$.__grid_focus_show = $$.getConfig(['grid', 'focus', 'show'], true); // point - point of each data - var __point_show = getConfig(['point', 'show'], true), - __point_r = getConfig(['point', 'r'], 2.5), - __point_focus_expand_enabled = getConfig(['point', 'focus', 'expand', 'enabled'], true), - __point_focus_expand_r = getConfig(['point', 'focus', 'expand', 'r']), - __point_select_r = getConfig(['point', 'focus', 'select', 'r']); + $$.__point_show = $$.getConfig(['point', 'show'], true); + $$.__point_r = $$.getConfig(['point', 'r'], 2.5); + $$.__point_focus_expand_enabled = $$.getConfig(['point', 'focus', 'expand', 'enabled'], true); + $$.__point_focus_expand_r = $$.getConfig(['point', 'focus', 'expand', 'r']); + $$.__point_select_r = $$.getConfig(['point', 'focus', 'select', 'r']); - var __line_connect_null = getConfig(['line', 'connect_null'], false); + $$.__line_connect_null = $$.getConfig(['line', 'connect_null'], false); // bar - var __bar_width = getConfig(['bar', 'width']), - __bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6), - __bar_zerobased = getConfig(['bar', 'zerobased'], true); + $$.__bar_width = $$.getConfig(['bar', 'width']); + $$.__bar_width_ratio = $$.getConfig(['bar', 'width', 'ratio'], 0.6); + $$.__bar_zerobased = $$.getConfig(['bar', 'zerobased'], true); // area - var __area_zerobased = getConfig(['area', 'zerobased'], true); + $$.__area_zerobased = $$.getConfig(['area', 'zerobased'], true); // pie - var __pie_label_show = getConfig(['pie', 'label', 'show'], true), - __pie_label_format = getConfig(['pie', 'label', 'format']), - __pie_label_threshold = getConfig(['pie', 'label', 'threshold'], 0.05), - __pie_sort = getConfig(['pie', 'sort'], true), - __pie_expand = getConfig(['pie', 'expand'], true); + $$.__pie_label_show = $$.getConfig(['pie', 'label', 'show'], true); + $$.__pie_label_format = $$.getConfig(['pie', 'label', 'format']); + $$.__pie_label_threshold = $$.getConfig(['pie', 'label', 'threshold'], 0.05); + $$.__pie_sort = $$.getConfig(['pie', 'sort'], true); + $$.__pie_expand = $$.getConfig(['pie', 'expand'], true); // gauge - var __gauge_label_show = getConfig(['gauge', 'label', 'show'], true), - __gauge_label_format = getConfig(['gauge', 'label', 'format']), - __gauge_expand = getConfig(['gauge', 'expand'], true), - __gauge_min = getConfig(['gauge', 'min'], 0), - __gauge_max = getConfig(['gauge', 'max'], 100), - __gauge_units = getConfig(['gauge', 'units']), - __gauge_width = getConfig(['gauge', 'width']); + $$.__gauge_label_show = $$.getConfig(['gauge', 'label', 'show'], true); + $$.__gauge_label_format = $$.getConfig(['gauge', 'label', 'format']); + $$.__gauge_expand = $$.getConfig(['gauge', 'expand'], true); + $$.__gauge_min = $$.getConfig(['gauge', 'min'], 0); + $$.__gauge_max = $$.getConfig(['gauge', 'max'], 100); + $$.__gauge_units = $$.getConfig(['gauge', 'units']); + $$.__gauge_width = $$.getConfig(['gauge', 'width']); // donut - var __donut_label_show = getConfig(['donut', 'label', 'show'], true), - __donut_label_format = getConfig(['donut', 'label', 'format']), - __donut_label_threshold = getConfig(['donut', 'label', 'threshold'], 0.05), - __donut_sort = getConfig(['donut', 'sort'], true), - __donut_expand = getConfig(['donut', 'expand'], true), - __donut_title = getConfig(['donut', 'title'], ""); + $$.__donut_label_show = $$.getConfig(['donut', 'label', 'show'], true); + $$.__donut_label_format = $$.getConfig(['donut', 'label', 'format']); + $$.__donut_label_threshold = $$.getConfig(['donut', 'label', 'threshold'], 0.05); + $$.__donut_sort = $$.getConfig(['donut', 'sort'], true); + $$.__donut_expand = $$.getConfig(['donut', 'expand'], true); + $$.__donut_title = $$.getConfig(['donut', 'title'], ""); // region - region to change style - var __regions = getConfig(['regions'], []); + $$.__regions = $$.getConfig(['regions'], []); // tooltip - show when mouseover on each data - var __tooltip_show = getConfig(['tooltip', 'show'], true), - __tooltip_grouped = getConfig(['tooltip', 'grouped'], true), - __tooltip_format_title = getConfig(['tooltip', 'format', 'title']), - __tooltip_format_name = getConfig(['tooltip', 'format', 'name']), - __tooltip_format_value = getConfig(['tooltip', 'format', 'value']), - __tooltip_contents = getConfig(['tooltip', 'contents'], function (d, defaultTitleFormat, defaultValueFormat, color) { - var titleFormat = __tooltip_format_title ? __tooltip_format_title : defaultTitleFormat, - nameFormat = __tooltip_format_name ? __tooltip_format_name : function (name) { return name; }, - valueFormat = __tooltip_format_value ? __tooltip_format_value : defaultValueFormat, + $$.__tooltip_show = $$.getConfig(['tooltip', 'show'], true); + $$.__tooltip_grouped = $$.getConfig(['tooltip', 'grouped'], true); + $$.__tooltip_format_title = $$.getConfig(['tooltip', 'format', 'title']); + $$.__tooltip_format_name = $$.getConfig(['tooltip', 'format', 'name']); + $$.__tooltip_format_value = $$.getConfig(['tooltip', 'format', 'value']); + $$.__tooltip_contents = $$.getConfig(['tooltip', 'contents'], function (d, defaultTitleFormat, defaultValueFormat, color) { + var titleFormat = $$.__tooltip_format_title ? $$.__tooltip_format_title : defaultTitleFormat, + nameFormat = $$.__tooltip_format_name ? $$.__tooltip_format_name : function (name) { return name; }, + valueFormat = $$.__tooltip_format_value ? $$.__tooltip_format_value : defaultValueFormat, text, i, title, value, name, bgcolor; for (i = 0; i < d.length; i++) { if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, 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 += ""; + text += ""; text += ""; text += ""; text += ""; } return text + "
" + title + "
" + name + "" + value + "
"; - }), - __tooltip_init_show = getConfig(['tooltip', 'init', 'show'], false), - __tooltip_init_x = getConfig(['tooltip', 'init', 'x'], 0), - __tooltip_init_position = getConfig(['tooltip', 'init', 'position'], {top: '0px', left: '50px'}); - - /*-- Set Variables --*/ + }); + $$.__tooltip_init_show = $$.getConfig(['tooltip', 'init', 'show'], false); + $$.__tooltip_init_x = $$.getConfig(['tooltip', 'init', 'x'], 0); + $$.__tooltip_init_position = $$.getConfig(['tooltip', 'init', 'position'], {top: '0px', left: '50px'}); - // MEMO: clipId needs to be unique because it conflicts when multiple charts exist - var clipId = "c3-" + (+new Date()) + '-clip', - clipIdForXAxis = clipId + '-xaxis', - clipIdForYAxis = clipId + '-yaxis', - clipPath = getClipPath(clipId), - clipPathForXAxis = getClipPath(clipIdForXAxis), - clipPathForYAxis = getClipPath(clipIdForYAxis); - - var isTimeSeries = (__axis_x_type === 'timeseries'), - isCategorized = (__axis_x_type.indexOf('categor') >= 0), - isCustomX = function () { return !isTimeSeries && (__data_x || notEmpty(__data_xs)); }; - - var dragStart = null, dragging = false, cancelClick = false, mouseover = false, transiting = false; - - var defaultColorPattern = d3.scale.category10().range(), - color = generateColor(__data_colors, notEmpty(__color_pattern) ? __color_pattern : defaultColorPattern, __data_color), - levelColor = notEmpty(__color_threshold) ? generateLevelColor(__color_pattern, __color_threshold) : null; - - var dataTimeFormat = __data_x_localtime ? d3.time.format : d3.time.format.utc, - axisTimeFormat = __axis_x_localtime ? d3.time.format : d3.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; }] - ]); - - var hiddenTargetIds = [], hiddenLegendIds = []; - - /*-- Set Chart Params --*/ - - var margin, margin2, margin3, width, width2, height, height2, currentWidth, currentHeight; - var radius, radiusExpanded, innerRadius, arcWidth, arcHeight, svgArc, svgArcExpanded, svgArcExpandedSub, pie; - var xMin, xMax, yMin, yMax, subXMin, subXMax, subYMin, subYMax; - var x, y, y2, subX, subY, subY2, xAxis, yAxis, y2Axis, subXAxis; - var axes = {}; - - var xOrient = __axis_rotated ? "left" : "bottom", - yOrient = __axis_rotated ? (__axis_y_inner ? "top" : "bottom") : (__axis_y_inner ? "right" : "left"), - y2Orient = __axis_rotated ? (__axis_y2_inner ? "bottom" : "top") : (__axis_y2_inner ? "left" : "right"), - subXOrient = __axis_rotated ? "left" : "bottom"; - - var translate = { - main : function () { return "translate(" + asHalfPixel(margin.left) + "," + asHalfPixel(margin.top) + ")"; }, - context : function () { return "translate(" + asHalfPixel(margin2.left) + "," + asHalfPixel(margin2.top) + ")"; }, - legend : function () { return "translate(" + margin3.left + "," + margin3.top + ")"; }, - x : function () { return "translate(0," + (__axis_rotated ? 0 : height) + ")"; }, - y : function () { return "translate(0," + (__axis_rotated ? height : 0) + ")"; }, - y2 : function () { return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + (__axis_rotated ? 0 : height2) + ")"; }, - arc: function () { return "translate(" + (arcWidth / 2) + "," + (arcHeight / 2) + ")"; } - }; + }; - var isLegendRight = __legend_position === 'right'; - var isLegendInset = __legend_position === 'inset'; - var isLegendTop = __legend_inset_anchor === 'top-left' || __legend_inset_anchor === 'top-right'; - var isLegendLeft = __legend_inset_anchor === 'top-left' || __legend_inset_anchor === 'bottom-left'; - var legendStep = 0, legendItemWidth = 0, legendItemHeight = 0, legendOpacityForHidden = 0.15; - var currentMaxTickWidth = 0; + c3.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) + }); + }); + } + }; - /*-- Define Functions --*/ - function getClipPath(id) { - var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; - return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; + c3.fn.$$.updateSizes = function () { + var $$ = this; + var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), + legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, + hasArc = this.hasArcType($$.data.targets), + xAxisHeight = $$.__axis_rotated || hasArc ? 0 : this.getHorizontalAxisHeight('x'), + subchartHeight = $$.__subchart_show && !hasArc ? ($$.__subchart_size_height + xAxisHeight) : 0; + + $$.currentWidth = this.getCurrentWidth(); + $$.currentHeight = this.getCurrentHeight(); + + // for main, context + if ($$.__axis_rotated) { + $$.margin = { + top: this.getHorizontalAxisHeight('y2') + this.getCurrentPaddingTop(), + right: hasArc ? 0 : this.getCurrentPaddingRight(), + bottom: this.getHorizontalAxisHeight('y') + legendHeightForBottom + this.getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : this.getCurrentPaddingLeft()) + }; + $$.margin2 = { + top: $$.margin.top, + right: NaN, + bottom: 20 + legendHeightForBottom, + left: $$.rotated_padding_left + }; + } else { + $$.margin = { + top: 4 + this.getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : this.getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + this.getCurrentPaddingBottom(), + left: hasArc ? 0 : this.getCurrentPaddingLeft() + }; + $$.margin2 = { + top: this.currentHeight - subchartHeight - legendHeightForBottom, + right: NaN, + bottom: xAxisHeight + legendHeightForBottom, + left: $$.margin.left + }; } + // for legend + var insetLegendPosition = { + top: $$.isLegendTop ? this.getCurrentPaddingTop() + $$.__legend_inset_y + 5.5 : $$.currentHeight - legendHeight - this.getCurrentPaddingBottom() - $$.__legend_inset_y, + left: $$.isLegendLeft ? this.getCurrentPaddingLeft() + $$.__legend_inset_x + 0.5 : $$.currentWidth - legendWidth - this.getCurrentPaddingRight() - $$.__legend_inset_x + 0.5 + }; + $$.margin3 = { + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + }; - function asHalfPixel(n) { - return Math.ceil(n) + 0.5; - } + $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; + $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; + if ($$.width < 0) { $$.width = 0; } + if ($$.height < 0) { $$.height = 0; } - function transformMain(withTransition, transitions) { - var 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", translate.main); - xAxis.attr("transform", translate.x); - yAxis.attr("transform", translate.y); - y2Axis.attr("transform", translate.y2); - main.select('.' + CLASS.chartArcs).attr("transform", translate.arc); - } - function transformContext(withTransition, transitions) { - var subXAxis; - if (transitions && transitions.axisSubX) { - subXAxis = transitions.axisSubX; - } else { - subXAxis = context.select('.' + CLASS.axisX); - if (withTransition) { subXAxis = subXAxis.transition(); } - } - context.attr("transform", translate.context); - subXAxis.attr("transform", translate.subx); + $$.width2 = $$.__axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width; + $$.height2 = $$.__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); + this.updateRadius(); + + if ($$.isLegendRight && hasArc) { + $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } - function transformLegend(withTransition) { - (withTransition ? legend.transition() : legend).attr("transform", translate.legend); + }; + c3.fn.$$.updateRadius = function () { + var $$ = this; + $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; + $$.radius = $$.radiusExpanded * 0.95; + if (this.hasDonutType($$.data.targets) || this.hasGaugeType($$.data.targets)) { + $$.innerRadius = $$.radius * ($$.__gauge_width ? ($$.radius - $$.__gauge_width) / $$.radius : 0.6); + } else { + $$.innerRadius = 0; } - function transformAll(withTransition, transitions) { - transformMain(withTransition, transitions); - if (__subchart_show) { transformContext(withTransition, transitions); } - transformLegend(withTransition); + }; + + + + c3.fn.$$.init = function (data) { + var $$ = this, d3 = this.d3; + var arcs, eventRect, grid, i, binding = true; + + $$.selectChart = d3.select($$.__bindto); + if ($$.selectChart.empty()) { + $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); + this.observeInserted($$.selectChart); + binding = false; } + $$.selectChart.html("").classed("c3", true); - //-- Sizes --// + // Init data as targets + $$.data.xs = {}; + $$.data.targets = $$.convertDataToTargets(data); - // TODO: configurabale - var rotated_padding_left = 30, rotated_padding_right = __axis_rotated && !__axis_x_show ? 0 : 30, rotated_padding_top = 5; + if ($$.__data_filter) { + $$.data.targets = $$.data.targets.filter($$.__data_filter); + } - // MEMO: each value should be int to avoid disabling antialiasing - function updateSizes() { - var legendHeight = getLegendHeight(), legendWidth = getLegendWidth(), - legendHeightForBottom = isLegendRight || isLegendInset ? 0 : legendHeight, - hasArc = hasArcType(c3.data.targets), - xAxisHeight = __axis_rotated || hasArc ? 0 : getHorizontalAxisHeight('x'), - subchartHeight = __subchart_show && !hasArc ? (__subchart_size_height + xAxisHeight) : 0; + // Set targets to hide if needed + if ($$.__data_hide) { + this.addHiddenTargetIds($$.__data_hide === true ? this.mapToIds($$.data.targets) : $$.__data_hide); + } - currentWidth = getCurrentWidth(); - currentHeight = getCurrentHeight(); + // when gauge, hide legend // TODO: fix + if (this.hasGaugeType($$.data.targets)) { + $$.__legend_show = false; + } - // for main, context - if (__axis_rotated) { - margin = { - top: getHorizontalAxisHeight('y2') + getCurrentPaddingTop(), - right: hasArc ? 0 : getCurrentPaddingRight(), - bottom: getHorizontalAxisHeight('y') + legendHeightForBottom + getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : getCurrentPaddingLeft()) - }; - margin2 = { - top: margin.top, - right: NaN, - bottom: 20 + legendHeightForBottom, - left: rotated_padding_left - }; - } else { - margin = { - top: 4 + getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + getCurrentPaddingBottom(), - left: hasArc ? 0 : getCurrentPaddingLeft() - }; - margin2 = { - top: currentHeight - subchartHeight - legendHeightForBottom, - right: NaN, - bottom: xAxisHeight + legendHeightForBottom, - left: margin.left - }; - } - // for legend - var insetLegendPosition = { - top: isLegendTop ? getCurrentPaddingTop() + __legend_inset_y + 5.5 : currentHeight - legendHeight - getCurrentPaddingBottom() - __legend_inset_y, - left: isLegendLeft ? getCurrentPaddingLeft() + __legend_inset_x + 0.5 : currentWidth - legendWidth - getCurrentPaddingRight() - __legend_inset_x + 0.5 - }; - margin3 = { - top: isLegendRight ? 0 : isLegendInset ? insetLegendPosition.top : currentHeight - legendHeight, - right: NaN, - bottom: 0, - left: isLegendRight ? currentWidth - legendWidth : isLegendInset ? insetLegendPosition.left : 0 - }; + // Init sizes and scales + this.updateSizes(); + this.updateScales(); - width = currentWidth - margin.left - margin.right; - height = currentHeight - margin.top - margin.bottom; - if (width < 0) { width = 0; } - if (height < 0) { height = 0; } + // Set domains for each scale + $$.x.domain(d3.extent(this.getXDomain($$.data.targets))); + $$.y.domain(this.getYDomain($$.data.targets, 'y')); + $$.y2.domain(this.getYDomain($$.data.targets, 'y2')); + $$.subX.domain($$.x.domain()); + $$.subY.domain($$.y.domain()); + $$.subY2.domain($$.y2.domain()); - width2 = __axis_rotated ? margin.left - rotated_padding_left - rotated_padding_right : width; - height2 = __axis_rotated ? height : currentHeight - margin2.top - margin2.bottom; - if (width2 < 0) { width2 = 0; } - if (height2 < 0) { height2 = 0; } + // Save original x domain for zoom update + $$.orgXDomain = $$.x.domain(); - // for arc - arcWidth = width - (isLegendRight ? legendWidth + 10 : 0); - arcHeight = height - (isLegendRight ? 0 : 10); - updateRadius(); + // Set initialized scales to brush and zoom + $$.brush.scale($$.subX); + if ($$.__zoom_enabled) { $$.zoom.scale($$.x); } - if (isLegendRight && hasArc) { - margin3.left = arcWidth / 2 + radiusExpanded * 1.1; - } - } - function updateXgridFocus() { - main.select('line.' + CLASS.xgridFocus) - .attr("x1", __axis_rotated ? 0 : -10) - .attr("x2", __axis_rotated ? width : -10) - .attr("y1", __axis_rotated ? -10 : 0) - .attr("y2", __axis_rotated ? -10 : height); - } - function updateRadius() { - var innerRadiusRatio; - radiusExpanded = Math.min(arcWidth, arcHeight) / 2; - radius = radiusExpanded * 0.95; - innerRadiusRatio = __gauge_width ? (radius - __gauge_width) / radius : 0.6; - innerRadius = hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? radius * innerRadiusRatio : 0; - } - function getSvgLeft() { - var leftAxisClass = __axis_rotated ? CLASS.axisX : CLASS.axisY, - leftAxis = main.select('.' + leftAxisClass).node(), - svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, - chartRect = selectChart.node().getBoundingClientRect(), - hasArc = hasArcType(c3.data.targets), - svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : getCurrentPaddingLeft()); - return svgLeft > 0 ? svgLeft : 0; - } - function getCurrentWidth() { - return __size_width ? __size_width : getParentWidth(); - } - function getCurrentHeight() { - var h = __size_height ? __size_height : getParentHeight(); - return h > 0 ? h : 320; - } - function getCurrentPaddingTop() { - return isValue(__padding_top) ? __padding_top : 0; - } - function getCurrentPaddingBottom() { - return isValue(__padding_bottom) ? __padding_bottom : 0; - } - function getCurrentPaddingLeft() { - if (isValue(__padding_left)) { - return __padding_left; - } else if (__axis_rotated) { - return !__axis_x_show ? 1 : Math.max(ceil10(getAxisWidthByAxisId('x')), 40); - } else { - return !__axis_y_show || __axis_y_inner ? 1 : ceil10(getAxisWidthByAxisId('y')); - } - } - function getCurrentPaddingRight() { - var defaultPadding = 10, legendWidthOnRight = isLegendRight ? getLegendWidth() + 20 : 0; - if (isValue(__padding_right)) { - return __padding_right + 1; // 1 is needed not to hide tick line - } else if (__axis_rotated) { - return defaultPadding + legendWidthOnRight; - } else { - return (!__axis_y2_show || __axis_y2_inner ? defaultPadding : ceil10(getAxisWidthByAxisId('y2'))) + legendWidthOnRight; - } + /*-- Basic Elements --*/ + + // Define svgs + $$.svg = $$.selectChart.append("svg") + .style("overflow", "hidden") + .on('mouseenter', function () { return $$.__onmouseover.call(c3); }) + .on('mouseleave', function () { return $$.__onmouseout.call(c3); }); + + // Define defs + $$.defs = $$.svg.append("defs"); + $$.defs.append("clipPath").attr("id", $$.clipId).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForXAxis).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForYAxis).append("rect"); + $$.updateSvgSize(); + + // Define regions + $$.main = $$.svg.append("g").attr("transform", $$.translate.main); + $$.context = $$.svg.append("g").attr("transform", $$.translate.context); + $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); + + if (!$$.__subchart_show) { + $$.context.style('visibility', 'hidden'); + } + + if (!$$.__legend_show) { + $$.legend.style('visibility', 'hidden'); + $$.hiddenLegendIds = $$.mapToIds($$.data.targets); + } + + // Define tooltip + $$.tooltip = $$.selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + + // MEMO: call here to update legend box and tranlate for all + // MEMO: translate will be upated by this, so transform not needed in updateLegend() + $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + + /*-- Main Region --*/ + + // text when empty + $$.main.append("text") + .attr("class", this.CLASS.text + ' ' + this.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 + $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr("class", this.CLASS.regions); + + // Grids + $$.grid = $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', this.CLASS.grid); + if ($$.__grid_x_show) { + $$.grid.append("g").attr("class", this.CLASS.xgrids); + } + if ($$.__grid_y_show) { + $$.grid.append('g').attr('class', this.CLASS.ygrids); + } + $$.grid.append('g').attr("class", this.CLASS.xgridLines); + $$.grid.append('g').attr('class', this.CLASS.ygridLines); + if ($$.__grid_focus_show) { + $$.grid.append('g') + .attr("class", this.CLASS.xgridFocus) + .append('line') + .attr('class', this.CLASS.xgridFocus); + } + + // Define g for chart area + $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', this.CLASS.chart); + + // Cover whole with rects for events + eventRect = $$.main.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.eventRects) + .style('fill-opacity', 0); + + // Define g for bar chart area + $$.main.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartBars); + + // Define g for line chart area + $$.main.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartLines); + + // Define g for arc chart area + arcs = $$.main.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartArcs) + .attr("transform", $$.translate.arc); + arcs.append('text') + .attr('class', this.CLASS.chartArcsTitle) + .style("text-anchor", "middle") + .text(this.getArcTitle()); + if (this.hasGaugeType($$.data.targets)) { + arcs.append('path') + .attr("class", this.CLASS.chartArcsBackground) + .attr("d", function () { + var d = { + data: [{value: $$.__gauge_max}], + startAngle: -1 * (Math.PI / 2), + endAngle: Math.PI / 2 + }; + return this.getArc(d, true, true); + }); + arcs.append("text") + .attr("dy", ".75em") + .attr("class", this.CLASS.chartArcsGaugeUnit) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text($$.__gauge_label_show ? $$.__gauge_units : ''); + arcs.append("text") + .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") + .attr("dy", "1.2em") + .attr("class", this.CLASS.chartArcsGaugeMin) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text($$.__gauge_label_show ? $$.__gauge_min : ''); + arcs.append("text") + .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") + .attr("dy", "1.2em") + .attr("class", this.CLASS.chartArcsGaugeMax) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text($$.__gauge_label_show ? $$.__gauge_max : ''); + } + + $$.main.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartTexts); + + // if zoom privileged, insert rect to forefront + $$.main.insert('rect', $$.__zoom_privileged ? null : 'g.' + this.CLASS.regions) + .attr('class', this.CLASS.zoomRect) + .attr('width', $$.width) + .attr('height', $$.height) + .style('opacity', 0) + .on("dblclick.zoom", null); + + // Set default extent if defined + if ($$.__axis_x_default) { + $$.brush.extent(typeof $$.__axis_x_default !== 'function' ? $$.__axis_x_default : $$.__axis_x_default(this.getXDomain())); + } + + // Add Axis + $$.axes.x = $$.main.append("g") + .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisX) + .attr("clip-path", $$.clipPathForXAxis) + .attr("transform", $$.translate.x) + .style("visibility", $$.__axis_x_show ? 'visible' : 'hidden'); + $$.axes.x.append("text") + .attr("class", this.CLASS.axisXLabel) + .attr("transform", $$.__axis_rotated ? "rotate(-90)" : "") + .style("text-anchor", function () { return $$.textAnchorForXAxisLabel(); }); + + $$.axes.y = $$.main.append("g") + .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY) + .attr("clip-path", $$.clipPathForYAxis) + .attr("transform", $$.translate.y) + .style("visibility", $$.__axis_y_show ? 'visible' : 'hidden'); + $$.axes.y.append("text") + .attr("class", this.CLASS.axisYLabel) + .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") + .style("text-anchor", function () { return $$.textAnchorForYAxisLabel(); }); + + $$.axes.y2 = $$.main.append("g") + .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY2) + // clip-path? + .attr("transform", $$.translate.y2) + .style("visibility", $$.__axis_y2_show ? 'visible' : 'hidden'); + $$.axes.y2.append("text") + .attr("class", this.CLASS.axisY2Label) + .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") + .style("text-anchor", function () { return $$.textAnchorForY2AxisLabel(); }); + + /*-- Context Region --*/ + + // Define g for chart area + $$.context.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', this.CLASS.chart); + + // Define g for bar chart area + $$.context.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartBars); + + // Define g for line chart area + $$.context.select('.' + this.CLASS.chart).append("g") + .attr("class", this.CLASS.chartLines); + + // Add extent rect for Brush + $$.context.append("g") + .attr("clip-path", $$.clipPath) + .attr("class", this.CLASS.brush) + .call($$.brush) + .selectAll("rect") + .attr($$.__axis_rotated ? "width" : "height", $$.__axis_rotated ? $$.width2 : $$.height2); + + // ATTENTION: This must be called AFTER chart added + // Add Axis + $$.axes.subx = $$.context.append("g") + .attr("class", this.CLASS.axisX) + .attr("transform", $$.translate.subx) + .attr("clip-path", $$.__axis_rotated ? "" : $$.clipPathForXAxis); + + // Set targets + this.updateTargets($$.data.targets); + + // Draw with targets + if (binding) { + this.updateDimension(); + this.redraw({ + withTransform: true, + withUpdateXDomain: true, + withUpdateOrgXDomain: true, + withTransitionForAxis: false + }); } - function getAxisWidthByAxisId(id) { - var position = getAxisLabelPositionById(id); - return position.isInner ? 20 + getMaxTickWidth(id) : 40 + getMaxTickWidth(id); - } - function getHorizontalAxisHeight(axisId) { - if (axisId === 'x' && !__axis_x_show) { return 0; } - if (axisId === 'x' && __axis_x_height) { return __axis_x_height; } - if (axisId === 'y' && !__axis_y_show) { return __legend_show && !isLegendRight && !isLegendInset ? 10 : 1; } - if (axisId === 'y2' && !__axis_y2_show) { return rotated_padding_top; } - return (getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); - } - function getParentRectValue(key) { - var parent = selectChart.node(), v; - while (parent && parent.tagName !== 'BODY') { - v = parent.getBoundingClientRect()[key]; - if (v) { - break; + + // Show tooltip if needed + if ($$.__tooltip_init_show) { + if ($$.isTimeSeries && typeof $$.__tooltip_init_x === 'string') { + $$.__tooltip_init_x = this.parseDate($$.__tooltip_init_x); + for (i = 0; i < $$.data.targets[0].values.length; i++) { + if (($$.data.targets[0].values[i].x - $$.__tooltip_init_x) === 0) { break; } } - parent = parent.parentNode; + $$.__tooltip_init_x = i; } - return v; - } - function getParentWidth() { - return getParentRectValue('width'); - } - function getParentHeight() { - var h = selectChart.style('height'); - return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; - } - function getAxisClipX(forHorizontal) { - // axis line width + padding for left - return forHorizontal ? -(1 + 30) : -(margin.left - 1); - } - function getAxisClipY(forHorizontal) { - return forHorizontal ? -20 : -4; - } - function getXAxisClipX() { - return getAxisClipX(!__axis_rotated); - } - function getXAxisClipY() { - return getAxisClipY(!__axis_rotated); + $$.tooltip.html($$.__tooltip_contents($$.data.targets.map(function (d) { + return this.addName(d.values[$$.__tooltip_init_x]); + }), this.getXAxisTickFormat(), this.getYFormat(this.hasArcType($$.data.targets)), $$.color)); + $$.tooltip.style("top", $$.__tooltip_init_position.top) + .style("left", $$.__tooltip_init_position.left) + .style("display", "block"); } - function getYAxisClipX() { - return getAxisClipX(__axis_rotated); - } - function getYAxisClipY() { - return getAxisClipY(__axis_rotated); - } - function getAxisClipWidth(forHorizontal) { - // width + axis line width + padding for left/right - return forHorizontal ? width + 2 + 30 + 30 : margin.left + 20; - } - function getAxisClipHeight(forHorizontal) { - return forHorizontal ? (__axis_x_height ? __axis_x_height : 0) + 80 : height + 8; - } - function getXAxisClipWidth() { - return getAxisClipWidth(!__axis_rotated); - } - function getXAxisClipHeight() { - return getAxisClipHeight(!__axis_rotated); + + // Bind resize event + if (window.onresize == null) { + window.onresize = this.generateResize(); } - function getYAxisClipWidth() { - return getAxisClipWidth(__axis_rotated); + if (window.onresize.add) { + window.onresize.add(function () { + $$.__onresize.call(c3); + }); + window.onresize.add(function () { + $$.this.flush(); + }); + window.onresize.add(function () { + $$.__onresized.call(c3); + }); } - function getYAxisClipHeight() { - return getAxisClipHeight(__axis_rotated); + + // export element of the chart + $$.this.element = $$.selectChart.node(); + }; + + + c3.fn.$$.updateTargets = function (targets) { + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; + var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS; + + /*-- Main --*/ + + //-- Text --// + mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) + .data(targets) + .attr('class', function (d) { return $$.classChartText(d); }); + mainTextEnter = mainTextUpdate.enter().append('g') + .attr('class', function (d) { return $$.classChartText(d); }) + .style('opacity', 0) + .style("pointer-events", "none"); + mainTextEnter.append('g') + .attr('class', function (d) { return $$.classTexts(d); }); + + //-- Bar --// + mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + .data(targets) + .attr('class', function (d) { return $$.classChartBar(d); }); + mainBarEnter = mainBarUpdate.enter().append('g') + .attr('class', function (d) { return $$.classChartBar(d); }) + .style('opacity', 0) + .style("pointer-events", "none"); + // Bars for each data + mainBarEnter.append('g') + .attr("class", function (d) { return $$.classBars(d); }) + .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }); + + //-- Line --// + mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + .data(targets) + .attr('class', function (d) { return $$.classChartLine(d); }); + mainLineEnter = mainLineUpdate.enter().append('g') + .attr('class', function (d) { return $$.classChartLine(d); }) + .style('opacity', 0) + .style("pointer-events", "none"); + // Lines for each data + mainLineEnter.append('g') + .attr("class", function (d) { return $$.classLines(d); }); + // Areas + mainLineEnter.append('g') + .attr('class', function (d) { return $$.classAreas(d); }); + // Circles for each data point on lines + mainLineEnter.append('g') + .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); + mainLineEnter.append('g') + .attr("class", function (d) { return $$.classCircles(d); }) + .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }); + // Update date for selected circles + targets.forEach(function (t) { + main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + d.value = t.values[d.index].value; + }); + }); + // MEMO: can not keep same color... + //mainLineUpdate.exit().remove(); + + //-- Pie --// + mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) + .data($$.pie(targets)) + .attr("class", function (d) { return $$.classChartArc(d); }); + mainPieEnter = mainPieUpdate.enter().append("g") + .attr("class", function (d) { return $$.classChartArc(d); }); + mainPieEnter.append('g') + .attr('class', function (d) { return $$.classArcs(d); }); + mainPieEnter.append("text") + .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") + .style("opacity", 0) + .style("text-anchor", "middle") + .style("pointer-events", "none"); + // MEMO: can not keep same color..., but not bad to update color in redraw + //mainPieUpdate.exit().remove(); + + /*-- Context --*/ + + if ($$.__subchart_show) { + + contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + .data(targets) + .attr('class', $$.classChartBar); + contextBarEnter = contextBarUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', $$.classChartBar); + // Bars for each data + contextBarEnter.append('g') + .attr("class", $$.classBars); + + //-- Line --// + contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + .data(targets) + .attr('class', $$.classChartLine); + contextLineEnter = contextLineUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', $$.classChartLine); + // Lines for each data + contextLineEnter.append("g") + .attr("class", $$.classLines); + // Area + contextLineEnter.append("g") + .attr("class", $$.classAreas); } - function getEventRectWidth() { - var target = getMaxDataCountTarget(c3.data.targets), - firstData, lastData, base, maxDataCount, ratio, w; - if (!target) { - return 0; - } - firstData = target.values[0], lastData = target.values[target.values.length - 1]; - base = x(lastData.x) - x(firstData.x); - if (base === 0) { - return __axis_rotated ? height : width; - } - maxDataCount = getMaxDataCount(); - ratio = (hasBarType(c3.data.targets) ? (maxDataCount - (isCategorized ? 0.25 : 1)) / maxDataCount : 1); - w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; - return w < 1 ? 1 : w; - } - function updateLegendStep(step) { - legendStep = step; - } - function updateLegendItemWidth(w) { - legendItemWidth = w; - } - function updateLegendItemHeight(h) { - legendItemHeight = h; - } - function getLegendWidth() { - return __legend_show ? isLegendRight || isLegendInset ? legendItemWidth * (legendStep + 1) : currentWidth : 0; - } - function getLegendHeight() { - var h = 0; - if (__legend_show) { - if (isLegendRight) { - h = currentHeight; - } else if (isLegendInset) { - h = __legend_inset_step ? Math.max(20, legendItemHeight) * (__legend_inset_step + 1) : height; - } else { - h = Math.max(20, legendItemHeight) * (legendStep + 1); + + /*-- Show --*/ + + // Fade-in each chart + $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) + .transition().duration($$.__transition_duration) + .style("opacity", 1); + }; + + c3.fn.$$.redraw = function (options, transitions) { + var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS, d3 = $$.d3; + var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; + var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var rectX, rectW; + var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; + var hideAxis = $$.hasArcType($$.data.targets); + var drawArea, drawAreaOnSub, drawBar, drawBarOnSub, drawLine, drawLineOnSub, xForText, yForText; + var duration, durationForExit, durationForAxis, waitForDraw; + var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; + + xgrid = xgridLines = mainCircle = mainText = $$.getEmptySelection(); + + 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); + withLegend = $$.getOption(options, "withLegend", false); + withTransitionForExit = $$.getOption(options, "withTransitionForExit", withTransition); + withTransitionForAxis = $$.getOption(options, "withTransitionForAxis", withTransition); + + duration = withTransition ? $$.__transition_duration : 0; + durationForExit = withTransitionForExit ? duration : 0; + durationForAxis = withTransitionForAxis ? duration : 0; + + transitions = transitions || $$.generateAxisTransitions(durationForAxis); + + // update legend and transform each g + if (withLegend && $$.__legend_show) { + $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); + } + + // 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); + // update axis tick values according to options + if (!$$.__axis_x_tick_values && ($$.__axis_x_tick_fit || $$.__axis_x_tick_count)) { + tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), $$.__axis_x_tick_count); + $$.xAxis.tickValues(tickValues); + $$.subXAxis.tickValues(tickValues); + } + } else { + $$.xAxis.tickValues([]); + $$.subXAxis.tickValues([]); + } + + $$.y.domain($$.getYDomain(targetsToShow, 'y')); + $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); + + // axes + $$.axes.x.style("opacity", hideAxis ? 0 : 1); + $$.axes.y.style("opacity", hideAxis ? 0 : 1); + $$.axes.y2.style("opacity", hideAxis ? 0 : 1); + $$.axes.subx.style("opacity", hideAxis ? 0 : 1); + transitions.axisX.call($$.xAxis); + transitions.axisY.call($$.yAxis); + transitions.axisY2.call($$.y2Axis); + transitions.axisSubX.call($$.subXAxis); + + // Update axis label + $$.updateAxisLabels(withTransition); + + // show/hide if manual culling needed + if (withUpdateXDomain && targetsToShow.length) { + if ($$.__axis_x_tick_culling && tickValues) { + for (i = 1; i < tickValues.length; i++) { + if (tickValues.length / i < $$.__axis_x_tick_culling_max) { + intervalForCulling = i; + break; + } } - } - return h; - } - - //-- Scales --// - - function updateScales() { - var xAxisTickFormat, xAxisTickValues, forInit = !x; - // update edges - xMin = __axis_rotated ? 1 : 0; - xMax = __axis_rotated ? height : width; - yMin = __axis_rotated ? 0 : height; - yMax = __axis_rotated ? width : 1; - subXMin = xMin; - subXMax = xMax; - subYMin = __axis_rotated ? 0 : height2; - subYMax = __axis_rotated ? width2 : 1; - // update scales - x = getX(xMin, xMax, forInit ? undefined : x.orgDomain(), function () { return xAxis.tickOffset(); }); - y = getY(yMin, yMax, forInit ? undefined : y.domain()); - y2 = getY(yMin, yMax, forInit ? undefined : y2.domain()); - subX = getX(xMin, xMax, orgXDomain, function (d) { return d % 1 ? 0 : subXAxis.tickOffset(); }); - subY = getY(subYMin, subYMax, forInit ? undefined : subY.domain()); - subY2 = getY(subYMin, subYMax, forInit ? undefined : subY2.domain()); - // update axes - xAxisTickFormat = getXAxisTickFormat(); - xAxisTickValues = __axis_x_tick_values ? __axis_x_tick_values : (forInit ? undefined : xAxis.tickValues()); - xAxis = getXAxis(x, xOrient, xAxisTickFormat, xAxisTickValues); - subXAxis = getXAxis(subX, subXOrient, xAxisTickFormat, xAxisTickValues); - yAxis = getYAxis(y, yOrient, __axis_y_tick_format, __axis_y_ticks); - y2Axis = getYAxis(y2, y2Orient, __axis_y2_tick_format, __axis_y2_ticks); - // Set initialized scales to brush and zoom - if (!forInit) { - brush.scale(subX); - if (__zoom_enabled) { zoom.scale(x); } - } - // update for arc - updateArc(); - } - function updateArc() { - svgArc = getSvgArc(); - svgArcExpanded = getSvgArcExpanded(); - svgArcExpandedSub = getSvgArcExpanded(0.98); - } - function getScale(min, max, forTimeseries) { - return (forTimeseries ? d3.time.scale() : d3.scale.linear()).range([min, max]); - } - function getX(min, max, domain, offset) { - var scale = getScale(min, max, isTimeSeries), - _scale = domain ? scale.domain(domain) : scale, key; - // Define customized scale if categorized axis - if (isCategorized) { - offset = offset || function () { return 0; }; - scale = function (d, raw) { - var v = _scale(d) + offset(d); - return raw ? v : Math.ceil(v); - }; - } else { - scale = function (d, raw) { - var v = _scale(d); - return raw ? v : Math.ceil(v); - }; - } - // define functions - for (key in _scale) { - scale[key] = _scale[key]; - } - scale.orgDomain = function () { - return _scale.domain(); - }; - // define custom domain() for categorized axis - if (isCategorized) { - scale.domain = function (domain) { - if (!arguments.length) { - domain = this.orgDomain(); - return [domain[0], domain[1] + 1]; + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { + var index = tickValues.indexOf(e); + if (index >= 0) { + d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); } - _scale.domain(domain); - return scale; - }; + }); + } else { + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); } - return scale; } - function getY(min, max, domain) { - var scale = getScale(min, max); - if (domain) { scale.domain(domain); } - return scale; - } - function getYScale(id) { - return getAxisId(id) === 'y2' ? y2 : y; - } - function getSubYScale(id) { - return getAxisId(id) === 'y2' ? subY2 : subY; + + // rotate tick text if needed + if (!$$.__axis_rotated && $$.__axis_x_tick_rotate) { + $$.rotateTickText($$.axes.x, transitions.axisX, $$.__axis_x_tick_rotate); } - //-- Axes --// + // setup drawer - MEMO: these must be called after axis updated + drawArea = $$.generateDrawArea(areaIndices, false); + drawBar = $$.generateDrawBar(barIndices); + drawLine = $$.generateDrawLine(lineIndices, false); + xForText = $$.generateXYForText(barIndices, true); + yForText = $$.generateXYForText(barIndices, false); - function getXAxis(scale, orient, tickFormat, tickValues) { - var axis = c3_axis(d3, isCategorized).scale(scale).orient(orient); + // Update sub domain + $$.subY.domain($$.y.domain()); + $$.subY2.domain($$.y2.domain()); - // Set tick - axis.tickFormat(tickFormat).tickValues(tickValues); - if (isCategorized) { - axis.tickCentered(__axis_x_tick_centered); - if (isEmpty(__axis_x_tick_culling)) { - __axis_x_tick_culling = false; - } - } else { - // TODO: move this to c3_axis - axis.tickOffset = function () { - var edgeX = getEdgeX(c3.data.targets), diff = x(edgeX[1]) - x(edgeX[0]), - base = diff ? diff : (__axis_rotated ? height : width); - return (base / getMaxDataCount()) / 2; - }; - } + // tooltip + $$.tooltip.style("display", "none"); - return axis; - } - function getYAxis(scale, orient, tickFormat, ticks) { - return c3_axis(d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); - } - function getAxisId(id) { - return id in __data_axes ? __data_axes[id] : 'y'; - } - function getXAxisTickFormat() { - var format = isTimeSeries ? defaultAxisTimeFormat : isCategorized ? categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; - if (__axis_x_tick_format) { - if (typeof __axis_x_tick_format === 'function') { - format = __axis_x_tick_format; - } else if (isTimeSeries) { - format = function (date) { - return date ? axisTimeFormat(__axis_x_tick_format)(date) : ""; - }; - } - } - return format; - } - function getAxisLabelOptionByAxisId(axisId) { - var option; - if (axisId === 'y') { - option = __axis_y_label; - } else if (axisId === 'y2') { - option = __axis_y2_label; - } else if (axisId === 'x') { - option = __axis_x_label; - } - return option; - } - function getAxisLabelText(axisId) { - var option = getAxisLabelOptionByAxisId(axisId); - return typeof option === 'string' ? option : option ? option.text : null; - } - function setAxisLabelText(axisId, text) { - var option = getAxisLabelOptionByAxisId(axisId); - if (typeof option === 'string') { - if (axisId === 'y') { - __axis_y_label = text; - } else if (axisId === 'y2') { - __axis_y2_label = text; - } else if (axisId === 'x') { - __axis_x_label = text; - } - } else if (option) { - option.text = text; - } - } - function xForRotatedTickText(r) { - return 10 * Math.sin(Math.PI * (r / 180)); - } - function yForRotatedTickText(r) { - return 11.5 - 2.5 * (r / 15); - } - function rotateTickText(axis, transition, rotate) { - axis.selectAll('.tick text') - .style("text-anchor", "start"); - transition.selectAll('.tick text') - .attr("y", yForRotatedTickText(rotate)) - .attr("x", xForRotatedTickText(rotate)) - .attr("transform", "rotate(" + rotate + ")"); - } - function getAxisLabelPosition(axisId, defaultPosition) { - var option = getAxisLabelOptionByAxisId(axisId), - position = (option && 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 - }; - } - function getXAxisLabelPosition() { - return getAxisLabelPosition('x', __axis_rotated ? 'inner-top' : 'inner-right'); - } - function getYAxisLabelPosition() { - return getAxisLabelPosition('y', __axis_rotated ? 'inner-right' : 'inner-top'); - } - function getY2AxisLabelPosition() { - return getAxisLabelPosition('y2', __axis_rotated ? 'inner-right' : 'inner-top'); - } - function getAxisLabelPositionById(id) { - return id === 'y2' ? getY2AxisLabelPosition() : id === 'y' ? getYAxisLabelPosition() : getXAxisLabelPosition(); - } - function textForXAxisLabel() { - return getAxisLabelText('x'); - } - function textForYAxisLabel() { - return getAxisLabelText('y'); - } - function textForY2AxisLabel() { - return getAxisLabelText('y2'); - } - function xForAxisLabel(forHorizontal, position) { - if (forHorizontal) { - return position.isLeft ? 0 : position.isCenter ? width / 2 : width; - } else { - return position.isBottom ? -height : position.isMiddle ? -height / 2 : 0; - } - } - 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"; - } - } - function textAnchorForAxisLabel(forHorizontal, position) { - if (forHorizontal) { - return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; - } else { - return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; - } - } - function xForXAxisLabel() { - return xForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); - } - function xForYAxisLabel() { - return xForAxisLabel(__axis_rotated, getYAxisLabelPosition()); - } - function xForY2AxisLabel() { - return xForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); - } - function dxForXAxisLabel() { - return dxForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); - } - function dxForYAxisLabel() { - return dxForAxisLabel(__axis_rotated, getYAxisLabelPosition()); - } - function dxForY2AxisLabel() { - return dxForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); - } - function dyForXAxisLabel() { - var position = getXAxisLabelPosition(); - if (__axis_rotated) { - return position.isInner ? "1.2em" : -25 - getMaxTickWidth('x'); - } else { - return position.isInner ? "-0.5em" : __axis_x_height ? __axis_x_height - 10 : "3em"; - } - } - function dyForYAxisLabel() { - var position = getYAxisLabelPosition(); - if (__axis_rotated) { - return position.isInner ? "-0.5em" : "3em"; - } else { - return position.isInner ? "1.2em" : -20 - getMaxTickWidth('y'); - } - } - function dyForY2AxisLabel() { - var position = getY2AxisLabelPosition(); - if (__axis_rotated) { - return position.isInner ? "1.2em" : "-2.2em"; - } else { - return position.isInner ? "-0.5em" : 30 + getMaxTickWidth('y2'); - } - } - function textAnchorForXAxisLabel() { - return textAnchorForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); - } - function textAnchorForYAxisLabel() { - return textAnchorForAxisLabel(__axis_rotated, getYAxisLabelPosition()); - } - function textAnchorForY2AxisLabel() { - return textAnchorForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); - } - function getMaxTickWidth(id) { - var maxWidth = 0, targetsToShow, scale, axis; - if (svg) { - targetsToShow = filterTargetsToShow(c3.data.targets); - if (id === 'y') { - scale = y.copy().domain(getYDomain(targetsToShow, 'y')); - axis = getYAxis(scale, yOrient, __axis_y_tick_format, __axis_y_ticks); - } else if (id === 'y2') { - scale = y2.copy().domain(getYDomain(targetsToShow, 'y2')); - axis = getYAxis(scale, y2Orient, __axis_y2_tick_format, __axis_y2_ticks); - } else { - scale = x.copy().domain(getXDomain(targetsToShow)); - axis = getXAxis(scale, xOrient, getXAxisTickFormat(), __axis_x_tick_values ? __axis_x_tick_values : xAxis.tickValues()); - } - main.append("g").call(axis).each(function () { - d3.select(this).selectAll('text').each(function () { - var box = this.getBoundingClientRect(); - if (maxWidth < box.width) { maxWidth = box.width; } - }); - }).remove(); - } - currentMaxTickWidth = maxWidth <= 0 ? currentMaxTickWidth : maxWidth; - return currentMaxTickWidth; - } - function updateAxisLabels(withTransition) { - 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", xForXAxisLabel) - .attr("dx", dxForXAxisLabel) - .attr("dy", dyForXAxisLabel) - .text(textForXAxisLabel); - (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", xForYAxisLabel) - .attr("dx", dxForYAxisLabel) - .attr("dy", dyForYAxisLabel) - .attr("dy", dyForYAxisLabel) - .text(textForYAxisLabel); - (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", xForY2AxisLabel) - .attr("dx", dxForY2AxisLabel) - .attr("dy", dyForY2AxisLabel) - .text(textForY2AxisLabel); - } - - //-- Arc --// - - pie = d3.layout.pie().value(function (d) { - return d.values.reduce(function (a, b) { return a + b.value; }, 0); - }); - if (!__pie_sort || !__donut_sort) { // TODO: this needs to be called by each type - pie.sort(null); - } + // xgrid focus + $$.updateXgridFocus(); - function descByStartAngle(a, b) { - return a.startAngle - b.startAngle; - } + // Data empty label positioning and text. + main.select("text." + CLASS.text + '.' + CLASS.empty) + .attr("x", $$.width / 2) + .attr("y", $$.height / 2) + .text($$.__data_empty_label_text) + .transition() + .style('opacity', targetsToShow.length ? 0 : 1); - function updateAngle(d) { - var found = false, index = 0; - pie(filterTargetsToShow(c3.data.targets)).sort(descByStartAngle).forEach(function (t) { - if (! found && t.data.id === d.data.id) { - found = true; - d = t; - d.index = index; + // grid + main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + if ($$.__grid_x_show) { + xgridAttr = $$.__axis_rotated ? { + 'x1': 0, + 'x2': $$.width, + 'y1': function (d) { return $$.x(d) - tickOffset; }, + 'y2': function (d) { return $$.x(d) - tickOffset; } + } : { + 'x1': function (d) { return $$.x(d) + tickOffset; }, + 'x2': function (d) { return $$.x(d) + tickOffset; }, + 'y1': 0, + 'y2': $$.height + }; + // this is used to flow + flushXGrid = function (withoutUpdate) { + xgridData = $$.generateGridData($$.__grid_x_type, $$.x); + tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; + xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) + .data(xgridData); + xgrid.enter().append('line').attr("class", CLASS.xgrid); + if (!withoutUpdate) { + xgrid.attr(xgridAttr) + .style("opacity", function () { return +d3.select(this).attr($$.__axis_rotated ? 'y1' : 'x1') === ($$.__axis_rotated ? $$.height : 0) ? 0 : 1; }); } - index++; - }); - if (isNaN(d.endAngle)) { - d.endAngle = d.startAngle; - } - if (isGaugeType(d.data)) { - var gMin = __gauge_min, gMax = __gauge_max, - gF = Math.abs(gMin) + gMax, - aTic = (Math.PI) / gF; - d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); - d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value)); - } - return found ? d : null; - } - - function getSvgArc() { - var arc = d3.svg.arc().outerRadius(radius).innerRadius(innerRadius), - newArc = function (d, withoutUpdate) { - var updated; - if (withoutUpdate) { return arc(d); } // for interpolate - updated = updateAngle(d); - return updated ? arc(updated) : "M 0 0"; - }; - // TODO: extends all function - newArc.centroid = arc.centroid; - return newArc; - } - function getSvgArcExpanded(rate) { - var arc = d3.svg.arc().outerRadius(radiusExpanded * (rate ? rate : 1)).innerRadius(innerRadius); - return function (d) { - var updated = updateAngle(d); - return updated ? arc(updated) : "M 0 0"; + xgrid.exit().remove(); }; - } - function getArc(d, withoutUpdate, force) { - return force || isArcType(d.data) ? svgArc(d, withoutUpdate) : "M 0 0"; - } - function transformForArcLabel(d) { - var updated = updateAngle(d), c, x, y, h, ratio, translate = ""; - if (updated && !hasGaugeType(c3.data.targets)) { - c = svgArc.centroid(updated); - x = isNaN(c[0]) ? 0 : c[0]; - y = isNaN(c[1]) ? 0 : c[1]; - h = Math.sqrt(x * x + y * y); - // TODO: ratio should be an option? - ratio = radius && h ? (36 / radius > 0.375 ? 1.175 - 36 / radius : 0.8) * radius / h : 0; - translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")"; - } - return translate; - } - function getArcRatio(d) { - var whole = hasGaugeType(c3.data.targets) ? Math.PI : (Math.PI * 2); - return d ? (d.endAngle - d.startAngle) / whole : null; - } - function convertToArcData(d) { - return addName({ - id: d.data.id, - value: d.value, - ratio: getArcRatio(d), - index: d.index, - }); - } - function textForArcLabel(d) { - var updated, value, ratio, format; - if (! shouldShowArcLabel()) { return ""; } - updated = updateAngle(d); - value = updated ? updated.value : null; - ratio = getArcRatio(updated); - if (! hasGaugeType(c3.data.targets) && ! meetsArcLabelThreshold(ratio)) { return ""; } - format = getArcLabelFormat(); - return format ? format(value, ratio) : defaultArcValueFormat(value, ratio); - } - function expandArc(id, withoutFadeOut) { - var target = svg.selectAll('.' + CLASS.chartArc + selectorTarget(id)), - noneTargets = svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); - - if (shouldExpand(id)) { - target.selectAll('path') - .transition().duration(50) - .attr("d", svgArcExpanded) - .transition().duration(100) - .attr("d", svgArcExpandedSub) - .each(function (d) { - if (isDonutType(d.data)) { - // callback here - } - }); - } - - if (!withoutFadeOut) { - noneTargets.style("opacity", 0.3); - } - } - function unexpandArc(id) { - var target = svg.selectAll('.' + CLASS.chartArc + selectorTarget(id)); - target.selectAll('path.' + CLASS.arc) - .transition().duration(50) - .attr("d", svgArc); - svg.selectAll('.' + CLASS.arc) + flushXGrid(); + } + xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) + .data($$.__grid_x_lines); + // enter + xgridLine = xgridLines.enter().append('g') + .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); + xgridLine.append('line') + .style("opacity", 0); + xgridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") + .attr('dx', $$.__axis_rotated ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // udpate + // done in d3.transition() of the end of this function + // exit + xgridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + // Y-Grid + if (withY && $$.__grid_y_show) { + ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) + .data($$.y.ticks($$.__grid_y_ticks)); + ygrid.enter().append('line') + .attr('class', CLASS.ygrid); + ygrid.attr("x1", $$.__axis_rotated ? $$.y : 0) + .attr("x2", $$.__axis_rotated ? $$.y : $$.width) + .attr("y1", $$.__axis_rotated ? 0 : $$.y) + .attr("y2", $$.__axis_rotated ? $$.height : $$.y); + ygrid.exit().remove(); + $$.smoothLines(ygrid, 'grid'); + } + if (withY) { + ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) + .data($$.__grid_y_lines); + // enter + ygridLine = ygridLines.enter().append('g') + .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); + ygridLine.append('line') + .style("opacity", 0); + ygridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", $$.__axis_rotated ? "rotate(-90)" : "") + .attr('dx', $$.__axis_rotated ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // update + var yv = function (d) { return $$.yv.call($$, d); }; + ygridLines.select('line') + .transition().duration(duration) + .attr("x1", $$.__axis_rotated ? yv : 0) + .attr("x2", $$.__axis_rotated ? yv : $$.width) + .attr("y1", $$.__axis_rotated ? 0 : yv) + .attr("y2", $$.__axis_rotated ? $$.height : yv) .style("opacity", 1); + ygridLines.select('text') + .transition().duration(duration) + .attr("x", $$.__axis_rotated ? 0 : $$.width) + .attr("y", yv) + .text(function (d) { return d.text; }) + .style("opacity", 1); + // exit + ygridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); } - function shouldShowArcLabel() { - var shouldShow = true; - if (hasDonutType(c3.data.targets)) { - shouldShow = __donut_label_show; - } else if (hasPieType(c3.data.targets)) { - shouldShow = __pie_label_show; - } - // when gauge, always true - return shouldShow; - } - function meetsArcLabelThreshold(ratio) { - var threshold = hasDonutType(c3.data.targets) ? __donut_label_threshold : __pie_label_threshold; - return ratio >= threshold; - } - function getArcLabelFormat() { - var format = __pie_label_format; - if (hasGaugeType(c3.data.targets)) { - format = __gauge_label_format; - } else if (hasDonutType(c3.data.targets)) { - format = __donut_label_format; - } - return format; - } - function getArcTitle() { - return hasDonutType(c3.data.targets) ? __donut_title : ""; - } - - //-- Domain --// - function getAxisPadding(padding, key, defaultValue, all) { - var ratio = padding.unit === 'ratio' ? all : 1; - return isValue(padding[key]) ? padding[key] * ratio : defaultValue; + // rect for regions + mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) + .data($$.__regions); + mainRegion.enter().append('g') + .attr('class', function (d) { return $$.classRegion(d); }) + .append('rect') + .style("fill-opacity", 0); + mainRegion.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + + // bars + mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(function (d) { return $$.barData(d); }); + mainBar.enter().append('path') + .attr("class", function (d) { return $$.classBar(d); }) + .style("stroke", function (d) { return $$.color(d.id); }) + .style("fill", function (d) { return $$.color(d.id); }); + mainBar + .style("opacity", function (d) { return $$.initialOpacity(d); }); + mainBar.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + // lines, areas and cricles + mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(function (d) { return $$.lineData(d); }); + mainLine.enter().append('path') + .attr('class', function (d) { return $$.classLine(d); }) + .style("stroke", $$.color); + mainLine + .style("opacity", function (d) { return $$.initialOpacity(d); }) + .attr('transform', null); + mainLine.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(function (d) { return $$.lineData(d); }); + mainArea.enter().append('path') + .attr("class", function (d) { return $$.classArea(d); }) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + mainArea + .style("opacity", $$.orgAreaOpacity); + mainArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + if ($$.__point_show) { + mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) + .data(function (d) { return $$.lineOrScatterData(d); }); + mainCircle.enter().append("circle") + .attr("class", function (d) { return $$.classCircle(d); }) + .attr("r", function (d) { return $$.pointR(d); }) + .style("fill", $$.color); + mainCircle + .style("opacity", function (d) { return $$.initialOpacity(d); }); + mainCircle.exit().remove(); + } + + if ($$.hasDataLabel()) { + mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) + .data($$.barOrLineData); + mainText.enter().append('text') + .attr("class", function (d) { return $$.classText(d); }) + .attr('text-anchor', function (d) { return $$.__axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .style("stroke", 'none') + .style("fill", function (d) { return $$.color(d); }) + .style("fill-opacity", 0); + mainText + .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); + mainText.exit() + .transition().duration(durationForExit) + .style('fill-opacity', 0) + .remove(); } - function getYDomainMin(targets) { - var ids = mapToIds(targets), ys = getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; - if (__data_groups.length > 0) { - hasNegativeValue = hasNegativeValueInTargets(targets); - for (j = 0; j < __data_groups.length; j++) { - // Determine baseId - idsInGroup = __data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); - if (idsInGroup.length === 0) { continue; } - baseId = idsInGroup[0]; - // Consider negative values - if (hasNegativeValue && ys[baseId]) { - ys[baseId].forEach(function (v, i) { - ys[baseId][i] = v < 0 ? v : 0; - }); - } - // Compute min - for (k = 1; k < idsInGroup.length; k++) { - id = idsInGroup[k]; - if (! ys[id]) { continue; } - ys[id].forEach(function (v, i) { - if (getAxisId(id) === getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { - ys[baseId][i] += +v; - } - }); - } + // arc + mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) + .data(function (d) { return $$.arcData(d); }); + mainArc.enter().append('path') + .attr("class", function (d) { return $$.classArc(d); }) + .style("fill", function (d) { return $$.color(d.data); }) + .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }) + .style("opacity", 0) + .each(function (d) { + if ($$.isGaugeType(d.data)) { + d.startAngle = d.endAngle = -1 * (Math.PI / 2); } - } - return d3.min(Object.keys(ys).map(function (key) { return d3.min(ys[key]); })); - } - function getYDomainMax(targets) { - var ids = mapToIds(targets), ys = getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; - if (__data_groups.length > 0) { - hasPositiveValue = hasPositiveValueInTargets(targets); - for (j = 0; j < __data_groups.length; j++) { - // Determine baseId - idsInGroup = __data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); - if (idsInGroup.length === 0) { continue; } - baseId = idsInGroup[0]; - // Consider positive values - if (hasPositiveValue && ys[baseId]) { - ys[baseId].forEach(function (v, i) { - ys[baseId][i] = v > 0 ? v : 0; - }); - } - // Compute max - for (k = 1; k < idsInGroup.length; k++) { - id = idsInGroup[k]; - if (! ys[id]) { continue; } - ys[id].forEach(function (v, i) { - if (getAxisId(id) === getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { - ys[baseId][i] += +v; - } - }); - } + this._current = d; + }) + .on('mouseover', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; } - } - return d3.max(Object.keys(ys).map(function (key) { return d3.max(ys[key]); })); - } - function getYDomain(targets, axisId) { - var yTargets = targets.filter(function (d) { return getAxisId(d.id) === axisId; }), - yMin = axisId === 'y2' ? __axis_y2_min : __axis_y_min, - yMax = axisId === 'y2' ? __axis_y2_max : __axis_y_max, - yDomainMin = isValue(yMin) ? yMin : getYDomainMin(yTargets), - yDomainMax = isValue(yMax) ? yMax : getYDomainMax(yTargets), - domainLength, padding, padding_top, padding_bottom, - center = axisId === 'y2' ? __axis_y2_center : __axis_y_center, - yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = (hasBarType(yTargets) && __bar_zerobased) || (hasAreaType(yTargets) && __area_zerobased), - showHorizontalDataLabel = hasDataLabel() && __axis_rotated, - showVerticalDataLabel = hasDataLabel() && !__axis_rotated; - if (yTargets.length === 0) { // use current domain if target of axisId is none - return axisId === 'y2' ? y2.domain() : y.domain(); - } - if (yDomainMin === yDomainMax) { - yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; - } - isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; - isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); + // transitions + $$.expandArc(updated.data.id); + $$.toggleFocusLegend(updated.data.id, true); + $$.__data_onmouseover.call(c3, arcData, this); + }) + .on('mousemove', function (d) { + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated), + selectedData = [arcData]; + $$.showTooltip(selectedData, d3.mouse(this)); + }) + .on('mouseout', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; + } + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); + // transitions + $$.unexpandArc(updated.data.id); + $$.revertLegend(); + $$.hideTooltip(); + $$.__data_onmouseout.call(c3, arcData, this); + }) + .on('click', function (d, i) { + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated); + $$.toggleShape(this, arcData, i); // onclick called in toogleShape() + }); + mainArc + .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .style("opacity", function (d) { return d === this._current ? 0 : 1; }) + .each(function () { $$.transiting = true; }) + .transition().duration(duration) + .attrTween("d", function (d) { + var updated = $$.updateAngle(d), interpolate; + if (! updated) { + return function () { return "M 0 0"; }; + } +/* + if (this._current === d) { + this._current = { + startAngle: Math.PI*2, + endAngle: Math.PI*2, + }; + } +*/ + if (isNaN(this._current.endAngle)) { + this._current.endAngle = this._current.startAngle; + } + interpolate = d3.interpolate(this._current, updated); + this._current = interpolate(0); + return function (t) { return $$.getArc(interpolate(t), true); }; + }) + .attr("transform", withTransform ? "scale(1)" : "") + .style("fill", function (d) { + return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); + }) // Where gauge reading color would receive customization. + .style("opacity", 1) + .call($$.endall, function () { + $$.transiting = false; + }); + mainArc.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + main.selectAll('.' + CLASS.chartArc).select('text') + .style("opacity", 0) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .text(function (d) { return $$.textForArcLabel(d); }) + .attr("transform", function (d) { return $$.transformForArcLabel(d); }) + .transition().duration(duration) + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); + main.select('.' + CLASS.chartArcsTitle) + .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); - // Bar/Area chart should be 0-based if all positive|negative - if (isZeroBased) { - if (isAllPositive) { yDomainMin = 0; } - if (isAllNegative) { yDomainMax = 0; } + // subchart + if ($$.__subchart_show) { + // reflect main chart to extent on subchart if zoomed + if (d3.event && d3.event.type === 'zoom') { + $$.brush.extent($$.x.orgDomain()).update(); } + // update subchart elements if needed + if (withSubchart) { - domainLength = Math.abs(yDomainMax - yDomainMin); - padding = padding_top = padding_bottom = domainLength * 0.1; + // rotate tick text if needed + if (!$$.__axis_rotated && $$.__axis_x_tick_rotate) { + $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.__axis_x_tick_rotate); + } - if (center) { - yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); - yDomainMax = yDomainAbs - center; - yDomainMin = center - yDomainAbs; - } - // add padding for data label - if (showHorizontalDataLabel) { - lengths = getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); - diff = diffDomain(y.range()); - ratio = [lengths[0] / diff, lengths[1] / diff]; - padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); - padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); - } else if (showVerticalDataLabel) { - lengths = getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); - padding_top += lengths[1]; - padding_bottom += lengths[0]; - } - if (axisId === 'y' && __axis_y_padding) { - padding_top = getAxisPadding(__axis_y_padding, 'top', padding, domainLength); - padding_bottom = getAxisPadding(__axis_y_padding, 'bottom', padding, domainLength); - } - if (axisId === 'y2' && __axis_y2_padding) { - padding_top = getAxisPadding(__axis_y2_padding, 'top', padding, domainLength); - padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength); - } - // Bar/Area chart should be 0-based if all positive|negative - if (isZeroBased) { - if (isAllPositive) { padding_bottom = yDomainMin; } - if (isAllNegative) { padding_top = -yDomainMax; } - } - return [yDomainMin - padding_bottom, yDomainMax + padding_top]; - } - function getXDomainMin(targets) { - return __axis_x_min ? (isTimeSeries ? parseDate(__axis_x_min) : __axis_x_min) : d3.min(targets, function (t) { return d3.min(t.values, function (v) { return v.x; }); }); - } - function getXDomainMax(targets) { - return __axis_x_max ? (isTimeSeries ? parseDate(__axis_x_max) : __axis_x_max) : d3.max(targets, function (t) { return d3.max(t.values, function (v) { return v.x; }); }); - } - function getXDomainPadding(targets) { - var edgeX = getEdgeX(targets), diff = edgeX[1] - edgeX[0], - maxDataCount, padding, paddingLeft, paddingRight; - if (isCategorized) { - padding = 0; - } else if (hasBarType(targets)) { - maxDataCount = getMaxDataCount(); - padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; - } else { - padding = diff * 0.01; - } - if (typeof __axis_x_padding === 'object' && notEmpty(__axis_x_padding)) { - paddingLeft = isValue(__axis_x_padding.left) ? __axis_x_padding.left : padding; - paddingRight = isValue(__axis_x_padding.right) ? __axis_x_padding.right : padding; - } else if (typeof __axis_x_padding === 'number') { - paddingLeft = paddingRight = __axis_x_padding; - } else { - paddingLeft = paddingRight = padding; - } - return {left: paddingLeft, right: paddingRight}; - } - function getXDomain(targets) { - var xDomain = [getXDomainMin(targets), getXDomainMax(targets)], - firstX = xDomain[0], lastX = xDomain[1], - padding = getXDomainPadding(targets), - min = 0, max = 0; - // show center of x domain if min and max are the same - if ((firstX - lastX) === 0 && !isCategorized) { - firstX = isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; - lastX = isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; - } - if (firstX || firstX === 0) { - min = isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; - } - if (lastX || lastX === 0) { - max = isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; - } - return [min, max]; - } - function updateXDomain(targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { - if (withUpdateOrgXDomain) { - x.domain(domain ? domain : d3.extent(getXDomain(targets))); - orgXDomain = x.domain(); - if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); } - subX.domain(x.domain()); - brush.scale(subX); - } - if (withUpdateXDomain) { - x.domain(domain ? domain : brush.empty() ? orgXDomain : brush.extent()); - if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); } + // extent rect + if (!$$.brush.empty()) { + $$.brush.extent($$.x.orgDomain()).update(); + } + // setup drawer - MEMO: this must be called after axis updated + drawAreaOnSub = $$.generateDrawArea(areaIndices, true); + drawBarOnSub = $$.generateDrawBar(barIndices, true); + drawLineOnSub = $$.generateDrawLine(lineIndices, true); + // bars + contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data($$.barData); + contextBar.enter().append('path') + .attr("class", $$.classBar) + .style("stroke", 'none') + .style("fill", $$.color); + contextBar + .style("opacity", $$.initialOpacity) + .transition().duration(duration) + .attr('d', drawBarOnSub) + .style('opacity', 1); + contextBar.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // lines + contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data($$.lineData); + contextLine.enter().append('path') + .attr('class', function (d) { return $$.classLine(d); }) + .style('stroke', $$.color); + contextLine + .style("opacity", $$.initialOpacity) + .transition().duration(duration) + .attr("d", drawLineOnSub) + .style('opacity', 1); + contextLine.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // area + contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data($$.lineData); + contextArea.enter().append('path') + .attr("class", function (d) { return $$.classArea(d); }) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + contextArea + .style("opacity", 0) + .transition().duration(duration) + .attr("d", drawAreaOnSub) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity); + contextArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); } - return x.domain(); - } - function diffDomain(d) { - return d[1] - d[0]; } - //-- Cache --// + // circles for select + main.selectAll('.' + CLASS.selectedCircles) + .filter(function (d) { return $$.isBarType(d); }) + .selectAll('circle') + .remove(); - function hasCaches(ids) { - for (var i = 0; i < ids.length; i++) { - if (! (ids[i] in cache)) { return false; } - } - return true; - } - function addCache(id, target) { - cache[id] = cloneTarget(target); - } - function getCaches(ids) { - var targets = []; - for (var i = 0; i < ids.length; i++) { - if (ids[i] in cache) { targets.push(cloneTarget(cache[ids[i]])); } - } - return targets; - } + if ($$.__interaction_enabled) { + // rect for mouseover + eventRect = main.select('.' + CLASS.eventRects) + .style('cursor', $$.__zoom_enabled ? $$.__axis_rotated ? 'ns-resize' : 'ew-resize' : null); + if ($$.notEmpty($$.__data_xs) && !$$.isSingleX($$.__data_xs)) { - //-- Regions --// + if (!eventRect.classed(CLASS.eventRectsMultiple)) { + eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) + .selectAll('.' + CLASS.eventRect).remove(); + } - function regionX(d) { - var xPos, yScale = d.axis === 'y' ? y : y2; - if (d.axis === 'y' || d.axis === 'y2') { - xPos = __axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; - } else { - xPos = __axis_rotated ? 0 : ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0); - } - return xPos; - } - function regionY(d) { - var yPos, yScale = d.axis === 'y' ? y : y2; - if (d.axis === 'y' || d.axis === 'y2') { - yPos = __axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); - } else { - yPos = __axis_rotated ? ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0) : 0; - } - return yPos; - } - function regionWidth(d) { - var start = regionX(d), end, yScale = d.axis === 'y' ? y : y2; - if (d.axis === 'y' || d.axis === 'y2') { - end = __axis_rotated ? ('end' in d ? yScale(d.end) : width) : width; - } else { - end = __axis_rotated ? width : ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : width); - } - return end < start ? 0 : end - start; - } - function regionHeight(d) { - var start = regionY(d), end, yScale = d.axis === 'y' ? y : y2; - if (d.axis === 'y' || d.axis === 'y2') { - end = __axis_rotated ? height : ('start' in d ? yScale(d.start) : height); + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + .data([0]); + // enter : only one rect will be added + $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height); + // exit : not needed because always only one rect exists } else { - end = __axis_rotated ? ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : height) : height; - } - return end < start ? 0 : end - start; - } - function isRegionOnX(d) { - return !d.axis || d.axis === 'x'; - } - - //-- Data --// - function isX(key) { - return (__data_x && key === __data_x) || (notEmpty(__data_xs) && hasValue(__data_xs, key)); - } - function isNotX(key) { - return !isX(key); - } - function getXKey(id) { - return __data_x ? __data_x : notEmpty(__data_xs) ? __data_xs[id] : null; - } - function getXValuesOfXKey(key, targets) { - var xValues, ids = targets && notEmpty(targets) ? mapToIds(targets) : []; - ids.forEach(function (id) { - if (getXKey(id) === key) { - xValues = c3.data.xs[id]; + if (!eventRect.classed(CLASS.eventRectsSingle)) { + eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) + .selectAll('.' + CLASS.eventRect).remove(); } - }); - return xValues; - } - function getXValue(id, i) { - return id in c3.data.xs && c3.data.xs[id] && isValue(c3.data.xs[id][i]) ? c3.data.xs[id][i] : i; - } - function getOtherTargetXs() { - var idsForX = Object.keys(c3.data.xs); - return idsForX.length ? c3.data.xs[idsForX[0]] : null; - } - function getOtherTargetX(index) { - var xs = getOtherTargetXs(); - return xs && index < xs.length ? xs[index] : null; - } - function addXs(xs) { - Object.keys(xs).forEach(function (id) { - __data_xs[id] = xs[id]; - }); - } - function isSingleX(xs) { - return d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; - } - - function addName(data) { - var name; - if (data) { - name = __data_names[data.id]; - data.name = name ? name : data.id; - } - return data; - } - function getValueOnIndex(values, index) { - var valueOnIndex = values.filter(function (v) { return v.index === index; }); - return valueOnIndex.length ? valueOnIndex[0] : null; - } - - function updateTargetX(targets, x) { - targets.forEach(function (t) { - t.values.forEach(function (v, i) { - v.x = generateTargetX(x[i], t.id, i); - }); - c3.data.xs[t.id] = x; - }); - } - function updateTargetXs(targets, xs) { - targets.forEach(function (t) { - if (xs[t.id]) { - updateTargetX([t], xs[t.id]); - } - }); - } - function generateTargetX(rawX, id, index) { - var x; - if (isTimeSeries) { - x = rawX ? parseDate(rawX) : parseDate(getXValue(id, index)); - } - else if (isCustomX() && !isCategorized) { - x = isValue(rawX) ? +rawX : getXValue(id, index); - } - else { - x = index; - } - return x; - } - function convertUrlToData(url, mimeType, keys, done) { - var type = mimeType ? mimeType : 'csv'; - d3.xhr(url, function (error, data) { - var d; - if (type === 'json') { - d = convertJsonToData(JSON.parse(data.response), keys); + if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { + rectW = function (d) { + var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], + w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; + return w < 0 ? 0 : w; + }; + rectX = function (d) { + var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; + return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; + }; } else { - d = convertCsvToData(data.response); + rectW = $$.getEventRectWidth(); + rectX = function (d) { + return $$.x(d.x) - (rectW / 2); + }; } - done(d); - }); - } - function convertCsvToData(csv) { - var rows = d3.csv.parseRows(csv), d; - if (rows.length === 1) { - d = [{}]; - rows[0].forEach(function (id) { - d[0][id] = null; + // Set data + maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); + main.select('.' + CLASS.eventRects) + .datum(maxDataCountTarget ? maxDataCountTarget.values : []); + // Update rects + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + .data(function (d) { return d; }); + // enter + $$.generateEventRectsForSingleX(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('class', function (d) { return $$.classEvent(d); }) + .attr("x", $$.__axis_rotated ? 0 : rectX) + .attr("y", $$.__axis_rotated ? rectX : 0) + .attr("width", $$.__axis_rotated ? $$.width : rectW) + .attr("height", $$.__axis_rotated ? rectW : $$.height); + // exit + eventRectUpdate.exit().remove(); + } + } + + // transition should be derived from one transition + d3.transition().duration(duration).each(function () { + var transitions = [], + cx = $$.__axis_rotated ? $$.circleY : $$.circleX, + cy = $$.__axis_rotated ? $$.circleX : $$.circleY; + + transitions.push(mainBar.transition() + .attr('d', drawBar) + .style("fill", $$.color) + .style("opacity", 1)); + transitions.push(mainLine.transition() + .attr("d", drawLine) + .style("stroke", $$.color) + .style("opacity", 1)); + transitions.push(mainArea.transition() + .attr("d", drawArea) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity)); + transitions.push(mainCircle.transition() + .style('opacity', function (d) { return $$.opacityForCircle(d); }) + .style("fill", $$.color) + .attr("cx", function (d, i) { return cx.call($$, d, i); }) + .attr("cy", function (d, i) { return cy.call($$, d, i); })); + transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() + .attr("cx", function (d, i) { return cx.call($$, d, i); }) + .attr("cy", function (d, i) { return cy.call($$, d, i); })); + transitions.push(mainText.transition() + .attr('x', xForText) + .attr('y', yForText) + .style("fill", $$.color) + .style("fill-opacity", options.flow ? 0 : $$.opacityForText)); + transitions.push(mainRegion.selectAll('rect').transition() + .attr("x", $$.regionX) + .attr("y", $$.regionY) + .attr("width", $$.regionWidth) + .attr("height", $$.regionHeight) + .style("fill-opacity", function (d) { return $$.isValue(d.opacity) ? d.opacity : 0.1; })); + transitions.push(xgridLines.select('line').transition() + .attr("x1", $$.__axis_rotated ? 0 : $$.xv) + .attr("x2", $$.__axis_rotated ? $$.width : $$.xv) + .attr("y1", $$.__axis_rotated ? $$.xv : $$.margin.top) + .attr("y2", $$.__axis_rotated ? $$.xv : $$.height) + .style("opacity", 1)); + transitions.push(xgridLines.select('text').transition() + .attr("x", $$.__axis_rotated ? $$.width : 0) + .attr("y", $$.xv) + .text(function (d) { return d.text; }) + .style("opacity", 1)); + // Wait for end of transitions if called from flow API + if (options.flow) { + waitForDraw = $$.generateWait(); + transitions.forEach(function (t) { + waitForDraw.add(t); }); - } else { - d = d3.csv.parse(csv); } - return d; - } - function convertJsonToData(json, keys) { - var new_rows = [], targetKeys, data; - if (keys) { // when keys specified, json would be an array that includes objects - targetKeys = keys.value; - if (keys.x) { - targetKeys.push(keys.x); - __data_x = keys.x; + }) + .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow + var translateX, scaleX = 1, transform, + flowIndex = options.flow.index, + flowLength = options.flow.length, + flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), + orgDomain = $$.x.domain(), domain, + durationForFlow = options.flow.duration || duration, + done = options.flow.done || function () {}, + wait = $$.generateWait(); + + // remove head data after rendered + $$.data.targets.forEach(function (d) { + d.values.splice(0, flowLength); + }); + + // update x domain to generate axis elements for flow + domain = $$.updateXDomain(targetsToShow, true, true); + // update elements related to x scale + if (flushXGrid) { flushXGrid(true); } + + // generate transform to flow + if (!options.flow.orgDataCount) { // if empty + if ($$.data.targets[0].values.length !== 1) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries) { + flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); + } else { + translateX = $$.diffDomain(domain) / 2; + } } - new_rows.push(targetKeys); - json.forEach(function (o) { - var new_row = []; - targetKeys.forEach(function (key) { - // convert undefined to null because undefined data will be removed in convertDataToTargets() - var v = typeof o[key] === 'undefined' ? null : o[key]; - new_row.push(v); - }); - new_rows.push(new_row); - }); - data = convertRowsToData(new_rows); + } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); } else { - Object.keys(json).forEach(function (key) { - new_rows.push([key].concat(json[key])); - }); - data = convertColumnsToData(new_rows); - } - return data; - } - function convertRowsToData(rows) { - var keys = rows[0], new_row = {}, new_rows = [], i, j; - for (i = 1; i < rows.length; i++) { - new_row = {}; - for (j = 0; j < rows[i].length; j++) { - new_row[keys[j]] = rows[i][j]; - } - new_rows.push(new_row); - } - return new_rows; - } - function convertColumnsToData(columns) { - var new_rows = [], i, j, key; - for (i = 0; i < columns.length; i++) { - key = columns[i][0]; - for (j = 1; j < columns[i].length; j++) { - if (isUndefined(new_rows[j - 1])) { - new_rows[j - 1] = {}; - } - new_rows[j - 1][key] = columns[i][j]; + if ($$.isTimeSeries) { + translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); + } else { + translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); } } - return new_rows; - } - function convertDataToTargets(data, appendXs) { - var ids = d3.keys(data[0]).filter(isNotX), xs = d3.keys(data[0]).filter(isX), targets; - - // save x for update data by load when custom x and c3.x API - ids.forEach(function (id) { - var xKey = getXKey(id); - - if (isCustomX() || isTimeSeries) { - // if included in input data - if (xs.indexOf(xKey) >= 0) { - c3.data.xs[id] = (appendXs && c3.data.xs[id] ? c3.data.xs[id] : []).concat( - data.map(function (d) { return d[xKey]; }) - .filter(isValue) - .map(function (rawX, i) { return generateTargetX(rawX, id, i); }) - ); - } - // if not included in input data, find from preloaded data of other id's x - else if (__data_x) { - c3.data.xs[id] = getOtherTargetXs(); - } - // if not included in input data, find from preloaded data - else if (notEmpty(__data_xs)) { - c3.data.xs[id] = getXValuesOfXKey(xKey, c3.data.targets); + scaleX = ($$.diffDomain(orgDomain) / $$.diffDomain(domain)); + transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; + + d3.transition().ease('linear').duration(durationForFlow).each(function () { + wait.add($$.axes.x.transition().call($$.xAxis)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); + }) + .call(wait, function () { + var i, shapes = [], texts = [], eventRects = []; + + // remove flowed elements + if (flowLength) { + for (i = 0; i < flowLength; i++) { + shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); + texts.push('.' + CLASS.text + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); } - // MEMO: if no x included, use same x of current will be used - } else { - c3.data.xs[id] = data.map(function (d, i) { return i; }); + $$.svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS.xgrid).remove(); } - }); - // check x is defined - ids.forEach(function (id) { - if (!c3.data.xs[id]) { - throw new Error('x is not defined for id = "' + id + '".'); - } + // draw again for removing flowed elements and reverting attr + xgrid + .attr('transform', null) + .attr(xgridAttr); + xgridLines + .attr('transform', null); + xgridLines.select('line') + .attr("x1", $$.__axis_rotated ? 0 : $$.xv) + .attr("x2", $$.__axis_rotated ? $$.width : $$.xv); + xgridLines.select('text') + .attr("x", $$.__axis_rotated ? $$.width : 0) + .attr("y", $$.xv); + mainBar + .attr('transform', null) + .attr("d", drawBar); + mainLine + .attr('transform', null) + .attr("d", drawLine); + mainArea + .attr('transform', null) + .attr("d", drawArea); + mainCircle + .attr('transform', null) + .attr("cx", $$.__axis_rotated ? $$.circleY : $$.circleX) + .attr("cy", $$.__axis_rotated ? $$.circleX : $$.circleY); + mainText + .attr('transform', null) + .attr('x', xForText) + .attr('y', yForText) + .style('fill-opacity', $$.opacityForText); + mainRegion + .attr('transform', null); + mainRegion.select('rect').filter($$.isRegionOnX) + .attr("x", $$.regionX) + .attr("width", $$.regionWidth); + eventRectUpdate + .attr("x", $$.__axis_rotated ? 0 : rectX) + .attr("y", $$.__axis_rotated ? rectX : 0) + .attr("width", $$.__axis_rotated ? $$.width : rectW) + .attr("height", $$.__axis_rotated ? rectW : $$.height); + + // callback for end of flow + done(); }); + }); - // convert to target - targets = ids.map(function (id, index) { - var convertedId = __data_id_converter(id); - return { - id: convertedId, - id_org: id, - values: data.map(function (d, i) { - var xKey = getXKey(id), rawX = d[xKey], x = generateTargetX(rawX, id, i); - // use x as categories if custom x and categorized - if (isCustomX() && isCategorized && index === 0 && rawX) { - if (i === 0) { __axis_x_categories = []; } - __axis_x_categories.push(rawX); - } - // mark as x = undefined if value is undefined and filter to remove after mapped - if (typeof d[id] === 'undefined' || c3.data.xs[id].length <= i) { - x = undefined; - } - return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; - }).filter(function (v) { return typeof v.x !== 'undefined'; }) - }; - }); + // update fadein condition + $$.mapToIds($$.data.targets).forEach(function (id) { + $$.withoutFadeIn[id] = true; + }); - // finish targets - targets.forEach(function (t) { - var i; - // sort values by its x - t.values = t.values.sort(function (v1, v2) { - var x1 = v1.x || v1.x === 0 ? v1.x : Infinity, - x2 = v2.x || v2.x === 0 ? v2.x : Infinity; - return x1 - x2; - }); - // indexing each value - i = 0; - t.values.forEach(function (v) { - v.index = i++; - }); - // this needs to be sorted because its index and value.index is identical - c3.data.xs[t.id].sort(function (v1, v2) { - return v1 - v2; - }); - }); + $$.updateZoom(); + }; + c3.fn.$$.redrawForBrush = function () { + var $$ = this, x = $$.x; + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false, + withUpdateXDomain: true + }); + $$.__subchart_onbrush.call(c3, x.orgDomain()); + }; + c3.fn.$$.redrawForZoom = function () { + var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain;; + if (!$$.__zoom_enabled) { + return; + } + if ($$.filterTargetsToShow($$.data.targets).length === 0) { + return; + } + if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { + x.domain(zoom.altDomain); + zoom.scale(x).updateScaleExtent(); + return; + } + if ($$.isCategorized && x.orgDomain()[0] === orgXDomain[0]) { + x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); + } + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false + }); + if (d3.event.sourceEvent.type === 'mousemove') { + $$.cancelClick = true; + } + $$.__zoom_onzoom.call(c3, x.orgDomain()); + }; + c3.fn.$$.updateAndRedraw = function (options) { + var $$ = this, 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) + this.updateSizes(); + // MEMO: called in updateLegend in redraw if withLegend + if (!(options.withLegend && $$.__legend_show)) { + transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.__transition_duration : 0); + // Update scales + $$.updateScales(); + $$.updateSvgSize(); + // Update g positions + $$.transformAll(options.withTransitionForTransform, transitions); + } + // Draw with new sizes & scales + $$.redraw(options, transitions); + }; - // set target types - if (__data_type) { - setTargetType(mapToIds(targets).filter(function (id) { return ! (id in __data_types); }), __data_type); - } + c3.fn.$$.generateEventRectsForSingleX = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, CLASS = $$.CLASS; + eventRectEnter.append("rect") + .attr("class", function (d) { return $$.classEvent(d); }) + .style("cursor", $$.__data_selection_enabled && $$.__data_selection_grouped ? "pointer" : null) + .on('mouseover', function (d) { + var index = d.index, selectedData, newData; - // cache as original id keyed - targets.forEach(function (d) { - addCache(d.id_org, d); - }); + if ($$.dragging) { return; } // do nothing if dragging + if ($$.hasArcType($$.data.targets)) { return; } - return targets; - } - function cloneTarget(target) { - return { - id : target.id, - id_org : target.id_org, - values : target.values.map(function (d) { - return {x: d.x, value: d.value, id: d.id}; - }) - }; - } - function getPrevX(i) { - var value = getValueOnIndex(c3.data.targets[0].values, i - 1); - return value ? value.x : null; - } - function getNextX(i) { - var value = getValueOnIndex(c3.data.targets[0].values, i + 1); - return value ? value.x : null; - } - function getMaxDataCount() { - return d3.max(c3.data.targets, function (t) { return t.values.length; }); - } - function getMaxDataCountTarget(targets) { - var length = targets.length, max = 0, maxTarget; - if (length > 1) { - targets.forEach(function (t) { - if (t.values.length > max) { - maxTarget = t; - max = t.values.length; - } + selectedData = $$.data.targets.map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); }); - } else { - maxTarget = length ? targets[0] : null; - } - return maxTarget; - } - function getEdgeX(targets) { - var target = getMaxDataCountTarget(targets), firstData, lastData; - if (!target) { - return [0, 0]; - } - firstData = target.values[0], lastData = target.values[target.values.length - 1]; - return [firstData.x, lastData.x]; - } - function mapToIds(targets) { - return targets.map(function (d) { return d.id; }); - } - function mapToTargetIds(ids) { - return ids ? (typeof ids === 'string' ? [ids] : ids) : mapToIds(c3.data.targets); - } - function hasTarget(targets, id) { - var ids = mapToIds(targets), i; - for (i = 0; i < ids.length; i++) { - if (ids[i] === id) { - return true; - } - } - return false; - } - function isTargetToShow(targetId) { - return hiddenTargetIds.indexOf(targetId) < 0; - } - function isLegendToShow(targetId) { - return hiddenLegendIds.indexOf(targetId) < 0; - } - function filterTargetsToShow(targets) { - return targets.filter(function (t) { return isTargetToShow(t.id); }); - } - function mapTargetsToUniqueXs(targets) { - var xs = d3.set(d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); - return isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); - } - function generateTickValues(xs, tickCount) { - var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; - if (tickCount) { - targetCount = typeof tickCount === 'function' ? tickCount() : tickCount; - // compute ticks according to __axis_x_tick_count - if (targetCount === 1) { - tickValues = [xs[0]]; - } else if (targetCount === 2) { - tickValues = [xs[0], xs[xs.length - 1]]; - } else if (targetCount > 2) { - count = targetCount - 2; - start = xs[0]; - end = xs[xs.length - 1]; - interval = (end - start) / (count + 1); - // re-construct uniqueXs - tickValues = [start]; - for (i = 0; i < count; i++) { - tickValue = +start + interval * (i + 1); - tickValues.push(isTimeSeries ? new Date(tickValue) : tickValue); + + // Sort selectedData as names order + newData = []; + Object.keys($$.__data_names).forEach(function (id) { + for (var j = 0; j < selectedData.length; j++) { + if (selectedData[j] && selectedData[j].id === id) { + newData.push(selectedData[j]); + selectedData.shift(j); + break; + } } - tickValues.push(end); - } - } - if (!isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } - return tickValues; - } - function addHiddenTargetIds(targetIds) { - hiddenTargetIds = hiddenTargetIds.concat(targetIds); - } - function removeHiddenTargetIds(targetIds) { - hiddenTargetIds = hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); - } - function addHiddenLegendIds(targetIds) { - hiddenLegendIds = hiddenLegendIds.concat(targetIds); - } - function removeHiddenLegendIds(targetIds) { - hiddenLegendIds = hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); - } - function getValuesAsIdKeyed(targets) { - var ys = {}; - targets.forEach(function (t) { - ys[t.id] = []; - t.values.forEach(function (v) { - ys[t.id].push(v.value); }); - }); - return ys; - } - function checkValueInTargets(targets, checker) { - var ids = Object.keys(targets), i, j, values; - for (i = 0; i < ids.length; i++) { - values = targets[ids[i]].values; - for (j = 0; j < values.length; j++) { - if (checker(values[j].value)) { - return true; - } + selectedData = newData.concat(selectedData); // Add remained + + // Expand shapes for selection + if ($$.__point_focus_expand_enabled) { $$.expandCircles(index); } + $$.expandBars(index); + + // Call event handler + $$.main.selectAll('.' + $$.CLASS.shape + '-' + index).each(function (d) { + $$.__data_onmouseover.call(c3, d); + }); + }) + .on('mouseout', function (d) { + var index = d.index; + if ($$.hasArcType($$.data.targets)) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + // Undo expanded shapes + $$.unexpandCircles(index); + $$.unexpandBars(); + // Call event handler + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + $$.__data_onmouseout.call(c3, d); + }); + }) + .on('mousemove', function (d) { + var selectedData, index = d.index, + eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType($$.data.targets)) { return; } + + // Show tooltip + selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + if ($$.__tooltip_grouped) { + $$.showTooltip(selectedData, d3.mouse(this)); + $$.showXGridFocus(selectedData); } - } - return false; - } - function hasNegativeValueInTargets(targets) { - return checkValueInTargets(targets, function (v) { return v < 0; }); - } - function hasPositiveValueInTargets(targets) { - return checkValueInTargets(targets, function (v) { return v > 0; }); - } - function categoryName(i) { - return i < __axis_x_categories.length ? __axis_x_categories[i] : i; - } - function generateClass(prefix, targetId) { - return " " + prefix + " " + prefix + getTargetSelectorSuffix(targetId); - } - function classText(d) { return generateClass(CLASS.text, d.index); } - function classTexts(d) { return generateClass(CLASS.texts, d.id); } - function classShape(d) { return generateClass(CLASS.shape, d.index); } - function classShapes(d) { return generateClass(CLASS.shapes, d.id); } - function classLine(d) { return classShape(d) + generateClass(CLASS.line, d.id); } - function classLines(d) { return classShapes(d) + generateClass(CLASS.lines, d.id); } - function classCircle(d) { return classShape(d) + generateClass(CLASS.circle, d.index); } - function classCircles(d) { return classShapes(d) + generateClass(CLASS.circles, d.id); } - function classBar(d) { return classShape(d) + generateClass(CLASS.bar, d.index); } - function classBars(d) { return classShapes(d) + generateClass(CLASS.bars, d.id); } - function classArc(d) { return classShape(d.data) + generateClass(CLASS.arc, d.data.id); } - function classArcs(d) { return classShapes(d.data) + generateClass(CLASS.arcs, d.data.id); } - function classArea(d) { return classShape(d) + generateClass(CLASS.area, d.id); } - function classAreas(d) { return classShapes(d) + generateClass(CLASS.areas, d.id); } - function classRegion(d, i) { return generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); } - function classEvent(d) { return generateClass(CLASS.eventRect, d.index); } - function classTarget(id) { - var additionalClassSuffix = __data_classes[id], additionalClass = ''; - if (additionalClassSuffix) { - additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; - } - return generateClass(CLASS.target, id) + additionalClass; - } - function classChartText(d) { return CLASS.chartText + classTarget(d.id); } - function classChartLine(d) { return CLASS.chartLine + classTarget(d.id); } - function classChartBar(d) { return CLASS.chartBar + classTarget(d.id); } - function classChartArc(d) { return CLASS.chartArc + classTarget(d.data.id); } - function getTargetSelectorSuffix(targetId) { - return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; - } - function selectorTarget(id) { return '.' + CLASS.target + getTargetSelectorSuffix(id); } - function selectorTargets(ids) { return ids.length ? ids.map(function (id) { return selectorTarget(id); }) : null; } - function selectorLegend(id) { return '.' + CLASS.legendItem + getTargetSelectorSuffix(id); } - function selectorLegends(ids) { return ids.length ? ids.map(function (id) { return selectorLegend(id); }) : null; } + if ($$.__tooltip_grouped && (!$$.__data_selection_enabled || $$.__data_selection_grouped)) { + return; + } - function initialOpacity(d) { - return d.value !== null && withoutFadeIn[d.id] ? 1 : 0; - } - function opacityForCircle(d) { - return isValue(d.value) ? isScatterType(d) ? 0.5 : 1 : 0; - } - function opacityForText() { - return hasDataLabel() ? 1 : 0; - } - function hasDataLabel() { - if (typeof __data_labels === 'boolean' && __data_labels) { - return true; - } else if (typeof __data_labels === 'object' && notEmpty(__data_labels)) { - return true; - } - return false; - } - function getDataLabelLength(min, max, axisId, key) { - var lengths = [0, 0], paddingCoef = 1.3; - selectChart.select('svg').selectAll('.dummy') - .data([min, max]) - .enter().append('text') - .text(function (d) { return formatByAxisId(axisId)(d); }) - .each(function (d, i) { - lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; - }) - .remove(); - return lengths; - } - function getYFormat(forArc) { - var formatForY = forArc && !hasGaugeType(c3.data.targets) ? defaultArcValueFormat : yFormat, - formatForY2 = forArc && !hasGaugeType(c3.data.targets) ? defaultArcValueFormat : y2Format; - return function (v, ratio, id) { - var format = getAxisId(id) === 'y2' ? formatForY2 : formatForY; - return format(v, ratio); - }; - } - function yFormat(v) { - var format = __axis_y_tick_format ? __axis_y_tick_format : defaultValueFormat; - return format(v); - } - function y2Format(v) { - var format = __axis_y2_tick_format ? __axis_y2_tick_format : defaultValueFormat; - return format(v); - } - function defaultValueFormat(v) { - return isValue(v) ? +v : ""; - } - function defaultArcValueFormat(v, ratio) { - return (ratio * 100).toFixed(1) + '%'; - } - function formatByAxisId(axisId) { - var format = function (v) { return isValue(v) ? +v : ""; }; - // find format according to axis id - if (typeof __data_labels.format === 'function') { - format = __data_labels.format; - } else if (typeof __data_labels.format === 'object') { - if (typeof __data_labels.format[axisId] === 'function') { - format = __data_labels.format[axisId]; + $$.main.selectAll('.' + CLASS.shape + '-' + index) + .each(function () { + d3.select(this).classed(CLASS.EXPANDED, true); + if ($$.__data_selection_enabled) { + eventRect.style('cursor', $$.__data_selection_grouped ? 'pointer' : null); + } + if (!$$.__tooltip_grouped) { + $$.hideXGridFocus(); + $$.hideTooltip(); + if (!$$.__data_selection_grouped) { + $$.unexpandCircles(index); + $$.unexpandBars(); + } + } + }) + .filter(function (d) { + if (this.nodeName === 'circle') { + return $$.isWithinCircle(this, $$.pointSelectR(d)); + } + else if (this.nodeName === 'path') { + return $$.isWithinBar(this); + } + }) + .each(function (d) { + if ($$.__data_selection_enabled && ($$.__data_selection_grouped || $$.__data_selection_isselectable(d))) { + eventRect.style('cursor', 'pointer'); + } + if (!$$.__tooltip_grouped) { + $$.showTooltip([d], d3.mouse(this)); + $$.showXGridFocus([d]); + if ($$.__point_focus_expand_enabled) { $$.expandCircles(index, d.id); } + $$.expandBars(index, d.id); + } + }); + }) + .on('click', function (d) { + var index = d.index; + if ($$.hasArcType($$.data.targets)) { return; } + if ($$.cancelClick) { + $$.cancelClick = false; + return; } - } - return format; - } + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); + }; - function xx(d) { - return d ? x(d.x) : null; - } - function xv(d) { - return Math.ceil(x(isTimeSeries ? parseDate(d.value) : d.value)); - } - function yv(d) { - var yScale = d.axis && d.axis === 'y2' ? y2 : y; - return Math.ceil(yScale(d.value)); - } - function subxx(d) { - return d ? subX(d.x) : null; - } + c3.fn.$$.generateEventRectsForMultipleXs = function (eventRectEnter) { + var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; + eventRectEnter.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height) + .attr('class', CLASS.eventRect) + .on('mouseout', function () { + if ($$.hasArcType($$.data.targets)) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + $$.unexpandCircles(); + }) + .on('mousemove', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest, sameXData, selectedData; - function findSameXOfValues(values, index) { - var i, targetX = values[index].x, sames = []; - for (i = index - 1; i >= 0; i--) { - if (targetX !== values[i].x) { break; } - sames.push(values[i]); - } - for (i = index; i < values.length; i++) { - if (targetX !== values[i].x) { break; } - sames.push(values[i]); - } - return sames; - } + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType(targetsToShow)) { return; } - function findClosestOfValues(values, pos, _min, _max) { // MEMO: values must be sorted by x - var min = _min ? _min : 0, - max = _max ? _max : values.length - 1, - med = Math.floor((max - min) / 2) + min, - value = values[med], - diff = x(value.x) - pos[__axis_rotated ? 1 : 0], - candidates; + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); - // Update range for search - diff > 0 ? max = med : min = med; + if (! closest) { return; } - // if candidates are two closest min and max, stop recursive call - if ((max - min) === 1 || (min === 0 && max === 0)) { + if ($$.isScatterType(closest)) { + sameXData = [closest]; + } else { + sameXData = $$.filterSameX(targetsToShow, closest.x); + } + + // show tooltip when cursor is close to some point + selectedData = sameXData.map(function (d) { + return $$.addName(d); + }); + $$.showTooltip(selectedData, mouse); - // Get candidates that has same min and max index - candidates = []; - if (values[min].x || values[min].x === 0) { - candidates = candidates.concat(findSameXOfValues(values, min)); + // expand points + if ($$.__point_focus_expand_enabled) { + $$.unexpandCircles(); + $$.expandCircles(closest.index, closest.id); } - if (values[max].x || values[max].x === 0) { - candidates = candidates.concat(findSameXOfValues(values, max)); + + // Show xgrid focus line + $$.showXGridFocus(selectedData); + + // Show cursor as pointer if point is close to mouse position + if ($$.dist(closest, mouse) < 100) { + $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); + if (!$$.mouseover) { + $$.__data_onmouseover.call(c3, closest); + $$.mouseover = true; + } + } else { + $$.svg.select('.' + CLASS.eventRect).style('cursor', null); + $$.__data_onmouseout.call(c3, closest); + $$.mouseover = false; } + }) + .on('click', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest; - // Determine the closest and return - return findClosest(candidates, pos); - } + if ($$.hasArcType(targetsToShow)) { return; } - return findClosestOfValues(values, pos, min, max); - } - function findClosestFromTargets(targets, pos) { - var candidates; + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); - // map to array of closest points of each target - candidates = targets.map(function (target) { - return findClosestOfValues(target.values, pos); - }); + if (! closest) { return; } - // decide closest point and return - return findClosest(candidates, pos); - } - function findClosest(values, pos) { - var minDist, closest; - values.forEach(function (v) { - var d = dist(v, pos); - if (d < minDist || ! minDist) { - minDist = d; - closest = v; + // select if selection enabled + if ($$.dist(closest, mouse) < 100) { + $$.main.select('.' + CLASS.circles + '-' + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.toggleShape(this, closest, closest.index); + }); } - }); - return closest; - } - function filterSameX(targets, x) { - return d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); - } + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); + }; - function getPathBox(path) { - var box = path.getBoundingClientRect(), - items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], - minX = items[0].x, minY = Math.min(items[0].y, items[1].y); - return {x: minX, y: minY, width: box.width, height: box.height}; - } - function isOrderDesc() { - return __data_order && __data_order.toLowerCase() === 'desc'; - } - function isOrderAsc() { - return __data_order && __data_order.toLowerCase() === 'asc'; - } - function orderTargets(targets) { - var orderAsc = isOrderAsc(), orderDesc = isOrderDesc(); - if (orderAsc || orderDesc) { - targets.sort(function (t1, t2) { - var reducer = function (p, c) { return p + Math.abs(c.value); }; - var t1Sum = t1.values.reduce(reducer, 0), - t2Sum = t2.values.reduce(reducer, 0); - return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; - }); - } else if (typeof __data_order === 'function') { - targets.sort(__data_order); - } // TODO: accept name array for order - return targets; - } - //-- Tooltip --// - function showTooltip(selectedData, mouse) { - var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = hasArcType(c3.data.targets), - dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (dataToShow.length === 0 || !__tooltip_show) { - return; - } - tooltip.html(__tooltip_contents(selectedData, getXAxisTickFormat(), getYFormat(forArc), color)).style("display", "block"); - - // Get tooltip dimensions - tWidth = tooltip.property('offsetWidth'); - tHeight = tooltip.property('offsetHeight'); - // Determin tooltip position - if (forArc) { - tooltipLeft = (width / 2) + mouse[0]; - tooltipTop = (height / 2) + mouse[1] + 20; - } else { - if (__axis_rotated) { - svgLeft = getSvgLeft(); - tooltipLeft = svgLeft + mouse[0] + 100; - tooltipRight = tooltipLeft + tWidth; - chartRight = getCurrentWidth() - getCurrentPaddingRight(); - tooltipTop = x(dataToShow[0].x) + 20; - } else { - svgLeft = getSvgLeft(); - tooltipLeft = svgLeft + getCurrentPaddingLeft() + x(dataToShow[0].x) + 20; - tooltipRight = tooltipLeft + tWidth; - chartRight = svgLeft + getCurrentWidth() - getCurrentPaddingRight(); - tooltipTop = mouse[1] + 15; - } - if (tooltipRight > chartRight) { - tooltipLeft -= tooltipRight - chartRight; - } - if (tooltipTop + tHeight > getCurrentHeight()) { - tooltipTop -= tHeight + 30; - } - } - // Set tooltip - tooltip - .style("top", tooltipTop + "px") - .style("left", tooltipLeft + 'px'); - } - function hideTooltip() { - tooltip.style("display", "none"); - } - - function showXGridFocus(selectedData) { - var dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (! __tooltip_show) { return; } - // Hide when scatter plot exists - if (hasScatterType(c3.data.targets) || hasArcType(c3.data.targets)) { return; } - var focusEl = main.selectAll('line.' + CLASS.xgridFocus); - focusEl - .style("visibility", "visible") - .data([dataToShow[0]]) - .attr(__axis_rotated ? 'y1' : 'x1', xx) - .attr(__axis_rotated ? 'y2' : 'x2', xx); - smoothLines(focusEl, 'grid'); - } - function hideXGridFocus() { - main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); - } - function generateGridData(type, scale) { - var gridData = [], xDomain, firstYear, lastYear, i, - tickNum = main.select("." + CLASS.axisX).selectAll('.tick').size(); - if (type === 'year') { - xDomain = getXDomain(); - firstYear = xDomain[0].getFullYear(); - lastYear = xDomain[1].getFullYear(); - for (i = firstYear; i <= lastYear; i++) { - gridData.push(new Date(i + '-01-01 00:00:00')); - } - } else { - gridData = scale.ticks(10); - if (gridData.length > tickNum) { // use only int - gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); - } - } - return gridData; - } - //-- Shape --// - function getShapeIndices(typeFilter) { - var indices = {}, i = 0, j, k; - filterTargetsToShow(c3.data.targets.filter(typeFilter)).forEach(function (d) { - for (j = 0; j < __data_groups.length; j++) { - if (__data_groups[j].indexOf(d.id) < 0) { continue; } - for (k = 0; k < __data_groups[j].length; k++) { - if (__data_groups[j][k] in indices) { - indices[d.id] = indices[__data_groups[j][k]]; - break; - } - } - } - if (isUndefined(indices[d.id])) { indices[d.id] = i++; } - }); - indices.__max__ = i - 1; - return indices; - } - function getShapeX(offset, targetsNum, indices, isSub) { - var scale = isSub ? subX : x; - return function (d) { - var index = d.id in indices ? indices[d.id] : 0; - return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; - }; - } - function getShapeY(isSub) { - return function (d) { - var scale = isSub ? getSubYScale(d.id) : getYScale(d.id); - return scale(d.value); - }; - } - function getShapeOffset(typeFilter, indices, isSub) { - var targets = orderTargets(filterTargetsToShow(c3.data.targets.filter(typeFilter))), - targetIds = targets.map(function (t) { return t.id; }); - return function (d, i) { - var scale = isSub ? getSubYScale(d.id) : getYScale(d.id), - y0 = scale(0), offset = y0; - targets.forEach(function (t) { - if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } - if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id) && t.values[i].value * d.value >= 0) { - offset += scale(t.values[i].value) - y0; - } - }); - return offset; - }; - } - //-- Circle --// + c3.fn.$$.initialOpacity = function (d) { + var $$ = this; + return d.value !== null && $$.withoutFadeIn[d.id] ? 1 : 0; + }; + c3.fn.$$.opacityForCircle = function (d) { + return this.isValue(d.value) ? this.isScatterType(d) ? 0.5 : 1 : 0; + }; + c3.fn.$$.opacityForText = function () { + return this.hasDataLabel() ? 1 : 0; + }; + c3.fn.$$.xx = function (d) { + var $$ = this; + return d ? $$.x(d.x) : null; + }; + c3.fn.$$.xv = function (d) { + return Math.ceil($$.x($$.isTimeSeries ? this.parseDate(d.value) : d.value)); + }; + c3.fn.$$.yv = function (d) { + var $$ = this, + yScale = d.axis && d.axis === 'y2' ? $$.y2 : $$.y; + return Math.ceil(yScale(d.value)); + }; + c3.fn.$$.subxx = function (d) { + return d ? $$.subX(d.x) : null; + }; - function circleX(d) { - return d.x || d.x === 0 ? x(d.x) : null; - } - function circleY(d, i) { - var lineIndices = getShapeIndices(isLineType), getPoint = generateGetLinePoint(lineIndices); - return __data_groups.length > 0 ? getPoint(d, i)[0][1] : getYScale(d.id)(d.value); - } - //-- Bar --// - function getBarW(axis, barTargetsNum) { - return typeof __bar_width === 'number' ? __bar_width : barTargetsNum ? (axis.tickOffset() * 2 * __bar_width_ratio) / barTargetsNum : 0; - } + c3.fn.$$.transformMain = function (withTransition, transitions) { + var $$ = this, xAxis, yAxis, y2Axis; + if (transitions && transitions.axisX) { + xAxis = transitions.axisX; + } else { + xAxis = $$.main.select('.' + this.CLASS.axisX); + if (withTransition) { xAxis = xAxis.transition(); } + } + if (transitions && transitions.axisY) { + yAxis = transitions.axisY; + } else { + yAxis = $$.main.select('.' + this.CLASS.axisY); + if (withTransition) { yAxis = yAxis.transition(); } + } + if (transitions && transitions.axisY2) { + y2Axis = transitions.axisY2; + } else { + y2Axis = $$.main.select('.' + this.CLASS.axisY2); + if (withTransition) { y2Axis = y2Axis.transition(); } + } + (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); + xAxis.attr("transform", $$.translate.x); + yAxis.attr("transform", $$.translate.y); + y2Axis.attr("transform", $$.translate.y2); + $$.main.select('.' + this.CLASS.chartArcs).attr("transform", $$.translate.arc); + }; + c3.fn.$$.transformContext = function (withTransition, transitions) { + var $$ = this.$$, subXAxis; + if (transitions && transitions.axisSubX) { + subXAxis = transitions.axisSubX; + } else { + subXAxis = $$.context.select('.' + this.CLASS.axisX); + if (withTransition) { subXAxis = subXAxis.transition(); } + } + $$.context.attr("transform", $$.translate.context); + subXAxis.attr("transform", $$.translate.subx); + }; + c3.fn.$$.transformLegend = function (withTransition) { + var $$ = this; + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); + }; + c3.fn.$$.transformAll = function (withTransition, transitions) { + var $$ = this; + $$.transformMain(withTransition, transitions); + if ($$.__subchart_show) { $$.transformContext(withTransition, transitions); } + $$.transformLegend(withTransition); + }; - //-- Type --// - function setTargetType(targetIds, type) { - mapToTargetIds(targetIds).forEach(function (id) { - withoutFadeIn[id] = (type === __data_types[id]); - __data_types[id] = type; - }); - if (!targetIds) { - __data_type = type; - } + c3.fn.$$.updateSvgSize = function () { + var $$ = this; + $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); + $$.svg.select('#' + $$.clipId).select('rect') + .attr('width', $$.width) + .attr('height', $$.height); + $$.svg.select('#' + $$.clipIdForXAxis).select('rect') + .attr('x', function () { return $$.getXAxisClipX(); }) + .attr('y', function () { return $$.getXAxisClipY(); }) + .attr('width', function () { return $$.getXAxisClipWidth(); }) + .attr('height', function () { return $$.getXAxisClipHeight(); }); + $$.svg.select('#' + $$.clipIdForYAxis).select('rect') + .attr('x', function () { return $$.getYAxisClipX(); }) + .attr('y', function () { return $$.getYAxisClipY(); }) + .attr('width', function () { return $$.getYAxisClipWidth(); }) + .attr('height', function () { return $$.getYAxisClipHeight(); }); + $$.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.fn.$$.updateDimension = function () { + var $$ = this; + if ($$.__axis_rotated) { + $$.axes.x.call($$.xAxis); + $$.axes.subx.call($$.subXAxis); + } else { + $$.axes.y.call($$.yAxis); + $$.axes.y2.call($$.y2Axis); } - function hasType(targets, type) { - var has = false; - targets.forEach(function (t) { - if (__data_types[t.id] === type) { has = true; } - if (!(t.id in __data_types) && type === 'line') { has = true; } + this.updateSizes(); + this.updateScales(); + this.updateSvgSize(); + this.transformAll(false); + }; + + c3.fn.$$.observeInserted = function (selection) { + var 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 + var interval = window.setInterval(function () { + // parentNode will NOT be null when completed + if (selection.node().parentNode) { + window.clearInterval(interval); + this.updateDimension(); + this.redraw({ + withTransform: true, + withUpdateXDomain: true, + withUpdateOrgXDomain: true, + withTransition: false, + withTransitionForTransform: false, + withLegend: true + }); + selection.transition().style('opacity', 1); + } + }, 10); + } }); - return has; - } + }); + observer.observe(selection.node(), {attributes: true, childList: true, characterData: true}); + }; - /* not used - function hasLineType(targets) { - return hasType(targets, 'line'); - } - */ - function hasAreaType(targets) { - return hasType(targets, 'area') || hasType(targets, 'area-spline') || hasType(targets, 'area-step'); - } - function hasBarType(targets) { - return hasType(targets, 'bar'); - } - function hasScatterType(targets) { - return hasType(targets, 'scatter'); - } - function hasPieType(targets) { - return __data_type === 'pie' || hasType(targets, 'pie'); - } - function hasGaugeType(targets) { - return hasType(targets, 'gauge'); - } - function hasDonutType(targets) { - return __data_type === 'donut' || hasType(targets, 'donut'); - } - function hasArcType(targets) { - return hasPieType(targets) || hasDonutType(targets) || hasGaugeType(targets); - } - function isLineType(d) { - var id = (typeof d === 'string') ? d : d.id; - return !__data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(__data_types[id]) >= 0; - } - function isStepType(d) { - var id = (typeof d === 'string') ? d : d.id; - return ['step', 'area-step'].indexOf(__data_types[id]) >= 0; - } - function isSplineType(d) { - var id = (typeof d === 'string') ? d : d.id; - return ['spline', 'area-spline'].indexOf(__data_types[id]) >= 0; - } - function isAreaType(d) { - var id = (typeof d === 'string') ? d : d.id; - return ['area', 'area-spline', 'area-step'].indexOf(__data_types[id]) >= 0; - } - function isBarType(d) { - var id = (typeof d === 'string') ? d : d.id; - return __data_types[id] === 'bar'; - } - function isScatterType(d) { - var id = (typeof d === 'string') ? d : d.id; - return __data_types[id] === 'scatter'; - } - function isPieType(d) { - var id = (typeof d === 'string') ? d : d.id; - return __data_types[id] === 'pie'; - } - function isGaugeType(d) { - var id = (typeof d === 'string') ? d : d.id; - return __data_types[id] === 'gauge'; - } - function isDonutType(d) { - var id = (typeof d === 'string') ? d : d.id; - return __data_types[id] === 'donut'; - } - function isArcType(d) { - return isPieType(d) || isDonutType(d) || isGaugeType(d); - } - function lineData(d) { - return isLineType(d) ? [d] : []; - } - function arcData(d) { - return isArcType(d.data) ? [d] : []; - } - /* not used - function scatterData(d) { - return isScatterType(d) ? d.values : []; - } - */ - function barData(d) { - return isBarType(d) ? d.values : []; + + c3.fn.$$.generateResize = function () { + var resizeFunctions = []; + function callResizeFunctions() { + resizeFunctions.forEach(function (f) { + f(); + }); } - function lineOrScatterData(d) { - return isLineType(d) || isScatterType(d) ? d.values : []; + callResizeFunctions.add = function (f) { + resizeFunctions.push(f); + }; + return callResizeFunctions; + }; + + + + c3.fn.$$.getCurrentWidth = function () { + var $$ = this; + return $$.__size_width ? $$.__size_width : $$.getParentWidth(); + }; + c3.fn.$$.getCurrentHeight = function () { + var $$ = this, h = $$.__size_height ? $$.__size_height : this.getParentHeight(); + return h > 0 ? h : 320; + }; + c3.fn.$$.getCurrentPaddingTop = function () { + var $$ = this; + return this.isValue($$.__padding_top) ? $$.__padding_top : 0; + }; + c3.fn.$$.getCurrentPaddingBottom = function () { + var $$ = this; + return this.isValue($$.__padding_bottom) ? $$.__padding_bottom : 0; + }; + c3.fn.$$.getCurrentPaddingLeft = function () { + var $$ = this; + if (this.isValue($$.__padding_left)) { + return $$.__padding_left; + } else if ($$.__axis_rotated) { + return !$$.__axis_x_show ? 1 : Math.max(this.ceil10(this.getAxisWidthByAxisId('x')), 40); + } else { + return !$$.__axis_y_show || $$.__axis_y_inner ? 1 : this.ceil10(this.getAxisWidthByAxisId('y')); } - function barOrLineData(d) { - return isBarType(d) || isLineType(d) ? d.values : []; + }; + c3.fn.$$.getCurrentPaddingRight = function () { + var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? this.getLegendWidth() + 20 : 0; + if (this.isValue($$.__padding_right)) { + return $$.__padding_right + 1; // 1 is needed not to hide tick line + } else if ($$.__axis_rotated) { + return defaultPadding + legendWidthOnRight; + } else { + return (!$$.__axis_y2_show || $$.__axis_y2_inner ? defaultPadding : this.ceil10(this.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } + }; - function shouldExpand(id) { - return (isDonutType(id) && __donut_expand) || (isGaugeType(id) && __gauge_expand) || (isPieType(id) && __pie_expand); + c3.fn.$$.getParentRectValue = function (key) { + var $$ = this, parent = $$.selectChart.node(), v; + while (parent && parent.tagName !== 'BODY') { + v = parent.getBoundingClientRect()[key]; + if (v) { + break; + } + parent = parent.parentNode; } + return v; + }; + c3.fn.$$.getParentWidth = function () { + return this.getParentRectValue('width'); + }; + c3.fn.$$.getParentHeight = function () { + var h = this.selectChart.style('height'); + return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; + }; - //-- Color --// - function generateColor(colors, pattern, callback) { - var ids = []; + c3.fn.$$.getSvgLeft = function () { + var $$ = this, + leftAxisClass = $$.__axis_rotated ? $$.CLASS.axisX : $$.CLASS.axisY, + leftAxis = $$.main.select('.' + leftAxisClass).node(), + svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, + chartRect = $$.selectChart.node().getBoundingClientRect(), + hasArc = $$.hasArcType($$.data.targets), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); + return svgLeft > 0 ? svgLeft : 0; + }; - return function (d) { - var id = d.id || d, color; - // if callback function is provided - if (colors[id] instanceof Function) { - color = colors[id](d); - } - // if specified, choose that color - else if (colors[id]) { - color = colors[id]; - } - // if not specified, choose from pattern - else { - if (ids.indexOf(id) < 0) { ids.push(id); } - color = pattern[ids.indexOf(id) % pattern.length]; - colors[id] = color; - } - return callback instanceof Function ? callback(color, d) : color; - }; - } + c3.fn.$$.getAxisWidthByAxisId = function (id) { + var position = this.getAxisLabelPositionById(id); + return position.isInner ? 20 + this.getMaxTickWidth(id) : 40 + this.getMaxTickWidth(id); + }; + c3.fn.$$.getHorizontalAxisHeight = function (axisId) { + var $$ = this; + if (axisId === 'x' && !$$.__axis_x_show) { return 0; } + if (axisId === 'x' && $$.__axis_x_height) { return $$.__axis_x_height; } + if (axisId === 'y' && !$$.__axis_y_show) { return $$.__legend_show && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !$$.__axis_y2_show) { return $$.rotated_padding_top; } + return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + }; - function generateLevelColor(colors, threshold) { - var asValue = threshold.unit === 'value', - values = threshold.values && threshold.values.length ? threshold.values : [], - max = threshold.max || 100; - return function (value) { - var i, v, color = colors[colors.length - 1]; - for (i = 0; i < values.length; i++) { - v = asValue ? value : (value * 100 / max); - if (v < values[i]) { - color = colors[i]; - break; - } - } - return color; - }; - } + c3.fn.$$.getEventRectWidth = function () { + var $$ = this; + var target = this.getMaxDataCountTarget($$.data.targets), + firstData, lastData, base, maxDataCount, ratio, w; + if (!target) { + return 0; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + base = $$.x(lastData.x) - $$.x(firstData.x); + if (base === 0) { + return $$.__axis_rotated ? $$.height : $$.width; + } + maxDataCount = this.getMaxDataCount(); + ratio = (this.hasBarType($$.data.targets) ? (maxDataCount - (this.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; + return w < 1 ? 1 : w; + }; - //-- Date --// - function parseDate(date) { - var parsedDate; - if (date instanceof Date) { - parsedDate = date; - } else if (typeof date === 'number') { - parsedDate = new Date(date); + /** + * c3.tooltip.js + */ + c3.fn.$$.showTooltip = function (selectedData, mouse) { + var $$ = this; + var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; + var forArc = $$.hasArcType($$.data.targets), + dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); + if (dataToShow.length === 0 || !$$.__tooltip_show) { + return; + } + $$.tooltip.html($$.__tooltip_contents(selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + + // Get tooltip dimensions + tWidth = $$.tooltip.property('offsetWidth'); + tHeight = $$.tooltip.property('offsetHeight'); + // Determin tooltip position + if (forArc) { + tooltipLeft = ($$.width / 2) + mouse[0]; + tooltipTop = ($$.height / 2) + mouse[1] + 20; + } else { + if ($$.__axis_rotated) { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + mouse[0] + 100; + tooltipRight = tooltipLeft + tWidth; + chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = $$.x(dataToShow[0].x) + 20; } else { - parsedDate = dataTimeFormat(__data_x_format).parse(date); - } - if (!parsedDate || isNaN(+parsedDate)) { - window.console.error("Failed to parse x '" + date + "' to Date object"); + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; + tooltipRight = tooltipLeft + tWidth; + chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = mouse[1] + 15; } - return parsedDate; - } - - //-- Util --// - function isWithinCircle(_this, _r) { - var mouse = d3.mouse(_this), d3_this = d3.select(_this); - var cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; - return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; - } - function isWithinBar(_this) { - var mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), - seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1); - var x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2; - var sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; - return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; - } - function isWithinRegions(x, regions) { - var i; - for (i = 0; i < regions.length; i++) { - if (regions[i].start < x && x <= regions[i].end) { return true; } + if (tooltipRight > chartRight) { + tooltipLeft -= tooltipRight - chartRight; + } + if (tooltipTop + tHeight > $$.getCurrentHeight()) { + tooltipTop -= tHeight + 30; } - return false; } + // Set tooltip + $$.tooltip + .style("top", tooltipTop + "px") + .style("left", tooltipLeft + 'px'); + }; + c3.fn.$$.hideTooltip = function () { + var $$ = this; + $$.tooltip.style("display", "none"); + }; - function isEmpty(o) { - return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); - } - function notEmpty(o) { - return Object.keys(o).length > 0; - } - function hasValue(dict, value) { + + /** + * c3.grid.js + */ + c3.fn.$$.showXGridFocus = function (selectedData) { + var $$ = this, dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); + if (! $$.__tooltip_show) { return; } + // Hide when scatter plot exists + if (this.hasScatterType($$.data.targets) || this.hasArcType($$.data.targets)) { return; } + var focusEl = $$.main.selectAll('line.' + this.CLASS.xgridFocus); + focusEl + .style("visibility", "visible") + .data([dataToShow[0]]) + .attr($$.__axis_rotated ? 'y1' : 'x1', function (d) { return $$.xx(d); }) + .attr($$.__axis_rotated ? 'y2' : 'x2', function (d) { return $$.xx(d); }); + this.smoothLines(focusEl, 'grid'); + }; + c3.fn.$$.hideXGridFocus = function () { + var $$ = this; + $$.main.select('line.' + $$.CLASS.xgridFocus).style("visibility", "hidden"); + }; + c3.fn.$$.updateXgridFocus = function () { + var $$ = this; + $$.main.select('line.' + this.CLASS.xgridFocus) + .attr("x1", $$.__axis_rotated ? 0 : -10) + .attr("x2", $$.__axis_rotated ? $$.width : -10) + .attr("y1", $$.__axis_rotated ? -10 : 0) + .attr("y2", $$.__axis_rotated ? -10 : $$.height); + }; + c3.fn.$$.generateGridData = function (type, scale) { + var gridData = [], xDomain, firstYear, lastYear, i, + tickNum = $$.main.select("." + this.CLASS.axisX).selectAll('.tick').size(); + if (type === 'year') { + xDomain = this.getXDomain(); + firstYear = xDomain[0].getFullYear(); + lastYear = xDomain[1].getFullYear(); + for (i = firstYear; i <= lastYear; i++) { + gridData.push(new Date(i + '-01-01 00:00:00')); + } + } else { + gridData = scale.ticks(10); + if (gridData.length > tickNum) { // use only int + gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } + } + return gridData; + }; + c3.fn.$$.getGridFilterToRemove = function (params) { + return params ? function (line) { var found = false; - Object.keys(dict).forEach(function (key) { - if (dict[key] === value) { found = true; } + [].concat(params).forEach(function (param) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + found = true; + } }); return found; + } : function () { return true; }; + }; + c3.fn.$$.removeGridLines = function (params, forX) { + var $$ = this, CLASS = $$.CLASS, + toRemove = $$.getGridFilterToRemove(params), + toShow = function (line) { return !toRemove(line); }, + classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, + classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; + $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) + .transition().duration($$.__transition_duration) + .style('opacity', 0).remove(); + if (forX) { + $$.__grid_x_lines = $$.__grid_x_lines.filter(toShow); + } else { + $$.__grid_y_lines = $$.__grid_y_lines.filter(toShow); } + }; - function dist(data, pos) { - var yScale = getAxisId(data.id) === 'y' ? y : y2, - xIndex = __axis_rotated ? 1 : 0, - yIndex = __axis_rotated ? 0 : 1; - return Math.pow(x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); - } - function endall(transition, callback) { - var n = 0; - transition - .each(function () { ++n; }) - .each("end", function () { - if (!--n) { callback.apply(this, arguments); } - }); + /** + * c3.legend.js + */ + c3.fn.$$.updateLegendStep = function (step) { + var $$ = this; + $$.legendStep = step; + }; + c3.fn.$$.updateLegendItemWidth = function (w) { + var $$ = this; + $$.legendItemWidth = w; + }; + c3.fn.$$.updateLegendItemHeight = function (h) { + var $$ = this; + $$.legendItemHeight = h; + }; + c3.fn.$$.getLegendWidth = function () { + var $$ = this; + return $$.__legend_show ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; + }; + c3.fn.$$.getLegendHeight = function () { + var $$ = this, h = 0; + if ($$.__legend_show) { + if ($$.isLegendRight) { + h = $$.currentHeight; + } else if ($$.isLegendInset) { + h = $$.__legend_inset_step ? Math.max(20, $$.legendItemHeight) * ($$.__legend_inset_step + 1) : $$.height; + } else { + h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); + } } + return h; + }; + c3.fn.$$.opacityForLegend = function (legendItem) { + var $$ = this; + return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; + }; + c3.fn.$$.opacityForUnfocusedLegend = function (legendItem) { + var $$ = this; + return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; + }; + c3.fn.$$.toggleFocusLegend = function (id, focus) { + var $$ = this; + $$.legend.selectAll('.' + $$.CLASS.legendItem) + .transition().duration(100) + .style('opacity', function (_id) { + var This = $$.d3.select(this); + if (id && _id !== id) { + return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); + } else { + return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } + }); + }; + c3.fn.$$.revertLegend = function () { + var $$ = this, d3 = $$.d3; + $$.legend.selectAll('.' + $$.CLASS.legendItem) + .transition().duration(100) + .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); + }; + c3.fn.$$.showLegend = function (targetIds) { + var $$ = this; + if (!$$.__legend_show) { + $$.__legend_show = true; + $$.legend.style('visibility', 'visible'); + } + $$.removeHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('visibility', 'visible') + .transition() + .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); + }; + c3.fn.$$.hideLegend = function (targetIds) { + var $$ = this; + if ($$.__legend_show && $$.isEmpty(targetIds)) { + $$.__legend_show = false; + $$.legend.style('visibility', 'hidden'); + } + $$.addHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('opacity', 0) + .style('visibility', 'hidden'); + }; + c3.fn.$$.updateLegend = function (targetIds, options, transitions) { + var $$ = this; + var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; + var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; + var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; + var withTransition, withTransitionForTransform; + var hasFocused = $$.legend.selectAll('.' + $$.CLASS.legendItemFocused).size(); + var texts, rects, tiles; + + options = options || {}; + withTransition = $$.getOption(options, "withTransition", true); + withTransitionForTransform = $$.getOption(options, "withTransitionForTransform", true); + + function updatePositions(textElement, id, reset) { + var box = $$.getTextRect(textElement.textContent, $$.CLASS.legendItem), + itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, + itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, + itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, + areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), + margin, maxLength; + + // MEMO: care about condifion of step, totalLength + function updateValues(id, withoutStep) { + if (!withoutStep) { + margin = (areaLength - totalLength - itemLength) / 2; + if (margin < posMin) { + margin = (areaLength - itemLength) / 2; + totalLength = 0; + step++; + } + } + steps[id] = step; + margins[step] = $$.isLegendInset ? 10 : margin; + offsets[id] = totalLength; + totalLength += itemLength; + } - function generateWait() { - var transitionsToWait = [], - f = function (transition, callback) { - var timer = setInterval(function () { - var done = 0; - transitionsToWait.forEach(function (t) { - if (t.empty()) { - done += 1; - return; - } - try { - t.transition(); - } catch (e) { - done += 1; - } - }); - if (done === transitionsToWait.length) { - clearInterval(timer); - if (callback) { callback(); } - } - }, 10); - }; - f.add = function (transition) { - transitionsToWait.push(transition); - }; - return f; - } + if (reset) { + totalLength = 0; + step = 0; + maxWidth = 0; + maxHeight = 0; + } - function getOption(options, key, defaultValue) { - return isDefined(options[key]) ? options[key] : defaultValue; - } + if ($$.__legend_show && !$$.isLegendToShow(id)) { + widths[id] = heights[id] = steps[id] = offsets[id] = 0; + return; + } - function ceil10(v) { - return Math.ceil(v / 10) * 10; - } + widths[id] = itemWidth; + heights[id] = itemHeight; - function getTextRect(text, cls) { - var rect; - d3.select('body').selectAll('.dummy') - .data([text]) - .enter().append('text') - .classed(cls ? cls : "", true) - .text(text) - .each(function () { rect = this.getBoundingClientRect(); }) - .remove(); - return rect; - } + if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } + if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } + maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; - function getInterpolate(d) { - return isSplineType(d) ? "cardinal" : isStepType(d) ? "step-after" : "linear"; - } + if ($$.__legend_equally) { + Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); + Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); + margin = (areaLength - maxLength * targetIds.length) / 2; + if (margin < posMin) { + totalLength = 0; + step = 0; + targetIds.forEach(function (id) { updateValues(id); }); + } + else { + updateValues(id, true); + } + } else { + updateValues(id); + } + } + + if ($$.isLegendRight) { + xForLegend = function (id) { return maxWidth * steps[id]; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else if ($$.isLegendInset) { + xForLegend = function (id) { return maxWidth * steps[id] + 10; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else { + xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + yForLegend = function (id) { return maxHeight * steps[id]; }; + } + xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; + yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; + xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; + yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; + + // Define g for legend area + l = $$.legend.selectAll('.' + $$.CLASS.legendItem) + .data(targetIds) + .enter().append('g') + .attr('class', function (id) { return $$.generateClass($$.CLASS.legendItem, id); }) + .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) + .style('cursor', 'pointer') + .on('click', function (id) { + typeof $$.__legend_item_onclick === 'function' ? $$.__legend_item_onclick.call(c3, id) : $$.this.toggle(id); + }) + .on('mouseover', function (id) { + $$.d3.select(this).classed($$.CLASS.legendItemFocused, true); + if (!$$.transiting) { + $$.this.focus(id); + } + if (typeof $$.__legend_item_onmouseover === 'function') { + $$.__legend_item_onmouseover.call(c3, id); + } + }) + .on('mouseout', function (id) { + $$.d3.select(this).classed($$.CLASS.legendItemFocused, false); + if (!$$.transiting) { + $$.this.revert(); + } + if (typeof $$.__legend_item_onmouseout === 'function') { + $$.__legend_item_onmouseout.call(c3, id); + } + }); + l.append('text') + .text(function (id) { return $$.isDefined($$.__data_names[id]) ? $$.__data_names[id] : id; }) + .each(function (id, i) { updatePositions(this, id, i === 0); }) + .style("pointer-events", "none") + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); + l.append('rect') + .attr("class", $$.CLASS.legendItemEvent) + .style('fill-opacity', 0) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); + l.append('rect') + .attr("class", $$.CLASS.legendItemTile) + .style("pointer-events", "none") + .style('fill', $$.color) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) + .attr('width', 10) + .attr('height', 10); + // Set background for inset legend + if ($$.isLegendInset && maxWidth !== 0) { + $$.legend.insert('g', '.' + $$.CLASS.legendItem) + .attr("class", $$.CLASS.legendBackground) + .append('rect') + .attr('height', $$.getLegendHeight() - 10) + .attr('width', maxWidth * (step + 1) + 10); + } + + texts = $$.legend.selectAll('text') + .data(targetIds) + .text(function (id) { return $$.isDefined($$.__data_names[id]) ? $$.__data_names[id] : id; }) // MEMO: needed for update + .each(function (id, i) { updatePositions(this, id, i === 0); }); + (withTransition ? texts.transition() : texts) + .attr('x', xForLegendText) + .attr('y', yForLegendText); + + rects = $$.legend.selectAll('rect.' + $$.CLASS.legendItemEvent) + .data(targetIds); + (withTransition ? rects.transition() : rects) + .attr('width', function (id) { return widths[id]; }) + .attr('height', function (id) { return heights[id]; }) + .attr('x', xForLegendRect) + .attr('y', yForLegendRect); + + tiles = $$.legend.selectAll('rect.' + $$.CLASS.legendItemTile) + .data(targetIds); + (withTransition ? tiles.transition() : tiles) + .style('fill', $$.color) + .attr('x', xForLegend) + .attr('y', yForLegend); + + // toggle legend state + $$.legend.selectAll('.' + $$.CLASS.legendItem) + .classed($$.CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) + .transition() + .style('opacity', function (id) { + var This = $$.d3.select(this); + if ($$.isTargetToShow(id)) { + return !hasFocused || This.classed($$.CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } else { + return $$.legendOpacityForHidden; + } + }); - function getEmptySelection() { - return d3.selectAll([]); - } + // Update all to reflect change of legend + $$.updateLegendItemWidth(maxWidth); + $$.updateLegendItemHeight(maxHeight); + $$.updateLegendStep(step); + // Update size and scale + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); + // Update g positions + $$.transformAll(withTransitionForTransform, transitions); + }; - //-- Selection --// - function selectPoint(target, d, i) { - __data_onselected.call(c3, d, target.node()); - // add selected-circle on low layer g - main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) - .data([d]) - .enter().append('circle') - .attr("class", function () { return generateClass(CLASS.selectedCircle, i); }) - .attr("cx", __axis_rotated ? circleY : circleX) - .attr("cy", __axis_rotated ? circleX : circleY) - .attr("stroke", function () { return color(d); }) - .attr("r", pointSelectR(d) * 1.4) - .transition().duration(100) - .attr("r", pointSelectR); - } - function unselectPoint(target, d, i) { - __data_onunselected.call(c3, d, target.node()); - // remove selected-circle from low layer g - main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) - .transition().duration(100).attr('r', 0) - .remove(); - } - function togglePoint(selected, target, d, i) { - selected ? selectPoint(target, d, i) : unselectPoint(target, d, i); - } - function selectBar(target, d) { - __data_onselected.call(c3, d, target.node()); - target.transition().duration(100).style("fill", function () { return d3.rgb(color(d)).brighter(0.75); }); - } - function unselectBar(target, d) { - __data_onunselected.call(c3, d, target.node()); - target.transition().duration(100).style("fill", function () { return color(d); }); - } - function toggleBar(selected, target, d, i) { - selected ? selectBar(target, d, i) : unselectBar(target, d, i); - } - function toggleArc(selected, target, d, i) { - toggleBar(selected, target, d.data, i); - } - function getToggle(that) { - // path selection not supported yet - return that.nodeName === 'circle' ? togglePoint : (d3.select(that).classed(CLASS.bar) ? toggleBar : toggleArc); - } - function filterRemoveNull(data) { - return data.filter(function (d) { return isValue(d.value); }); - } + c3.fn.$$.getClipPath = function (id) { + var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; + return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; + }; + c3.fn.$$.getAxisClipX = function (forHorizontal) { + var $$ = this; + // axis line width + padding for left + return forHorizontal ? -(1 + 30) : -($$.margin.left - 1); + }; + c3.fn.$$.getAxisClipY = function (forHorizontal) { + return forHorizontal ? -20 : -4; + }; + c3.fn.$$.getXAxisClipX = function () { + var $$ = this; + return $$.getAxisClipX(!$$.__axis_rotated); + }; + c3.fn.$$.getXAxisClipY = function () { + var $$ = this; + return this.getAxisClipY(!$$.__axis_rotated); + }; + c3.fn.$$.getYAxisClipX = function () { + var $$ = this; + return this.getAxisClipX($$.__axis_rotated); + }; + c3.fn.$$.getYAxisClipY = function () { + var $$ = this; + return this.getAxisClipY($$.__axis_rotated); + }; + c3.fn.$$.getAxisClipWidth = function (forHorizontal) { + var $$ = this; + // width + axis line width + padding for left/right + return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; + }; + c3.fn.$$.getAxisClipHeight = function (forHorizontal) { + var $$ = this; + return forHorizontal ? ($$.__axis_x_height ? $$.__axis_x_height : 0) + 80 : $$.height + 8; + }; + c3.fn.$$.getXAxisClipWidth = function () { + var $$ = this; + return this.getAxisClipWidth(!$$.__axis_rotated); + }; + c3.fn.$$.getXAxisClipHeight = function () { + var $$ = this; + return this.getAxisClipHeight(!$$.__axis_rotated); + }; + c3.fn.$$.getYAxisClipWidth = function () { + var $$ = this; + return this.getAxisClipWidth($$.__axis_rotated); + }; + c3.fn.$$.getYAxisClipHeight = function () { + var $$ = this; + return this.getAxisClipHeight($$.__axis_rotated); + }; - //-- Point --// - function pointR(d) { - return __point_show && !isStepType(d) ? (typeof __point_r === 'function' ? __point_r(d) : __point_r) : 0; - } - function pointExpandedR(d) { - return __point_focus_expand_enabled ? (__point_focus_expand_r ? __point_focus_expand_r : pointR(d) * 1.75) : pointR(d); - } - function pointSelectR(d) { - return __point_select_r ? __point_select_r : pointR(d) * 4; + /** + * $$.data.js + */ + c3.fn.$$.isX = function (key) { + var $$ = this; + return ($$.__data_x && key === $$.__data_x) || (this.notEmpty($$.__data_xs) && this.hasValue($$.__data_xs, key)); + }; + c3.fn.$$.isNotX = function (key) { + return !this.isX(key); + }; + c3.fn.$$.getXKey = function (id) { + var $$ = this; + return $$.__data_x ? $$.__data_x : this.notEmpty($$.__data_xs) ? $$.__data_xs[id] : null; + }; + c3.fn.$$.getXValuesOfXKey = function (key, targets) { + var xValues, ids = targets && this.notEmpty(targets) ? mapToIds(targets) : []; + ids.forEach(function (id) { + if (this.getXKey(id) === key) { + xValues = $$.data.xs[id]; + } + }); + return xValues; + }; + c3.fn.$$.getXValue = function (id, i) { + return id in $$.data.xs && $$.data.xs[id] && this.isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; + }; + c3.fn.$$.getOtherTargetXs = function () { + var idsForX = Object.keys($$.data.xs); + return idsForX.length ? $$.data.xs[idsForX[0]] : null; + }; + c3.fn.$$.getOtherTargetX = function (index) { + var xs = this.getOtherTargetXs(); + return xs && index < xs.length ? xs[index] : null; + }; + c3.fn.$$.addXs = function (xs) { + Object.keys(xs).forEach(function (id) { + $$.__data_xs[id] = xs[id]; + }); + }; + c3.fn.$$.isSingleX = function (xs) { + return $$.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; + }; + c3.fn.$$.addName = function (data) { + var $$ = this, name; + if (data) { + name = $$.__data_names[data.id]; + data.name = name ? name : data.id; } - - //-- Shape --// - - function getCircles(i, id) { - return (id ? main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix(id)) : main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); + return data; + }; + c3.fn.$$.getValueOnIndex = function (values, index) { + var valueOnIndex = values.filter(function (v) { return v.index === index; }); + return valueOnIndex.length ? valueOnIndex[0] : null; + }; + c3.fn.$$.updateTargetX = function (targets, x) { + targets.forEach(function (t) { + t.values.forEach(function (v, i) { + v.x = generateTargetX(x[i], t.id, i); + }); + $$.data.xs[t.id] = x; + }); + }; + c3.fn.$$.updateTargetXs = function (targets, xs) { + targets.forEach(function (t) { + if (xs[t.id]) { + this.updateTargetX([t], xs[t.id]); + } + }); + }; + c3.fn.$$.generateTargetX = function (rawX, id, index) { + var $$ = this, x; + if ($$.isTimeSeries) { + x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); } - function expandCircles(i, id) { - getCircles(i, id) - .classed(CLASS.EXPANDED, true) - .attr('r', pointExpandedR); + else if ($$.isCustomX() && !$$.isCategorized) { + x = $$.isValue(rawX) ? +rawX : $$.getXValue(id, index); } - function unexpandCircles(i) { - getCircles(i) - .filter(function () { return d3.select(this).classed(CLASS.EXPANDED); }) - .classed(CLASS.EXPANDED, false) - .attr('r', pointR); + else { + x = index; } - function getBars(i) { - return main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); + return x; + }; + c3.fn.$$.convertUrlToData = function (url, mimeType, keys, done) { + var type = mimeType ? mimeType : 'csv'; + $$.d3.xhr(url, function (error, data) { + var d; + if (type === 'json') { + d = this.convertJsonToData(JSON.parse(data.response), keys); + } else { + d = this.convertCsvToData(data.response); + } + done(d); + }); + }; + c3.fn.$$.cloneTarget = function (target) { + return { + id : target.id, + id_org : target.id_org, + values : target.values.map(function (d) { + return {x: d.x, value: d.value, id: d.id}; + }) + }; + }; + c3.fn.$$.getPrevX = function (i) { + var value = this.getValueOnIndex($$.data.targets[0].values, i - 1); + return value ? value.x : null; + }; + c3.fn.$$.getNextX = function (i) { + var value = this.getValueOnIndex($$.data.targets[0].values, i + 1); + return value ? value.x : null; + }; + c3.fn.$$.getMaxDataCount = function () { + var $$ = this; + return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); + }; + c3.fn.$$.getMaxDataCountTarget = function (targets) { + var length = targets.length, max = 0, maxTarget; + if (length > 1) { + targets.forEach(function (t) { + if (t.values.length > max) { + maxTarget = t; + max = t.values.length; + } + }); + } else { + maxTarget = length ? targets[0] : null; } - function expandBars(i) { - getBars(i).classed(CLASS.EXPANDED, true); + return maxTarget; + }; + c3.fn.$$.getEdgeX = function (targets) { + var target = this.getMaxDataCountTarget(targets), firstData, lastData; + if (!target) { + return [0, 0]; } - function unexpandBars(i) { - getBars(i).classed(CLASS.EXPANDED, false); + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + return [firstData.x, lastData.x]; + }; + c3.fn.$$.mapToIds = function (targets) { + return targets.map(function (d) { return d.id; }); + }; + c3.fn.$$.mapToTargetIds = function (ids) { + return ids ? (typeof ids === 'string' ? [ids] : ids) : mapToIds($$.data.targets); + }; + c3.fn.$$.hasTarget = function (targets, id) { + var ids = this.mapToIds(targets), i; + for (i = 0; i < ids.length; i++) { + if (ids[i] === id) { + return true; + } } - - function generateDrawArea(areaIndices, isSub) { - var area = d3.svg.area(), - getPoint = generateGetAreaPoint(areaIndices, isSub), - yScaleGetter = isSub ? getSubYScale : getYScale, - value0 = function (d, i) { - return __data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter(d.id)(0); - }, - value1 = function (d, i) { - return __data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter(d.id)(d.value); - }; - - area = __axis_rotated ? area.x0(value0).x1(value1).y(xx) : area.x(xx).y0(value0).y1(value1); - - return function (d) { - var data = filterRemoveNull(d.values), x0 = 0, y0 = 0, path; - - if (isAreaType(d)) { - path = area.interpolate(getInterpolate(d))(data); - } else { - if (data[0]) { - x0 = x(data[0].x); - y0 = getYScale(d.id)(data[0].value); - } - path = __axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + return false; + }; + c3.fn.$$.isTargetToShow = function (targetId) { + return this.hiddenTargetIds.indexOf(targetId) < 0; + }; + c3.fn.$$.isLegendToShow = function (targetId) { + return this.hiddenLegendIds.indexOf(targetId) < 0; + }; + c3.fn.$$.filterTargetsToShow = function (targets) { + var $$ = this; + return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); + }; + c3.fn.$$.mapTargetsToUniqueXs = function (targets) { + var $$ = this; + var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); + return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); + }; + c3.fn.$$.addHiddenTargetIds = function (targetIds) { + var $$ = this; + $$.hiddenTargetIds = $$.hiddenTargetIds.concat(targetIds); + }; + c3.fn.$$.removeHiddenTargetIds = function (targetIds) { + var $$ = this; + $$.hiddenTargetIds = $$.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + }; + c3.fn.$$.addHiddenLegendIds = function (targetIds) { + var $$ = this; + $$.hiddenLegendIds = $$.hiddenLegendIds.concat(targetIds); + }; + c3.fn.$$.removeHiddenLegendIds = function (targetIds) { + var $$ = this; + $$.hiddenLegendIds = $$.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + }; + c3.fn.$$.getValuesAsIdKeyed = function (targets) { + var ys = {}; + targets.forEach(function (t) { + ys[t.id] = []; + t.values.forEach(function (v) { + ys[t.id].push(v.value); + }); + }); + return ys; + }; + c3.fn.$$.checkValueInTargets = function (targets, checker) { + var ids = Object.keys(targets), i, j, values; + for (i = 0; i < ids.length; i++) { + values = targets[ids[i]].values; + for (j = 0; j < values.length; j++) { + if (checker(values[j].value)) { + return true; } - return path ? path : "M 0 0"; - }; + } } - - function generateDrawLine(lineIndices, isSub) { - var line = d3.svg.line(), - getPoint = generateGetLinePoint(lineIndices, isSub), - yScaleGetter = isSub ? getSubYScale : getYScale, - xValue = isSub ? subxx : xx, - yValue = function (d, i) { - return __data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter(d.id)(d.value); - }; - - line = __axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); - if (!__line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } - return function (d) { - var data = __line_connect_null ? filterRemoveNull(d.values) : d.values, - x = isSub ? x : subX, y = yScaleGetter(d.id), x0 = 0, y0 = 0, path; - if (isLineType(d)) { - if (__data_regions[d.id]) { - path = lineWithRegions(data, x, y, __data_regions[d.id]); - } else { - path = line.interpolate(getInterpolate(d))(data); - } - } else { - if (data[0]) { - x0 = x(data[0].x); - y0 = y(data[0].value); - } - path = __axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; - } - return path ? path : "M 0 0"; - }; + return false; + }; + c3.fn.$$.hasNegativeValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v < 0; }); + }; + c3.fn.$$.hasPositiveValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v > 0; }); + }; + c3.fn.$$.isOrderDesc = function () { + var $$ = this; + return $$.__data_order && $$.__data_order.toLowerCase() === 'desc'; + }; + c3.fn.$$.isOrderAsc = function () { + var $$ = this; + return $$.__data_order && $$.__data_order.toLowerCase() === 'asc'; + }; + c3.fn.$$.orderTargets = function (targets) { + var $$ = this, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); + if (orderAsc || orderDesc) { + targets.sort(function (t1, t2) { + var reducer = function (p, c) { return p + Math.abs(c.value); }; + var t1Sum = t1.values.reduce(reducer, 0), + t2Sum = t2.values.reduce(reducer, 0); + return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; + }); + } else if (typeof $$.__data_order === 'function') { + targets.sort($$.__data_order); + } // TODO: accept name array for order + return targets; + }; + c3.fn.$$.filterSameX = function (targets, x) { + return $$.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); + }; + c3.fn.$$.filterRemoveNull = function (data) { + var $$ = this; + return data.filter(function (d) { return $$.isValue(d.value); }); + }; + c3.fn.$$.hasDataLabel = function () { + var $$ = this; + if (typeof $$.__data_labels === 'boolean' && $$.__data_labels) { + return true; + } else if (typeof $$.__data_labels === 'object' && this.notEmpty($$.__data_labels)) { + return true; } + return false; + }; + c3.fn.$$.getDataLabelLength = function (min, max, axisId, key) { + var lengths = [0, 0], paddingCoef = 1.3; + $$.selectChart.select('svg').selectAll('.dummy') + .data([min, max]) + .enter().append('text') + .text(function (d) { return this.formatByAxisId(axisId)(d); }) + .each(function (d, i) { + lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; + }) + .remove(); + return lengths; + }; + c3.fn.$$.isNoneArc = function (d) { + var $$ = this; + return $$.hasTarget($$.data.targets, d.id); + }; + c3.fn.$$.isArc = function (d) { + var $$ = this; + return 'data' in d && $$.hasTarget($$.data.targets, d.data.id); + }; - function generateDrawBar(barIndices, isSub) { - var getPoints = generateGetBarPoints(barIndices, isSub); - return function (d, i) { - // 4 points that make a bar - var points = getPoints(d, i); - - // switch points if axis is rotated, not applicable for sub chart - var indexX = __axis_rotated ? 1 : 0; - var indexY = __axis_rotated ? 0 : 1; - - var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + - 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + - 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + - 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + - 'z'; - return path; - }; + /** + * c3.data.convert.js + */ + c3.fn.$$.convertCsvToData = function (csv) { + var rows = $$.d3.csv.parseRows(csv), d; + if (rows.length === 1) { + d = [{}]; + rows[0].forEach(function (id) { + d[0][id] = null; + }); + } else { + d = $$.d3.csv.parse(csv); } - function generateXYForText(barIndices, forX) { - var getPoints = generateGetBarPoints(barIndices, false), - getter = forX ? getXForText : getYForText; - return function (d, i) { - return getter(getPoints(d, i), d, this); - }; + return d; + }; + c3.fn.$$.convertJsonToData = function (json, keys) { + var new_rows = [], targetKeys, data; + if (keys) { // when keys specified, json would be an array that includes objects + targetKeys = keys.value; + if (keys.x) { + targetKeys.push(keys.x); + $$.__data_x = keys.x; + } + new_rows.push(targetKeys); + json.forEach(function (o) { + var new_row = []; + targetKeys.forEach(function (key) { + // convert undefined to null because undefined data will be removed in convertDataToTargets() + var v = typeof o[key] === 'undefined' ? null : o[key]; + new_row.push(v); + }); + new_rows.push(new_row); + }); + data = this.convertRowsToData(new_rows); + } else { + Object.keys(json).forEach(function (key) { + new_rows.push([key].concat(json[key])); + }); + data = this.convertColumnsToData(new_rows); } - function getXForText(points, d, textElement) { - var box = textElement.getBoundingClientRect(), xPos, padding; - if (__axis_rotated) { - padding = isBarType(d) ? 4 : 6; - xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); - } else { - xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + return data; + }; + c3.fn.$$.convertRowsToData = function (rows) { + var keys = rows[0], new_row = {}, new_rows = [], i, j; + for (i = 1; i < rows.length; i++) { + new_row = {}; + for (j = 0; j < rows[i].length; j++) { + new_row[keys[j]] = rows[i][j]; } - return xPos > width ? width - box.width : xPos; + new_rows.push(new_row); } - function getYForText(points, d, textElement) { - var box = textElement.getBoundingClientRect(), yPos; - if (__axis_rotated) { - yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; - } else { - yPos = points[2][1] + (d.value < 0 ? box.height : isBarType(d) ? -3 : -6); - } - return yPos < box.height ? box.height : yPos; - } - - function generateGetAreaPoint(areaIndices, isSub) { // partial duplication of generateGetBarPoints - var areaTargetsNum = areaIndices.__max__ + 1, - x = getShapeX(0, areaTargetsNum, areaIndices, !!isSub), - y = getShapeY(!!isSub), - areaOffset = getShapeOffset(isAreaType, areaIndices, !!isSub), - yScale = isSub ? getSubYScale : getYScale; - return function (d, i) { - var y0 = yScale(d.id)(0), - offset = areaOffset(d, i) || y0, // offset is for stacked area chart - posX = x(d), posY = y(d); - // fix posY not to overflow opposite quadrant - if (__axis_rotated) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + return new_rows; + }; + c3.fn.$$.convertColumnsToData = function (columns) { + var new_rows = [], i, j, key; + for (i = 0; i < columns.length; i++) { + key = columns[i][0]; + for (j = 1; j < columns[i].length; j++) { + if (this.isUndefined(new_rows[j - 1])) { + new_rows[j - 1] = {}; } - // 1 point that marks the area position - return [ - [posX, offset], - [posX, posY - (y0 - offset)] - ]; - }; + new_rows[j - 1][key] = columns[i][j]; + } } - - function generateGetBarPoints(barIndices, isSub) { - var barTargetsNum = barIndices.__max__ + 1, - barW = getBarW(xAxis, barTargetsNum), - barX = getShapeX(barW, barTargetsNum, barIndices, !!isSub), - barY = getShapeY(!!isSub), - barOffset = getShapeOffset(isBarType, barIndices, !!isSub), - yScale = isSub ? getSubYScale : getYScale; - return function (d, i) { - var y0 = yScale(d.id)(0), - offset = barOffset(d, i) || y0, // offset is for stacked bar chart - posX = barX(d), posY = barY(d); - // fix posY not to overflow opposite quadrant - if (__axis_rotated) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + return new_rows; + }; + c3.fn.$$.convertDataToTargets = function (data, appendXs) { + var $$ = this; + var ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), + xs = $$.d3.keys(data[0]).filter($$.isX, $$), + targets; + + // save x for update data by load when custom x and c3.x API + ids.forEach(function (id) { + var xKey = $$.getXKey(id); + + if ($$.isCustomX() || $$.isTimeSeries) { + // if included in input data + if (xs.indexOf(xKey) >= 0) { + $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( + data.map(function (d) { return d[xKey]; }) + .filter(this.isValue) + .map(function (rawX, i) { return this.generateTargetX(rawX, id, i); }) + ); } - // 4 points that make a bar - return [ - [posX, offset], - [posX, posY - (y0 - offset)], - [posX + barW, posY - (y0 - offset)], - [posX + barW, offset] - ]; - }; - } - - function generateGetLinePoint(lineIndices, isSub) { // partial duplication of generateGetBarPoints - var lineTargetsNum = lineIndices.__max__ + 1, - x = getShapeX(0, lineTargetsNum, lineIndices, !!isSub), - y = getShapeY(!!isSub), - lineOffset = getShapeOffset(isLineType, lineIndices, !!isSub), - yScale = isSub ? getSubYScale : getYScale; - return function (d, i) { - var y0 = yScale(d.id)(0), - offset = lineOffset(d, i) || y0, // offset is for stacked area chart - posX = x(d), posY = y(d); - // fix posY not to overflow opposite quadrant - if (__axis_rotated) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + // if not included in input data, find from preloaded data of other id's x + else if ($$.__data_x) { + $$.data.xs[id] = this.getOtherTargetXs(); } - // 1 point that marks the line position - return [ - [posX, posY - (y0 - offset)] - ]; - }; - } - - function lineWithRegions(d, x, y, _regions) { - var prev = -1, i, j; - var s = "M", sWithRegion; - var xp, yp, dx, dy, dd, diff, diffx2; - var xValue, yValue; - var regions = []; - - // Check start/end of regions - if (isDefined(_regions)) { - for (i = 0; i < _regions.length; i++) { - regions[i] = {}; - if (isUndefined(_regions[i].start)) { - regions[i].start = d[0].x; - } else { - regions[i].start = isTimeSeries ? parseDate(_regions[i].start) : _regions[i].start; - } - if (isUndefined(_regions[i].end)) { - regions[i].end = d[d.length - 1].x; - } else { - regions[i].end = isTimeSeries ? parseDate(_regions[i].end) : _regions[i].end; - } + // if not included in input data, find from preloaded data + else if (this.notEmpty($$.__data_xs)) { + $$.data.xs[id] = this.getXValuesOfXKey(xKey, $$.data.targets); } - } - - // Set scales - xValue = __axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); }; - yValue = __axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; - - // Define svg generator function for region - if (isTimeSeries) { - sWithRegion = function (d0, d1, j, diff) { - var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, - xv0 = new Date(x0 + x_diff * j), - xv1 = new Date(x0 + x_diff * (j + diff)); - return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); - }; + // MEMO: if no x included, use same x of current will be used } else { - sWithRegion = function (d0, d1, j, diff) { - return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); - }; + $$.data.xs[id] = data.map(function (d, i) { return i; }); } + }, this); - // Generate - for (i = 0; i < d.length; i++) { - - // Draw as normal - if (isUndefined(regions) || ! isWithinRegions(d[i].x, regions)) { - s += " " + xValue(d[i]) + " " + yValue(d[i]); - } - // Draw with region // TODO: Fix for horizotal charts - else { - xp = getScale(d[i - 1].x, d[i].x, isTimeSeries); - yp = getScale(d[i - 1].value, d[i].value); - - dx = x(d[i].x) - x(d[i - 1].x); - dy = y(d[i].value) - y(d[i - 1].value); - dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - diff = 2 / dd; - diffx2 = diff * 2; - - for (j = diff; j <= 1; j += diffx2) { - s += sWithRegion(d[i - 1], d[i], j, diff); - } - } - prev = d[i].x; + // check x is defined + ids.forEach(function (id) { + if (!$$.data.xs[id]) { + throw new Error('x is not defined for id = "' + id + '".'); } + }); - return s; - } - - //-- Define brush/zoom -// - - var brush, zoom = function () {}; - - brush = d3.svg.brush().on("brush", redrawForBrush); - brush.update = function () { - if (context) { context.select('.' + CLASS.brush).call(this); } - return this; - }; - brush.scale = function (scale) { - return __axis_rotated ? this.y(scale) : this.x(scale); - }; + // convert to target + targets = ids.map(function (id, index) { + var convertedId = $$.__data_id_converter(id); + return { + id: convertedId, + id_org: id, + values: data.map(function (d, i) { + var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); + // use x as categories if custom x and categorized + if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { + if (i === 0) { $$.__axis_x_categories = []; } + $$.__axis_x_categories.push(rawX); + } + // mark as x = undefined if value is undefined and filter to remove after mapped + if (typeof d[id] === 'undefined' || $$.data.xs[id].length <= i) { + x = undefined; + } + return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; + }).filter(function (v) { return typeof v.x !== 'undefined'; }) + }; + }); - zoom = d3.behavior.zoom() - .on("zoomstart", function () { zoom.altDomain = d3.event.sourceEvent.altKey ? x.orgDomain() : null; }) - .on("zoom", redrawForZoom); - zoom.scale = function (scale) { - return __axis_rotated ? this.y(scale) : this.x(scale); - }; - zoom.orgScaleExtent = function () { - var extent = __zoom_extent ? __zoom_extent : [1, 10]; - return [extent[0], Math.max(getMaxDataCount() / extent[1], extent[1])]; - }; - zoom.updateScaleExtent = function () { - var ratio = diffDomain(x.orgDomain()) / diffDomain(orgXDomain), extent = this.orgScaleExtent(); - this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); - return this; - }; + // finish targets + targets.forEach(function (t) { + var i; + // sort values by its x + t.values = t.values.sort(function (v1, v2) { + var x1 = v1.x || v1.x === 0 ? v1.x : Infinity, + x2 = v2.x || v2.x === 0 ? v2.x : Infinity; + return x1 - x2; + }); + // indexing each value + i = 0; + t.values.forEach(function (v) { + v.index = i++; + }); + // this needs to be sorted because its index and value.index is identical + $$.data.xs[t.id].sort(function (v1, v2) { + return v1 - v2; + }); + }); - function updateZoom() { - var z = __zoom_enabled ? zoom : function () {}; - main.select('.' + CLASS.zoomRect).call(z); - main.selectAll('.' + CLASS.eventRect).call(z); + // set target types + if ($$.__data_type) { + this.setTargetType(this.mapToIds(targets).filter(function (id) { return ! (id in $$.__data_types); }), $$.__data_type); } - /*-- Draw Chart --*/ - - // for svg elements - var svg, defs, main, context, legend, tooltip, selectChart; - - // for brush area culculation - var orgXDomain; + // cache as original id keyed + targets.forEach(function (d) { + $$.addCache(d.id_org, d); + }); - // for save value - var orgAreaOpacity, withoutFadeIn = {}; + return targets; + }; - function updateDimension() { - if (__axis_rotated) { - axes.x.call(xAxis); - axes.subx.call(subXAxis); - } else { - axes.y.call(yAxis); - axes.y2.call(y2Axis); + /** + * c3.data.load.js + */ + c3.fn.$$.load = function (targets, args) { + var $$ = this; + if (targets) { + // filter loading targets if needed + if (args.filter) { + targets = targets.filter(args.filter); + } + // set type if args.types || args.type specified + if (args.type || args.types) { + targets.forEach(function (t) { + $$.setTargetType(t.id, args.types ? args.types[t.id] : args.type); + }); } - updateSizes(); - updateScales(); - updateSvgSize(); - transformAll(false); - } - - function observeInserted(selection) { - var 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 - var interval = window.setInterval(function () { - // parentNode will NOT be null when completed - if (selection.node().parentNode) { - window.clearInterval(interval); - updateDimension(); - redraw({ - withTransform: true, - withUpdateXDomain: true, - withUpdateOrgXDomain: true, - withTransition: false, - withTransitionForTransform: false, - withLegend: true - }); - selection.transition().style('opacity', 1); - } - }, 10); + // Update/Add data + $$.data.targets.forEach(function (d) { + for (var i = 0; i < targets.length; i++) { + if (d.id === targets[i].id) { + d.values = targets[i].values; + targets.splice(i, 1); + break; } - }); + } }); - observer.observe(selection.node(), {attributes: true, childList: true, characterData: true}); + $$.data.targets = $$.data.targets.concat(targets); // add remained } - function init(data) { - var arcs, eventRect, grid, i, binding = true; - - selectChart = d3.select(__bindto); - if (selectChart.empty()) { - selectChart = d3.select(document.createElement('div')).style('opacity', 0); - observeInserted(selectChart); - binding = false; - } - selectChart.html("").classed("c3", true); + // Set targets + $$.updateTargets($$.data.targets); - // Init data as targets - c3.data.xs = {}; - c3.data.targets = convertDataToTargets(data); + // Redraw with new targets + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (__data_filter) { - c3.data.targets = c3.data.targets.filter(__data_filter); - } - - // Set targets to hide if needed - if (__data_hide) { - addHiddenTargetIds(__data_hide === true ? mapToIds(c3.data.targets) : __data_hide); - } - - // when gauge, hide legend // TODO: fix - if (hasGaugeType(c3.data.targets)) { - __legend_show = false; - } - - // Init sizes and scales - updateSizes(); - updateScales(); - - // Set domains for each scale - x.domain(d3.extent(getXDomain(c3.data.targets))); - y.domain(getYDomain(c3.data.targets, 'y')); - y2.domain(getYDomain(c3.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 - brush.scale(subX); - if (__zoom_enabled) { zoom.scale(x); } - - /*-- Basic Elements --*/ - - // Define svgs - svg = selectChart.append("svg") - .style("overflow", "hidden") - .on('mouseenter', function () { return __onmouseover.call(c3); }) - .on('mouseleave', function () { return __onmouseout.call(c3); }); - - // Define defs - defs = svg.append("defs"); - defs.append("clipPath").attr("id", clipId).append("rect"); - defs.append("clipPath").attr("id", clipIdForXAxis).append("rect"); - defs.append("clipPath").attr("id", clipIdForYAxis).append("rect"); - updateSvgSize(); - - // Define regions - main = svg.append("g").attr("transform", translate.main); - context = svg.append("g").attr("transform", translate.context); - legend = svg.append("g").attr("transform", translate.legend); - - if (!__subchart_show) { - context.style('visibility', 'hidden'); - } - - if (!__legend_show) { - legend.style('visibility', 'hidden'); - hiddenLegendIds = mapToIds(c3.data.targets); - } - - // Define tooltip - tooltip = selectChart - .style("position", "relative") - .append("div") - .style("position", "absolute") - .style("pointer-events", "none") - .style("z-index", "10") - .style("display", "none"); - - // MEMO: call here to update legend box and tranlate for all - // MEMO: translate will be upated by this, so transform not needed in updateLegend() - updateLegend(mapToIds(c3.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); - - /*-- 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 - main.append('g') - .attr("clip-path", clipPath) - .attr("class", CLASS.regions); - - // Grids - grid = main.append('g') - .attr("clip-path", clipPath) - .attr('class', CLASS.grid); - if (__grid_x_show) { - grid.append("g").attr("class", CLASS.xgrids); - } - if (__grid_y_show) { - grid.append('g').attr('class', CLASS.ygrids); - } - grid.append('g').attr("class", CLASS.xgridLines); - grid.append('g').attr('class', CLASS.ygridLines); - if (__grid_focus_show) { - grid.append('g') - .attr("class", CLASS.xgridFocus) - .append('line') - .attr('class', CLASS.xgridFocus); - } + if (typeof args.done === 'function') { + args.done(); + } + }; + c3.fn.$$.loadFromArgs = function (args) { + var $$ = this; + if (args.data) { + $$.load($$.convertDataToTargets(args.data), args); + } + else if (args.url) { + $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { + $$.load($$.convertDataToTargets(data), args); + }); + } + else if (args.json) { + $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); + } + else if (args.rows) { + $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); + } + else if (args.columns) { + $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); + } + else { + $$.load(null, args); + } + }; + c3.fn.$$.unload = function (targetIds, done) { + var $$ = this; + if (typeof done !== 'function') { + done = function () {}; + } + // filter existing target + targetIds = targetIds.filter(function (id) { return $$.hasTarget($$.data.targets, id); }); + // If no target, call done and return + if (!targetIds || targetIds.length === 0) { + done(); + return; + } + $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) + .transition() + .style('opacity', 0) + .remove() + .call($$.endall, done); + targetIds.forEach(function (id) { + // Reset fadein for future load + $$.withoutFadeIn[id] = false; + // Remove target's elements + $$.legend.selectAll('.' + $$.CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); + // Remove target + $$.data.targets = $$.data.targets.filter(function (t) { + return t.id !== id; + }); + }); + }; - // Define g for chart area - main.append('g') - .attr("clip-path", clipPath) - .attr('class', CLASS.chart); - - // Cover whole with rects for events - eventRect = main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.eventRects) - .style('fill-opacity', 0); - - // Define g for bar chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); - - // Define g for line chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); - - // Define g for arc chart area - arcs = main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartArcs) - .attr("transform", translate.arc); - arcs.append('text') - .attr('class', CLASS.chartArcsTitle) - .style("text-anchor", "middle") - .text(getArcTitle()); - if (hasGaugeType(c3.data.targets)) { - arcs.append('path') - .attr("class", CLASS.chartArcsBackground) - .attr("d", function () { - var d = { - data: [{value: __gauge_max}], - startAngle: -1 * (Math.PI / 2), - endAngle: Math.PI / 2 - }; - return getArc(d, true, true); - }); - arcs.append("text") - .attr("dy", ".75em") - .attr("class", CLASS.chartArcsGaugeUnit) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(__gauge_label_show ? __gauge_units : ''); - arcs.append("text") - .attr("dx", -1 * (innerRadius + ((radius - innerRadius) / 2)) + "px") - .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMin) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(__gauge_label_show ? __gauge_min : ''); - arcs.append("text") - .attr("dx", innerRadius + ((radius - innerRadius) / 2) + "px") - .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMax) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(__gauge_label_show ? __gauge_max : ''); - } - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartTexts); + /** + * c3.data.category.js + */ + c3.fn.$$.categoryName = function (i) { + var $$ = this; + return i < $$.__axis_x_categories.length ? $$.__axis_x_categories[i] : i; + }; - // if zoom privileged, insert rect to forefront - main.insert('rect', __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 (__axis_x_default) { - brush.extent(typeof __axis_x_default !== 'function' ? __axis_x_default : __axis_x_default(getXDomain())); - } - // Add Axis - axes.x = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisX) - .attr("clip-path", clipPathForXAxis) - .attr("transform", translate.x) - .style("visibility", __axis_x_show ? 'visible' : 'hidden'); - axes.x.append("text") - .attr("class", CLASS.axisXLabel) - .attr("transform", __axis_rotated ? "rotate(-90)" : "") - .style("text-anchor", textAnchorForXAxisLabel); - - axes.y = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY) - .attr("clip-path", clipPathForYAxis) - .attr("transform", translate.y) - .style("visibility", __axis_y_show ? 'visible' : 'hidden'); - axes.y.append("text") - .attr("class", CLASS.axisYLabel) - .attr("transform", __axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", textAnchorForYAxisLabel); - - axes.y2 = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY2) - // clip-path? - .attr("transform", translate.y2) - .style("visibility", __axis_y2_show ? 'visible' : 'hidden'); - axes.y2.append("text") - .attr("class", CLASS.axisY2Label) - .attr("transform", __axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", textAnchorForY2AxisLabel); - - /*-- Context Region --*/ - - // Define g for chart area - context.append('g') - .attr("clip-path", clipPath) - .attr('class', CLASS.chart); - - // Define g for bar chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); - - // Define g for line chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); - - // Add extent rect for Brush - context.append("g") - .attr("clip-path", clipPath) - .attr("class", CLASS.brush) - .call(brush) - .selectAll("rect") - .attr(__axis_rotated ? "width" : "height", __axis_rotated ? width2 : height2); - - // ATTENTION: This must be called AFTER chart added - // Add Axis - axes.subx = context.append("g") - .attr("class", CLASS.axisX) - .attr("transform", translate.subx) - .attr("clip-path", __axis_rotated ? "" : clipPathForXAxis); - - // Set targets - updateTargets(c3.data.targets); - - // Draw with targets - if (binding) { - updateDimension(); - redraw({ - withTransform: true, - withUpdateXDomain: true, - withUpdateOrgXDomain: true, - withTransitionForAxis: false, - }); - } - // Show tooltip if needed - if (__tooltip_init_show) { - if (isTimeSeries && typeof __tooltip_init_x === 'string') { - __tooltip_init_x = parseDate(__tooltip_init_x); - for (i = 0; i < c3.data.targets[0].values.length; i++) { - if ((c3.data.targets[0].values[i].x - __tooltip_init_x) === 0) { break; } - } - __tooltip_init_x = i; + /** + * c3.shape.js + */ + c3.fn.$$.getShapeIndices = function (typeFilter) { + var $$ = this; + var indices = {}, i = 0, j, k; + $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { + for (j = 0; j < $$.__data_groups.length; j++) { + if ($$.__data_groups[j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < $$.__data_groups[j].length; k++) { + if ($$.__data_groups[j][k] in indices) { + indices[d.id] = indices[$$.__data_groups[j][k]]; + break; + } } - tooltip.html(__tooltip_contents(c3.data.targets.map(function (d) { - return addName(d.values[__tooltip_init_x]); - }), getXAxisTickFormat(), getYFormat(hasArcType(c3.data.targets)), color)); - tooltip.style("top", __tooltip_init_position.top) - .style("left", __tooltip_init_position.left) - .style("display", "block"); } + if ($$.isUndefined(indices[d.id])) { indices[d.id] = i++; } + }); + indices.__max__ = i - 1; + return indices; + }; + c3.fn.$$.getShapeX = function (offset, targetsNum, indices, isSub) { + var $$ = this, scale = isSub ? $$.subX : $$.x; + return function (d) { + var index = d.id in indices ? indices[d.id] : 0; + return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; + }; + }; + c3.fn.$$.getShapeY = function (isSub) { + var $$ = this; + return function (d) { + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); + return scale(d.value); + }; + }; + c3.fn.$$.getShapeOffset = function (typeFilter, indices, isSub) { + var $$ = this, + targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), + targetIds = targets.map(function (t) { return t.id; }); + return function (d, i) { + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id), + y0 = scale(0), offset = y0; + targets.forEach(function (t) { + if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } + if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id) && t.values[i].value * d.value >= 0) { + offset += scale(t.values[i].value) - y0; + } + }); + return offset; + }; + }; - // Bind resize event - if (window.onresize == null) { - window.onresize = generateResize(); - } - if (window.onresize.add) { - window.onresize.add(function () { - __onresize.call(c3); - }); - window.onresize.add(function () { - c3.flush(); - }); - window.onresize.add(function () { - __onresized.call(c3); - }); - } - - // export element of the chart - c3.element = selectChart.node(); - } - - function generateEventRectsForSingleX(eventRectEnter) { - eventRectEnter.append("rect") - .attr("class", classEvent) - .style("cursor", __data_selection_enabled && __data_selection_grouped ? "pointer" : null) - .on('mouseover', function (d) { - var index = d.index, selectedData, newData; - - if (dragging) { return; } // do nothing if dragging - if (hasArcType(c3.data.targets)) { return; } - - selectedData = c3.data.targets.map(function (t) { - return addName(getValueOnIndex(t.values, index)); - }); + c3.fn.$$.getInterpolate = function (d) { + var $$ = this; + return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; + }; - // Sort selectedData as names order - newData = []; - Object.keys(__data_names).forEach(function (id) { - for (var j = 0; j < selectedData.length; j++) { - if (selectedData[j] && selectedData[j].id === id) { - newData.push(selectedData[j]); - selectedData.shift(j); - break; - } - } - }); - selectedData = newData.concat(selectedData); // Add remained - // Expand shapes for selection - if (__point_focus_expand_enabled) { expandCircles(index); } - expandBars(index); + c3.fn.$$.circleX = function (d) { + var $$ = this; + return d.x || d.x === 0 ? $$.x(d.x) : null; + }; + c3.fn.$$.circleY = function (d, i) { + var $$ = this, lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + }; + c3.fn.$$.getCircles = function (i, id) { + var $$ = this, CLASS = $$.CLASS; + return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); + }; + c3.fn.$$.expandCircles = function (i, id) { + var $$ = this, CLASS = $$.CLASS; + $$.getCircles(i, id) + .classed(CLASS.EXPANDED, true) + .attr('r', function (d) { return $$.pointExpandedR(d); }); + }; + c3.fn.$$.unexpandCircles = function (i) { + var $$ = this, CLASS = $$.CLASS; + $$.getCircles(i) + .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) + .classed(CLASS.EXPANDED, false) + .attr('r', function (d) { return $$.pointR(d); }); + }; + c3.fn.$$.pointR = function (d) { + var $$ = this; + return $$.__point_show && !$$.isStepType(d) ? (typeof $$.__point_r === 'function' ? $$.__point_r(d) : $$.__point_r) : 0; + }; + c3.fn.$$.pointExpandedR = function (d) { + var $$ = this; + return $$.__point_focus_expand_enabled ? ($$.__point_focus_expand_r ? $$.__point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); + }; + c3.fn.$$.pointSelectR = function (d) { + var $$ = this; + return $$.__point_select_r ? $$.__point_select_r : $$.pointR(d) * 4; + }; - // Call event handler - main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - __data_onmouseover.call(c3, d); - }); - }) - .on('mouseout', function (d) { - var index = d.index; - if (hasArcType(c3.data.targets)) { return; } - hideXGridFocus(); - hideTooltip(); - // Undo expanded shapes - unexpandCircles(index); - unexpandBars(); - // Call event handler - main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - __data_onmouseout.call(c3, d); - }); - }) - .on('mousemove', function (d) { - var selectedData, index = d.index, eventRect = svg.select('.' + CLASS.eventRect + '-' + index); - if (dragging) { return; } // do nothing when dragging - if (hasArcType(c3.data.targets)) { return; } - // Show tooltip - selectedData = filterTargetsToShow(c3.data.targets).map(function (t) { - return addName(getValueOnIndex(t.values, index)); - }); + c3.fn.$$.getBarW = function (axis, barTargetsNum) { + var $$ = this; + return typeof $$.__bar_width === 'number' ? $$.__bar_width : barTargetsNum ? (axis.tickOffset() * 2 * $$.__bar_width_ratio) / barTargetsNum : 0; + }; + c3.fn.$$.getBars = function (i) { + var $$ = this; + return $$.main.selectAll('.' + this.CLASS.bar + (this.isValue(i) ? '-' + i : '')); + }; + c3.fn.$$.expandBars = function (i) { + this.getBars(i).classed(this.CLASS.EXPANDED, true); + }; + c3.fn.$$.unexpandBars = function (i) { + this.getBars(i).classed(this.CLASS.EXPANDED, false); + }; + c3.fn.$$.generateDrawBar = function (barIndices, isSub) { + var $$ = this, getPoints = this.generateGetBarPoints(barIndices, isSub); + return function (d, i) { + // 4 points that make a bar + var points = getPoints(d, i); + + // switch points if axis is rotated, not applicable for sub chart + var indexX = $$.__axis_rotated ? 1 : 0; + var indexY = $$.__axis_rotated ? 0 : 1; + + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + + 'z'; + + return path; + }; + }; + c3.fn.$$.generateGetBarPoints = function (barIndices, isSub) { + var $$ = this, + barTargetsNum = barIndices.__max__ + 1, + barW = $$.getBarW($$.xAxis, barTargetsNum), + barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = $$.getShapeY(!!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = barOffset(d, i) || y0, // offset is for stacked bar chart + posX = barX(d), posY = barY(d); + // fix posY not to overflow opposite quadrant + if ($$.__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 4 points that make a bar + return [ + [posX, offset], + [posX, posY - (y0 - offset)], + [posX + barW, posY - (y0 - offset)], + [posX + barW, offset] + ]; + }; + }; - if (__tooltip_grouped) { - showTooltip(selectedData, d3.mouse(this)); - showXGridFocus(selectedData); - } + c3.fn.$$.generateDrawArea = function (areaIndices, isSub) { + var $$ = this, area = $$.d3.svg.area(), + getPoint = $$.generateGetAreaPoint(areaIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + value0 = function (d, i) { + return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + }, + value1 = function (d, i) { + return $$.__data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value); + }; - if (__tooltip_grouped && (!__data_selection_enabled || __data_selection_grouped)) { - return; - } + area = $$.__axis_rotated ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); - main.selectAll('.' + CLASS.shape + '-' + index) - .each(function () { - d3.select(this).classed(CLASS.EXPANDED, true); - if (__data_selection_enabled) { - eventRect.style('cursor', __data_selection_grouped ? 'pointer' : null); - } - if (!__tooltip_grouped) { - hideXGridFocus(); - hideTooltip(); - if (!__data_selection_grouped) { - unexpandCircles(index); - unexpandBars(); - } - } - }) - .filter(function (d) { - if (this.nodeName === 'circle') { - return isWithinCircle(this, pointSelectR(d)); - } - else if (this.nodeName === 'path') { - return isWithinBar(this); - } - }) - .each(function (d) { - if (__data_selection_enabled && (__data_selection_grouped || __data_selection_isselectable(d))) { - eventRect.style('cursor', 'pointer'); - } - if (!__tooltip_grouped) { - showTooltip([d], d3.mouse(this)); - showXGridFocus([d]); - if (__point_focus_expand_enabled) { expandCircles(index, d.id); } - expandBars(index, d.id); - } - }); - }) - .on('click', function (d) { - var index = d.index; - if (hasArcType(c3.data.targets)) { return; } - if (cancelClick) { - cancelClick = false; - return; - } - main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { toggleShape(this, d, index); }); - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { drag(d3.mouse(this)); }) - .on('dragstart', function () { dragstart(d3.mouse(this)); }) - .on('dragend', function () { dragend(); }) - ) - .on("dblclick.zoom", null); - } - - function generateEventRectsForMultipleXs(eventRectEnter) { - eventRectEnter.append('rect') - .attr('x', 0) - .attr('y', 0) - .attr('width', width) - .attr('height', height) - .attr('class', CLASS.eventRect) - .on('mouseout', function () { - if (hasArcType(c3.data.targets)) { return; } - hideXGridFocus(); - hideTooltip(); - unexpandCircles(); - }) - .on('mousemove', function () { - var targetsToShow = filterTargetsToShow(c3.data.targets); - var mouse, closest, sameXData, selectedData; - - if (dragging) { return; } // do nothing when dragging - if (hasArcType(targetsToShow)) { return; } - - mouse = d3.mouse(this); - closest = findClosestFromTargets(targetsToShow, mouse); - - if (! closest) { return; } - - if (isScatterType(closest)) { - sameXData = [closest]; - } else { - sameXData = filterSameX(targetsToShow, closest.x); - } + return function (d) { + var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + if ($$.isAreaType(d)) { + path = area.interpolate($$.getInterpolate(d))(data); + } else { + if (data[0]) { + x0 = $$.x(data[0].x); + y0 = $$.getYScale(d.id)(data[0].value); + } + path = $$.__axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; + }; - // show tooltip when cursor is close to some point - selectedData = sameXData.map(function (d) { - return addName(d); - }); - showTooltip(selectedData, mouse); + c3.fn.$$.generateDrawLine = function (lineIndices, isSub) { + var $$ = this, line = $$.d3.svg.line(), + getPoint = $$.generateGetLinePoint(lineIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + yValue = function (d, i) { + return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); + }; - // expand points - if (__point_focus_expand_enabled) { - unexpandCircles(); - expandCircles(closest.index, closest.id); - } + line = $$.__axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!$$.__line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } + return function (d) { + var data = $$.__line_connect_null ? $$.filterRemoveNull(d.values) : d.values, + x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; + if ($$.isLineType(d)) { + if ($$.__data_regions[d.id]) { + path = $$.lineWithRegions(data, x, y, $$.__data_regions[d.id]); + } else { + path = line.interpolate($$.getInterpolate(d))(data); + } + } else { + if (data[0]) { + x0 = x(data[0].x); + y0 = y(data[0].value); + } + path = $$.__axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; + }; - // Show xgrid focus line - showXGridFocus(selectedData); + c3.fn.$$.generateXYForText = function (barIndices, forX) { + var getPoints = this.generateGetBarPoints(barIndices, false), + getter = forX ? this.getXForText : this.getYForText; + return function (d, i) { + return getter(getPoints(d, i), d, this); + }; + }; + c3.fn.$$.getXForText = function (points, d, textElement) { + var box = textElement.getBoundingClientRect(), xPos, padding; + if ($$.__axis_rotated) { + padding = this.isBarType(d) ? 4 : 6; + xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); + } else { + xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + } + return xPos > $$.width ? $$.width - box.width : xPos; + }; + c3.fn.$$.getYForText = function (points, d, textElement) { + var box = textElement.getBoundingClientRect(), yPos; + if ($$.__axis_rotated) { + yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; + } else { + yPos = points[2][1] + (d.value < 0 ? box.height : this.isBarType(d) ? -3 : -6); + } + return yPos < box.height ? box.height : yPos; + }; - // Show cursor as pointer if point is close to mouse position - if (dist(closest, mouse) < 100) { - svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); - if (!mouseover) { - __data_onmouseover.call(c3, closest); - mouseover = true; - } - } else { - svg.select('.' + CLASS.eventRect).style('cursor', null); - __data_onmouseout.call(c3, closest); - mouseover = false; - } - }) - .on('click', function () { - var targetsToShow = filterTargetsToShow(c3.data.targets); - var mouse, closest; + c3.fn.$$.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, + areaTargetsNum = areaIndices.__max__ + 1, + x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = $$.getShapeY(!!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = areaOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if ($$.__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the area position + return [ + [posX, offset], + [posX, posY - (y0 - offset)] + ]; + }; + }; - if (hasArcType(targetsToShow)) { return; } + c3.fn.$$.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, + lineTargetsNum = lineIndices.__max__ + 1, + x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), + y = $$.getShapeY(!!isSub), + lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = lineOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if ($$.__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the line position + return [ + [posX, posY - (y0 - offset)] + ]; + }; + }; - mouse = d3.mouse(this); - closest = findClosestFromTargets(targetsToShow, mouse); - if (! closest) { return; } + c3.fn.$$.lineWithRegions = function (d, x, y, _regions) { + var prev = -1, i, j; + var s = "M", sWithRegion; + var xp, yp, dx, dy, dd, diff, diffx2; + var xValue, yValue; + var regions = []; - // select if selection enabled - if (dist(closest, mouse) < 100) { - main.select('.' + CLASS.circles + '-' + getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { - toggleShape(this, closest, closest.index); - }); - } - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { drag(d3.mouse(this)); }) - .on('dragstart', function () { dragstart(d3.mouse(this)); }) - .on('dragend', function () { dragend(); }) - ) - .on("dblclick.zoom", null); - } - - function toggleShape(that, d, i) { - var shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; - if (that.nodeName === 'circle') { - isWithin = isWithinCircle(that, pointSelectR(d) * 1.5); - toggle = togglePoint; - } - else if (that.nodeName === 'path') { - if (shape.classed(CLASS.bar)) { - isWithin = isWithinBar(that); - toggle = toggleBar; - } else { // would be arc - isWithin = true; - toggle = toggleArc; + // Check start/end of regions + if (this.isDefined(_regions)) { + for (i = 0; i < _regions.length; i++) { + regions[i] = {}; + if (this.isUndefined(_regions[i].start)) { + regions[i].start = d[0].x; + } else { + regions[i].start = $$.isTimeSeries ? this.parseDate(_regions[i].start) : _regions[i].start; } - } - if (__data_selection_grouped || isWithin) { - if (__data_selection_enabled && __data_selection_isselectable(d)) { - if (!__data_selection_multiple) { - main.selectAll('.' + CLASS.shapes + (__data_selection_grouped ? getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { - var shape = d3.select(this); - if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } - }); - } - shape.classed(CLASS.SELECTED, !isSelected); - toggle(!isSelected, shape, d, i); + if (this.isUndefined(_regions[i].end)) { + regions[i].end = d[d.length - 1].x; + } else { + regions[i].end = $$.isTimeSeries ? this.parseDate(_regions[i].end) : _regions[i].end; } - __data_onclick.call(c3, d, that); } } - function drag(mouse) { - var sx, sy, mx, my, minX, maxX, minY, maxY; - - if (hasArcType(c3.data.targets)) { return; } - if (! __data_selection_enabled) { return; } // do nothing if not selectable - if (__zoom_enabled && ! zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior - if (!__data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection - - sx = dragStart[0]; - sy = dragStart[1]; - mx = mouse[0]; - my = mouse[1]; - minX = Math.min(sx, mx); - maxX = Math.max(sx, mx); - minY = (__data_selection_grouped) ? margin.top : Math.min(sy, my); - maxY = (__data_selection_grouped) ? height : Math.max(sy, my); - - main.select('.' + CLASS.dragarea) - .attr('x', minX) - .attr('y', minY) - .attr('width', maxX - minX) - .attr('height', maxY - minY); - // TODO: binary search when multiple xs - main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) - .filter(function (d) { return __data_selection_isselectable(d); }) - .each(function (d, i) { - var shape = d3.select(this), - isSelected = shape.classed(CLASS.SELECTED), - isIncluded = shape.classed(CLASS.INCLUDED), - _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS.circle)) { - _x = shape.attr("cx") * 1; - _y = shape.attr("cy") * 1; - toggle = togglePoint; - isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; - } - else if (shape.classed(CLASS.bar)) { - box = getPathBox(this); - _x = box.x; - _y = box.y; - _w = box.width; - _h = box.height; - toggle = toggleBar; - isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); - } else { - // line/area selection not supported yet - return; - } - if (isWithin ^ isIncluded) { - shape.classed(CLASS.INCLUDED, !isIncluded); - // TODO: included/unincluded callback here - shape.classed(CLASS.SELECTED, !isSelected); - toggle(!isSelected, shape, d, i); - } - }); - } - - function dragstart(mouse) { - if (hasArcType(c3.data.targets)) { return; } - if (! __data_selection_enabled) { return; } // do nothing if not selectable - dragStart = mouse; - main.select('.' + CLASS.chart).append('rect') - .attr('class', CLASS.dragarea) - .style('opacity', 0.1); - dragging = true; - __data_ondragstart.call(c3); - } + // Set scales + xValue = $$.__axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); }; + yValue = $$.__axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; - function dragend() { - if (hasArcType(c3.data.targets)) { return; } - if (! __data_selection_enabled) { return; } // do nothing if not selectable - main.select('.' + CLASS.dragarea) - .transition().duration(100) - .style('opacity', 0) - .remove(); - main.selectAll('.' + CLASS.shape) - .classed(CLASS.INCLUDED, false); - dragging = false; - __data_ondragend.call(c3); - } - - function smoothLines(el, type) { - 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), - }); - }); - } + // Define svg generator function for region + if ($$.isTimeSeries) { + sWithRegion = function (d0, d1, j, diff) { + var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, + xv0 = new Date(x0 + x_diff * j), + xv1 = new Date(x0 + x_diff * (j + diff)); + return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); + }; + } else { + sWithRegion = function (d0, d1, j, diff) { + return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); + }; } - function redraw(options, transitions) { - var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; - var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; - var areaIndices = getShapeIndices(isAreaType), barIndices = getShapeIndices(isBarType), lineIndices = getShapeIndices(isLineType), maxDataCountTarget, tickOffset; - var rectX, rectW; - var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = hasArcType(c3.data.targets); - var drawArea, drawAreaOnSub, drawBar, drawBarOnSub, drawLine, drawLineOnSub, xForText, yForText; - var duration, durationForExit, durationForAxis, waitForDraw; - var targetsToShow = filterTargetsToShow(c3.data.targets), tickValues, i, intervalForCulling; - - xgrid = xgridLines = mainCircle = mainText = getEmptySelection(); - - 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); - withLegend = getOption(options, "withLegend", false); - withTransitionForExit = getOption(options, "withTransitionForExit", withTransition); - withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition); - - duration = withTransition ? __transition_duration : 0; - durationForExit = withTransitionForExit ? duration : 0; - durationForAxis = withTransitionForAxis ? duration : 0; - - transitions = transitions || generateAxisTransitions(durationForAxis); - - // update legend and transform each g - if (withLegend && __legend_show) { - updateLegend(mapToIds(c3.data.targets), options, transitions); - } + // Generate + for (i = 0; i < d.length; i++) { - // MEMO: needed for grids calculation - if (isCategorized && targetsToShow.length === 0) { - x.domain([0, axes.x.selectAll('.tick').size()]); + // Draw as normal + if (this.isUndefined(regions) || ! this.isWithinRegions(d[i].x, regions)) { + s += " " + xValue(d[i]) + " " + yValue(d[i]); } + // Draw with region // TODO: Fix for horizotal charts + else { + xp = this.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); + yp = this.getScale(d[i - 1].value, d[i].value); - if (targetsToShow.length) { - updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); - // update axis tick values according to options - if (!__axis_x_tick_values && (__axis_x_tick_fit || __axis_x_tick_count)) { - tickValues = generateTickValues(mapTargetsToUniqueXs(targetsToShow), __axis_x_tick_count); - xAxis.tickValues(tickValues); - subXAxis.tickValues(tickValues); - } - } else { - xAxis.tickValues([]); - subXAxis.tickValues([]); - } + dx = x(d[i].x) - x(d[i - 1].x); + dy = y(d[i].value) - y(d[i - 1].value); + dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + diff = 2 / dd; + diffx2 = diff * 2; - y.domain(getYDomain(targetsToShow, 'y')); - y2.domain(getYDomain(targetsToShow, 'y2')); - - // axes - axes.x.style("opacity", hideAxis ? 0 : 1); - axes.y.style("opacity", hideAxis ? 0 : 1); - axes.y2.style("opacity", hideAxis ? 0 : 1); - axes.subx.style("opacity", hideAxis ? 0 : 1); - transitions.axisX.call(xAxis); - transitions.axisY.call(yAxis); - transitions.axisY2.call(y2Axis); - transitions.axisSubX.call(subXAxis); - - // Update axis label - updateAxisLabels(withTransition); - - // show/hide if manual culling needed - if (withUpdateXDomain && targetsToShow.length) { - if (__axis_x_tick_culling && tickValues) { - for (i = 1; i < tickValues.length; i++) { - if (tickValues.length / i < __axis_x_tick_culling_max) { - intervalForCulling = i; - break; - } - } - svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { - var index = tickValues.indexOf(e); - if (index >= 0) { - d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); - } - }); - } else { - svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); + for (j = diff; j <= 1; j += diffx2) { + s += sWithRegion(d[i - 1], d[i], j, diff); } } + prev = d[i].x; + } - // rotate tick text if needed - if (!__axis_rotated && __axis_x_tick_rotate) { - rotateTickText(axes.x, transitions.axisX, __axis_x_tick_rotate); - } + return s; + }; - // setup drawer - MEMO: these must be called after axis updated - drawArea = generateDrawArea(areaIndices, false); - drawBar = generateDrawBar(barIndices); - drawLine = generateDrawLine(lineIndices, false); - xForText = generateXYForText(barIndices, true); - yForText = generateXYForText(barIndices, false); - - // Update sub domain - subY.domain(y.domain()); - subY2.domain(y2.domain()); - - // tooltip - tooltip.style("display", "none"); - - // 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(__data_empty_label_text) - .transition() - .style('opacity', targetsToShow.length ? 0 : 1); - - // grid - main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); - if (__grid_x_show) { - xgridAttr = __axis_rotated ? { - 'x1': 0, - 'x2': width, - 'y1': function (d) { return x(d) - tickOffset; }, - 'y2': function (d) { return x(d) - tickOffset; } - } : { - 'x1': function (d) { return x(d) + tickOffset; }, - 'x2': function (d) { return x(d) + tickOffset; }, - 'y1': 0, - 'y2': height - }; - // this is used to flow - flushXGrid = function (withoutUpdate) { - xgridData = generateGridData(__grid_x_type, x); - tickOffset = isCategorized ? xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) - .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS.xgrid); - if (!withoutUpdate) { - xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr(__axis_rotated ? 'y1' : 'x1') === (__axis_rotated ? height : 0) ? 0 : 1; }); - } - xgrid.exit().remove(); - }; - flushXGrid(); - } - xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) - .data(__grid_x_lines); - // enter - xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); - xgridLine.append('line') - .style("opacity", 0); - xgridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", __axis_rotated ? "" : "rotate(-90)") - .attr('dx', __axis_rotated ? 0 : -margin.top) - .attr('dy', -5) - .style("opacity", 0); - // udpate - // done in d3.transition() of the end of this function - // exit - xgridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - // Y-Grid - if (withY && __grid_y_show) { - ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) - .data(y.ticks(__grid_y_ticks)); - ygrid.enter().append('line') - .attr('class', CLASS.ygrid); - ygrid.attr("x1", __axis_rotated ? y : 0) - .attr("x2", __axis_rotated ? y : width) - .attr("y1", __axis_rotated ? 0 : y) - .attr("y2", __axis_rotated ? height : y); - ygrid.exit().remove(); - smoothLines(ygrid, 'grid'); - } - if (withY) { - ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) - .data(__grid_y_lines); - // enter - ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); - ygridLine.append('line') - .style("opacity", 0); - ygridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", __axis_rotated ? "rotate(-90)" : "") - .attr('dx', __axis_rotated ? 0 : -margin.top) - .attr('dy', -5) - .style("opacity", 0); - // update - ygridLines.select('line') - .transition().duration(duration) - .attr("x1", __axis_rotated ? yv : 0) - .attr("x2", __axis_rotated ? yv : width) - .attr("y1", __axis_rotated ? 0 : yv) - .attr("y2", __axis_rotated ? height : yv) - .style("opacity", 1); - ygridLines.select('text') - .transition().duration(duration) - .attr("x", __axis_rotated ? 0 : width) - .attr("y", yv) - .text(function (d) { return d.text; }) - .style("opacity", 1); - // exit - ygridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - } - // rect for regions - mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) - .data(__regions); - mainRegion.enter().append('g') - .attr('class', classRegion) - .append('rect') - .style("fill-opacity", 0); - mainRegion.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - // bars - mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(barData); - mainBar.enter().append('path') - .attr("class", classBar) - .style("stroke", function (d) { return color(d.id); }) - .style("fill", function (d) { return color(d.id); }); - mainBar - .style("opacity", initialOpacity); - mainBar.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); + c3.fn.$$.isWithinCircle = function (_this, _r) { + var mouse = $$.d3.mouse(_this), d3_this = $$.d3.select(_this); + var cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; + return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; + }; + c3.fn.$$.isWithinBar = function (_this) { + var mouse = $$.d3.mouse(_this), box = _this.getBoundingClientRect(), + seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1); + var x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2; + var sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; + return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; + }; + c3.fn.$$.isWithinRegions = function (x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; + }; - // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(lineData); - mainLine.enter().append('path') - .attr('class', classLine) - .style("stroke", color); - mainLine - .style("opacity", initialOpacity) - .attr('transform', null); - mainLine.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(lineData); - mainArea.enter().append('path') - .attr("class", classArea) - .style("fill", color) - .style("opacity", function () { orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); - mainArea - .style("opacity", orgAreaOpacity); - mainArea.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - if (__point_show) { - mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) - .data(lineOrScatterData); - mainCircle.enter().append("circle") - .attr("class", classCircle) - .attr("r", pointR) - .style("fill", color); - mainCircle - .style("opacity", initialOpacity); - mainCircle.exit().remove(); - } - if (hasDataLabel()) { - mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) - .data(barOrLineData); - mainText.enter().append('text') - .attr("class", classText) - .attr('text-anchor', function (d) { return __axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) - .style("stroke", 'none') - .style("fill", color) - .style("fill-opacity", 0); - mainText - .text(function (d) { return formatByAxisId(getAxisId(d.id))(d.value, d.id); }); - mainText.exit() - .transition().duration(durationForExit) - .style('fill-opacity', 0) - .remove(); - } + c3.fn.$$.findSameXOfValues = function (values, index) { + var i, targetX = values[index].x, sames = []; + for (i = index - 1; i >= 0; i--) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + for (i = index; i < values.length; i++) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + return sames; + }; - // arc - mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(arcData); - mainArc.enter().append('path') - .attr("class", classArc) - .style("fill", function (d) { return color(d.data); }) - .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }) - .style("opacity", 0) - .each(function (d) { - if (isGaugeType(d.data)) { - d.startAngle = d.endAngle = -1 * (Math.PI / 2); - } - this._current = d; - }) - .on('mouseover', function (d) { - var updated, arcData; - if (transiting) { // skip while transiting - return; - } - updated = updateAngle(d); - arcData = convertToArcData(updated); - // transitions - expandArc(updated.data.id); - toggleFocusLegend(updated.data.id, true); - __data_onmouseover.call(c3, arcData, this); - }) - .on('mousemove', function (d) { - var updated = updateAngle(d), arcData = convertToArcData(updated), selectedData = [arcData]; - showTooltip(selectedData, d3.mouse(this)); - }) - .on('mouseout', function (d) { - var updated, arcData; - if (transiting) { // skip while transiting - return; - } - updated = updateAngle(d); - arcData = convertToArcData(updated); - // transitions - unexpandArc(updated.data.id); - revertLegend(); - hideTooltip(); - __data_onmouseout.call(c3, arcData, this); - }) - .on('click', function (d, i) { - var updated = updateAngle(d), arcData = convertToArcData(updated); - toggleShape(this, arcData, i); // onclick called in toogleShape() - }); - mainArc - .attr("transform", function (d) { return !isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) - .style("opacity", function (d) { return d === this._current ? 0 : 1; }) - .each(function () { transiting = true; }) - .transition().duration(duration) - .attrTween("d", function (d) { - var updated = updateAngle(d), interpolate; + c3.fn.$$.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + var min = _min ? _min : 0, + max = _max ? _max : values.length - 1, + med = Math.floor((max - min) / 2) + min, + value = values[med], + diff = $$.x(value.x) - pos[$$.__axis_rotated ? 1 : 0], + candidates; - if (! updated) { - return function () { return "M 0 0"; }; - } -/* - if (this._current === d) { - this._current = { - startAngle: Math.PI*2, - endAngle: Math.PI*2, - }; - } -*/ - if (isNaN(this._current.endAngle)) { - this._current.endAngle = this._current.startAngle; - } - interpolate = d3.interpolate(this._current, updated); - this._current = interpolate(0); - return function (t) { return getArc(interpolate(t), true); }; - }) - .attr("transform", withTransform ? "scale(1)" : "") - .style("fill", function (d) { - return levelColor ? levelColor(d.data.values[0].value) : color(d.data.id); - }) // Where gauge reading color would receive customization. - .style("opacity", 1) - .call(endall, function () { - transiting = false; - }); - mainArc.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - main.selectAll('.' + CLASS.chartArc).select('text') - .style("opacity", 0) - .attr('class', function (d) { return isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) - .text(textForArcLabel) - .attr("transform", transformForArcLabel) - .transition().duration(duration) - .style("opacity", function (d) { return isTargetToShow(d.data.id) && isArcType(d.data) ? 1 : 0; }); - main.select('.' + CLASS.chartArcsTitle) - .style("opacity", hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? 1 : 0); - - // subchart - if (__subchart_show) { - // reflect main chart to extent on subchart if zoomed - if (d3.event && d3.event.type === 'zoom') { - brush.extent(x.orgDomain()).update(); - } - // update subchart elements if needed - if (withSubchart) { + // Update range for search + diff > 0 ? max = med : min = med; - // rotate tick text if needed - if (!__axis_rotated && __axis_x_tick_rotate) { - rotateTickText(axes.subx, transitions.axisSubX, __axis_x_tick_rotate); - } + // if candidates are two closest min and max, stop recursive call + if ((max - min) === 1 || (min === 0 && max === 0)) { - // extent rect - if (!brush.empty()) { - brush.extent(x.orgDomain()).update(); - } - // setup drawer - MEMO: this must be called after axis updated - drawAreaOnSub = generateDrawArea(areaIndices, true); - drawBarOnSub = generateDrawBar(barIndices, true); - drawLineOnSub = generateDrawLine(lineIndices, true); - // bars - contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(barData); - contextBar.enter().append('path') - .attr("class", classBar) - .style("stroke", 'none') - .style("fill", color); - contextBar - .style("opacity", initialOpacity) - .transition().duration(duration) - .attr('d', drawBarOnSub) - .style('opacity', 1); - contextBar.exit().transition().duration(duration) - .style('opacity', 0) - .remove(); - // lines - contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(lineData); - contextLine.enter().append('path') - .attr('class', classLine) - .style('stroke', color); - contextLine - .style("opacity", initialOpacity) - .transition().duration(duration) - .attr("d", drawLineOnSub) - .style('opacity', 1); - contextLine.exit().transition().duration(duration) - .style('opacity', 0) - .remove(); - // area - contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(lineData); - contextArea.enter().append('path') - .attr("class", classArea) - .style("fill", color) - .style("opacity", function () { orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); - contextArea - .style("opacity", 0) - .transition().duration(duration) - .attr("d", drawAreaOnSub) - .style("fill", color) - .style("opacity", orgAreaOpacity); - contextArea.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - } + // Get candidates that has same min and max index + candidates = []; + if (values[min].x || values[min].x === 0) { + candidates = candidates.concat(this.findSameXOfValues(values, min)); + } + if (values[max].x || values[max].x === 0) { + candidates = candidates.concat(this.findSameXOfValues(values, max)); } - // circles for select - main.selectAll('.' + CLASS.selectedCircles) - .filter(function (d) { return isBarType(d); }) - .selectAll('circle') - .remove(); - - if (__interaction_enabled) { - // rect for mouseover - eventRect = main.select('.' + CLASS.eventRects) - .style('cursor', __zoom_enabled ? __axis_rotated ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty(__data_xs) && !isSingleX(__data_xs)) { - - if (!eventRect.classed(CLASS.eventRectsMultiple)) { - eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) - .selectAll('.' + CLASS.eventRect).remove(); - } + // Determine the closest and return + return this.findClosest(candidates, pos); + } - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) - .data([0]); - // enter : only one rect will be added - generateEventRectsForMultipleXs(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('x', 0) - .attr('y', 0) - .attr('width', width) - .attr('height', height); - // exit : not needed because always only one rect exists - } else { + return this.findClosestOfValues(values, pos, min, max); + }; + c3.fn.$$.findClosestFromTargets = function (targets, pos) { + var candidates; - if (!eventRect.classed(CLASS.eventRectsSingle)) { - eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) - .selectAll('.' + CLASS.eventRect).remove(); - } + // map to array of closest points of each target + candidates = targets.map(function (target) { + return this.findClosestOfValues(target.values, pos); + }); - if ((isCustomX() || isTimeSeries) && !isCategorized) { - rectW = function (d) { - var prevX = getPrevX(d.index), nextX = getNextX(d.index), dx = c3.data.xs[d.id][d.index], - w = (x(nextX ? nextX : dx) - x(prevX ? prevX : dx)) / 2; - return w < 0 ? 0 : w; - }; - rectX = function (d) { - var prevX = getPrevX(d.index), dx = c3.data.xs[d.id][d.index]; - return (x(dx) + x(prevX ? prevX : dx)) / 2; - }; - } else { - rectW = getEventRectWidth(); - rectX = function (d) { - return x(d.x) - (rectW / 2); - }; - } - // Set data - maxDataCountTarget = getMaxDataCountTarget(c3.data.targets); - main.select('.' + CLASS.eventRects) - .datum(maxDataCountTarget ? maxDataCountTarget.values : []); - // Update rects - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) - .data(function (d) { return d; }); - // enter - generateEventRectsForSingleX(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('class', classEvent) - .attr("x", __axis_rotated ? 0 : rectX) - .attr("y", __axis_rotated ? rectX : 0) - .attr("width", __axis_rotated ? width : rectW) - .attr("height", __axis_rotated ? rectW : height); - // exit - eventRectUpdate.exit().remove(); - } + // decide closest point and return + return this.findClosest(candidates, pos); + }; + c3.fn.$$.findClosest = function (values, pos) { + var minDist, closest; + values.forEach(function (v) { + var d = this.dist(v, pos); + if (d < minDist || ! minDist) { + minDist = d; + closest = v; } + }); + return closest; + }; + c3.fn.$$.dist = function (data, pos) { + var yScale = this.getAxisId(data.id) === 'y' ? $$.y : $$.y2, + xIndex = $$.__axis_rotated ? 1 : 0, + yIndex = $$.__axis_rotated ? 0 : 1; + return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + }; - // transition should be derived from one transition - d3.transition().duration(duration).each(function () { - var transitions = []; - - transitions.push(mainBar.transition() - .attr('d', drawBar) - .style("fill", color) - .style("opacity", 1)); - transitions.push(mainLine.transition() - .attr("d", drawLine) - .style("stroke", color) - .style("opacity", 1)); - transitions.push(mainArea.transition() - .attr("d", drawArea) - .style("fill", color) - .style("opacity", orgAreaOpacity)); - transitions.push(mainCircle.transition() - .style('opacity', opacityForCircle) - .style("fill", color) - .attr("cx", __axis_rotated ? circleY : circleX) - .attr("cy", __axis_rotated ? circleX : circleY)); - transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() - .attr("cx", __axis_rotated ? circleY : circleX) - .attr("cy", __axis_rotated ? circleX : circleY)); - transitions.push(mainText.transition() - .attr('x', xForText) - .attr('y', yForText) - .style("fill", color) - .style("fill-opacity", options.flow ? 0 : opacityForText)); - transitions.push(mainRegion.selectAll('rect').transition() - .attr("x", regionX) - .attr("y", regionY) - .attr("width", regionWidth) - .attr("height", regionHeight) - .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); - transitions.push(xgridLines.select('line').transition() - .attr("x1", __axis_rotated ? 0 : xv) - .attr("x2", __axis_rotated ? width : xv) - .attr("y1", __axis_rotated ? xv : margin.top) - .attr("y2", __axis_rotated ? xv : height) - .style("opacity", 1)); - transitions.push(xgridLines.select('text').transition() - .attr("x", __axis_rotated ? width : 0) - .attr("y", xv) - .text(function (d) { return d.text; }) - .style("opacity", 1)); - // Wait for end of transitions if called from flow API - if (options.flow) { - waitForDraw = generateWait(); - transitions.forEach(function (t) { - waitForDraw.add(t); - }); - } - }) - .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow - var translateX, scaleX = 1, transform, - flowIndex = options.flow.index, - flowLength = options.flow.length, - flowStart = getValueOnIndex(c3.data.targets[0].values, flowIndex), - flowEnd = getValueOnIndex(c3.data.targets[0].values, flowIndex + flowLength), - orgDomain = x.domain(), domain, - durationForFlow = options.flow.duration || duration, - done = options.flow.done || function () {}, - wait = generateWait(); - - // remove head data after rendered - c3.data.targets.forEach(function (d) { - d.values.splice(0, flowLength); - }); - // update x domain to generate axis elements for flow - domain = updateXDomain(targetsToShow, true, true); - // update elements related to x scale - if (flushXGrid) { flushXGrid(true); } + c3.fn.$$.setTargetType = function (targetIds, type) { + var $$ = this; + $$.mapToTargetIds(targetIds).forEach(function (id) { + $$.withoutFadeIn[id] = (type === $$.__data_types[id]); + $$.__data_types[id] = type; + }); + if (!targetIds) { + $$.__data_type = type; + } + }; + c3.fn.$$.hasType = function (targets, type) { + var $$ = this, has = false; + targets.forEach(function (t) { + if ($$.__data_types[t.id] === type) { has = true; } + if (!(t.id in $$.__data_types) && type === 'line') { has = true; } + }); + return has; + }; - // generate transform to flow - if (!options.flow.orgDataCount) { // if empty - if (c3.data.targets[0].values.length !== 1) { - translateX = x(orgDomain[0]) - x(domain[0]); - } else { - if (isTimeSeries) { - flowStart = getValueOnIndex(c3.data.targets[0].values, 0); - flowEnd = getValueOnIndex(c3.data.targets[0].values, c3.data.targets[0].values.length - 1); - translateX = x(flowStart.x) - x(flowEnd.x); - } else { - translateX = diffDomain(domain) / 2; - } - } - } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { - translateX = x(orgDomain[0]) - x(domain[0]); - } else { - if (isTimeSeries) { - translateX = (x(orgDomain[0]) - x(domain[0])); - } else { - translateX = (x(flowStart.x) - x(flowEnd.x)); - } - } - scaleX = (diffDomain(orgDomain) / diffDomain(domain)); - transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; - - d3.transition().ease('linear').duration(durationForFlow).each(function () { - wait.add(axes.x.transition().call(xAxis)); - wait.add(mainBar.transition().attr('transform', transform)); - wait.add(mainLine.transition().attr('transform', transform)); - wait.add(mainArea.transition().attr('transform', transform)); - wait.add(mainCircle.transition().attr('transform', transform)); - wait.add(mainText.transition().attr('transform', transform)); - wait.add(mainRegion.filter(isRegionOnX).transition().attr('transform', transform)); - wait.add(xgrid.transition().attr('transform', transform)); - wait.add(xgridLines.transition().attr('transform', transform)); - }) - .call(wait, function () { - var i, shapes = [], texts = [], eventRects = []; - - // remove flowed elements - if (flowLength) { - for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); - texts.push('.' + CLASS.text + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); - } - svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); - svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); - svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); - svg.select('.' + CLASS.xgrid).remove(); - } + /* not used + function hasLineType(targets) { + return hasType(targets, 'line'); + } + */ + c3.fn.$$.hasAreaType = function (targets) { + return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); + }; + c3.fn.$$.hasBarType = function (targets) { + return this.hasType(targets, 'bar'); + }; + c3.fn.$$.hasScatterType = function (targets) { + return this.hasType(targets, 'scatter'); + }; + c3.fn.$$.hasPieType = function (targets) { + var $$ = this; + return $$.__data_type === 'pie' || $$.hasType(targets, 'pie'); + }; + c3.fn.$$.hasGaugeType = function (targets) { + return this.hasType(targets, 'gauge'); + }; + c3.fn.$$.hasDonutType = function (targets) { + var $$ = this; + return $$.__data_type === 'donut' || $$.hasType(targets, 'donut'); + }; + c3.fn.$$.hasArcType = function (targets) { + return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); + }; + c3.fn.$$.isLineType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return !$$.__data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf($$.__data_types[id]) >= 0; + }; + c3.fn.$$.isStepType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return ['step', 'area-step'].indexOf($$.__data_types[id]) >= 0; + }; + c3.fn.$$.isSplineType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return ['spline', 'area-spline'].indexOf($$.__data_types[id]) >= 0; + }; + c3.fn.$$.isAreaType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return ['area', 'area-spline', 'area-step'].indexOf($$.__data_types[id]) >= 0; + }; + c3.fn.$$.isBarType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return $$.__data_types[id] === 'bar'; + }; + c3.fn.$$.isScatterType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return $$.__data_types[id] === 'scatter'; + }; + c3.fn.$$.isPieType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return $$.__data_types[id] === 'pie'; + }; + c3.fn.$$.isGaugeType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return $$.__data_types[id] === 'gauge'; + }; + c3.fn.$$.isDonutType = function (d) { + var $$ = this, id = (typeof d === 'string') ? d : d.id; + return $$.__data_types[id] === 'donut'; + }; + c3.fn.$$.isArcType = function (d) { + return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); + }; + c3.fn.$$.lineData = function (d) { + return this.isLineType(d) ? [d] : []; + }; + c3.fn.$$.arcData = function (d) { + return this.isArcType(d.data) ? [d] : []; + }; + /* not used + function scatterData(d) { + return isScatterType(d) ? d.values : []; + } + */ + c3.fn.$$.barData = function (d) { + return this.isBarType(d) ? d.values : []; + }; + c3.fn.$$.lineOrScatterData = function (d) { + return this.isLineType(d) || this.isScatterType(d) ? d.values : []; + }; + c3.fn.$$.barOrLineData = function (d) { + return this.isBarType(d) || this.isLineType(d) ? d.values : []; + }; - // draw again for removing flowed elements and reverting attr - xgrid - .attr('transform', null) - .attr(xgridAttr); - xgridLines - .attr('transform', null); - xgridLines.select('line') - .attr("x1", __axis_rotated ? 0 : xv) - .attr("x2", __axis_rotated ? width : xv); - xgridLines.select('text') - .attr("x", __axis_rotated ? width : 0) - .attr("y", xv); - mainBar - .attr('transform', null) - .attr("d", drawBar); - mainLine - .attr('transform', null) - .attr("d", drawLine); - mainArea - .attr('transform', null) - .attr("d", drawArea); - mainCircle - .attr('transform', null) - .attr("cx", __axis_rotated ? circleY : circleX) - .attr("cy", __axis_rotated ? circleX : circleY); - mainText - .attr('transform', null) - .attr('x', xForText) - .attr('y', yForText) - .style('fill-opacity', opacityForText); - mainRegion - .attr('transform', null); - mainRegion.select('rect').filter(isRegionOnX) - .attr("x", regionX) - .attr("width", regionWidth); - eventRectUpdate - .attr("x", __axis_rotated ? 0 : rectX) - .attr("y", __axis_rotated ? rectX : 0) - .attr("width", __axis_rotated ? width : rectW) - .attr("height", __axis_rotated ? rectW : height); - - // callback for end of flow - done(); - }); - }); - // update fadein condition - mapToIds(c3.data.targets).forEach(function (id) { - withoutFadeIn[id] = true; - }); - updateZoom(); - } - function redrawForBrush() { - redraw({ - withTransition: false, - withY: false, - withSubchart: false, - withUpdateXDomain: true - }); - __subchart_onbrush.call(c3, x.orgDomain()); - } - function redrawForZoom() { - if (!__zoom_enabled) { - return; - } - if (filterTargetsToShow(c3.data.targets).length === 0) { - return; + /** + * c3.date.js + */ + c3.fn.$$.parseDate = function (date) { + var parsedDate; + if (date instanceof Date) { + parsedDate = date; + } else if (typeof date === 'number') { + parsedDate = new Date(date); + } else { + parsedDate = this.dataTimeFormat($$.__data_x_format).parse(date); + } + if (!parsedDate || isNaN(+parsedDate)) { + window.console.error("Failed to parse x '" + date + "' to Date object"); + } + return parsedDate; + }; + + + /** + * c3.color.js + */ + c3.fn.$$.generateColor = function (colors, pattern, callback) { + var ids = []; + + return function (d) { + var id = d.id || d, color; + + // if callback function is provided + if (colors[id] instanceof Function) { + color = colors[id](d); } - if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { - x.domain(zoom.altDomain); - zoom.scale(x).updateScaleExtent(); - return; + // if specified, choose that color + else if (colors[id]) { + color = colors[id]; } - if (isCategorized && x.orgDomain()[0] === orgXDomain[0]) { - x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); + // if not specified, choose from pattern + else { + if (ids.indexOf(id) < 0) { ids.push(id); } + color = pattern[ids.indexOf(id) % pattern.length]; + colors[id] = color; } - redraw({ - withTransition: false, - withY: false, - withSubchart: false - }); - if (d3.event.sourceEvent.type === 'mousemove') { - cancelClick = true; + return callback instanceof Function ? callback(color, d) : color; + }; + }; + c3.fn.$$.generateLevelColor = function (colors, threshold) { + var asValue = threshold.unit === 'value', + values = threshold.values && threshold.values.length ? threshold.values : [], + max = threshold.max || 100; + return function (value) { + var i, v, color = colors[colors.length - 1]; + for (i = 0; i < values.length; i++) { + v = asValue ? value : (value * 100 / max); + if (v < values[i]) { + color = colors[i]; + break; + } } - __zoom_onzoom.call(c3, x.orgDomain()); - } + return color; + }; + }; - function generateResize() { - var resizeFunctions = []; - function callResizeFunctions() { - resizeFunctions.forEach(function (f) { - f(); - }); - } - callResizeFunctions.add = function (f) { - resizeFunctions.push(f); + + /** + * c3.scale.js + */ + c3.fn.$$.getScale = function (min, max, forTimeseries) { + return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); + }; + c3.fn.$$.getX = function (min, max, domain, offset) { + var $$ = this; + var scale = this.getScale(min, max, $$.isTimeSeries), + _scale = domain ? scale.domain(domain) : scale, key; + // Define customized scale if categorized axis + if ($$.isCategorized) { + offset = offset || function () { return 0; }; + scale = function (d, raw) { + var v = _scale(d) + offset(d); + return raw ? v : Math.ceil(v); }; - return callResizeFunctions; - } - - function updateSvgSize() { - svg.attr('width', currentWidth).attr('height', currentHeight); - svg.select('#' + clipId).select('rect') - .attr('width', width) - .attr('height', height); - svg.select('#' + clipIdForXAxis).select('rect') - .attr('x', getXAxisClipX) - .attr('y', getXAxisClipY) - .attr('width', getXAxisClipWidth) - .attr('height', getXAxisClipHeight); - svg.select('#' + clipIdForYAxis).select('rect') - .attr('x', getYAxisClipX) - .attr('y', getYAxisClipY) - .attr('width', getYAxisClipWidth) - .attr('height', getYAxisClipHeight); - 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"); - } - - function generateAxisTransitions(duration) { - 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, + } else { + scale = function (d, raw) { + var v = _scale(d); + return raw ? v : Math.ceil(v); }; } - - function updateAndRedraw(options) { - var 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 && __legend_show)) { - transitions = generateAxisTransitions(options.withTransitionForAxis ? __transition_duration : 0); - // Update scales - updateScales(); - updateSvgSize(); - // Update g positions - transformAll(options.withTransitionForTransform, transitions); - } - // Draw with new sizes & scales - redraw(options, transitions); + // define functions + for (key in _scale) { + scale[key] = _scale[key]; } + scale.orgDomain = function () { + return _scale.domain(); + }; + // define custom domain() for categorized axis + if ($$.isCategorized) { + scale.domain = function (domain) { + if (!arguments.length) { + domain = this.orgDomain(); + return [domain[0], domain[1] + 1]; + } + _scale.domain(domain); + return scale; + }; + } + return scale; + }; + c3.fn.$$.getY = function (min, max, domain) { + var scale = this.getScale(min, max); + if (domain) { scale.domain(domain); } + return scale; + }; + c3.fn.$$.getYScale = function (id) { + var $$ = this; + return $$.getAxisId(id) === 'y2' ? $$.y2 : $$.y; + }; + c3.fn.$$.getSubYScale = function (id) { + var $$ = this; + return $$.getAxisId(id) === 'y2' ? $$.subY2 : $$.subY; + }; + c3.fn.$$.updateScales = function () { + var $$ = this, xAxisTickFormat, xAxisTickValues, forInit = !$$.x; + // update edges + $$.xMin = $$.__axis_rotated ? 1 : 0; + $$.xMax = $$.__axis_rotated ? $$.height : $$.width; + $$.yMin = $$.__axis_rotated ? 0 : $$.height; + $$.yMax = $$.__axis_rotated ? $$.width : 1; + $$.subXMin = $$.xMin; + $$.subXMax = $$.xMax; + $$.subYMin = $$.__axis_rotated ? 0 : $$.height2; + $$.subYMax = $$.__axis_rotated ? $$.width2 : 1; + // update scales + $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); + $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); + $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); + $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); + $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); + $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); + // update axes + $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickValues = $$.__axis_x_tick_values ? $$.__axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, $$.__axis_y_tick_format, $$.__axis_y_ticks); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, $$.__axis_y2_tick_format, $$.__axis_y2_ticks); + // Set initialized scales to brush and zoom + if (!forInit) { + $$.brush.scale($$.subX); + if ($$.__zoom_enabled) { $$.zoom.scale($$.x); } + } + // update for arc + this.updateArc(); + }; + c3.fn.$$.updateArc = function () { + var $$ = this; + $$.svgArc = this.getSvgArc(); + $$.svgArcExpanded = this.getSvgArcExpanded(); + $$.svgArcExpandedSub = this.getSvgArcExpanded(0.98); + }; - function updateTargets(targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; - var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; - - /*-- Main --*/ - - //-- Text --// - mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) - .data(targets) - .attr('class', classChartText); - mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', classChartText) - .style('opacity', 0) - .style("pointer-events", "none"); - mainTextEnter.append('g') - .attr('class', classTexts); - - //-- Bar --// - mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) - .data(targets) - .attr('class', classChartBar); - mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', classChartBar) - .style('opacity', 0) - .style("pointer-events", "none"); - // Bars for each data - mainBarEnter.append('g') - .attr("class", classBars) - .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }); - - //-- Line --// - mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) - .data(targets) - .attr('class', classChartLine); - mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', classChartLine) - .style('opacity', 0) - .style("pointer-events", "none"); - // Lines for each data - mainLineEnter.append('g') - .attr("class", classLines); - // Areas - mainLineEnter.append('g') - .attr('class', classAreas); - // Circles for each data point on lines - mainLineEnter.append('g') - .attr("class", function (d) { return generateClass(CLASS.selectedCircles, d.id); }); - mainLineEnter.append('g') - .attr("class", classCircles) - .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }); - // Update date for selected circles - targets.forEach(function (t) { - main.selectAll('.' + CLASS.selectedCircles + getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { - d.value = t.values[d.index].value; - }); - }); - // MEMO: can not keep same color... - //mainLineUpdate.exit().remove(); - - //-- Pie --// - mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) - .data(pie(targets)) - .attr("class", classChartArc); - mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", classChartArc); - mainPieEnter.append('g') - .attr('class', classArcs); - mainPieEnter.append("text") - .attr("dy", hasGaugeType(c3.data.targets) ? "-0.35em" : ".35em") - .style("opacity", 0) - .style("text-anchor", "middle") - .style("pointer-events", "none"); - // MEMO: can not keep same color..., but not bad to update color in redraw - //mainPieUpdate.exit().remove(); - - /*-- Context --*/ - - if (__subchart_show) { - contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) - .data(targets) - .attr('class', classChartBar); - contextBarEnter = contextBarUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', classChartBar); - // Bars for each data - contextBarEnter.append('g') - .attr("class", classBars); - - //-- Line --// - contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) - .data(targets) - .attr('class', classChartLine); - contextLineEnter = contextLineUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', classChartLine); - // Lines for each data - contextLineEnter.append("g") - .attr("class", classLines); - // Area - contextLineEnter.append("g") - .attr("class", classAreas); + /** + * c3.domain.js + */ + c3.fn.$$.getYDomainMin = function (targets) { + var $$ = this, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasNegativeValue; + if ($$.__data_groups.length > 0) { + hasNegativeValue = $$.hasNegativeValueInTargets(targets); + for (j = 0; j < $$.__data_groups.length; j++) { + // Determine baseId + idsInGroup = $$.__data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider negative values + if (hasNegativeValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v < 0 ? v : 0; + }); + } + // Compute min + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + ys[baseId][i] += +v; + } + }); + } } - - /*-- Show --*/ - - // Fade-in each chart - svg.selectAll('.' + CLASS.target).filter(function (d) { return isTargetToShow(d.id); }) - .transition().duration(__transition_duration) - .style("opacity", 1); } - - function load(targets, args) { - if (targets) { - // filter loading targets if needed - if (args.filter) { - targets = targets.filter(args.filter); - } - // set type if args.types || args.type specified - if (args.type || args.types) { - targets.forEach(function (t) { - args.types ? setTargetType(t.id, args.types[t.id]) : setTargetType(t.id, args.type); + return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); + }; + c3.fn.$$.getYDomainMax = function (targets) { + var $$ = this, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasPositiveValue; + if ($$.__data_groups.length > 0) { + hasPositiveValue = $$.hasPositiveValueInTargets(targets); + for (j = 0; j < $$.__data_groups.length; j++) { + // Determine baseId + idsInGroup = $$.__data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider positive values + if (hasPositiveValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v > 0 ? v : 0; }); } - // Update/Add data - c3.data.targets.forEach(function (d) { - for (var i = 0; i < targets.length; i++) { - if (d.id === targets[i].id) { - d.values = targets[i].values; - targets.splice(i, 1); - break; + // Compute max + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + ys[baseId][i] += +v; } - } - }); - c3.data.targets = c3.data.targets.concat(targets); // add remained + }); + } } + } + return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); + }; + c3.fn.$$.getYDomain = function (targets, axisId) { + var $$ = this; + var yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), + yMin = axisId === 'y2' ? $$.__axis_y2_min : $$.__axis_y_min, + yMax = axisId === 'y2' ? $$.__axis_y2_max : $$.__axis_y_max, + yDomainMin = this.isValue(yMin) ? yMin : this.getYDomainMin(yTargets), + yDomainMax = this.isValue(yMax) ? yMax : this.getYDomainMax(yTargets), + domainLength, padding, padding_top, padding_bottom, + center = axisId === 'y2' ? $$.__axis_y2_center : $$.__axis_y_center, + yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, + isZeroBased = (this.hasBarType(yTargets) && $$.__bar_zerobased) || (this.hasAreaType(yTargets) && $$.__area_zerobased), + showHorizontalDataLabel = this.hasDataLabel() && $$.__axis_rotated, + showVerticalDataLabel = this.hasDataLabel() && !$$.__axis_rotated; + if (yTargets.length === 0) { // use current domain if target of axisId is none + return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); + } + if (yDomainMin === yDomainMax) { + yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; + } + isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; + isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { yDomainMin = 0; } + if (isAllNegative) { yDomainMax = 0; } + } + + domainLength = Math.abs(yDomainMax - yDomainMin); + padding = padding_top = padding_bottom = domainLength * 0.1; + + if (center) { + yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); + yDomainMax = yDomainAbs - center; + yDomainMin = center - yDomainAbs; + } + // add padding for data label + if (showHorizontalDataLabel) { + lengths = this.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + diff = this.diffDomain($$.y.range()); + ratio = [lengths[0] / diff, lengths[1] / diff]; + padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); + padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); + } else if (showVerticalDataLabel) { + lengths = this.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + padding_top += lengths[1]; + padding_bottom += lengths[0]; + } + if (axisId === 'y' && $$.__axis_y_padding) { + padding_top = this.getAxisPadding($$.__axis_y_padding, 'top', padding, domainLength); + padding_bottom = this.getAxisPadding($$.__axis_y_padding, 'bottom', padding, domainLength); + } + if (axisId === 'y2' && $$.__axis_y2_padding) { + padding_top = this.getAxisPadding($$.__axis_y2_padding, 'top', padding, domainLength); + padding_bottom = this.getAxisPadding($$.__axis_y2_padding, 'bottom', padding, domainLength); + } + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { padding_bottom = yDomainMin; } + if (isAllNegative) { padding_top = -yDomainMax; } + } + return [yDomainMin - padding_bottom, yDomainMax + padding_top]; + }; + c3.fn.$$.getXDomainMin = function (targets) { + var $$ = this; + return $$.__axis_x_min ? ($$.isTimeSeries ? this.parseDate($$.__axis_x_min) : $$.__axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); + }; + c3.fn.$$.getXDomainMax = function (targets) { + var $$ = this; + return $$.__axis_x_max ? ($$.isTimeSeries ? this.parseDate($$.__axis_x_max) : $$.__axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); + }; + c3.fn.$$.getXDomainPadding = function (targets) { + var $$ = this; + var edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], + maxDataCount, padding, paddingLeft, paddingRight; + if ($$.isCategorized) { + padding = 0; + } else if (this.hasBarType(targets)) { + maxDataCount = this.getMaxDataCount(); + padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; + } else { + padding = diff * 0.01; + } + if (typeof $$.__axis_x_padding === 'object' && this.notEmpty($$.__axis_x_padding)) { + paddingLeft = this.isValue($$.__axis_x_padding.left) ? $$.__axis_x_padding.left : padding; + paddingRight = this.isValue($$.__axis_x_padding.right) ? $$.__axis_x_padding.right : padding; + } else if (typeof $$.__axis_x_padding === 'number') { + paddingLeft = paddingRight = $$.__axis_x_padding; + } else { + paddingLeft = paddingRight = padding; + } + return {left: paddingLeft, right: paddingRight}; + }; + c3.fn.$$.getXDomain = function (targets) { + var $$ = this; + var xDomain = [this.getXDomainMin(targets), this.getXDomainMax(targets)], + firstX = xDomain[0], lastX = xDomain[1], + padding = this.getXDomainPadding(targets), + min = 0, max = 0; + // show center of x domain if min and max are the same + if ((firstX - lastX) === 0 && !$$.isCategorized) { + firstX = $$.isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$.isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; + } + if (firstX || firstX === 0) { + min = $$.isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + } + if (lastX || lastX === 0) { + max = $$.isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + } + return [min, max]; + }; + c3.fn.$$.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + var $$ = this; + if (withUpdateOrgXDomain) { + $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); + $$.orgXDomain = $$.x.domain(); + if ($$.__zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } + $$.subX.domain($$.x.domain()); + $$.brush.scale($$.subX); + } + if (withUpdateXDomain) { + $$.x.domain(domain ? domain : $$.brush.empty() ? $$.orgXDomain : $$.brush.extent()); + if ($$.__zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } + } + return $$.x.domain(); + }; - // Set targets - updateTargets(c3.data.targets); - // Redraw with new targets - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (typeof args.done === 'function') { - args.done(); + + c3.fn.$$.getXAxis = function (scale, orient, tickFormat, tickValues) { + var $$ = this, + axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); + + // Set tick + axis.tickFormat(tickFormat).tickValues(tickValues); + if ($$.isCategorized) { + axis.tickCentered($$.__axis_x_tick_centered); + if ($$.isEmpty($$.__axis_x_tick_culling)) { + $$.__axis_x_tick_culling = false; } + } else { + // TODO: move this to c3_axis + axis.tickOffset = function () { + var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), + base = diff ? diff : ($$.__axis_rotated ? $$.height : $$.width); + return (base / $$.getMaxDataCount()) / 2; + }; } - function loadFromArgs(args) { - if (args.data) { - load(convertDataToTargets(args.data), args); - } - else if (args.url) { - convertUrlToData(args.url, args.mimeType, args.keys, function (data) { - load(convertDataToTargets(data), args); - }); - } - else if (args.json) { - load(convertDataToTargets(convertJsonToData(args.json, args.keys)), args); - } - else if (args.rows) { - load(convertDataToTargets(convertRowsToData(args.rows)), args); - } - else if (args.columns) { - load(convertDataToTargets(convertColumnsToData(args.columns)), args); + + return axis; + }; + c3.fn.$$.getYAxis = function (scale, orient, tickFormat, ticks) { + var $$ = this; + return c3_axis($$.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); + }; + c3.fn.$$.getAxisId = function (id) { + var $$ = this; + return id in $$.__data_axes ? $$.__data_axes[id] : 'y'; + }; + c3.fn.$$.getXAxisTickFormat = function () { + var $$ = this; + var format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + if ($$.__axis_x_tick_format) { + if (typeof $$.__axis_x_tick_format === 'function') { + format = $$.__axis_x_tick_format; + } else if ($$.isTimeSeries) { + format = function (date) { + return date ? $$.axisTimeFormat($$.__axis_x_tick_format)(date) : ""; + }; } - else { - load(null, args); + } + return function (v) { return format.call($$, v); }; + }; + c3.fn.$$.getAxisLabelOptionByAxisId = function (axisId) { + var $$ = this, option; + if (axisId === 'y') { + option = $$.__axis_y_label; + } else if (axisId === 'y2') { + option = $$.__axis_y2_label; + } else if (axisId === 'x') { + option = $$.__axis_x_label; + } + return option; + }; + c3.fn.$$.getAxisLabelText = function (axisId) { + var option = this.getAxisLabelOptionByAxisId(axisId); + return typeof option === 'string' ? option : option ? option.text : null; + }; + c3.fn.$$.setAxisLabelText = function (axisId, text) { + var option = this.getAxisLabelOptionByAxisId(axisId); + if (typeof option === 'string') { + if (axisId === 'y') { + $$.__axis_y_label = text; + } else if (axisId === 'y2') { + $$.__axis_y2_label = text; + } else if (axisId === 'x') { + $$.__axis_x_label = text; } + } else if (option) { + option.text = text; + } + }; + c3.fn.$$.getAxisLabelPosition = function (axisId, defaultPosition) { + var option = this.getAxisLabelOptionByAxisId(axisId), + position = (option && 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 + }; + }; + c3.fn.$$.getXAxisLabelPosition = function () { + var $$ = this; + return this.getAxisLabelPosition('x', $$.__axis_rotated ? 'inner-top' : 'inner-right'); + }; + c3.fn.$$.getYAxisLabelPosition = function () { + var $$ = this; + return this.getAxisLabelPosition('y', $$.__axis_rotated ? 'inner-right' : 'inner-top'); + }; + c3.fn.$$.getY2AxisLabelPosition = function () { + var $$ = this; + return this.getAxisLabelPosition('y2', $$.__axis_rotated ? 'inner-right' : 'inner-top'); + }; + c3.fn.$$.getAxisLabelPositionById = function (id) { + var $$ = this; + return id === 'y2' ? $$.getY2AxisLabelPosition() : id === 'y' ? $$.getYAxisLabelPosition() : $$.getXAxisLabelPosition(); + }; + c3.fn.$$.textForXAxisLabel = function () { + return this.getAxisLabelText('x'); + }; + c3.fn.$$.textForYAxisLabel = function () { + return this.getAxisLabelText('y'); + }; + c3.fn.$$.textForY2AxisLabel = function () { + return this.getAxisLabelText('y2'); + }; + c3.fn.$$.xForAxisLabel = function (forHorizontal, position) { + var $$ = this; + if (forHorizontal) { + return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; + } else { + return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; + } + }; + c3.fn.$$.dxForAxisLabel = function (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"; + } + }; + c3.fn.$$.textAnchorForAxisLabel = function (forHorizontal, position) { + if (forHorizontal) { + return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; + } else { + return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; + } + }; + c3.fn.$$.xForXAxisLabel = function () { + var $$ = this; + return $$.xForAxisLabel(!$$.__axis_rotated, $$.getXAxisLabelPosition()); + }; + c3.fn.$$.xForYAxisLabel = function () { + return this.xForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); + }; + c3.fn.$$.xForY2AxisLabel = function () { + return this.xForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); + }; + c3.fn.$$.dxForXAxisLabel = function () { + return this.dxForAxisLabel(!this.__axis_rotated, this.getXAxisLabelPosition()); + }; + c3.fn.$$.dxForYAxisLabel = function () { + return this.dxForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); + }; + c3.fn.$$.dxForY2AxisLabel = function () { + return this.dxForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); + }; + c3.fn.$$.dyForXAxisLabel = function () { + var $$ = this, position = $$.getXAxisLabelPosition(); + if ($$.__axis_rotated) { + return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); + } else { + return position.isInner ? "-0.5em" : $$.__axis_x_height ? $$.__axis_x_height - 10 : "3em"; } + }; + c3.fn.$$.dyForYAxisLabel = function () { + var $$ = this, position = $$.getYAxisLabelPosition(); + if ($$.__axis_rotated) { + return position.isInner ? "-0.5em" : "3em"; + } else { + return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); + } + }; + c3.fn.$$.dyForY2AxisLabel = function () { + var $$ = this, position = $$.getY2AxisLabelPosition(); + if ($$.__axis_rotated) { + return position.isInner ? "1.2em" : "-2.2em"; + } else { + return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); + } + }; + c3.fn.$$.textAnchorForXAxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel(!$$.__axis_rotated, $$.getXAxisLabelPosition()); + }; + c3.fn.$$.textAnchorForYAxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel($$.__axis_rotated, $$.getYAxisLabelPosition()); + }; + c3.fn.$$.textAnchorForY2AxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel($$.__axis_rotated, $$.getY2AxisLabelPosition()); + }; - function unload(targetIds, done) { - if (typeof done !== 'function') { - done = function () {}; - } - // filter existing target - targetIds = targetIds.filter(function (id) { return hasTarget(c3.data.targets, id); }); - // If no target, call done and return - if (!targetIds || targetIds.length === 0) { - done(); - return; + c3.fn.$$.xForRotatedTickText = function (r) { + return 10 * Math.sin(Math.PI * (r / 180)); + }; + c3.fn.$$.yForRotatedTickText = function (r) { + return 11.5 - 2.5 * (r / 15); + }; + c3.fn.$$.rotateTickText = function (axis, transition, rotate) { + axis.selectAll('.tick text') + .style("text-anchor", "start"); + transition.selectAll('.tick text') + .attr("y", this.yForRotatedTickText(rotate)) + .attr("x", this.xForRotatedTickText(rotate)) + .attr("transform", "rotate(" + rotate + ")"); + }; + + c3.fn.$$.getMaxTickWidth = function (id) { + var $$ = this; + var maxWidth = 0, targetsToShow, scale, axis; + if ($$.svg) { + targetsToShow = this.filterTargetsToShow($$.data.targets); + if (id === 'y') { + scale = $$.y.copy().domain(this.getYDomain(targetsToShow, 'y')); + axis = this.getYAxis(scale, $$.yOrient, $$.__axis_y_tick_format, $$.__axis_y_ticks); + } else if (id === 'y2') { + scale = $$.y2.copy().domain(this.getYDomain(targetsToShow, 'y2')); + axis = this.getYAxis(scale, $$.y2Orient, $$.__axis_y2_tick_format, $$.__axis_y2_ticks); + } else { + scale = $$.x.copy().domain(this.getXDomain(targetsToShow)); + axis = this.getXAxis(scale, $$.xOrient, this.getXAxisTickFormat(), $$.__axis_x_tick_values ? $$.__axis_x_tick_values : $$.xAxis.tickValues()); } - svg.selectAll(targetIds.map(function (id) { return selectorTarget(id); })) - .transition() - .style('opacity', 0) - .remove() - .call(endall, done); - targetIds.forEach(function (id) { - // Reset fadein for future load - withoutFadeIn[id] = false; - // Remove target's elements - legend.selectAll('.' + CLASS.legendItem + getTargetSelectorSuffix(id)).remove(); - // Remove target - c3.data.targets = c3.data.targets.filter(function (t) { - return t.id !== id; + $$.main.append("g").call(axis).each(function () { + $$.d3.select(this).selectAll('text').each(function () { + var box = this.getBoundingClientRect(); + if (maxWidth < box.width) { maxWidth = box.width; } }); - }); + }).remove(); + } + $$.currentMaxTickWidth = maxWidth <= 0 ? $$.currentMaxTickWidth : maxWidth; + return $$.currentMaxTickWidth; + }; + + c3.fn.$$.updateAxisLabels = function (withTransition) { + var $$ = this; + var axisXLabel = $$.main.select('.' + this.CLASS.axisX + ' .' + this.CLASS.axisXLabel), + axisYLabel = $$.main.select('.' + this.CLASS.axisY + ' .' + this.CLASS.axisYLabel), + axisY2Label = $$.main.select('.' + this.CLASS.axisY2 + ' .' + this.CLASS.axisY2Label); + (withTransition ? axisXLabel.transition() : axisXLabel) + .attr("x", function () { return $$.xForXAxisLabel(); }) + .attr("dx", function () { return $$.dxForXAxisLabel(); }) + .attr("dy", function () { return $$.dyForXAxisLabel(); }) + .text(function () { return $$.textForXAxisLabel(); }); + (withTransition ? axisYLabel.transition() : axisYLabel) + .attr("x", function () { return $$.xForYAxisLabel(); }) + .attr("dx", function () { return $$.dxForYAxisLabel(); }) + .attr("dy", function () { return $$.dyForYAxisLabel(); }) + .attr("dy", function () { return $$.dyForYAxisLabel(); }) + .text(function () { return $$.textForYAxisLabel(); }); + (withTransition ? axisY2Label.transition() : axisY2Label) + .attr("x", function () { return $$.xForY2AxisLabel(); }) + .attr("dx", function () { return $$.dxForY2AxisLabel(); }) + .attr("dy", function () { return $$.dyForY2AxisLabel(); }) + .text(function () { return $$.textForY2AxisLabel(); }); + }; + + c3.fn.$$.getAxisPadding = function (padding, key, defaultValue, all) { + var ratio = padding.unit === 'ratio' ? all : 1; + return this.isValue(padding[key]) ? padding[key] * ratio : defaultValue; + }; + + c3.fn.$$.generateTickValues = function (xs, tickCount) { + var $$ = this; + var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; + if (tickCount) { + targetCount = typeof tickCount === 'function' ? tickCount() : tickCount; + // compute ticks according to $$.__axis_x_tick_count + if (targetCount === 1) { + tickValues = [xs[0]]; + } else if (targetCount === 2) { + tickValues = [xs[0], xs[xs.length - 1]]; + } else if (targetCount > 2) { + count = targetCount - 2; + start = xs[0]; + end = xs[xs.length - 1]; + interval = (end - start) / (count + 1); + // re-construct uniqueXs + tickValues = [start]; + for (i = 0; i < count; i++) { + tickValue = +start + interval * (i + 1); + tickValues.push($$.isTimeSeries ? new Date(tickValue) : tickValue); + } + tickValues.push(end); + } } + if (!$$.isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + return tickValues; + }; - /*-- Draw Legend --*/ - function opacityForLegend(legendItem) { - return legendItem.classed(CLASS.legendItemHidden) ? legendOpacityForHidden : 1; + /** + * c3.region.js + */ + c3.fn.$$.regionX = function (d) { + var xPos, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + xPos = $$.__axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; + } else { + xPos = $$.__axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0); + } + return xPos; + }; + c3.fn.$$.regionY = function (d) { + var yPos, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + yPos = $$.__axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); + } else { + yPos = $$.__axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0) : 0; + } + return yPos; + }; + c3.fn.$$.regionWidth = function (d) { + var start = this.regionX(d), end, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = $$.__axis_rotated ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; + } else { + end = $$.__axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.width); + } + return end < start ? 0 : end - start; + }; + c3.fn.$$.regionHeight = function (d) { + var start = this.regionY(d), end, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = $$.__axis_rotated ? $$.height : ('start' in d ? yScale(d.start) : $$.height); + } else { + end = $$.__axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.height) : $$.height; + } + return end < start ? 0 : end - start; + }; + c3.fn.$$.isRegionOnX = function (d) { + return !d.axis || d.axis === 'x'; + }; + + + + + /** + * c3.arc.js + */ + c3.fn.$$.updateAngle = function (d) { + var $$ = this, found = false, index = 0; + $$.pie($$.filterTargetsToShow($$.data.targets)).sort(this.descByStartAngle).forEach(function (t) { + if (! found && t.data.id === d.data.id) { + found = true; + d = t; + d.index = index; + } + index++; + }); + if (isNaN(d.endAngle)) { + d.endAngle = d.startAngle; } - function opacityForUnfocusedLegend(legendItem) { - return legendItem.classed(CLASS.legendItemHidden) ? legendOpacityForHidden : 0.3; + if (this.isGaugeType(d.data)) { + var gMin = $$.__gauge_min, gMax = $$.__gauge_max, + gF = Math.abs(gMin) + gMax, + aTic = (Math.PI) / gF; + d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); + d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value)); } - function toggleFocusLegend(id, focus) { - legend.selectAll('.' + CLASS.legendItem) + return found ? d : null; + }; + c3.fn.$$.getSvgArc = function () { + var $$ = this; + var arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), + newArc = function (d, withoutUpdate) { + var updated; + if (withoutUpdate) { return arc(d); } // for interpolate + updated = $$.updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; + // TODO: extends all function + newArc.centroid = arc.centroid; + return newArc; + }; + c3.fn.$$.getSvgArcExpanded = function (rate) { + var $$ = this; + var arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); + return function (d) { + var updated = $$.updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; + }; + c3.fn.$$.getArc = function (d, withoutUpdate, force) { + return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; + }; + c3.fn.$$.transformForArcLabel = function (d) { + var $$ = this, updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !this.hasGaugeType($$.data.targets)) { + c = this.svgArc.centroid(updated); + x = isNaN(c[0]) ? 0 : c[0]; + y = isNaN(c[1]) ? 0 : c[1]; + h = Math.sqrt(x * x + y * y); + // TODO: ratio should be an option? + ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0; + translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")"; + } + return translate; + }; + c3.fn.$$.getArcRatio = function (d) { + var $$ = this, whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); + return d ? (d.endAngle - d.startAngle) / whole : null; + }; + c3.fn.$$.convertToArcData = function (d) { + return this.addName({ + id: d.data.id, + value: d.value, + ratio: this.getArcRatio(d), + index: d.index + }); + }; + c3.fn.$$.textForArcLabel = function (d) { + var $$ = this, updated, value, ratio, format; + if (! $$.shouldShowArcLabel()) { return ""; } + updated = $$.updateAngle(d); + value = updated ? updated.value : null; + ratio = $$.getArcRatio(updated); + if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } + format = $$.getArcLabelFormat(); + return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); + }; + c3.fn.$$.expandArc = function (id, withoutFadeOut) { + var $$ = this, CLASS= $$.CLASS, + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), + noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); + + if ($$.shouldExpand(id)) { + target.selectAll('path') + .transition().duration(50) + .attr("d", $$.svgArcExpanded) .transition().duration(100) - .style('opacity', function (_id) { - var This = d3.select(this); - if (id && _id !== id) { - return focus ? opacityForUnfocusedLegend(This) : opacityForLegend(This); - } else { - return focus ? opacityForLegend(This) : opacityForUnfocusedLegend(This); + .attr("d", $$.svgArcExpandedSub) + .each(function (d) { + if ($$.isDonutType(d.data)) { + // callback here } }); } - function revertLegend() { - legend.selectAll('.' + CLASS.legendItem) - .transition().duration(100) - .style('opacity', function () { return opacityForLegend(d3.select(this)); }); + if (!withoutFadeOut) { + noneTargets.style("opacity", 0.3); } - function showLegend(targetIds) { - if (!__legend_show) { - __legend_show = true; - legend.style('visibility', 'visible'); - } - removeHiddenLegendIds(targetIds); - legend.selectAll(selectorLegends(targetIds)) - .style('visibility', 'visible') - .transition() - .style('opacity', function () { return opacityForLegend(d3.select(this)); }); - } - function hideLegend(targetIds) { - if (__legend_show && isEmpty(targetIds)) { - __legend_show = false; - legend.style('visibility', 'hidden'); + }; + c3.fn.$$.unexpandArc = function (id) { + var $$ = this, CLASS = $$.CLASS, + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); + target.selectAll('path.' + CLASS.arc) + .transition().duration(50) + .attr("d", $$.svgArc); + $$.svg.selectAll('.' + CLASS.arc) + .style("opacity", 1); + }; + c3.fn.$$.shouldExpand = function (id) { + var $$ = this; + return ($$.isDonutType(id) && $$.__donut_expand) || ($$.isGaugeType(id) && $$.__gauge_expand) || ($$.isPieType(id) && $$.__pie_expand); + }; + c3.fn.$$.shouldShowArcLabel = function () { + var $$ = this, shouldShow = true; + if (this.hasDonutType($$.data.targets)) { + shouldShow = $$.__donut_label_show; + } else if (this.hasPieType($$.data.targets)) { + shouldShow = $$.__pie_label_show; + } + // when gauge, always true + return shouldShow; + }; + c3.fn.$$.meetsArcLabelThreshold = function (ratio) { + var $$ = this, threshold = this.hasDonutType($$.data.targets) ? $$.__donut_label_threshold : $$.__pie_label_threshold; + return ratio >= threshold; + }; + c3.fn.$$.getArcLabelFormat = function () { + var $$ = this, format = $$.__pie_label_format; + if (this.hasGaugeType($$.data.targets)) { + format = $$.__gauge_label_format; + } else if (this.hasDonutType($$.data.targets)) { + format = $$.__donut_label_format; + } + return format; + }; + c3.fn.$$.getArcTitle = function () { + var $$ = this; + return $$.hasDonutType($$.data.targets) ? $$.__donut_title : ""; + }; + c3.fn.$$.descByStartAngle = function (a, b) { + return a.startAngle - b.startAngle; + }; + + + + /** + * c3.cache.js + */ + c3.fn.$$.hasCaches = function (ids) { + for (var i = 0; i < ids.length; i++) { + if (! (ids[i] in $$.cache)) { return false; } + } + return true; + }; + c3.fn.$$.addCache = function (id, target) { + var $$ = this; + $$.cache[id] = $$.cloneTarget(target); + }; + c3.fn.$$.getCaches = function (ids) { + var targets = [], i; + for (i = 0; i < ids.length; i++) { + if (ids[i] in $$.cache) { targets.push(this.cloneTarget($$.cache[ids[i]])); } + } + return targets; + }; + + + /** + * c3.zoom.js + */ + c3.fn.$$.updateZoom = function () { + var $$ = this, z = $$.__zoom_enabled ? $$.zoom : function () {}; + $$.main.select('.' + this.CLASS.zoomRect).call(z); + $$.main.selectAll('.' + this.CLASS.eventRect).call(z); + }; + + + + + /** + * c3.util.js + */ + c3.fn.$$.isValue = function (v) { + return v || v === 0; + }; + c3.fn.$$.isUndefined = function (v) { + return typeof v === 'undefined'; + }; + c3.fn.$$.isDefined = function (v) { + return typeof v !== 'undefined'; + }; + c3.fn.$$.ceil10 = function (v) { + return Math.ceil(v / 10) * 10; + }; + c3.fn.$$.asHalfPixel = function (n) { + return Math.ceil(n) + 0.5; + }; + c3.fn.$$.diffDomain = function (d) { + return d[1] - d[0]; + }; + c3.fn.$$.isEmpty = function (o) { + return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); + }; + c3.fn.$$.notEmpty = function (o) { + return Object.keys(o).length > 0; + }; + c3.fn.$$.getOption = function (options, key, defaultValue) { + return typeof options[key] !== 'undefined' ? options[key] : defaultValue; + }; + c3.fn.$$.hasValue = function (dict, value) { + var found = false; + Object.keys(dict).forEach(function (key) { + if (dict[key] === value) { found = true; } + }); + return found; + }; + c3.fn.$$.getPathBox = function (path) { + var box = path.getBoundingClientRect(), + items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], + minX = items[0].x, minY = Math.min(items[0].y, items[1].y); + return {x: minX, y: minY, width: box.width, height: box.height}; + }; + c3.fn.$$.getTextRect = function (text, cls) { + var $$ = this, rect; + $$.d3.select('body').selectAll('.dummy') + .data([text]) + .enter().append('text') + .classed(cls ? cls : "", true) + .text(text) + .each(function () { rect = this.getBoundingClientRect(); }) + .remove(); + return rect; + }; + + c3.fn.$$.getEmptySelection = function () { + var $$ = this; + return $$.d3.selectAll([]); + }; + + + /** + * c3.selection.js + */ + c3.fn.$$.selectPoint = function (target, d, i) { + var $$ = this; + $$.__data_onselected.call(c3, d, target.node()); + // add selected-circle on low layer g + main.select('.' + this.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + .data([d]) + .enter().append('circle') + .attr("class", function () { return generateClass(this.CLASS.selectedCircle, i); }) + .attr("cx", $$.__axis_rotated ? circleY : circleX) + .attr("cy", $$.__axis_rotated ? circleX : circleY) + .attr("stroke", function () { return color(d); }) + .attr("r", pointSelectR(d) * 1.4) + .transition().duration(100) + .attr("r", pointSelectR); + }; + c3.fn.$$.unselectPoint = function (target, d, i) { + var $$ = this; + $$.__data_onunselected.call(c3, d, target.node()); + // remove selected-circle from low layer g + main.select('.' + $$.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + .transition().duration(100).attr('r', 0) + .remove(); + }; + c3.fn.$$.togglePoint = function (selected, target, d, i) { + selected ? selectPoint(target, d, i) : unselectPoint(target, d, i); + }; + c3.fn.$$.selectBar = function (target, d) { + $$.__data_onselected.call(c3, d, target.node()); + target.transition().duration(100).style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + }; + c3.fn.$$.unselectBar = function (target, d) { + $$.__data_onunselected.call(c3, d, target.node()); + target.transition().duration(100).style("fill", function () { return $$.color(d); }); + }; + c3.fn.$$.toggleBar = function (selected, target, d, i) { + selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); + }; + c3.fn.$$.toggleArc = function (selected, target, d, i) { + this.toggleBar(selected, target, d.data, i); + }; + c3.fn.$$.getToggle = function (that) { + // path selection not supported yet + return that.nodeName === 'circle' ? this.togglePoint : ($$.d3.select(that).classed(this.CLASS.bar) ? this.toggleBar : this.toggleArc); + }; + c3.fn.$$.toggleShape = function (that, d, i) { + var $$ = this, CLASS = $$.CLASS, d3 = $$.d3, + shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; + if (that.nodeName === 'circle') { + isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); + toggle = $$.togglePoint; + } + else if (that.nodeName === 'path') { + if (shape.classed(CLASS.bar)) { + isWithin = $$.isWithinBar(that); + toggle = $$.toggleBar; + } else { // would be arc + isWithin = true; + toggle = $$.toggleArc; + } + } + if ($$.__data_selection_grouped || isWithin) { + if ($$.__data_selection_enabled && $$.__data_selection_isselectable(d)) { + if (!$$.__data_selection_multiple) { + $$.main.selectAll('.' + CLASS.shapes + ($$.__data_selection_grouped ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this); + if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } + }); + } + shape.classed(CLASS.SELECTED, !isSelected); + toggle(!isSelected, shape, d, i); } - addHiddenLegendIds(targetIds); - legend.selectAll(selectorLegends(targetIds)) - .style('opacity', 0) - .style('visibility', 'hidden'); - } - - function updateLegend(targetIds, options, transitions) { - var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; - var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; - var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; - var withTransition, withTransitionForTransform; - var hasFocused = legend.selectAll('.' + CLASS.legendItemFocused).size(); - var texts, rects, tiles; - - options = options || {}; - withTransition = getOption(options, "withTransition", true); - withTransitionForTransform = getOption(options, "withTransitionForTransform", true); - - function updatePositions(textElement, id, reset) { - var box = getTextRect(textElement.textContent, CLASS.legendItem), - itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, - itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, - itemLength = isLegendRight || isLegendInset ? itemHeight : itemWidth, - areaLength = isLegendRight || isLegendInset ? getLegendHeight() : getLegendWidth(), - margin, maxLength; - - // MEMO: care about condifion of step, totalLength - function updateValues(id, withoutStep) { - if (!withoutStep) { - margin = (areaLength - totalLength - itemLength) / 2; - if (margin < posMin) { - margin = (areaLength - itemLength) / 2; - totalLength = 0; - step++; + $$.__data_onclick.call(c3, d, that); + } + }; + + + /** + * c3.transition.js + */ + c3.fn.$$.generateAxisTransitions = function (duration) { + var $$ = this, 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 + }; + }; + c3.fn.$$.endall = function (transition, callback) { + var n = 0; + transition + .each(function () { ++n; }) + .each("end", function () { + if (!--n) { callback.apply(this, arguments); } + }); + }; + c3.fn.$$.generateWait = function () { + var transitionsToWait = [], + f = function (transition, callback) { + var timer = setInterval(function () { + var done = 0; + transitionsToWait.forEach(function (t) { + if (t.empty()) { + done += 1; + return; + } + try { + t.transition(); + } catch (e) { + done += 1; } + }); + if (done === transitionsToWait.length) { + clearInterval(timer); + if (callback) { callback(); } } - steps[id] = step; - margins[step] = isLegendInset ? 10 : margin; - offsets[id] = totalLength; - totalLength += itemLength; - } + }, 10); + }; + f.add = function (transition) { + transitionsToWait.push(transition); + }; + return f; + }; - if (reset) { - totalLength = 0; - step = 0; - maxWidth = 0; - maxHeight = 0; - } - if (__legend_show && !isLegendToShow(id)) { - widths[id] = heights[id] = steps[id] = offsets[id] = 0; - return; - } + /** + * c3.transform.js + */ + c3.fn.$$.transformTo = function (targetIds, type, optionsForRedraw) { + var $$ = this, + withTransitionForAxis = !$$.hasArcType($$.data.targets), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); + }; - widths[id] = itemWidth; - heights[id] = itemHeight; - if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } - if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } - maxLength = isLegendRight || isLegendInset ? maxHeight : maxWidth; + /** + * c3.class.js + */ + c3.fn.$$.CLASS = { + target: 'c3-target', + chart : 'c3-chart', + chartLine: 'c3-chart-line', + chartLines: 'c3-chart-lines', + chartBar: 'c3-chart-bar', + chartBars: 'c3-chart-bars', + chartText: 'c3-chart-text', + chartTexts: 'c3-chart-texts', + chartArc: 'c3-chart-arc', + chartArcs: 'c3-chart-arcs', + chartArcsTitle: 'c3-chart-arcs-title', + chartArcsBackground: 'c3-chart-arcs-background', + chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', + chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', + chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', + selectedCircle: 'c3-selected-circle', + selectedCircles: 'c3-selected-circles', + eventRect: 'c3-event-rect', + eventRects: 'c3-event-rects', + eventRectsSingle: 'c3-event-rects-single', + eventRectsMultiple: 'c3-event-rects-multiple', + zoomRect: 'c3-zoom-rect', + brush: 'c3-brush', + focused: 'c3-focused', + region: 'c3-region', + regions: 'c3-regions', + tooltip: 'c3-tooltip', + tooltipName: 'c3-tooltip-name', + shape: 'c3-shape', + shapes: 'c3-shapes', + line: 'c3-line', + lines: 'c3-lines', + bar: 'c3-bar', + bars: 'c3-bars', + circle: 'c3-circle', + circles: 'c3-circles', + arc: 'c3-arc', + arcs: 'c3-arcs', + area: 'c3-area', + areas: 'c3-areas', + empty: 'c3-empty', + text: 'c3-text', + texts: 'c3-texts', + gaugeValue: 'c3-gauge-value', + grid: 'c3-grid', + xgrid: 'c3-xgrid', + xgrids: 'c3-xgrids', + xgridLine: 'c3-xgrid-line', + xgridLines: 'c3-xgrid-lines', + xgridFocus: 'c3-xgrid-focus', + ygrid: 'c3-ygrid', + ygrids: 'c3-ygrids', + ygridLine: 'c3-ygrid-line', + ygridLines: 'c3-ygrid-lines', + axis: 'c3-axis', + axisX: 'c3-axis-x', + axisXLabel: 'c3-axis-x-label', + axisY: 'c3-axis-y', + axisYLabel: 'c3-axis-y-label', + axisY2: 'c3-axis-y2', + axisY2Label: 'c3-axis-y2-label', + legendBackground: 'c3-legend-background', + legendItem: 'c3-legend-item', + legendItemEvent: 'c3-legend-item-event', + legendItemTile: 'c3-legend-item-tile', + legendItemHidden: 'c3-legend-item-hidden', + legendItemFocused: 'c3-legend-item-focused', + dragarea: 'c3-dragarea', + EXPANDED: '_expanded_', + SELECTED: '_selected_', + INCLUDED: '_included_' + }; + c3.fn.$$.generateClass = function (prefix, targetId) { + var $$ = this; + return " " + prefix + " " + prefix + $$.getTargetSelectorSuffix(targetId); + }; + c3.fn.$$.classText = function (d) { + return this.generateClass(this.CLASS.text, d.index); + }; + c3.fn.$$.classTexts = function (d) { + return this.generateClass(this.CLASS.texts, d.id); + }; + c3.fn.$$.classShape = function (d) { + return this.generateClass(this.CLASS.shape, d.index); + }; + c3.fn.$$.classShapes = function (d) { + return this.generateClass(this.CLASS.shapes, d.id); + }; + c3.fn.$$.classLine = function (d) { + return this.classShape(d) + this.generateClass(this.CLASS.line, d.id); + }; + c3.fn.$$.classLines = function (d) { + return this.classShapes(d) + this.generateClass(this.CLASS.lines, d.id); + }; + c3.fn.$$.classCircle = function (d) { + return this.classShape(d) + this.generateClass(this.CLASS.circle, d.index); + }; + c3.fn.$$.classCircles = function (d) { + return this.classShapes(d) + this.generateClass(this.CLASS.circles, d.id); + }; + c3.fn.$$.classBar = function (d) { + return this.classShape(d) + this.generateClass(this.CLASS.bar, d.index); + }; + c3.fn.$$.classBars = function (d) { + return this.classShapes(d) + this.generateClass(this.CLASS.bars, d.id); + }; + c3.fn.$$.classArc = function (d) { + return this.classShape(d.data) + this.generateClass(this.CLASS.arc, d.data.id); + }; + c3.fn.$$.classArcs = function (d) { + return this.classShapes(d.data) + this.generateClass(this.CLASS.arcs, d.data.id); + }; + c3.fn.$$.classArea = function (d) { + return this.classShape(d) + this.generateClass(this.CLASS.area, d.id); + }; + c3.fn.$$.classAreas = function (d) { + return this.classShapes(d) + this.generateClass(this.CLASS.areas, d.id); + }; + c3.fn.$$.classRegion = function (d, i) { + return this.generateClass(this.CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); + }; + c3.fn.$$.classEvent = function (d) { + return this.generateClass(this.CLASS.eventRect, d.index); + }; + c3.fn.$$.classTarget = function (id) { + var $$ = this; + var additionalClassSuffix = $$.__data_classes[id], additionalClass = ''; + if (additionalClassSuffix) { + additionalClass = ' ' + $$.CLASS.target + '-' + additionalClassSuffix; + } + return $$.generateClass($$.CLASS.target, id) + additionalClass; + }; + c3.fn.$$.classChartText = function (d) { + return this.CLASS.chartText + this.classTarget(d.id); + }; + c3.fn.$$.classChartLine = function (d) { + return this.CLASS.chartLine + this.classTarget(d.id); + }; + c3.fn.$$.classChartBar = function (d) { + return this.CLASS.chartBar + this.classTarget(d.id); + }; + c3.fn.$$.classChartArc = function (d) { + return this.CLASS.chartArc + this.classTarget(d.data.id); + }; + c3.fn.$$.getTargetSelectorSuffix = function (targetId) { + return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; + }; + c3.fn.$$.selectorTarget = function (id) { + var $$ = this; + return '.' + $$.CLASS.target + $$.getTargetSelectorSuffix(id); + }; + c3.fn.$$.selectorTargets = function (ids) { + var $$ = this; + return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; + }; + c3.fn.$$.selectorLegend = function (id) { + var $$ = this; + return '.' + $$.CLASS.legendItem + $$.getTargetSelectorSuffix(id); + }; + c3.fn.$$.selectorLegends = function (ids) { + var $$ = this; + return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; + }; - if (__legend_equally) { - Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); - Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); - margin = (areaLength - maxLength * targetIds.length) / 2; - if (margin < posMin) { - totalLength = 0; - step = 0; - targetIds.forEach(function (id) { updateValues(id); }); - } - else { - updateValues(id, true); - } + + + /** + * c3.format.js + */ + c3.fn.$$.getYFormat = function (forArc) { + var $$ = this, + formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; + return function (v, ratio, id) { + var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; + return format.call($$, v, ratio); + }; + }; + c3.fn.$$.yFormat = function (v) { + var $$ = this, format = $$.__axis_y_tick_format ? $$.__axis_y_tick_format : $$.defaultValueFormat; + return format.call($$, v); + }; + c3.fn.$$.y2Format = function (v) { + var $$ = this, format = $$.__axis_y2_tick_format ? $$.__axis_y2_tick_format : $$.defaultValueFormat; + return format.call($$, v); + }; + c3.fn.$$.defaultValueFormat = function (v) { + return this.isValue(v) ? +v : ""; + }; + c3.fn.$$.defaultArcValueFormat = function (v, ratio) { + return (ratio * 100).toFixed(1) + '%'; + }; + c3.fn.$$.formatByAxisId = function (axisId) { + var $$ = this.$$, format = function (v) { return this.isValue(v) ? +v : ""; }; + // find format according to axis id + if (typeof $$.__data_labels.format === 'function') { + format = $$.__data_labels.format; + } else if (typeof $$.__data_labels.format === 'object') { + if (typeof $$.__data_labels.format[axisId] === 'function') { + format = $$.__data_labels.format[axisId]; + } + } + return format; + }; + + + + /** + * c3.drag.js + */ + c3.fn.$$.drag = function (mouse) { + var $$ = this, main = $$.main, CLASS = $$.CLASS, d3 = $$.d3; + var sx, sy, mx, my, minX, maxX, minY, maxY; + + if ($$.hasArcType($$.data.targets)) { return; } + if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable + if ($$.__zoom_enabled && ! $$.zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior + if (!$$.__data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection + + sx = $$.dragStart[0]; + sy = $$.dragStart[1]; + mx = mouse[0]; + my = mouse[1]; + minX = Math.min(sx, mx); + maxX = Math.max(sx, mx); + minY = ($$.__data_selection_grouped) ? $$.margin.top : Math.min(sy, my); + maxY = ($$.__data_selection_grouped) ? $$.height : Math.max(sy, my); + + main.select('.' + CLASS.dragarea) + .attr('x', minX) + .attr('y', minY) + .attr('width', maxX - minX) + .attr('height', maxY - minY); + // TODO: binary search when multiple xs + main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) + .filter(function (d) { return $$.__data_selection_isselectable(d); }) + .each(function (d, i) { + var shape = d3.select(this), + isSelected = shape.classed(CLASS.SELECTED), + isIncluded = shape.classed(CLASS.INCLUDED), + _x, _y, _w, _h, toggle, isWithin = false, box; + if (shape.classed(CLASS.circle)) { + _x = shape.attr("cx") * 1; + _y = shape.attr("cy") * 1; + toggle = $$.togglePoint; + isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; + } + else if (shape.classed(CLASS.bar)) { + box = $$.getPathBox(this); + _x = box.x; + _y = box.y; + _w = box.width; + _h = box.height; + toggle = $$.toggleBar; + isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); } else { - updateValues(id); + // line/area selection not supported yet + return; } - } + if (isWithin ^ isIncluded) { + shape.classed(CLASS.INCLUDED, !isIncluded); + // TODO: included/unincluded callback here + shape.classed(CLASS.SELECTED, !isSelected); + toggle.call($$, !isSelected, shape, d, i); + } + }); + }; - if (isLegendRight) { - xForLegend = function (id) { return maxWidth * steps[id]; }; - yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else if (isLegendInset) { - xForLegend = function (id) { return maxWidth * steps[id] + 10; }; - yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else { - xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - yForLegend = function (id) { return maxHeight * steps[id]; }; - } - xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; - yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; - xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; - yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; - - // Define g for legend area - l = legend.selectAll('.' + CLASS.legendItem) - .data(targetIds) - .enter().append('g') - .attr('class', function (id) { return generateClass(CLASS.legendItem, id); }) - .style('visibility', function (id) { return isLegendToShow(id) ? 'visible' : 'hidden'; }) - .style('cursor', 'pointer') - .on('click', function (id) { - typeof __legend_item_onclick === 'function' ? __legend_item_onclick.call(c3, id) : c3.toggle(id); - }) - .on('mouseover', function (id) { - d3.select(this).classed(CLASS.legendItemFocused, true); - if (!transiting) { - c3.focus(id); - } - if (typeof __legend_item_onmouseover === 'function') { - __legend_item_onmouseover.call(c3, id); - } - }) - .on('mouseout', function (id) { - d3.select(this).classed(CLASS.legendItemFocused, false); - if (!transiting) { - c3.revert(); - } - if (typeof __legend_item_onmouseout === 'function') { - __legend_item_onmouseout.call(c3, id); - } - }); - l.append('text') - .text(function (id) { return isDefined(__data_names[id]) ? __data_names[id] : id; }) - .each(function (id, i) { updatePositions(this, id, i === 0); }) - .style("pointer-events", "none") - .attr('x', isLegendRight || isLegendInset ? xForLegendText : -200) - .attr('y', isLegendRight || isLegendInset ? -200 : yForLegendText); - l.append('rect') - .attr("class", CLASS.legendItemEvent) - .style('fill-opacity', 0) - .attr('x', isLegendRight || isLegendInset ? xForLegendRect : -200) - .attr('y', isLegendRight || isLegendInset ? -200 : yForLegendRect); - l.append('rect') - .attr("class", CLASS.legendItemTile) - .style("pointer-events", "none") - .style('fill', color) - .attr('x', isLegendRight || isLegendInset ? xForLegendText : -200) - .attr('y', isLegendRight || isLegendInset ? -200 : yForLegend) - .attr('width', 10) - .attr('height', 10); - // Set background for inset legend - if (isLegendInset && maxWidth !== 0) { - legend.insert('g', '.' + CLASS.legendItem) - .attr("class", CLASS.legendBackground) - .append('rect') - .attr('height', getLegendHeight() - 10) - .attr('width', maxWidth * (step + 1) + 10); - } + c3.fn.$$.dragstart = function (mouse) { + var $$ = this; + if ($$.hasArcType($$.data.targets)) { return; } + if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable + $$.dragStart = mouse; + $$.main.select('.' + $$.CLASS.chart).append('rect') + .attr('class', $$.CLASS.dragarea) + .style('opacity', 0.1); + $$.dragging = true; + $$.__data_ondragstart.call(c3); + }; + + c3.fn.$$.dragend = function () { + var $$ = this; + if ($$.hasArcType($$.data.targets)) { return; } + if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable + $$.main.select('.' + $$.CLASS.dragarea) + .transition().duration(100) + .style('opacity', 0) + .remove(); + $$.main.selectAll('.' + $$.CLASS.shape) + .classed($$.CLASS.INCLUDED, false); + $$.dragging = false; + $$.__data_ondragend.call(c3); + }; - texts = legend.selectAll('text') - .data(targetIds) - .text(function (id) { return isDefined(__data_names[id]) ? __data_names[id] : id; }) // MEMO: needed for update - .each(function (id, i) { updatePositions(this, id, i === 0); }); - (withTransition ? texts.transition() : texts) - .attr('x', xForLegendText) - .attr('y', yForLegendText); - - rects = legend.selectAll('rect.' + CLASS.legendItemEvent) - .data(targetIds); - (withTransition ? rects.transition() : rects) - .attr('width', function (id) { return widths[id]; }) - .attr('height', function (id) { return heights[id]; }) - .attr('x', xForLegendRect) - .attr('y', yForLegendRect); - - tiles = legend.selectAll('rect.' + CLASS.legendItemTile) - .data(targetIds); - (withTransition ? tiles.transition() : tiles) - .style('fill', color) - .attr('x', xForLegend) - .attr('y', yForLegend); - - // toggle legend state - legend.selectAll('.' + CLASS.legendItem) - .classed(CLASS.legendItemHidden, function (id) { return !isTargetToShow(id); }) - .transition() - .style('opacity', function (id) { - var This = d3.select(this); - if (isTargetToShow(id)) { - return !hasFocused || This.classed(CLASS.legendItemFocused) ? opacityForLegend(This) : opacityForUnfocusedLegend(This); - } else { - return legendOpacityForHidden; - } - }); - // Update all to reflect change of legend - updateLegendItemWidth(maxWidth); - updateLegendItemHeight(maxHeight); - updateLegendStep(step); - // Update size and scale - updateSizes(); - updateScales(); - updateSvgSize(); - // Update g positions - transformAll(withTransitionForTransform, transitions); - } - /*-- Event Handling --*/ - function isNoneArc(d) { - return hasTarget(c3.data.targets, d.id); - } - function isArc(d) { - return 'data' in d && hasTarget(c3.data.targets, d.data.id); + + /** + * c3.api.js (or c3.api.focus.js, etc?) + */ + c3.fn.chart.focus = function (targetId) { + var $$ = this.$$, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), + candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + function focus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + this.revert(); + this.defocus(); + focus(candidatesForNoneArc.classed($$.CLASS.focused, true)); + focus(candidatesForArc); + if ($$.hasArcType($$.data.targets)) { + $$.expandArc(targetId, true); + } + $$.toggleFocusLegend(targetId, true); + }; + + c3.fn.chart.defocus = function (targetId) { + var $$ = this.$$, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), + candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + function defocus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); + } + this.revert(); + defocus(candidatesForNoneArc.classed($$.CLASS.focused, false)); + defocus(candidatesForArc); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); + } + $$.toggleFocusLegend(targetId, false); + }; + + c3.fn.chart.revert = function (targetId) { + var $$ = this.$$, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), + candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + function revert(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } - function getGridFilterToRemove(params) { - return params ? function (line) { - var found = false; - [].concat(params).forEach(function (param) { - if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { - found = true; - } - }); - return found; - } : function () { return true; }; - } - function removeGridLines(params, forX) { - var toRemove = getGridFilterToRemove(params), - toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, - classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; - main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) - .transition().duration(__transition_duration) - .style('opacity', 0).remove(); - if (forX) { - __grid_x_lines = __grid_x_lines.filter(toShow); - } else { - __grid_y_lines = __grid_y_lines.filter(toShow); - } + revert(candidatesForNoneArc.classed($$.CLASS.focused, false)); + revert(candidatesForArc); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); } - function transformTo(targetIds, type, optionsForRedraw) { - var withTransitionForAxis = !hasArcType(c3.data.targets), - options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; - options.withTransitionForTransform = false; - transiting = false; - setTargetType(targetIds, type); - updateAndRedraw(options); - } - - c3.focus = function (targetId) { - var candidates = svg.selectAll(selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(isNoneArc), - candidatesForArc = candidates.filter(isArc); - function focus(targets) { - filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); - } - c3.revert(); - c3.defocus(); - focus(candidatesForNoneArc.classed(CLASS.focused, true)); - focus(candidatesForArc); - if (hasArcType(c3.data.targets)) { - expandArc(targetId, true); - } - toggleFocusLegend(targetId, true); - }; - - c3.defocus = function (targetId) { - var candidates = svg.selectAll(selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(isNoneArc), - candidatesForArc = candidates.filter(isArc); - function defocus(targets) { - filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); - } - c3.revert(); - defocus(candidatesForNoneArc.classed(CLASS.focused, false)); - defocus(candidatesForArc); - if (hasArcType(c3.data.targets)) { - unexpandArc(targetId); - } - toggleFocusLegend(targetId, false); - }; + $$.revertLegend(); + }; - c3.revert = function (targetId) { - var candidates = svg.selectAll(selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(isNoneArc), - candidatesForArc = candidates.filter(isArc); - function revert(targets) { - filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); - } - revert(candidatesForNoneArc.classed(CLASS.focused, false)); - revert(candidatesForArc); - if (hasArcType(c3.data.targets)) { - unexpandArc(targetId); - } - revertLegend(); - }; + c3.fn.chart.show = function (targetIds, options) { + var $$ = this.$$; - c3.show = function (targetIds, options) { - targetIds = mapToTargetIds(targetIds); - options = options || {}; + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; - removeHiddenTargetIds(targetIds); - svg.selectAll(selectorTargets(targetIds)) - .transition() - .style('opacity', 1); + $$.removeHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 1); - if (options.withLegend) { - showLegend(targetIds); - } + if (options.withLegend) { + $$.showLegend(targetIds); + } - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - }; + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + }; - c3.hide = function (targetIds, options) { - targetIds = mapToTargetIds(targetIds); - options = options || {}; + c3.fn.chart.hide = function (targetIds, options) { + var $$ = this.$$; - addHiddenTargetIds(targetIds); - svg.selectAll(selectorTargets(targetIds)) - .transition() - .style('opacity', 0); + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; - if (options.withLegend) { - hideLegend(targetIds); - } + $$.addHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 0); - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - }; + if (options.withLegend) { + $$.hideLegend(targetIds); + } - c3.toggle = function (targetId) { - isTargetToShow(targetId) ? c3.hide(targetId) : c3.show(targetId); - }; + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + }; - c3.unzoom = function () { - brush.clear().update(); - redraw({withUpdateXDomain: true}); - }; - c3.zoom = function () { - }; - c3.zoom.enable = function (enabled) { - __zoom_enabled = enabled; - updateAndRedraw(); - }; + c3.fn.chart.toggle = function (targetId) { + var $$ = this.$$; + $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); + }; - c3.load = function (args) { - // update xs if specified - if (args.xs) { - addXs(args.xs); - } - // update classes if exists - if ('classes' in args) { - Object.keys(args.classes).forEach(function (id) { - __data_classes[id] = args.classes[id]; - }); - } - // update categories if exists - if ('categories' in args && isCategorized) { - __axis_x_categories = args.categories; - } - // use cache if exists - if ('cacheIds' in args && hasCaches(args.cacheIds)) { - load(getCaches(args.cacheIds), args.done); - return; - } - // unload if needed - if ('unload' in args) { - // TODO: do not unload if target will load (included in url/rows/columns) - unload(mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { - loadFromArgs(args); - }); - } else { - loadFromArgs(args); - } - }; + c3.fn.chart.zoom = function () { + }; + c3.fn.chart.zoom.enable = function (enabled) { + var $$ = this.$$; + $$.__zoom_enabled = enabled; + $$.updateAndRedraw(); + }; + c3.fn.chart.unzoom = function () { + var $$ = this.$$; + $$.brush.clear().update(); + $$.redraw({withUpdateXDomain: true}); + }; - c3.unload = function (args) { - args = args || {}; - unload(mapToTargetIds(args.ids), function () { - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (typeof args.done === 'function') { args.done(); } + c3.fn.chart.load = function (args) { + var $$ = this.$$; + // update xs if specified + if (args.xs) { + $$.addXs(args.xs); + } + // update classes if exists + if ('classes' in args) { + Object.keys(args.classes).forEach(function (id) { + $$.__data_classes[id] = args.classes[id]; }); - }; - - c3.flow = function (args) { - var targets = convertDataToTargets(convertColumnsToData(args.columns), true), notfoundIds = [], - orgDataCount = getMaxDataCount(), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + } + // update categories if exists + if ('categories' in args && $$.isCategorized) { + $$.__axis_x_categories = args.categories; + } + // use cache if exists + if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { + $$.load($$.getCaches(args.cacheIds), args.done); + return; + } + // unload if needed + if ('unload' in args) { + // TODO: do not unload if target will load (included in url/rows/columns) + $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + $$.loadFromArgs(args); + }); + } else { + $$.loadFromArgs(args); + } + }; - // Update/Add data - c3.data.targets.forEach(function (t) { - var found = false, i, j; - for (i = 0; i < targets.length; i++) { - if (t.id === targets[i].id) { - found = true; - - if (t.values[t.values.length - 1]) { - tail = t.values[t.values.length - 1].index + 1; - } - length = targets[i].values.length; + c3.fn.chart.unload = function (args) { + var $$ = this.$$; + args = args || {}; + $$.unload($$.mapToTargetIds(args.ids), function () { + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + if (typeof args.done === 'function') { args.done(); } + }); + }; - for (j = 0; j < length; j++) { - targets[i].values[j].index = tail + j; - if (!isTimeSeries) { - targets[i].values[j].x = tail + j; - } - } - t.values = t.values.concat(targets[i].values); + c3.fn.chart.flow = function (args) { + var $$ = this.$$, + targets = $$.convertDataToTargets($$.convertColumnsToData(args.columns), true), + notfoundIds = [], orgDataCount = $$.getMaxDataCount(), + dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + + // Update/Add data + $$.data.targets.forEach(function (t) { + var found = false, i, j; + for (i = 0; i < targets.length; i++) { + if (t.id === targets[i].id) { + found = true; - targets.splice(i, 1); - break; + if (t.values[t.values.length - 1]) { + tail = t.values[t.values.length - 1].index + 1; } - } - if (!found) { notfoundIds.push(t.id); } - }); + length = targets[i].values.length; - // Append null for not found targets - c3.data.targets.forEach(function (t) { - var i, j; - for (i = 0; i < notfoundIds.length; i++) { - if (t.id === notfoundIds[i]) { - tail = t.values[t.values.length - 1].index + 1; - for (j = 0; j < length; j++) { - t.values.push({ - id: t.id, - index: tail + j, - x: isTimeSeries ? getOtherTargetX(tail + j) : tail + j, - value: null - }); + for (j = 0; j < length; j++) { + targets[i].values[j].index = tail + j; + if (!$$.isTimeSeries) { + targets[i].values[j].x = tail + j; } } + t.values = t.values.concat(targets[i].values); + + targets.splice(i, 1); + break; } - }); + } + if (!found) { notfoundIds.push(t.id); } + }); - // Generate null values for new target - if (c3.data.targets.length) { - targets.forEach(function (t) { - var i, missing = []; - for (i = c3.data.targets[0].values[0].index; i < tail; i++) { - missing.push({ + // Append null for not found targets + $$.data.targets.forEach(function (t) { + var i, j; + for (i = 0; i < notfoundIds.length; i++) { + if (t.id === notfoundIds[i]) { + tail = t.values[t.values.length - 1].index + 1; + for (j = 0; j < length; j++) { + t.values.push({ id: t.id, - index: i, - x: isTimeSeries ? getOtherTargetX(i) : i, + index: tail + j, + x: $$.isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j, value: null }); } - t.values.forEach(function (v) { - v.index += tail; - if (!isTimeSeries) { - v.x += tail; - } - }); - t.values = missing.concat(t.values); - }); - } - c3.data.targets = c3.data.targets.concat(targets); // add remained - - // check data count because behavior needs to change when it's only one - dataCount = getMaxDataCount(); - baseTarget = c3.data.targets[0]; - baseValue = baseTarget.values[0]; - - // Update length to flow if needed - if (isDefined(args.to)) { - length = 0; - to = isTimeSeries ? parseDate(args.to) : args.to; - baseTarget.values.forEach(function (v) { - if (v.x < to) { length++; } - }); - } else if (isDefined(args.length)) { - length = args.length; + } } + }); - // If only one data, update the domain to flow from left edge of the chart - if (!orgDataCount) { - if (isTimeSeries) { - if (baseTarget.values.length > 1) { - diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; - } else { - diff = baseValue.x - getXDomain(c3.data.targets)[0]; - } - } else { - diff = 1; - } - domain = [baseValue.x - diff, baseValue.x]; - updateXDomain(null, true, true, domain); - } else if (orgDataCount === 1) { - if (isTimeSeries) { - diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; - domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; - updateXDomain(null, true, true, domain); + // Generate null values for new target + if ($$.data.targets.length) { + targets.forEach(function (t) { + var i, missing = []; + for (i = $$.data.targets[0].values[0].index; i < tail; i++) { + missing.push({ + id: t.id, + index: i, + x: $$.isTimeSeries ? $$.getOtherTargetX(i) : i, + value: null + }); } - } + t.values.forEach(function (v) { + v.index += tail; + if (!$$.isTimeSeries) { + v.x += tail; + } + }); + t.values = missing.concat(t.values); + }); + } + $$.data.targets = $$.data.targets.concat(targets); // add remained + + // check data count because behavior needs to change when it's only one + dataCount = $$.getMaxDataCount(); + baseTarget = $$.data.targets[0]; + baseValue = baseTarget.values[0]; - // Set targets - updateTargets(c3.data.targets); - - // Redraw with new targets - redraw({ - flow: { - index: baseValue.index, - length: length, - duration: isValue(args.duration) ? args.duration : __transition_duration, - done: args.done, - orgDataCount: orgDataCount, - }, - withLegend: true, - withTransition: orgDataCount > 1, + // Update length to flow if needed + if ($$.isDefined(args.to)) { + length = 0; + to = $$.isTimeSeries ? $$.parseDate(args.to) : args.to; + baseTarget.values.forEach(function (v) { + if (v.x < to) { length++; } }); - }; + } else if ($$.isDefined(args.length)) { + length = args.length; + } - c3.selected = function (targetId) { - return d3.merge( - main.selectAll('.' + CLASS.shapes + getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) - .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) - .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) - ); - }; + // If only one data, update the domain to flow from left edge of the chart + if (!orgDataCount) { + if ($$.isTimeSeries) { + if (baseTarget.values.length > 1) { + diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; + } else { + diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; + } + } else { + diff = 1; + } + domain = [baseValue.x - diff, baseValue.x]; + $$.updateXDomain(null, true, true, domain); + } else if (orgDataCount === 1) { + if ($$.isTimeSeries) { + diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; + domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; + $$.updateXDomain(null, true, true, domain); + } + } + + // Set targets + $$.updateTargets($$.data.targets); + + // Redraw with new targets + $$.redraw({ + flow: { + index: baseValue.index, + length: length, + duration: $$.isValue(args.duration) ? args.duration : $$.__transition_duration, + done: args.done, + orgDataCount: orgDataCount, + }, + withLegend: true, + withTransition: orgDataCount > 1, + }); + }; - c3.select = function (ids, indices, resetOther) { - if (! __data_selection_enabled) { return; } - main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = getToggle(this), - isTargetId = __data_selection_grouped || !ids || ids.indexOf(id) >= 0, - isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); - // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { - return; + c3.fn.chart.selected = function (targetId) { + var $$ = this.$$, d3 = $$.d3, CLASS = $$.CLASS; + return d3.merge( + $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) + .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) + .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) + ); + }; + c3.fn.chart.select = function (ids, indices, resetOther) { + var $$ = this.$$, CLASS = $$.CLASS, d3 = $$.d3; + if (! $$.__data_selection_enabled) { return; } + $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = $$.__data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS.SELECTED); + // line/area selection not supported yet + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + return; + } + if (isTargetId && isTargetIndex) { + if ($$.__data_selection_isselectable(d) && !isSelected) { + toggle(true, shape.classed(CLASS.SELECTED, true), d, i); } - if (isTargetId && isTargetIndex) { - if (__data_selection_isselectable(d) && !isSelected) { - toggle(true, shape.classed(CLASS.SELECTED, true), d, i); - } - } else if (isDefined(resetOther) && resetOther) { + } else if ($$.isDefined(resetOther) && resetOther) { + if (isSelected) { + toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + } + } + }); + }; + c3.fn.chart.unselect = function (ids, indices) { + var $$ = this.$$, CLASS = $$.CLASS, d3 = $$.d3; + if (! $$.__data_selection_enabled) { return; } + $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = $$.__data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS.SELECTED); + // line/area selection not supported yet + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + return; + } + if (isTargetId && isTargetIndex) { + if ($$.__data_selection_isselectable(d)) { if (isSelected) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } } - }); - }; - - c3.unselect = function (ids, indices) { - if (! __data_selection_enabled) { return; } - main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = getToggle(this), - isTargetId = __data_selection_grouped || !ids || ids.indexOf(id) >= 0, - isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); - // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { - return; - } - if (isTargetId && isTargetIndex) { - if (__data_selection_isselectable(d)) { - if (isSelected) { - toggle(false, shape.classed(CLASS.SELECTED, false), d, i); - } - } - } - }); - }; + } + }); + }; - c3.transform = function (type, targetIds) { - var options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; - transformTo(targetIds, type, options); - }; + c3.fn.chart.transform = function (type, targetIds) { + var $$ = this.$$, + options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; + $$.transformTo(targetIds, type, options); + }; - c3.groups = function (groups) { - if (isUndefined(groups)) { return __data_groups; } - __data_groups = groups; - redraw(); - return __data_groups; - }; + c3.fn.chart.groups = function (groups) { + var $$ = this.$$; + if ($$.isUndefined(groups)) { return $$.__data_groups; } + $$.__data_groups = groups; + $$.redraw(); + return $$.__data_groups; + }; - c3.xgrids = function (grids) { - if (! grids) { return __grid_x_lines; } - __grid_x_lines = grids; - redraw(); - return __grid_x_lines; - }; - c3.xgrids.add = function (grids) { - if (! grids) { return; } - return c3.xgrids(__grid_x_lines.concat(grids)); - }; - c3.xgrids.remove = function (params) { // TODO: multiple - removeGridLines(params, true); - }; + c3.fn.chart.xgrids = function (grids) { + var $$ = this.$$; + if (! grids) { return $$.__grid_x_lines; } + $$.__grid_x_lines = grids; + $$.redraw(); + return $$.__grid_x_lines; + }; + c3.fn.chart.xgrids.add = function (grids) { + var $$ = this.$$; + return this.xgrids($$.__grid_x_lines.concat(grids ? grids : [])); + }; + c3.fn.chart.xgrids.remove = function (params) { // TODO: multiple + var $$ = this.$$; + $$.removeGridLines(params, true); + }; - c3.ygrids = function (grids) { - if (! grids) { return __grid_y_lines; } - __grid_y_lines = grids; - redraw(); - return __grid_y_lines; - }; - c3.ygrids.add = function (grids) { - if (! grids) { return; } - return c3.ygrids(__grid_y_lines.concat(grids)); - }; - c3.ygrids.remove = function (params) { // TODO: multiple - removeGridLines(params, false); - }; + c3.fn.chart.ygrids = function (grids) { + var $$ = this.$$; + if (! grids) { return $$.__grid_y_lines; } + $$.__grid_y_lines = grids; + $$.redraw(); + return $$.__grid_y_lines; + }; + c3.fn.chart.ygrids.add = function (grids) { + var $$ = this.$$; + return c3.ygrids($$.__grid_y_lines.concat(grids ? grids : [])); + }; + c3.fn.chart.ygrids.remove = function (params) { // TODO: multiple + var $$ = this.$$; + $$.removeGridLines(params, false); + }; - c3.regions = function (regions) { - if (!regions) { return __regions; } - __regions = regions; - redraw(); - return __regions; - }; - c3.regions.add = function (regions) { - if (!regions) { return __regions; } - __regions = __regions.concat(regions); - redraw(); - return __regions; - }; - c3.regions.remove = function (options) { - var duration, classes, regions; + c3.fn.chart.regions = function (regions) { + var $$ = this.$$; + if (!regions) { return $$.__regions; } + $$.__regions = regions; + $$.redraw(); + return $$.__regions; + }; + c3.fn.chart.regions.add = function (regions) { + var $$ = this.$$; + if (!regions) { return $$.__regions; } + $$.__regions = $$.__regions.concat(regions); + $$.redraw(); + return $$.__regions; + }; + c3.fn.chart.regions.remove = function (options) { + var $$ = this.$$, CLASS = $$.CLASS, + duration, classes, regions; - options = options || {}; - duration = getOption(options, "duration", __transition_duration); - classes = getOption(options, "classes", [CLASS.region]); + options = options || {}; + duration = $$.getOption(options, "duration", $$.__transition_duration); + classes = $$.getOption(options, "classes", [CLASS.region]); - regions = main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); - (duration ? regions.transition().duration(duration) : regions) - .style('opacity', 0) - .remove(); + regions = $$.main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); + (duration ? regions.transition().duration(duration) : regions) + .style('opacity', 0) + .remove(); - __regions = __regions.filter(function (region) { - var found = false; - if (!region.class) { - return true; - } - region.class.split(' ').forEach(function (c) { - if (classes.indexOf(c) >= 0) { found = true; } - }); - return !found; + $$.__regions = $$.__regions.filter(function (region) { + var found = false; + if (!region.class) { + return true; + } + region.class.split(' ').forEach(function (c) { + if (classes.indexOf(c) >= 0) { found = true; } }); + return !found; + }); - return __regions; - }; + return $$.__regions; + }; - c3.data.get = function (targetId) { - var target = c3.data.getAsTarget(targetId); - return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; - }; - c3.data.getAsTarget = function (targetId) { - var targets = c3.data.targets.filter(function (t) { return t.id === targetId; }); - return targets.length > 0 ? targets[0] : undefined; - }; - c3.data.names = function (names) { - if (!arguments.length) { return __data_names; } - Object.keys(names).forEach(function (id) { - __data_names[id] = names[id]; - }); - redraw({withLegend: true}); - return __data_names; - }; - c3.data.colors = function (colors) { - if (!arguments.length) { return __data_colors; } - Object.keys(colors).forEach(function (id) { - __data_colors[id] = colors[id]; - }); - redraw({withLegend: true}); - return __data_colors; - }; + c3.fn.chart.data = function () { + }; + c3.fn.chart.data.get = function (targetId) { + var $$ = this.$$, + target = this.data.getAsTarget(targetId); + return $$.isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; + }; + c3.fn.chart.data.getAsTarget = function (targetId) { + var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); + return targets.length > 0 ? targets[0] : undefined; + }; + c3.fn.chart.data.names = function (names) { + var $$ = this.$$; + if (!arguments.length) { return $$.__data_names; } + Object.keys(names).forEach(function (id) { + $$.__data_names[id] = names[id]; + }); + $$.redraw({withLegend: true}); + return $$.__data_names; + }; + c3.fn.chart.data.colors = function (colors) { + var $$ = this.$$; + if (!arguments.length) { return $$.__data_colors; } + Object.keys(colors).forEach(function (id) { + $$.__data_colors[id] = colors[id]; + }); + $$.redraw({withLegend: true}); + return $$.__data_colors; + }; + c3.fn.chart.category = function (i, category) { + var $$ = this.$$; + if (arguments.length > 1) { + $$.__axis_x_categories[i] = category; + $$.redraw(); + } + return $$.__axis_x_categories[i]; + }; + c3.fn.chart.categories = function (categories) { + var $$ = this.$$; + if (!arguments.length) { return $$.__axis_x_categories; } + $$.__axis_x_categories = categories; + $$.redraw(); + return $$.__axis_x_categories; + }; - c3.category = function (i, category) { - if (arguments.length > 1) { - __axis_x_categories[i] = category; - redraw(); - } - return __axis_x_categories[i]; - }; - c3.categories = function (categories) { - if (!arguments.length) { return __axis_x_categories; } - __axis_x_categories = categories; - redraw(); - return __axis_x_categories; - }; + // TODO: fix + c3.fn.chart.color = function (id) { + var $$ = this.$$; + return $$.color(id); // more patterns + }; - c3.color = color; + c3.fn.chart.x = function (x) { + var $$ = this.$$; + if (arguments.length) { + $$.updateTargetX($$.data.targets, x); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; + }; + c3.fn.chart.xs = function (xs) { + var $$ = this.$$; + if (arguments.length) { + $$.updateTargetXs($$.data.targets, xs); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; + }; - c3.x = function (x) { - if (arguments.length) { - updateTargetX(c3.data.targets, x); - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } - return c3.data.xs; - }; - c3.xs = function (xs) { - if (arguments.length) { - updateTargetXs(c3.data.targets, xs); - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } - return c3.data.xs; - }; - c3.axis.labels = function (labels) { - if (arguments.length) { - Object.keys(labels).forEach(function (axisId) { - setAxisLabelText(axisId, labels[axisId]); - }); - updateAxisLabels(); - } - // TODO: return some values? - }; - c3.axis.max = function (max) { - if (arguments.length) { - if (typeof max === 'object') { - if (isValue(max.x)) { __axis_x_max = max.x; } - if (isValue(max.y)) { __axis_y_max = max.y; } - if (isValue(max.y2)) { __axis_y2_max = max.y2; } - } else { - __axis_y_max = __axis_y2_max = max; - } - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } - }; - c3.axis.min = function (min) { - if (arguments.length) { - if (typeof min === 'object') { - if (isValue(min.x)) { __axis_x_min = min.x; } - if (isValue(min.y)) { __axis_y_min = min.y; } - if (isValue(min.y2)) { __axis_y2_min = min.y2; } - } else { - __axis_y_min = __axis_y2_min = min; - } - redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + c3.fn.chart.axis = function () { + }; + c3.fn.chart.axis.labels = function (labels) { + var $$ = this.$$; + if (arguments.length) { + Object.keys(labels).forEach(function (axisId) { + $$.setAxisLabelText(axisId, labels[axisId]); + }); + $$.updateAxisLabels(); + } + // TODO: return some values? + }; + c3.fn.chart.axis.max = function (max) { + var $$ = this.$$; + if (arguments.length) { + if (typeof max === 'object') { + if ($$.isValue(max.x)) { $$.__axis_x_max = max.x; } + if ($$.isValue(max.y)) { $$.__axis_y_max = max.y; } + if ($$.isValue(max.y2)) { $$.__axis_y2_max = max.y2; } + } else { + $$.__axis_y_max = $$.__axis_y2_max = max; } - }; - c3.axis.range = function (range) { - if (arguments.length) { - if (typeof range.max !== 'undefined') { c3.axis.max(range.max); } - if (typeof range.min !== 'undefined') { c3.axis.min(range.min); } + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + }; + c3.fn.chart.axis.min = function (min) { + var $$ = this.$$; + if (arguments.length) { + if (typeof min === 'object') { + if ($$.isValue(min.x)) { $$.__axis_x_min = min.x; } + if ($$.isValue(min.y)) { $$.__axis_y_min = min.y; } + if ($$.isValue(min.y2)) { $$.__axis_y2_min = min.y2; } + } else { + $$.__axis_y_min = $$.__axis_y2_min = min; } - }; - - c3.legend.show = function (targetIds) { - showLegend(mapToTargetIds(targetIds)); - updateAndRedraw({withLegend: true}); - }; - c3.legend.hide = function (targetIds) { - hideLegend(mapToTargetIds(targetIds)); - updateAndRedraw({withLegend: true}); - }; - - c3.resize = function (size) { - __size_width = size ? size.width : null; - __size_height = size ? size.height : null; - c3.flush(); - }; + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + }; + c3.fn.chart.axis.range = function (range) { + var $$ = this.$$; + if (arguments.length) { + if (typeof range.max !== 'undefined') { this.axis.max(range.max); } + if (typeof range.min !== 'undefined') { this.axis.min(range.min); } + } + }; - c3.flush = function () { - updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); - }; - c3.destroy = function () { - c3.data.targets = undefined; - c3.data.xs = {}; - selectChart.classed('c3', false).html(""); - window.onresize = null; - }; + c3.fn.chart.legend = function () { + }; + c3.fn.chart.legend.show = function (targetIds) { + var $$ = this.$$; + $$.showLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); + }; + c3.fn.chart.legend.hide = function (targetIds) { + var $$ = this.$$; + $$.hideLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); + }; - /*-- Load data and init chart with defined functions --*/ + c3.fn.chart.resize = function (size) { + var $$ = this.$$; + $$.__size_width = size ? size.width : null; + $$.__size_height = size ? size.height : null; + this.flush(); + }; - if (config.data.url) { - convertUrlToData(config.data.url, config.data.mimeType, config.data.keys, init); - } - else if (config.data.json) { - init(convertJsonToData(config.data.json, config.data.keys)); - } - else if (config.data.rows) { - init(convertRowsToData(config.data.rows)); - } - else if (config.data.columns) { - init(convertColumnsToData(config.data.columns)); - } - else { - throw Error('url or json or rows or columns is required.'); - } + c3.fn.chart.flush = function () { + var $$ = this.$$; + $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); + }; - return c3; + c3.fn.chart.destroy = function () { + var $$ = this.$$; + $$.data.targets = undefined; + $$.data.xs = {}; + $$.selectChart.classed('c3', false).html(""); + window.onresize = null; }; - function isValue(v) { - return v || v === 0; - } - function isUndefined(v) { - return typeof v === 'undefined'; - } - function isDefined(v) { - return typeof v !== 'undefined'; - } - if (typeof define === "function" && define.amd) { - define("c3", ["d3"], c3); - } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { - module.exports = c3; - } else { - window.c3 = c3; - } + /** + * c3.axis.js + */ // Features: // 1. category axis // 2. ceil values of translate/x/y to int for half pixel antialiasing @@ -5534,4 +5900,5 @@ return axis; } -})(window); + +})(window.c3); diff --git a/c3.old.js b/c3.old.js new file mode 100644 index 0000000..dca10f5 --- /dev/null +++ b/c3.old.js @@ -0,0 +1,5537 @@ +(function (window) { + 'use strict'; + + /*global define, module, exports, require */ + + var c3 = { + version: "0.2.4" + }; + + var CLASS = { + target: 'c3-target', + chart : 'c3-chart', + chartLine: 'c3-chart-line', + chartLines: 'c3-chart-lines', + chartBar: 'c3-chart-bar', + chartBars: 'c3-chart-bars', + chartText: 'c3-chart-text', + chartTexts: 'c3-chart-texts', + chartArc: 'c3-chart-arc', + chartArcs: 'c3-chart-arcs', + chartArcsTitle: 'c3-chart-arcs-title', + chartArcsBackground: 'c3-chart-arcs-background', + chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', + chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', + chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', + selectedCircle: 'c3-selected-circle', + selectedCircles: 'c3-selected-circles', + eventRect: 'c3-event-rect', + eventRects: 'c3-event-rects', + eventRectsSingle: 'c3-event-rects-single', + eventRectsMultiple: 'c3-event-rects-multiple', + zoomRect: 'c3-zoom-rect', + brush: 'c3-brush', + focused: 'c3-focused', + region: 'c3-region', + regions: 'c3-regions', + tooltip: 'c3-tooltip', + tooltipName: 'c3-tooltip-name', + shape: 'c3-shape', + shapes: 'c3-shapes', + line: 'c3-line', + lines: 'c3-lines', + bar: 'c3-bar', + bars: 'c3-bars', + circle: 'c3-circle', + circles: 'c3-circles', + arc: 'c3-arc', + arcs: 'c3-arcs', + area: 'c3-area', + areas: 'c3-areas', + empty: 'c3-empty', + text: 'c3-text', + texts: 'c3-texts', + gaugeValue: 'c3-gauge-value', + grid: 'c3-grid', + xgrid: 'c3-xgrid', + xgrids: 'c3-xgrids', + xgridLine: 'c3-xgrid-line', + xgridLines: 'c3-xgrid-lines', + xgridFocus: 'c3-xgrid-focus', + ygrid: 'c3-ygrid', + ygrids: 'c3-ygrids', + ygridLine: 'c3-ygrid-line', + ygridLines: 'c3-ygrid-lines', + axis: 'c3-axis', + axisX: 'c3-axis-x', + axisXLabel: 'c3-axis-x-label', + axisY: 'c3-axis-y', + axisYLabel: 'c3-axis-y-label', + axisY2: 'c3-axis-y2', + axisY2Label: 'c3-axis-y2-label', + legendBackground: 'c3-legend-background', + legendItem: 'c3-legend-item', + legendItemEvent: 'c3-legend-item-event', + legendItemTile: 'c3-legend-item-tile', + legendItemHidden: 'c3-legend-item-hidden', + legendItemFocused: 'c3-legend-item-focused', + dragarea: 'c3-dragarea', + EXPANDED: '_expanded_', + SELECTED: '_selected_', + INCLUDED: '_included_', + }; + + /* + * Generate chart according to config + */ + c3.generate = function (config) { + + var d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + + var c3 = { data : {}, axis: {}, legend: {} }, + cache = {}; + + /*-- Handle Config --*/ + + function checkConfig(key, message) { + if (! (key in config)) { throw Error(message); } + } + + function getConfig(keys, defaultValue) { + var target = config, i, isLast, nextTarget; + for (i = 0; i < keys.length; i++) { + // return default if key not found + if (typeof target === 'object' && !(keys[i] in target)) { return defaultValue; } + // Check next key's value + isLast = (i === keys.length - 1); + nextTarget = target[keys[i]]; + if (!isLast && typeof nextTarget !== 'object') { + return defaultValue; + } + target = nextTarget; + } + return target; + } + + // bindto - id to bind the chart + var __bindto = getConfig(['bindto'], '#chart'); + + var __size_width = getConfig(['size', 'width']), + __size_height = getConfig(['size', 'height']); + + var __padding_left = getConfig(['padding', 'left']), + __padding_right = getConfig(['padding', 'right']), + __padding_top = getConfig(['padding', 'top']), + __padding_bottom = getConfig(['padding', 'bottom']); + + var __zoom_enabled = getConfig(['zoom', 'enabled'], false), + __zoom_extent = getConfig(['zoom', 'extent']), + __zoom_privileged = getConfig(['zoom', 'privileged'], false), + __zoom_onzoom = getConfig(['zoom', 'onzoom'], function () {}); + + var __interaction_enabled = getConfig(['interaction', 'enabled'], true); + + var __onmouseover = getConfig(['onmouseover'], function () {}), + __onmouseout = getConfig(['onmouseout'], function () {}), + __onresize = getConfig(['onresize'], function () {}), + __onresized = getConfig(['onresized'], function () {}); + + var __transition_duration = getConfig(['transition', 'duration'], 350); + + // data - data configuration + checkConfig('data', 'data is required in config'); + + var __data_x = getConfig(['data', 'x']), + __data_xs = getConfig(['data', 'xs'], {}), + __data_x_format = getConfig(['data', 'x_format'], '%Y-%m-%d'), + __data_x_localtime = getConfig(['data', 'x_localtime'], true), + __data_id_converter = getConfig(['data', 'id_converter'], function (id) { return id; }), + __data_names = getConfig(['data', 'names'], {}), + __data_classes = getConfig(['data', 'classes'], {}), + __data_groups = getConfig(['data', 'groups'], []), + __data_axes = getConfig(['data', 'axes'], {}), + __data_type = getConfig(['data', 'type']), + __data_types = getConfig(['data', 'types'], {}), + __data_labels = getConfig(['data', 'labels'], {}), + __data_order = getConfig(['data', 'order']), + __data_regions = getConfig(['data', 'regions'], {}), + __data_color = getConfig(['data', 'color']), + __data_colors = getConfig(['data', 'colors'], {}), + __data_hide = getConfig(['data', 'hide'], false), + __data_filter = getConfig(['data', 'filter']), + __data_selection_enabled = getConfig(['data', 'selection', 'enabled'], false), + __data_selection_grouped = getConfig(['data', 'selection', 'grouped'], false), + __data_selection_isselectable = getConfig(['data', 'selection', 'isselectable'], function () { return true; }), + __data_selection_multiple = getConfig(['data', 'selection', 'multiple'], true), + __data_onclick = getConfig(['data', 'onclick'], function () {}), + __data_onmouseover = getConfig(['data', 'onmouseover'], function () {}), + __data_onmouseout = getConfig(['data', 'onmouseout'], function () {}), + __data_onselected = getConfig(['data', 'onselected'], function () {}), + __data_onunselected = getConfig(['data', 'onunselected'], function () {}), + __data_ondragstart = getConfig(['data', 'ondragstart'], function () {}), + __data_ondragend = getConfig(['data', 'ondragend'], function () {}); + + // configuration for no plot-able data supplied. + var __data_empty_label_text = getConfig(['data', 'empty', 'label', 'text'], ""); + + // subchart + var __subchart_show = getConfig(['subchart', 'show'], false), + __subchart_size_height = getConfig(['subchart', 'size', 'height'], 60), + __subchart_onbrush = getConfig(['subchart', 'onbrush'], function () {}); + + // color + var __color_pattern = getConfig(['color', 'pattern'], []), + __color_threshold = getConfig(['color', 'threshold'], {}); + + // legend + var __legend_show = getConfig(['legend', 'show'], true), + __legend_position = getConfig(['legend', 'position'], 'bottom'), + __legend_inset_anchor = getConfig(['legend', 'inset', 'anchor'], 'top-left'), + __legend_inset_x = getConfig(['legend', 'inset', 'x'], 10), + __legend_inset_y = getConfig(['legend', 'inset', 'y'], 0), + __legend_inset_step = getConfig(['legend', 'inset', 'step']), + __legend_item_onclick = getConfig(['legend', 'item', 'onclick']), + __legend_item_onmouseover = getConfig(['legend', 'item', 'onmouseover']), + __legend_item_onmouseout = getConfig(['legend', 'item', 'onmouseout']), + __legend_equally = getConfig(['legend', 'equally'], false); + + // axis + var __axis_rotated = getConfig(['axis', 'rotated'], false), + __axis_x_show = getConfig(['axis', 'x', 'show'], true), + __axis_x_type = getConfig(['axis', 'x', 'type'], 'indexed'), + __axis_x_localtime = getConfig(['axis', 'x', 'localtime'], true), + __axis_x_categories = getConfig(['axis', 'x', 'categories'], []), + __axis_x_tick_centered = getConfig(['axis', 'x', 'tick', 'centered'], false), + __axis_x_tick_format = getConfig(['axis', 'x', 'tick', 'format']), + __axis_x_tick_culling = getConfig(['axis', 'x', 'tick', 'culling'], {}), + __axis_x_tick_culling_max = getConfig(['axis', 'x', 'tick', 'culling', 'max'], 10), + __axis_x_tick_count = getConfig(['axis', 'x', 'tick', 'count']), + __axis_x_tick_fit = getConfig(['axis', 'x', 'tick', 'fit'], true), + __axis_x_tick_values = getConfig(['axis', 'x', 'tick', 'values'], null), + __axis_x_tick_rotate = getConfig(['axis', 'x', 'tick', 'rotate']), + __axis_x_max = getConfig(['axis', 'x', 'max'], null), + __axis_x_min = getConfig(['axis', 'x', 'min'], null), + __axis_x_padding = getConfig(['axis', 'x', 'padding'], {}), + __axis_x_height = getConfig(['axis', 'x', 'height']), + __axis_x_default = getConfig(['axis', 'x', 'default']), + __axis_x_label = getConfig(['axis', 'x', 'label'], {}), + __axis_y_show = getConfig(['axis', 'y', 'show'], true), + __axis_y_max = getConfig(['axis', 'y', 'max']), + __axis_y_min = getConfig(['axis', 'y', 'min']), + __axis_y_center = getConfig(['axis', 'y', 'center']), + __axis_y_label = getConfig(['axis', 'y', 'label'], {}), + __axis_y_inner = getConfig(['axis', 'y', 'inner'], false), + __axis_y_tick_format = getConfig(['axis', 'y', 'tick', 'format']), + __axis_y_padding = getConfig(['axis', 'y', 'padding']), + __axis_y_ticks = getConfig(['axis', 'y', 'ticks'], 10), + __axis_y2_show = getConfig(['axis', 'y2', 'show'], false), + __axis_y2_max = getConfig(['axis', 'y2', 'max']), + __axis_y2_min = getConfig(['axis', 'y2', 'min']), + __axis_y2_center = getConfig(['axis', 'y2', 'center']), + __axis_y2_label = getConfig(['axis', 'y2', 'label'], {}), + __axis_y2_inner = getConfig(['axis', 'y2', 'inner'], false), + __axis_y2_tick_format = getConfig(['axis', 'y2', 'tick', 'format']), + __axis_y2_padding = getConfig(['axis', 'y2', 'padding']), + __axis_y2_ticks = getConfig(['axis', 'y2', 'ticks'], 10); + + // grid + var __grid_x_show = getConfig(['grid', 'x', 'show'], false), + __grid_x_type = getConfig(['grid', 'x', 'type'], 'tick'), + __grid_x_lines = getConfig(['grid', 'x', 'lines'], []), + __grid_y_show = getConfig(['grid', 'y', 'show'], false), + // not used + // __grid_y_type = getConfig(['grid', 'y', 'type'], 'tick'), + __grid_y_lines = getConfig(['grid', 'y', 'lines'], []), + __grid_y_ticks = getConfig(['grid', 'y', 'ticks'], 10), + __grid_focus_show = getConfig(['grid', 'focus', 'show'], true); + + // point - point of each data + var __point_show = getConfig(['point', 'show'], true), + __point_r = getConfig(['point', 'r'], 2.5), + __point_focus_expand_enabled = getConfig(['point', 'focus', 'expand', 'enabled'], true), + __point_focus_expand_r = getConfig(['point', 'focus', 'expand', 'r']), + __point_select_r = getConfig(['point', 'focus', 'select', 'r']); + + var __line_connect_null = getConfig(['line', 'connect_null'], false); + + // bar + var __bar_width = getConfig(['bar', 'width']), + __bar_width_ratio = getConfig(['bar', 'width', 'ratio'], 0.6), + __bar_zerobased = getConfig(['bar', 'zerobased'], true); + + // area + var __area_zerobased = getConfig(['area', 'zerobased'], true); + + // pie + var __pie_label_show = getConfig(['pie', 'label', 'show'], true), + __pie_label_format = getConfig(['pie', 'label', 'format']), + __pie_label_threshold = getConfig(['pie', 'label', 'threshold'], 0.05), + __pie_sort = getConfig(['pie', 'sort'], true), + __pie_expand = getConfig(['pie', 'expand'], true); + + // gauge + var __gauge_label_show = getConfig(['gauge', 'label', 'show'], true), + __gauge_label_format = getConfig(['gauge', 'label', 'format']), + __gauge_expand = getConfig(['gauge', 'expand'], true), + __gauge_min = getConfig(['gauge', 'min'], 0), + __gauge_max = getConfig(['gauge', 'max'], 100), + __gauge_units = getConfig(['gauge', 'units']), + __gauge_width = getConfig(['gauge', 'width']); + + // donut + var __donut_label_show = getConfig(['donut', 'label', 'show'], true), + __donut_label_format = getConfig(['donut', 'label', 'format']), + __donut_label_threshold = getConfig(['donut', 'label', 'threshold'], 0.05), + __donut_sort = getConfig(['donut', 'sort'], true), + __donut_expand = getConfig(['donut', 'expand'], true), + __donut_title = getConfig(['donut', 'title'], ""); + + // region - region to change style + var __regions = getConfig(['regions'], []); + + // tooltip - show when mouseover on each data + var __tooltip_show = getConfig(['tooltip', 'show'], true), + __tooltip_grouped = getConfig(['tooltip', 'grouped'], true), + __tooltip_format_title = getConfig(['tooltip', 'format', 'title']), + __tooltip_format_name = getConfig(['tooltip', 'format', 'name']), + __tooltip_format_value = getConfig(['tooltip', 'format', 'value']), + __tooltip_contents = getConfig(['tooltip', 'contents'], function (d, defaultTitleFormat, defaultValueFormat, color) { + var titleFormat = __tooltip_format_title ? __tooltip_format_title : defaultTitleFormat, + nameFormat = __tooltip_format_name ? __tooltip_format_name : function (name) { return name; }, + valueFormat = __tooltip_format_value ? __tooltip_format_value : defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } + + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "" + (title || title === 0 ? "" : ""); + } + + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = levelColor ? levelColor(d[i].value) : color(d[i].id); + + text += ""; + text += ""; + text += ""; + text += ""; + } + return text + "
" + title + "
" + name + "" + value + "
"; + }), + __tooltip_init_show = getConfig(['tooltip', 'init', 'show'], false), + __tooltip_init_x = getConfig(['tooltip', 'init', 'x'], 0), + __tooltip_init_position = getConfig(['tooltip', 'init', 'position'], {top: '0px', left: '50px'}); + + /*-- Set Variables --*/ + + // MEMO: clipId needs to be unique because it conflicts when multiple charts exist + var clipId = "c3-" + (+new Date()) + '-clip', + clipIdForXAxis = clipId + '-xaxis', + clipIdForYAxis = clipId + '-yaxis', + clipPath = getClipPath(clipId), + clipPathForXAxis = getClipPath(clipIdForXAxis), + clipPathForYAxis = getClipPath(clipIdForYAxis); + + var isTimeSeries = (__axis_x_type === 'timeseries'), + isCategorized = (__axis_x_type.indexOf('categor') >= 0), + isCustomX = function () { return !isTimeSeries && (__data_x || notEmpty(__data_xs)); }; + + var dragStart = null, dragging = false, cancelClick = false, mouseover = false, transiting = false; + + var defaultColorPattern = d3.scale.category10().range(), + color = generateColor(__data_colors, notEmpty(__color_pattern) ? __color_pattern : defaultColorPattern, __data_color), + levelColor = notEmpty(__color_threshold) ? generateLevelColor(__color_pattern, __color_threshold) : null; + + var dataTimeFormat = __data_x_localtime ? d3.time.format : d3.time.format.utc, + axisTimeFormat = __axis_x_localtime ? d3.time.format : d3.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; }] + ]); + + var hiddenTargetIds = [], hiddenLegendIds = []; + + /*-- Set Chart Params --*/ + + var margin, margin2, margin3, width, width2, height, height2, currentWidth, currentHeight; + var radius, radiusExpanded, innerRadius, arcWidth, arcHeight, svgArc, svgArcExpanded, svgArcExpandedSub, pie; + var xMin, xMax, yMin, yMax, subXMin, subXMax, subYMin, subYMax; + var x, y, y2, subX, subY, subY2, xAxis, yAxis, y2Axis, subXAxis; + var axes = {}; + + var xOrient = __axis_rotated ? "left" : "bottom", + yOrient = __axis_rotated ? (__axis_y_inner ? "top" : "bottom") : (__axis_y_inner ? "right" : "left"), + y2Orient = __axis_rotated ? (__axis_y2_inner ? "bottom" : "top") : (__axis_y2_inner ? "left" : "right"), + subXOrient = __axis_rotated ? "left" : "bottom"; + + var translate = { + main : function () { return "translate(" + asHalfPixel(margin.left) + "," + asHalfPixel(margin.top) + ")"; }, + context : function () { return "translate(" + asHalfPixel(margin2.left) + "," + asHalfPixel(margin2.top) + ")"; }, + legend : function () { return "translate(" + margin3.left + "," + margin3.top + ")"; }, + x : function () { return "translate(0," + (__axis_rotated ? 0 : height) + ")"; }, + y : function () { return "translate(0," + (__axis_rotated ? height : 0) + ")"; }, + y2 : function () { return "translate(" + (__axis_rotated ? 0 : width) + "," + (__axis_rotated ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + (__axis_rotated ? 0 : height2) + ")"; }, + arc: function () { return "translate(" + (arcWidth / 2) + "," + (arcHeight / 2) + ")"; } + }; + + var isLegendRight = __legend_position === 'right'; + var isLegendInset = __legend_position === 'inset'; + var isLegendTop = __legend_inset_anchor === 'top-left' || __legend_inset_anchor === 'top-right'; + var isLegendLeft = __legend_inset_anchor === 'top-left' || __legend_inset_anchor === 'bottom-left'; + var legendStep = 0, legendItemWidth = 0, legendItemHeight = 0, legendOpacityForHidden = 0.15; + var currentMaxTickWidth = 0; + + /*-- Define Functions --*/ + + function getClipPath(id) { + var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; + return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; + } + + function asHalfPixel(n) { + return Math.ceil(n) + 0.5; + } + + function transformMain(withTransition, transitions) { + var 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", translate.main); + xAxis.attr("transform", translate.x); + yAxis.attr("transform", translate.y); + y2Axis.attr("transform", translate.y2); + main.select('.' + CLASS.chartArcs).attr("transform", translate.arc); + } + function transformContext(withTransition, transitions) { + var subXAxis; + if (transitions && transitions.axisSubX) { + subXAxis = transitions.axisSubX; + } else { + subXAxis = context.select('.' + CLASS.axisX); + if (withTransition) { subXAxis = subXAxis.transition(); } + } + context.attr("transform", translate.context); + subXAxis.attr("transform", translate.subx); + } + function transformLegend(withTransition) { + (withTransition ? legend.transition() : legend).attr("transform", translate.legend); + } + function transformAll(withTransition, transitions) { + transformMain(withTransition, transitions); + if (__subchart_show) { transformContext(withTransition, transitions); } + transformLegend(withTransition); + } + + //-- Sizes --// + + // TODO: configurabale + var rotated_padding_left = 30, rotated_padding_right = __axis_rotated && !__axis_x_show ? 0 : 30, rotated_padding_top = 5; + + // MEMO: each value should be int to avoid disabling antialiasing + function updateSizes() { + var legendHeight = getLegendHeight(), legendWidth = getLegendWidth(), + legendHeightForBottom = isLegendRight || isLegendInset ? 0 : legendHeight, + hasArc = hasArcType(c3.data.targets), + xAxisHeight = __axis_rotated || hasArc ? 0 : getHorizontalAxisHeight('x'), + subchartHeight = __subchart_show && !hasArc ? (__subchart_size_height + xAxisHeight) : 0; + + currentWidth = getCurrentWidth(); + currentHeight = getCurrentHeight(); + + // for main, context + if (__axis_rotated) { + margin = { + top: getHorizontalAxisHeight('y2') + getCurrentPaddingTop(), + right: hasArc ? 0 : getCurrentPaddingRight(), + bottom: getHorizontalAxisHeight('y') + legendHeightForBottom + getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : getCurrentPaddingLeft()) + }; + margin2 = { + top: margin.top, + right: NaN, + bottom: 20 + legendHeightForBottom, + left: rotated_padding_left + }; + } else { + margin = { + top: 4 + getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + getCurrentPaddingBottom(), + left: hasArc ? 0 : getCurrentPaddingLeft() + }; + margin2 = { + top: currentHeight - subchartHeight - legendHeightForBottom, + right: NaN, + bottom: xAxisHeight + legendHeightForBottom, + left: margin.left + }; + } + // for legend + var insetLegendPosition = { + top: isLegendTop ? getCurrentPaddingTop() + __legend_inset_y + 5.5 : currentHeight - legendHeight - getCurrentPaddingBottom() - __legend_inset_y, + left: isLegendLeft ? getCurrentPaddingLeft() + __legend_inset_x + 0.5 : currentWidth - legendWidth - getCurrentPaddingRight() - __legend_inset_x + 0.5 + }; + margin3 = { + top: isLegendRight ? 0 : isLegendInset ? insetLegendPosition.top : currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: isLegendRight ? currentWidth - legendWidth : isLegendInset ? insetLegendPosition.left : 0 + }; + + width = currentWidth - margin.left - margin.right; + height = currentHeight - margin.top - margin.bottom; + if (width < 0) { width = 0; } + if (height < 0) { height = 0; } + + width2 = __axis_rotated ? margin.left - rotated_padding_left - rotated_padding_right : width; + height2 = __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); + updateRadius(); + + if (isLegendRight && hasArc) { + margin3.left = arcWidth / 2 + radiusExpanded * 1.1; + } + } + function updateXgridFocus() { + main.select('line.' + CLASS.xgridFocus) + .attr("x1", __axis_rotated ? 0 : -10) + .attr("x2", __axis_rotated ? width : -10) + .attr("y1", __axis_rotated ? -10 : 0) + .attr("y2", __axis_rotated ? -10 : height); + } + function updateRadius() { + var innerRadiusRatio; + radiusExpanded = Math.min(arcWidth, arcHeight) / 2; + radius = radiusExpanded * 0.95; + innerRadiusRatio = __gauge_width ? (radius - __gauge_width) / radius : 0.6; + innerRadius = hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? radius * innerRadiusRatio : 0; + } + function getSvgLeft() { + var leftAxisClass = __axis_rotated ? CLASS.axisX : CLASS.axisY, + leftAxis = main.select('.' + leftAxisClass).node(), + svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, + chartRect = selectChart.node().getBoundingClientRect(), + hasArc = hasArcType(c3.data.targets), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : getCurrentPaddingLeft()); + return svgLeft > 0 ? svgLeft : 0; + } + function getCurrentWidth() { + return __size_width ? __size_width : getParentWidth(); + } + function getCurrentHeight() { + var h = __size_height ? __size_height : getParentHeight(); + return h > 0 ? h : 320; + } + function getCurrentPaddingTop() { + return isValue(__padding_top) ? __padding_top : 0; + } + function getCurrentPaddingBottom() { + return isValue(__padding_bottom) ? __padding_bottom : 0; + } + function getCurrentPaddingLeft() { + if (isValue(__padding_left)) { + return __padding_left; + } else if (__axis_rotated) { + return !__axis_x_show ? 1 : Math.max(ceil10(getAxisWidthByAxisId('x')), 40); + } else { + return !__axis_y_show || __axis_y_inner ? 1 : ceil10(getAxisWidthByAxisId('y')); + } + } + function getCurrentPaddingRight() { + var defaultPadding = 10, legendWidthOnRight = isLegendRight ? getLegendWidth() + 20 : 0; + if (isValue(__padding_right)) { + return __padding_right + 1; // 1 is needed not to hide tick line + } else if (__axis_rotated) { + return defaultPadding + legendWidthOnRight; + } else { + return (!__axis_y2_show || __axis_y2_inner ? defaultPadding : ceil10(getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + } + } + function getAxisWidthByAxisId(id) { + var position = getAxisLabelPositionById(id); + return position.isInner ? 20 + getMaxTickWidth(id) : 40 + getMaxTickWidth(id); + } + function getHorizontalAxisHeight(axisId) { + if (axisId === 'x' && !__axis_x_show) { return 0; } + if (axisId === 'x' && __axis_x_height) { return __axis_x_height; } + if (axisId === 'y' && !__axis_y_show) { return __legend_show && !isLegendRight && !isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !__axis_y2_show) { return rotated_padding_top; } + return (getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + } + function getParentRectValue(key) { + var parent = selectChart.node(), v; + while (parent && parent.tagName !== 'BODY') { + v = parent.getBoundingClientRect()[key]; + if (v) { + break; + } + parent = parent.parentNode; + } + return v; + } + function getParentWidth() { + return getParentRectValue('width'); + } + function getParentHeight() { + var h = selectChart.style('height'); + return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; + } + function getAxisClipX(forHorizontal) { + // axis line width + padding for left + return forHorizontal ? -(1 + 30) : -(margin.left - 1); + } + function getAxisClipY(forHorizontal) { + return forHorizontal ? -20 : -4; + } + function getXAxisClipX() { + return getAxisClipX(!__axis_rotated); + } + function getXAxisClipY() { + return getAxisClipY(!__axis_rotated); + } + function getYAxisClipX() { + return getAxisClipX(__axis_rotated); + } + function getYAxisClipY() { + return getAxisClipY(__axis_rotated); + } + function getAxisClipWidth(forHorizontal) { + // width + axis line width + padding for left/right + return forHorizontal ? width + 2 + 30 + 30 : margin.left + 20; + } + function getAxisClipHeight(forHorizontal) { + return forHorizontal ? (__axis_x_height ? __axis_x_height : 0) + 80 : height + 8; + } + function getXAxisClipWidth() { + return getAxisClipWidth(!__axis_rotated); + } + function getXAxisClipHeight() { + return getAxisClipHeight(!__axis_rotated); + } + function getYAxisClipWidth() { + return getAxisClipWidth(__axis_rotated); + } + function getYAxisClipHeight() { + return getAxisClipHeight(__axis_rotated); + } + function getEventRectWidth() { + var target = getMaxDataCountTarget(c3.data.targets), + firstData, lastData, base, maxDataCount, ratio, w; + if (!target) { + return 0; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + base = x(lastData.x) - x(firstData.x); + if (base === 0) { + return __axis_rotated ? height : width; + } + maxDataCount = getMaxDataCount(); + ratio = (hasBarType(c3.data.targets) ? (maxDataCount - (isCategorized ? 0.25 : 1)) / maxDataCount : 1); + w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; + return w < 1 ? 1 : w; + } + function updateLegendStep(step) { + legendStep = step; + } + function updateLegendItemWidth(w) { + legendItemWidth = w; + } + function updateLegendItemHeight(h) { + legendItemHeight = h; + } + function getLegendWidth() { + return __legend_show ? isLegendRight || isLegendInset ? legendItemWidth * (legendStep + 1) : currentWidth : 0; + } + function getLegendHeight() { + var h = 0; + if (__legend_show) { + if (isLegendRight) { + h = currentHeight; + } else if (isLegendInset) { + h = __legend_inset_step ? Math.max(20, legendItemHeight) * (__legend_inset_step + 1) : height; + } else { + h = Math.max(20, legendItemHeight) * (legendStep + 1); + } + } + return h; + } + + //-- Scales --// + + function updateScales() { + var xAxisTickFormat, xAxisTickValues, forInit = !x; + // update edges + xMin = __axis_rotated ? 1 : 0; + xMax = __axis_rotated ? height : width; + yMin = __axis_rotated ? 0 : height; + yMax = __axis_rotated ? width : 1; + subXMin = xMin; + subXMax = xMax; + subYMin = __axis_rotated ? 0 : height2; + subYMax = __axis_rotated ? width2 : 1; + // update scales + x = getX(xMin, xMax, forInit ? undefined : x.orgDomain(), function () { return xAxis.tickOffset(); }); + y = getY(yMin, yMax, forInit ? undefined : y.domain()); + y2 = getY(yMin, yMax, forInit ? undefined : y2.domain()); + subX = getX(xMin, xMax, orgXDomain, function (d) { return d % 1 ? 0 : subXAxis.tickOffset(); }); + subY = getY(subYMin, subYMax, forInit ? undefined : subY.domain()); + subY2 = getY(subYMin, subYMax, forInit ? undefined : subY2.domain()); + // update axes + xAxisTickFormat = getXAxisTickFormat(); + xAxisTickValues = __axis_x_tick_values ? __axis_x_tick_values : (forInit ? undefined : xAxis.tickValues()); + xAxis = getXAxis(x, xOrient, xAxisTickFormat, xAxisTickValues); + subXAxis = getXAxis(subX, subXOrient, xAxisTickFormat, xAxisTickValues); + yAxis = getYAxis(y, yOrient, __axis_y_tick_format, __axis_y_ticks); + y2Axis = getYAxis(y2, y2Orient, __axis_y2_tick_format, __axis_y2_ticks); + // Set initialized scales to brush and zoom + if (!forInit) { + brush.scale(subX); + if (__zoom_enabled) { zoom.scale(x); } + } + // update for arc + updateArc(); + } + function updateArc() { + svgArc = getSvgArc(); + svgArcExpanded = getSvgArcExpanded(); + svgArcExpandedSub = getSvgArcExpanded(0.98); + } + function getScale(min, max, forTimeseries) { + return (forTimeseries ? d3.time.scale() : d3.scale.linear()).range([min, max]); + } + function getX(min, max, domain, offset) { + var scale = getScale(min, max, isTimeSeries), + _scale = domain ? scale.domain(domain) : scale, key; + // Define customized scale if categorized axis + if (isCategorized) { + offset = offset || function () { return 0; }; + scale = function (d, raw) { + var v = _scale(d) + offset(d); + return raw ? v : Math.ceil(v); + }; + } else { + scale = function (d, raw) { + var v = _scale(d); + return raw ? v : Math.ceil(v); + }; + } + // define functions + for (key in _scale) { + scale[key] = _scale[key]; + } + scale.orgDomain = function () { + return _scale.domain(); + }; + // define custom domain() for categorized axis + if (isCategorized) { + scale.domain = function (domain) { + if (!arguments.length) { + domain = this.orgDomain(); + return [domain[0], domain[1] + 1]; + } + _scale.domain(domain); + return scale; + }; + } + return scale; + } + function getY(min, max, domain) { + var scale = getScale(min, max); + if (domain) { scale.domain(domain); } + return scale; + } + function getYScale(id) { + return getAxisId(id) === 'y2' ? y2 : y; + } + function getSubYScale(id) { + return getAxisId(id) === 'y2' ? subY2 : subY; + } + + //-- Axes --// + + function getXAxis(scale, orient, tickFormat, tickValues) { + var axis = c3_axis(d3, isCategorized).scale(scale).orient(orient); + + // Set tick + axis.tickFormat(tickFormat).tickValues(tickValues); + if (isCategorized) { + axis.tickCentered(__axis_x_tick_centered); + if (isEmpty(__axis_x_tick_culling)) { + __axis_x_tick_culling = false; + } + } else { + // TODO: move this to c3_axis + axis.tickOffset = function () { + var edgeX = getEdgeX(c3.data.targets), diff = x(edgeX[1]) - x(edgeX[0]), + base = diff ? diff : (__axis_rotated ? height : width); + return (base / getMaxDataCount()) / 2; + }; + } + + return axis; + } + function getYAxis(scale, orient, tickFormat, ticks) { + return c3_axis(d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); + } + function getAxisId(id) { + return id in __data_axes ? __data_axes[id] : 'y'; + } + function getXAxisTickFormat() { + var format = isTimeSeries ? defaultAxisTimeFormat : isCategorized ? categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + if (__axis_x_tick_format) { + if (typeof __axis_x_tick_format === 'function') { + format = __axis_x_tick_format; + } else if (isTimeSeries) { + format = function (date) { + return date ? axisTimeFormat(__axis_x_tick_format)(date) : ""; + }; + } + } + return format; + } + function getAxisLabelOptionByAxisId(axisId) { + var option; + if (axisId === 'y') { + option = __axis_y_label; + } else if (axisId === 'y2') { + option = __axis_y2_label; + } else if (axisId === 'x') { + option = __axis_x_label; + } + return option; + } + function getAxisLabelText(axisId) { + var option = getAxisLabelOptionByAxisId(axisId); + return typeof option === 'string' ? option : option ? option.text : null; + } + function setAxisLabelText(axisId, text) { + var option = getAxisLabelOptionByAxisId(axisId); + if (typeof option === 'string') { + if (axisId === 'y') { + __axis_y_label = text; + } else if (axisId === 'y2') { + __axis_y2_label = text; + } else if (axisId === 'x') { + __axis_x_label = text; + } + } else if (option) { + option.text = text; + } + } + function xForRotatedTickText(r) { + return 10 * Math.sin(Math.PI * (r / 180)); + } + function yForRotatedTickText(r) { + return 11.5 - 2.5 * (r / 15); + } + function rotateTickText(axis, transition, rotate) { + axis.selectAll('.tick text') + .style("text-anchor", "start"); + transition.selectAll('.tick text') + .attr("y", yForRotatedTickText(rotate)) + .attr("x", xForRotatedTickText(rotate)) + .attr("transform", "rotate(" + rotate + ")"); + } + function getAxisLabelPosition(axisId, defaultPosition) { + var option = getAxisLabelOptionByAxisId(axisId), + position = (option && 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 + }; + } + function getXAxisLabelPosition() { + return getAxisLabelPosition('x', __axis_rotated ? 'inner-top' : 'inner-right'); + } + function getYAxisLabelPosition() { + return getAxisLabelPosition('y', __axis_rotated ? 'inner-right' : 'inner-top'); + } + function getY2AxisLabelPosition() { + return getAxisLabelPosition('y2', __axis_rotated ? 'inner-right' : 'inner-top'); + } + function getAxisLabelPositionById(id) { + return id === 'y2' ? getY2AxisLabelPosition() : id === 'y' ? getYAxisLabelPosition() : getXAxisLabelPosition(); + } + function textForXAxisLabel() { + return getAxisLabelText('x'); + } + function textForYAxisLabel() { + return getAxisLabelText('y'); + } + function textForY2AxisLabel() { + return getAxisLabelText('y2'); + } + function xForAxisLabel(forHorizontal, position) { + if (forHorizontal) { + return position.isLeft ? 0 : position.isCenter ? width / 2 : width; + } else { + return position.isBottom ? -height : position.isMiddle ? -height / 2 : 0; + } + } + 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"; + } + } + function textAnchorForAxisLabel(forHorizontal, position) { + if (forHorizontal) { + return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; + } else { + return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; + } + } + function xForXAxisLabel() { + return xForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); + } + function xForYAxisLabel() { + return xForAxisLabel(__axis_rotated, getYAxisLabelPosition()); + } + function xForY2AxisLabel() { + return xForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); + } + function dxForXAxisLabel() { + return dxForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); + } + function dxForYAxisLabel() { + return dxForAxisLabel(__axis_rotated, getYAxisLabelPosition()); + } + function dxForY2AxisLabel() { + return dxForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); + } + function dyForXAxisLabel() { + var position = getXAxisLabelPosition(); + if (__axis_rotated) { + return position.isInner ? "1.2em" : -25 - getMaxTickWidth('x'); + } else { + return position.isInner ? "-0.5em" : __axis_x_height ? __axis_x_height - 10 : "3em"; + } + } + function dyForYAxisLabel() { + var position = getYAxisLabelPosition(); + if (__axis_rotated) { + return position.isInner ? "-0.5em" : "3em"; + } else { + return position.isInner ? "1.2em" : -20 - getMaxTickWidth('y'); + } + } + function dyForY2AxisLabel() { + var position = getY2AxisLabelPosition(); + if (__axis_rotated) { + return position.isInner ? "1.2em" : "-2.2em"; + } else { + return position.isInner ? "-0.5em" : 30 + getMaxTickWidth('y2'); + } + } + function textAnchorForXAxisLabel() { + return textAnchorForAxisLabel(!__axis_rotated, getXAxisLabelPosition()); + } + function textAnchorForYAxisLabel() { + return textAnchorForAxisLabel(__axis_rotated, getYAxisLabelPosition()); + } + function textAnchorForY2AxisLabel() { + return textAnchorForAxisLabel(__axis_rotated, getY2AxisLabelPosition()); + } + function getMaxTickWidth(id) { + var maxWidth = 0, targetsToShow, scale, axis; + if (svg) { + targetsToShow = filterTargetsToShow(c3.data.targets); + if (id === 'y') { + scale = y.copy().domain(getYDomain(targetsToShow, 'y')); + axis = getYAxis(scale, yOrient, __axis_y_tick_format, __axis_y_ticks); + } else if (id === 'y2') { + scale = y2.copy().domain(getYDomain(targetsToShow, 'y2')); + axis = getYAxis(scale, y2Orient, __axis_y2_tick_format, __axis_y2_ticks); + } else { + scale = x.copy().domain(getXDomain(targetsToShow)); + axis = getXAxis(scale, xOrient, getXAxisTickFormat(), __axis_x_tick_values ? __axis_x_tick_values : xAxis.tickValues()); + } + main.append("g").call(axis).each(function () { + d3.select(this).selectAll('text').each(function () { + var box = this.getBoundingClientRect(); + if (maxWidth < box.width) { maxWidth = box.width; } + }); + }).remove(); + } + currentMaxTickWidth = maxWidth <= 0 ? currentMaxTickWidth : maxWidth; + return currentMaxTickWidth; + } + function updateAxisLabels(withTransition) { + 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", xForXAxisLabel) + .attr("dx", dxForXAxisLabel) + .attr("dy", dyForXAxisLabel) + .text(textForXAxisLabel); + (withTransition ? axisYLabel.transition() : axisYLabel) + .attr("x", xForYAxisLabel) + .attr("dx", dxForYAxisLabel) + .attr("dy", dyForYAxisLabel) + .attr("dy", dyForYAxisLabel) + .text(textForYAxisLabel); + (withTransition ? axisY2Label.transition() : axisY2Label) + .attr("x", xForY2AxisLabel) + .attr("dx", dxForY2AxisLabel) + .attr("dy", dyForY2AxisLabel) + .text(textForY2AxisLabel); + } + + //-- Arc --// + + pie = d3.layout.pie().value(function (d) { + return d.values.reduce(function (a, b) { return a + b.value; }, 0); + }); + if (!__pie_sort || !__donut_sort) { // TODO: this needs to be called by each type + pie.sort(null); + } + + function descByStartAngle(a, b) { + return a.startAngle - b.startAngle; + } + + function updateAngle(d) { + var found = false, index = 0; + pie(filterTargetsToShow(c3.data.targets)).sort(descByStartAngle).forEach(function (t) { + if (! found && t.data.id === d.data.id) { + found = true; + d = t; + d.index = index; + } + index++; + }); + if (isNaN(d.endAngle)) { + d.endAngle = d.startAngle; + } + if (isGaugeType(d.data)) { + var gMin = __gauge_min, gMax = __gauge_max, + gF = Math.abs(gMin) + gMax, + aTic = (Math.PI) / gF; + d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); + d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value)); + } + return found ? d : null; + } + + function getSvgArc() { + var arc = d3.svg.arc().outerRadius(radius).innerRadius(innerRadius), + newArc = function (d, withoutUpdate) { + var updated; + if (withoutUpdate) { return arc(d); } // for interpolate + updated = updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; + // TODO: extends all function + newArc.centroid = arc.centroid; + return newArc; + } + function getSvgArcExpanded(rate) { + var arc = d3.svg.arc().outerRadius(radiusExpanded * (rate ? rate : 1)).innerRadius(innerRadius); + return function (d) { + var updated = updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; + } + function getArc(d, withoutUpdate, force) { + return force || isArcType(d.data) ? svgArc(d, withoutUpdate) : "M 0 0"; + } + function transformForArcLabel(d) { + var updated = updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !hasGaugeType(c3.data.targets)) { + c = svgArc.centroid(updated); + x = isNaN(c[0]) ? 0 : c[0]; + y = isNaN(c[1]) ? 0 : c[1]; + h = Math.sqrt(x * x + y * y); + // TODO: ratio should be an option? + ratio = radius && h ? (36 / radius > 0.375 ? 1.175 - 36 / radius : 0.8) * radius / h : 0; + translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")"; + } + return translate; + } + function getArcRatio(d) { + var whole = hasGaugeType(c3.data.targets) ? Math.PI : (Math.PI * 2); + return d ? (d.endAngle - d.startAngle) / whole : null; + } + function convertToArcData(d) { + return addName({ + id: d.data.id, + value: d.value, + ratio: getArcRatio(d), + index: d.index, + }); + } + function textForArcLabel(d) { + var updated, value, ratio, format; + if (! shouldShowArcLabel()) { return ""; } + updated = updateAngle(d); + value = updated ? updated.value : null; + ratio = getArcRatio(updated); + if (! hasGaugeType(c3.data.targets) && ! meetsArcLabelThreshold(ratio)) { return ""; } + format = getArcLabelFormat(); + return format ? format(value, ratio) : defaultArcValueFormat(value, ratio); + } + function expandArc(id, withoutFadeOut) { + var target = svg.selectAll('.' + CLASS.chartArc + selectorTarget(id)), + noneTargets = svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); + + if (shouldExpand(id)) { + target.selectAll('path') + .transition().duration(50) + .attr("d", svgArcExpanded) + .transition().duration(100) + .attr("d", svgArcExpandedSub) + .each(function (d) { + if (isDonutType(d.data)) { + // callback here + } + }); + } + + if (!withoutFadeOut) { + noneTargets.style("opacity", 0.3); + } + } + function unexpandArc(id) { + var target = svg.selectAll('.' + CLASS.chartArc + selectorTarget(id)); + target.selectAll('path.' + CLASS.arc) + .transition().duration(50) + .attr("d", svgArc); + svg.selectAll('.' + CLASS.arc) + .style("opacity", 1); + } + function shouldShowArcLabel() { + var shouldShow = true; + if (hasDonutType(c3.data.targets)) { + shouldShow = __donut_label_show; + } else if (hasPieType(c3.data.targets)) { + shouldShow = __pie_label_show; + } + // when gauge, always true + return shouldShow; + } + function meetsArcLabelThreshold(ratio) { + var threshold = hasDonutType(c3.data.targets) ? __donut_label_threshold : __pie_label_threshold; + return ratio >= threshold; + } + function getArcLabelFormat() { + var format = __pie_label_format; + if (hasGaugeType(c3.data.targets)) { + format = __gauge_label_format; + } else if (hasDonutType(c3.data.targets)) { + format = __donut_label_format; + } + return format; + } + function getArcTitle() { + return hasDonutType(c3.data.targets) ? __donut_title : ""; + } + + //-- Domain --// + + function getAxisPadding(padding, key, defaultValue, all) { + var ratio = padding.unit === 'ratio' ? all : 1; + return isValue(padding[key]) ? padding[key] * ratio : defaultValue; + } + + function getYDomainMin(targets) { + var ids = mapToIds(targets), ys = getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; + if (__data_groups.length > 0) { + hasNegativeValue = hasNegativeValueInTargets(targets); + for (j = 0; j < __data_groups.length; j++) { + // Determine baseId + idsInGroup = __data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider negative values + if (hasNegativeValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v < 0 ? v : 0; + }); + } + // Compute min + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if (getAxisId(id) === getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + ys[baseId][i] += +v; + } + }); + } + } + } + return d3.min(Object.keys(ys).map(function (key) { return d3.min(ys[key]); })); + } + function getYDomainMax(targets) { + var ids = mapToIds(targets), ys = getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; + if (__data_groups.length > 0) { + hasPositiveValue = hasPositiveValueInTargets(targets); + for (j = 0; j < __data_groups.length; j++) { + // Determine baseId + idsInGroup = __data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider positive values + if (hasPositiveValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v > 0 ? v : 0; + }); + } + // Compute max + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if (getAxisId(id) === getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + ys[baseId][i] += +v; + } + }); + } + } + } + return d3.max(Object.keys(ys).map(function (key) { return d3.max(ys[key]); })); + } + function getYDomain(targets, axisId) { + var yTargets = targets.filter(function (d) { return getAxisId(d.id) === axisId; }), + yMin = axisId === 'y2' ? __axis_y2_min : __axis_y_min, + yMax = axisId === 'y2' ? __axis_y2_max : __axis_y_max, + yDomainMin = isValue(yMin) ? yMin : getYDomainMin(yTargets), + yDomainMax = isValue(yMax) ? yMax : getYDomainMax(yTargets), + domainLength, padding, padding_top, padding_bottom, + center = axisId === 'y2' ? __axis_y2_center : __axis_y_center, + yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, + isZeroBased = (hasBarType(yTargets) && __bar_zerobased) || (hasAreaType(yTargets) && __area_zerobased), + showHorizontalDataLabel = hasDataLabel() && __axis_rotated, + showVerticalDataLabel = hasDataLabel() && !__axis_rotated; + if (yTargets.length === 0) { // use current domain if target of axisId is none + return axisId === 'y2' ? y2.domain() : y.domain(); + } + if (yDomainMin === yDomainMax) { + yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; + } + isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; + isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { yDomainMin = 0; } + if (isAllNegative) { yDomainMax = 0; } + } + + domainLength = Math.abs(yDomainMax - yDomainMin); + padding = padding_top = padding_bottom = domainLength * 0.1; + + if (center) { + yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); + yDomainMax = yDomainAbs - center; + yDomainMin = center - yDomainAbs; + } + // add padding for data label + if (showHorizontalDataLabel) { + lengths = getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + diff = diffDomain(y.range()); + ratio = [lengths[0] / diff, lengths[1] / diff]; + padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); + padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); + } else if (showVerticalDataLabel) { + lengths = getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + padding_top += lengths[1]; + padding_bottom += lengths[0]; + } + if (axisId === 'y' && __axis_y_padding) { + padding_top = getAxisPadding(__axis_y_padding, 'top', padding, domainLength); + padding_bottom = getAxisPadding(__axis_y_padding, 'bottom', padding, domainLength); + } + if (axisId === 'y2' && __axis_y2_padding) { + padding_top = getAxisPadding(__axis_y2_padding, 'top', padding, domainLength); + padding_bottom = getAxisPadding(__axis_y2_padding, 'bottom', padding, domainLength); + } + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { padding_bottom = yDomainMin; } + if (isAllNegative) { padding_top = -yDomainMax; } + } + return [yDomainMin - padding_bottom, yDomainMax + padding_top]; + } + function getXDomainMin(targets) { + return __axis_x_min ? (isTimeSeries ? parseDate(__axis_x_min) : __axis_x_min) : d3.min(targets, function (t) { return d3.min(t.values, function (v) { return v.x; }); }); + } + function getXDomainMax(targets) { + return __axis_x_max ? (isTimeSeries ? parseDate(__axis_x_max) : __axis_x_max) : d3.max(targets, function (t) { return d3.max(t.values, function (v) { return v.x; }); }); + } + function getXDomainPadding(targets) { + var edgeX = getEdgeX(targets), diff = edgeX[1] - edgeX[0], + maxDataCount, padding, paddingLeft, paddingRight; + if (isCategorized) { + padding = 0; + } else if (hasBarType(targets)) { + maxDataCount = getMaxDataCount(); + padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; + } else { + padding = diff * 0.01; + } + if (typeof __axis_x_padding === 'object' && notEmpty(__axis_x_padding)) { + paddingLeft = isValue(__axis_x_padding.left) ? __axis_x_padding.left : padding; + paddingRight = isValue(__axis_x_padding.right) ? __axis_x_padding.right : padding; + } else if (typeof __axis_x_padding === 'number') { + paddingLeft = paddingRight = __axis_x_padding; + } else { + paddingLeft = paddingRight = padding; + } + return {left: paddingLeft, right: paddingRight}; + } + function getXDomain(targets) { + var xDomain = [getXDomainMin(targets), getXDomainMax(targets)], + firstX = xDomain[0], lastX = xDomain[1], + padding = getXDomainPadding(targets), + min = 0, max = 0; + // show center of x domain if min and max are the same + if ((firstX - lastX) === 0 && !isCategorized) { + firstX = isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; + } + if (firstX || firstX === 0) { + min = isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + } + if (lastX || lastX === 0) { + max = isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + } + return [min, max]; + } + function updateXDomain(targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + if (withUpdateOrgXDomain) { + x.domain(domain ? domain : d3.extent(getXDomain(targets))); + orgXDomain = x.domain(); + if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); } + subX.domain(x.domain()); + brush.scale(subX); + } + if (withUpdateXDomain) { + x.domain(domain ? domain : brush.empty() ? orgXDomain : brush.extent()); + if (__zoom_enabled) { zoom.scale(x).updateScaleExtent(); } + } + return x.domain(); + } + function diffDomain(d) { + return d[1] - d[0]; + } + + //-- Cache --// + + function hasCaches(ids) { + for (var i = 0; i < ids.length; i++) { + if (! (ids[i] in cache)) { return false; } + } + return true; + } + function addCache(id, target) { + cache[id] = cloneTarget(target); + } + function getCaches(ids) { + var targets = []; + for (var i = 0; i < ids.length; i++) { + if (ids[i] in cache) { targets.push(cloneTarget(cache[ids[i]])); } + } + return targets; + } + + //-- Regions --// + + function regionX(d) { + var xPos, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + xPos = __axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; + } else { + xPos = __axis_rotated ? 0 : ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0); + } + return xPos; + } + function regionY(d) { + var yPos, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + yPos = __axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); + } else { + yPos = __axis_rotated ? ('start' in d ? x(isTimeSeries ? parseDate(d.start) : d.start) : 0) : 0; + } + return yPos; + } + function regionWidth(d) { + var start = regionX(d), end, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = __axis_rotated ? ('end' in d ? yScale(d.end) : width) : width; + } else { + end = __axis_rotated ? width : ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : width); + } + return end < start ? 0 : end - start; + } + function regionHeight(d) { + var start = regionY(d), end, yScale = d.axis === 'y' ? y : y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = __axis_rotated ? height : ('start' in d ? yScale(d.start) : height); + } else { + end = __axis_rotated ? ('end' in d ? x(isTimeSeries ? parseDate(d.end) : d.end) : height) : height; + } + return end < start ? 0 : end - start; + } + function isRegionOnX(d) { + return !d.axis || d.axis === 'x'; + } + + //-- Data --// + + function isX(key) { + return (__data_x && key === __data_x) || (notEmpty(__data_xs) && hasValue(__data_xs, key)); + } + function isNotX(key) { + return !isX(key); + } + function getXKey(id) { + return __data_x ? __data_x : notEmpty(__data_xs) ? __data_xs[id] : null; + } + function getXValuesOfXKey(key, targets) { + var xValues, ids = targets && notEmpty(targets) ? mapToIds(targets) : []; + ids.forEach(function (id) { + if (getXKey(id) === key) { + xValues = c3.data.xs[id]; + } + }); + return xValues; + } + function getXValue(id, i) { + return id in c3.data.xs && c3.data.xs[id] && isValue(c3.data.xs[id][i]) ? c3.data.xs[id][i] : i; + } + function getOtherTargetXs() { + var idsForX = Object.keys(c3.data.xs); + return idsForX.length ? c3.data.xs[idsForX[0]] : null; + } + function getOtherTargetX(index) { + var xs = getOtherTargetXs(); + return xs && index < xs.length ? xs[index] : null; + } + function addXs(xs) { + Object.keys(xs).forEach(function (id) { + __data_xs[id] = xs[id]; + }); + } + function isSingleX(xs) { + return d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; + } + + function addName(data) { + var name; + if (data) { + name = __data_names[data.id]; + data.name = name ? name : data.id; + } + return data; + } + + function getValueOnIndex(values, index) { + var valueOnIndex = values.filter(function (v) { return v.index === index; }); + return valueOnIndex.length ? valueOnIndex[0] : null; + } + + function updateTargetX(targets, x) { + targets.forEach(function (t) { + t.values.forEach(function (v, i) { + v.x = generateTargetX(x[i], t.id, i); + }); + c3.data.xs[t.id] = x; + }); + } + function updateTargetXs(targets, xs) { + targets.forEach(function (t) { + if (xs[t.id]) { + updateTargetX([t], xs[t.id]); + } + }); + } + function generateTargetX(rawX, id, index) { + var x; + if (isTimeSeries) { + x = rawX ? parseDate(rawX) : parseDate(getXValue(id, index)); + } + else if (isCustomX() && !isCategorized) { + x = isValue(rawX) ? +rawX : getXValue(id, index); + } + else { + x = index; + } + return x; + } + function convertUrlToData(url, mimeType, keys, done) { + var type = mimeType ? mimeType : 'csv'; + d3.xhr(url, function (error, data) { + var d; + if (type === 'json') { + d = convertJsonToData(JSON.parse(data.response), keys); + } else { + d = convertCsvToData(data.response); + } + done(d); + }); + } + function convertCsvToData(csv) { + var rows = d3.csv.parseRows(csv), d; + if (rows.length === 1) { + d = [{}]; + rows[0].forEach(function (id) { + d[0][id] = null; + }); + } else { + d = d3.csv.parse(csv); + } + return d; + } + function convertJsonToData(json, keys) { + var new_rows = [], targetKeys, data; + if (keys) { // when keys specified, json would be an array that includes objects + targetKeys = keys.value; + if (keys.x) { + targetKeys.push(keys.x); + __data_x = keys.x; + } + new_rows.push(targetKeys); + json.forEach(function (o) { + var new_row = []; + targetKeys.forEach(function (key) { + // convert undefined to null because undefined data will be removed in convertDataToTargets() + var v = typeof o[key] === 'undefined' ? null : o[key]; + new_row.push(v); + }); + new_rows.push(new_row); + }); + data = convertRowsToData(new_rows); + } else { + Object.keys(json).forEach(function (key) { + new_rows.push([key].concat(json[key])); + }); + data = convertColumnsToData(new_rows); + } + return data; + } + function convertRowsToData(rows) { + var keys = rows[0], new_row = {}, new_rows = [], i, j; + for (i = 1; i < rows.length; i++) { + new_row = {}; + for (j = 0; j < rows[i].length; j++) { + new_row[keys[j]] = rows[i][j]; + } + new_rows.push(new_row); + } + return new_rows; + } + function convertColumnsToData(columns) { + var new_rows = [], i, j, key; + for (i = 0; i < columns.length; i++) { + key = columns[i][0]; + for (j = 1; j < columns[i].length; j++) { + if (isUndefined(new_rows[j - 1])) { + new_rows[j - 1] = {}; + } + new_rows[j - 1][key] = columns[i][j]; + } + } + return new_rows; + } + function convertDataToTargets(data, appendXs) { + var ids = d3.keys(data[0]).filter(isNotX), xs = d3.keys(data[0]).filter(isX), targets; + + // save x for update data by load when custom x and c3.x API + ids.forEach(function (id) { + var xKey = getXKey(id); + + if (isCustomX() || isTimeSeries) { + // if included in input data + if (xs.indexOf(xKey) >= 0) { + c3.data.xs[id] = (appendXs && c3.data.xs[id] ? c3.data.xs[id] : []).concat( + data.map(function (d) { return d[xKey]; }) + .filter(isValue) + .map(function (rawX, i) { return generateTargetX(rawX, id, i); }) + ); + } + // if not included in input data, find from preloaded data of other id's x + else if (__data_x) { + c3.data.xs[id] = getOtherTargetXs(); + } + // if not included in input data, find from preloaded data + else if (notEmpty(__data_xs)) { + c3.data.xs[id] = getXValuesOfXKey(xKey, c3.data.targets); + } + // MEMO: if no x included, use same x of current will be used + } else { + c3.data.xs[id] = data.map(function (d, i) { return i; }); + } + }); + + // check x is defined + ids.forEach(function (id) { + if (!c3.data.xs[id]) { + throw new Error('x is not defined for id = "' + id + '".'); + } + }); + + // convert to target + targets = ids.map(function (id, index) { + var convertedId = __data_id_converter(id); + return { + id: convertedId, + id_org: id, + values: data.map(function (d, i) { + var xKey = getXKey(id), rawX = d[xKey], x = generateTargetX(rawX, id, i); + // use x as categories if custom x and categorized + if (isCustomX() && isCategorized && index === 0 && rawX) { + if (i === 0) { __axis_x_categories = []; } + __axis_x_categories.push(rawX); + } + // mark as x = undefined if value is undefined and filter to remove after mapped + if (typeof d[id] === 'undefined' || c3.data.xs[id].length <= i) { + x = undefined; + } + return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; + }).filter(function (v) { return typeof v.x !== 'undefined'; }) + }; + }); + + // finish targets + targets.forEach(function (t) { + var i; + // sort values by its x + t.values = t.values.sort(function (v1, v2) { + var x1 = v1.x || v1.x === 0 ? v1.x : Infinity, + x2 = v2.x || v2.x === 0 ? v2.x : Infinity; + return x1 - x2; + }); + // indexing each value + i = 0; + t.values.forEach(function (v) { + v.index = i++; + }); + // this needs to be sorted because its index and value.index is identical + c3.data.xs[t.id].sort(function (v1, v2) { + return v1 - v2; + }); + }); + + // set target types + if (__data_type) { + setTargetType(mapToIds(targets).filter(function (id) { return ! (id in __data_types); }), __data_type); + } + + // cache as original id keyed + targets.forEach(function (d) { + addCache(d.id_org, d); + }); + + return targets; + } + function cloneTarget(target) { + return { + id : target.id, + id_org : target.id_org, + values : target.values.map(function (d) { + return {x: d.x, value: d.value, id: d.id}; + }) + }; + } + function getPrevX(i) { + var value = getValueOnIndex(c3.data.targets[0].values, i - 1); + return value ? value.x : null; + } + function getNextX(i) { + var value = getValueOnIndex(c3.data.targets[0].values, i + 1); + return value ? value.x : null; + } + function getMaxDataCount() { + return d3.max(c3.data.targets, function (t) { return t.values.length; }); + } + function getMaxDataCountTarget(targets) { + var length = targets.length, max = 0, maxTarget; + if (length > 1) { + targets.forEach(function (t) { + if (t.values.length > max) { + maxTarget = t; + max = t.values.length; + } + }); + } else { + maxTarget = length ? targets[0] : null; + } + return maxTarget; + } + function getEdgeX(targets) { + var target = getMaxDataCountTarget(targets), firstData, lastData; + if (!target) { + return [0, 0]; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + return [firstData.x, lastData.x]; + } + function mapToIds(targets) { + return targets.map(function (d) { return d.id; }); + } + function mapToTargetIds(ids) { + return ids ? (typeof ids === 'string' ? [ids] : ids) : mapToIds(c3.data.targets); + } + function hasTarget(targets, id) { + var ids = mapToIds(targets), i; + for (i = 0; i < ids.length; i++) { + if (ids[i] === id) { + return true; + } + } + return false; + } + function isTargetToShow(targetId) { + return hiddenTargetIds.indexOf(targetId) < 0; + } + function isLegendToShow(targetId) { + return hiddenLegendIds.indexOf(targetId) < 0; + } + function filterTargetsToShow(targets) { + return targets.filter(function (t) { return isTargetToShow(t.id); }); + } + function mapTargetsToUniqueXs(targets) { + var xs = d3.set(d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); + return isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); + } + function generateTickValues(xs, tickCount) { + var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; + if (tickCount) { + targetCount = typeof tickCount === 'function' ? tickCount() : tickCount; + // compute ticks according to __axis_x_tick_count + if (targetCount === 1) { + tickValues = [xs[0]]; + } else if (targetCount === 2) { + tickValues = [xs[0], xs[xs.length - 1]]; + } else if (targetCount > 2) { + count = targetCount - 2; + start = xs[0]; + end = xs[xs.length - 1]; + interval = (end - start) / (count + 1); + // re-construct uniqueXs + tickValues = [start]; + for (i = 0; i < count; i++) { + tickValue = +start + interval * (i + 1); + tickValues.push(isTimeSeries ? new Date(tickValue) : tickValue); + } + tickValues.push(end); + } + } + if (!isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + return tickValues; + } + function addHiddenTargetIds(targetIds) { + hiddenTargetIds = hiddenTargetIds.concat(targetIds); + } + function removeHiddenTargetIds(targetIds) { + hiddenTargetIds = hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + } + function addHiddenLegendIds(targetIds) { + hiddenLegendIds = hiddenLegendIds.concat(targetIds); + } + function removeHiddenLegendIds(targetIds) { + hiddenLegendIds = hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + } + function getValuesAsIdKeyed(targets) { + var ys = {}; + targets.forEach(function (t) { + ys[t.id] = []; + t.values.forEach(function (v) { + ys[t.id].push(v.value); + }); + }); + return ys; + } + function checkValueInTargets(targets, checker) { + var ids = Object.keys(targets), i, j, values; + for (i = 0; i < ids.length; i++) { + values = targets[ids[i]].values; + for (j = 0; j < values.length; j++) { + if (checker(values[j].value)) { + return true; + } + } + } + return false; + } + function hasNegativeValueInTargets(targets) { + return checkValueInTargets(targets, function (v) { return v < 0; }); + } + function hasPositiveValueInTargets(targets) { + return checkValueInTargets(targets, function (v) { return v > 0; }); + } + function categoryName(i) { + return i < __axis_x_categories.length ? __axis_x_categories[i] : i; + } + function generateClass(prefix, targetId) { + return " " + prefix + " " + prefix + getTargetSelectorSuffix(targetId); + } + function classText(d) { return generateClass(CLASS.text, d.index); } + function classTexts(d) { return generateClass(CLASS.texts, d.id); } + function classShape(d) { return generateClass(CLASS.shape, d.index); } + function classShapes(d) { return generateClass(CLASS.shapes, d.id); } + function classLine(d) { return classShape(d) + generateClass(CLASS.line, d.id); } + function classLines(d) { return classShapes(d) + generateClass(CLASS.lines, d.id); } + function classCircle(d) { return classShape(d) + generateClass(CLASS.circle, d.index); } + function classCircles(d) { return classShapes(d) + generateClass(CLASS.circles, d.id); } + function classBar(d) { return classShape(d) + generateClass(CLASS.bar, d.index); } + function classBars(d) { return classShapes(d) + generateClass(CLASS.bars, d.id); } + function classArc(d) { return classShape(d.data) + generateClass(CLASS.arc, d.data.id); } + function classArcs(d) { return classShapes(d.data) + generateClass(CLASS.arcs, d.data.id); } + function classArea(d) { return classShape(d) + generateClass(CLASS.area, d.id); } + function classAreas(d) { return classShapes(d) + generateClass(CLASS.areas, d.id); } + function classRegion(d, i) { return generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); } + function classEvent(d) { return generateClass(CLASS.eventRect, d.index); } + function classTarget(id) { + var additionalClassSuffix = __data_classes[id], additionalClass = ''; + if (additionalClassSuffix) { + additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; + } + return generateClass(CLASS.target, id) + additionalClass; + } + function classChartText(d) { return CLASS.chartText + classTarget(d.id); } + function classChartLine(d) { return CLASS.chartLine + classTarget(d.id); } + function classChartBar(d) { return CLASS.chartBar + classTarget(d.id); } + function classChartArc(d) { return CLASS.chartArc + classTarget(d.data.id); } + + function getTargetSelectorSuffix(targetId) { + return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; + } + function selectorTarget(id) { return '.' + CLASS.target + getTargetSelectorSuffix(id); } + function selectorTargets(ids) { return ids.length ? ids.map(function (id) { return selectorTarget(id); }) : null; } + function selectorLegend(id) { return '.' + CLASS.legendItem + getTargetSelectorSuffix(id); } + function selectorLegends(ids) { return ids.length ? ids.map(function (id) { return selectorLegend(id); }) : null; } + + function initialOpacity(d) { + return d.value !== null && withoutFadeIn[d.id] ? 1 : 0; + } + function opacityForCircle(d) { + return isValue(d.value) ? isScatterType(d) ? 0.5 : 1 : 0; + } + function opacityForText() { + return hasDataLabel() ? 1 : 0; + } + function hasDataLabel() { + if (typeof __data_labels === 'boolean' && __data_labels) { + return true; + } else if (typeof __data_labels === 'object' && notEmpty(__data_labels)) { + return true; + } + return false; + } + function getDataLabelLength(min, max, axisId, key) { + var lengths = [0, 0], paddingCoef = 1.3; + selectChart.select('svg').selectAll('.dummy') + .data([min, max]) + .enter().append('text') + .text(function (d) { return formatByAxisId(axisId)(d); }) + .each(function (d, i) { + lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; + }) + .remove(); + return lengths; + } + function getYFormat(forArc) { + var formatForY = forArc && !hasGaugeType(c3.data.targets) ? defaultArcValueFormat : yFormat, + formatForY2 = forArc && !hasGaugeType(c3.data.targets) ? defaultArcValueFormat : y2Format; + return function (v, ratio, id) { + var format = getAxisId(id) === 'y2' ? formatForY2 : formatForY; + return format(v, ratio); + }; + } + function yFormat(v) { + var format = __axis_y_tick_format ? __axis_y_tick_format : defaultValueFormat; + return format(v); + } + function y2Format(v) { + var format = __axis_y2_tick_format ? __axis_y2_tick_format : defaultValueFormat; + return format(v); + } + function defaultValueFormat(v) { + return isValue(v) ? +v : ""; + } + function defaultArcValueFormat(v, ratio) { + return (ratio * 100).toFixed(1) + '%'; + } + function formatByAxisId(axisId) { + var format = function (v) { return isValue(v) ? +v : ""; }; + // find format according to axis id + if (typeof __data_labels.format === 'function') { + format = __data_labels.format; + } else if (typeof __data_labels.format === 'object') { + if (typeof __data_labels.format[axisId] === 'function') { + format = __data_labels.format[axisId]; + } + } + return format; + } + + function xx(d) { + return d ? x(d.x) : null; + } + function xv(d) { + return Math.ceil(x(isTimeSeries ? parseDate(d.value) : d.value)); + } + function yv(d) { + var yScale = d.axis && d.axis === 'y2' ? y2 : y; + return Math.ceil(yScale(d.value)); + } + function subxx(d) { + return d ? subX(d.x) : null; + } + + function findSameXOfValues(values, index) { + var i, targetX = values[index].x, sames = []; + for (i = index - 1; i >= 0; i--) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + for (i = index; i < values.length; i++) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + return sames; + } + + function findClosestOfValues(values, pos, _min, _max) { // MEMO: values must be sorted by x + var min = _min ? _min : 0, + max = _max ? _max : values.length - 1, + med = Math.floor((max - min) / 2) + min, + value = values[med], + diff = x(value.x) - pos[__axis_rotated ? 1 : 0], + candidates; + + // Update range for search + diff > 0 ? max = med : min = med; + + // if candidates are two closest min and max, stop recursive call + if ((max - min) === 1 || (min === 0 && max === 0)) { + + // Get candidates that has same min and max index + candidates = []; + if (values[min].x || values[min].x === 0) { + candidates = candidates.concat(findSameXOfValues(values, min)); + } + if (values[max].x || values[max].x === 0) { + candidates = candidates.concat(findSameXOfValues(values, max)); + } + + // Determine the closest and return + return findClosest(candidates, pos); + } + + return findClosestOfValues(values, pos, min, max); + } + function findClosestFromTargets(targets, pos) { + var candidates; + + // map to array of closest points of each target + candidates = targets.map(function (target) { + return findClosestOfValues(target.values, pos); + }); + + // decide closest point and return + return findClosest(candidates, pos); + } + function findClosest(values, pos) { + var minDist, closest; + values.forEach(function (v) { + var d = dist(v, pos); + if (d < minDist || ! minDist) { + minDist = d; + closest = v; + } + }); + return closest; + } + function filterSameX(targets, x) { + return d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); + } + + function getPathBox(path) { + var box = path.getBoundingClientRect(), + items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], + minX = items[0].x, minY = Math.min(items[0].y, items[1].y); + return {x: minX, y: minY, width: box.width, height: box.height}; + } + + function isOrderDesc() { + return __data_order && __data_order.toLowerCase() === 'desc'; + } + function isOrderAsc() { + return __data_order && __data_order.toLowerCase() === 'asc'; + } + function orderTargets(targets) { + var orderAsc = isOrderAsc(), orderDesc = isOrderDesc(); + if (orderAsc || orderDesc) { + targets.sort(function (t1, t2) { + var reducer = function (p, c) { return p + Math.abs(c.value); }; + var t1Sum = t1.values.reduce(reducer, 0), + t2Sum = t2.values.reduce(reducer, 0); + return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; + }); + } else if (typeof __data_order === 'function') { + targets.sort(__data_order); + } // TODO: accept name array for order + return targets; + } + + //-- Tooltip --// + + function showTooltip(selectedData, mouse) { + var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; + var forArc = hasArcType(c3.data.targets), + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (dataToShow.length === 0 || !__tooltip_show) { + return; + } + tooltip.html(__tooltip_contents(selectedData, getXAxisTickFormat(), getYFormat(forArc), color)).style("display", "block"); + + // Get tooltip dimensions + tWidth = tooltip.property('offsetWidth'); + tHeight = tooltip.property('offsetHeight'); + // Determin tooltip position + if (forArc) { + tooltipLeft = (width / 2) + mouse[0]; + tooltipTop = (height / 2) + mouse[1] + 20; + } else { + if (__axis_rotated) { + svgLeft = getSvgLeft(); + tooltipLeft = svgLeft + mouse[0] + 100; + tooltipRight = tooltipLeft + tWidth; + chartRight = getCurrentWidth() - getCurrentPaddingRight(); + tooltipTop = x(dataToShow[0].x) + 20; + } else { + svgLeft = getSvgLeft(); + tooltipLeft = svgLeft + getCurrentPaddingLeft() + x(dataToShow[0].x) + 20; + tooltipRight = tooltipLeft + tWidth; + chartRight = svgLeft + getCurrentWidth() - getCurrentPaddingRight(); + tooltipTop = mouse[1] + 15; + } + + if (tooltipRight > chartRight) { + tooltipLeft -= tooltipRight - chartRight; + } + if (tooltipTop + tHeight > getCurrentHeight()) { + tooltipTop -= tHeight + 30; + } + } + // Set tooltip + tooltip + .style("top", tooltipTop + "px") + .style("left", tooltipLeft + 'px'); + } + function hideTooltip() { + tooltip.style("display", "none"); + } + + function showXGridFocus(selectedData) { + var dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (! __tooltip_show) { return; } + // Hide when scatter plot exists + if (hasScatterType(c3.data.targets) || hasArcType(c3.data.targets)) { return; } + var focusEl = main.selectAll('line.' + CLASS.xgridFocus); + focusEl + .style("visibility", "visible") + .data([dataToShow[0]]) + .attr(__axis_rotated ? 'y1' : 'x1', xx) + .attr(__axis_rotated ? 'y2' : 'x2', xx); + smoothLines(focusEl, 'grid'); + } + function hideXGridFocus() { + main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + } + function generateGridData(type, scale) { + var gridData = [], xDomain, firstYear, lastYear, i, + tickNum = main.select("." + CLASS.axisX).selectAll('.tick').size(); + if (type === 'year') { + xDomain = getXDomain(); + firstYear = xDomain[0].getFullYear(); + lastYear = xDomain[1].getFullYear(); + for (i = firstYear; i <= lastYear; i++) { + gridData.push(new Date(i + '-01-01 00:00:00')); + } + } else { + gridData = scale.ticks(10); + if (gridData.length > tickNum) { // use only int + gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } + } + return gridData; + } + + //-- Shape --// + + function getShapeIndices(typeFilter) { + var indices = {}, i = 0, j, k; + filterTargetsToShow(c3.data.targets.filter(typeFilter)).forEach(function (d) { + for (j = 0; j < __data_groups.length; j++) { + if (__data_groups[j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < __data_groups[j].length; k++) { + if (__data_groups[j][k] in indices) { + indices[d.id] = indices[__data_groups[j][k]]; + break; + } + } + } + if (isUndefined(indices[d.id])) { indices[d.id] = i++; } + }); + indices.__max__ = i - 1; + return indices; + } + function getShapeX(offset, targetsNum, indices, isSub) { + var scale = isSub ? subX : x; + return function (d) { + var index = d.id in indices ? indices[d.id] : 0; + return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; + }; + } + function getShapeY(isSub) { + return function (d) { + var scale = isSub ? getSubYScale(d.id) : getYScale(d.id); + return scale(d.value); + }; + } + function getShapeOffset(typeFilter, indices, isSub) { + var targets = orderTargets(filterTargetsToShow(c3.data.targets.filter(typeFilter))), + targetIds = targets.map(function (t) { return t.id; }); + return function (d, i) { + var scale = isSub ? getSubYScale(d.id) : getYScale(d.id), + y0 = scale(0), offset = y0; + targets.forEach(function (t) { + if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } + if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id) && t.values[i].value * d.value >= 0) { + offset += scale(t.values[i].value) - y0; + } + }); + return offset; + }; + } + + //-- Circle --// + + function circleX(d) { + return d.x || d.x === 0 ? x(d.x) : null; + } + function circleY(d, i) { + var lineIndices = getShapeIndices(isLineType), getPoint = generateGetLinePoint(lineIndices); + return __data_groups.length > 0 ? getPoint(d, i)[0][1] : getYScale(d.id)(d.value); + } + + //-- Bar --// + + function getBarW(axis, barTargetsNum) { + return typeof __bar_width === 'number' ? __bar_width : barTargetsNum ? (axis.tickOffset() * 2 * __bar_width_ratio) / barTargetsNum : 0; + } + + //-- Type --// + + function setTargetType(targetIds, type) { + mapToTargetIds(targetIds).forEach(function (id) { + withoutFadeIn[id] = (type === __data_types[id]); + __data_types[id] = type; + }); + if (!targetIds) { + __data_type = type; + } + } + function hasType(targets, type) { + var has = false; + targets.forEach(function (t) { + if (__data_types[t.id] === type) { has = true; } + if (!(t.id in __data_types) && type === 'line') { has = true; } + }); + return has; + } + + /* not used + function hasLineType(targets) { + return hasType(targets, 'line'); + } + */ + function hasAreaType(targets) { + return hasType(targets, 'area') || hasType(targets, 'area-spline') || hasType(targets, 'area-step'); + } + function hasBarType(targets) { + return hasType(targets, 'bar'); + } + function hasScatterType(targets) { + return hasType(targets, 'scatter'); + } + function hasPieType(targets) { + return __data_type === 'pie' || hasType(targets, 'pie'); + } + function hasGaugeType(targets) { + return hasType(targets, 'gauge'); + } + function hasDonutType(targets) { + return __data_type === 'donut' || hasType(targets, 'donut'); + } + function hasArcType(targets) { + return hasPieType(targets) || hasDonutType(targets) || hasGaugeType(targets); + } + function isLineType(d) { + var id = (typeof d === 'string') ? d : d.id; + return !__data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(__data_types[id]) >= 0; + } + function isStepType(d) { + var id = (typeof d === 'string') ? d : d.id; + return ['step', 'area-step'].indexOf(__data_types[id]) >= 0; + } + function isSplineType(d) { + var id = (typeof d === 'string') ? d : d.id; + return ['spline', 'area-spline'].indexOf(__data_types[id]) >= 0; + } + function isAreaType(d) { + var id = (typeof d === 'string') ? d : d.id; + return ['area', 'area-spline', 'area-step'].indexOf(__data_types[id]) >= 0; + } + function isBarType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'bar'; + } + function isScatterType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'scatter'; + } + function isPieType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'pie'; + } + function isGaugeType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'gauge'; + } + function isDonutType(d) { + var id = (typeof d === 'string') ? d : d.id; + return __data_types[id] === 'donut'; + } + function isArcType(d) { + return isPieType(d) || isDonutType(d) || isGaugeType(d); + } + function lineData(d) { + return isLineType(d) ? [d] : []; + } + function arcData(d) { + return isArcType(d.data) ? [d] : []; + } + /* not used + function scatterData(d) { + return isScatterType(d) ? d.values : []; + } + */ + function barData(d) { + return isBarType(d) ? d.values : []; + } + function lineOrScatterData(d) { + return isLineType(d) || isScatterType(d) ? d.values : []; + } + function barOrLineData(d) { + return isBarType(d) || isLineType(d) ? d.values : []; + } + + function shouldExpand(id) { + return (isDonutType(id) && __donut_expand) || (isGaugeType(id) && __gauge_expand) || (isPieType(id) && __pie_expand); + } + + //-- Color --// + + function generateColor(colors, pattern, callback) { + var ids = []; + + return function (d) { + var id = d.id || d, color; + + // if callback function is provided + if (colors[id] instanceof Function) { + color = colors[id](d); + } + // if specified, choose that color + else if (colors[id]) { + color = colors[id]; + } + // if not specified, choose from pattern + else { + if (ids.indexOf(id) < 0) { ids.push(id); } + color = pattern[ids.indexOf(id) % pattern.length]; + colors[id] = color; + } + return callback instanceof Function ? callback(color, d) : color; + }; + } + + function generateLevelColor(colors, threshold) { + var asValue = threshold.unit === 'value', + values = threshold.values && threshold.values.length ? threshold.values : [], + max = threshold.max || 100; + return function (value) { + var i, v, color = colors[colors.length - 1]; + for (i = 0; i < values.length; i++) { + v = asValue ? value : (value * 100 / max); + if (v < values[i]) { + color = colors[i]; + break; + } + } + return color; + }; + } + + //-- Date --// + + function parseDate(date) { + var parsedDate; + if (date instanceof Date) { + parsedDate = date; + } else if (typeof date === 'number') { + parsedDate = new Date(date); + } else { + parsedDate = dataTimeFormat(__data_x_format).parse(date); + } + if (!parsedDate || isNaN(+parsedDate)) { + window.console.error("Failed to parse x '" + date + "' to Date object"); + } + return parsedDate; + } + + //-- Util --// + + function isWithinCircle(_this, _r) { + var mouse = d3.mouse(_this), d3_this = d3.select(_this); + var cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; + return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; + } + function isWithinBar(_this) { + var mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), + seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1); + var x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2; + var sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; + return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; + } + function isWithinRegions(x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; + } + + function isEmpty(o) { + return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); + } + function notEmpty(o) { + return Object.keys(o).length > 0; + } + function hasValue(dict, value) { + var found = false; + Object.keys(dict).forEach(function (key) { + if (dict[key] === value) { found = true; } + }); + return found; + } + + function dist(data, pos) { + var yScale = getAxisId(data.id) === 'y' ? y : y2, + xIndex = __axis_rotated ? 1 : 0, + yIndex = __axis_rotated ? 0 : 1; + return Math.pow(x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + } + + function endall(transition, callback) { + var n = 0; + transition + .each(function () { ++n; }) + .each("end", function () { + if (!--n) { callback.apply(this, arguments); } + }); + } + + function generateWait() { + var transitionsToWait = [], + f = function (transition, callback) { + var timer = setInterval(function () { + var done = 0; + transitionsToWait.forEach(function (t) { + if (t.empty()) { + done += 1; + return; + } + try { + t.transition(); + } catch (e) { + done += 1; + } + }); + if (done === transitionsToWait.length) { + clearInterval(timer); + if (callback) { callback(); } + } + }, 10); + }; + f.add = function (transition) { + transitionsToWait.push(transition); + }; + return f; + } + + function getOption(options, key, defaultValue) { + return isDefined(options[key]) ? options[key] : defaultValue; + } + + function ceil10(v) { + return Math.ceil(v / 10) * 10; + } + + function getTextRect(text, cls) { + var rect; + d3.select('body').selectAll('.dummy') + .data([text]) + .enter().append('text') + .classed(cls ? cls : "", true) + .text(text) + .each(function () { rect = this.getBoundingClientRect(); }) + .remove(); + return rect; + } + + function getInterpolate(d) { + return isSplineType(d) ? "cardinal" : isStepType(d) ? "step-after" : "linear"; + } + + function getEmptySelection() { + return d3.selectAll([]); + } + + //-- Selection --// + + function selectPoint(target, d, i) { + __data_onselected.call(c3, d, target.node()); + // add selected-circle on low layer g + main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + .data([d]) + .enter().append('circle') + .attr("class", function () { return generateClass(CLASS.selectedCircle, i); }) + .attr("cx", __axis_rotated ? circleY : circleX) + .attr("cy", __axis_rotated ? circleX : circleY) + .attr("stroke", function () { return color(d); }) + .attr("r", pointSelectR(d) * 1.4) + .transition().duration(100) + .attr("r", pointSelectR); + } + function unselectPoint(target, d, i) { + __data_onunselected.call(c3, d, target.node()); + // remove selected-circle from low layer g + main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + .transition().duration(100).attr('r', 0) + .remove(); + } + function togglePoint(selected, target, d, i) { + selected ? selectPoint(target, d, i) : unselectPoint(target, d, i); + } + + function selectBar(target, d) { + __data_onselected.call(c3, d, target.node()); + target.transition().duration(100).style("fill", function () { return d3.rgb(color(d)).brighter(0.75); }); + } + function unselectBar(target, d) { + __data_onunselected.call(c3, d, target.node()); + target.transition().duration(100).style("fill", function () { return color(d); }); + } + function toggleBar(selected, target, d, i) { + selected ? selectBar(target, d, i) : unselectBar(target, d, i); + } + function toggleArc(selected, target, d, i) { + toggleBar(selected, target, d.data, i); + } + function getToggle(that) { + // path selection not supported yet + return that.nodeName === 'circle' ? togglePoint : (d3.select(that).classed(CLASS.bar) ? toggleBar : toggleArc); + } + + function filterRemoveNull(data) { + return data.filter(function (d) { return isValue(d.value); }); + } + + //-- Point --// + + function pointR(d) { + return __point_show && !isStepType(d) ? (typeof __point_r === 'function' ? __point_r(d) : __point_r) : 0; + } + function pointExpandedR(d) { + return __point_focus_expand_enabled ? (__point_focus_expand_r ? __point_focus_expand_r : pointR(d) * 1.75) : pointR(d); + } + function pointSelectR(d) { + return __point_select_r ? __point_select_r : pointR(d) * 4; + } + + //-- Shape --// + + function getCircles(i, id) { + return (id ? main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix(id)) : main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); + } + function expandCircles(i, id) { + getCircles(i, id) + .classed(CLASS.EXPANDED, true) + .attr('r', pointExpandedR); + } + function unexpandCircles(i) { + getCircles(i) + .filter(function () { return d3.select(this).classed(CLASS.EXPANDED); }) + .classed(CLASS.EXPANDED, false) + .attr('r', pointR); + } + function getBars(i) { + return main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); + } + function expandBars(i) { + getBars(i).classed(CLASS.EXPANDED, true); + } + function unexpandBars(i) { + getBars(i).classed(CLASS.EXPANDED, false); + } + + function generateDrawArea(areaIndices, isSub) { + var area = d3.svg.area(), + getPoint = generateGetAreaPoint(areaIndices, isSub), + yScaleGetter = isSub ? getSubYScale : getYScale, + value0 = function (d, i) { + return __data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter(d.id)(0); + }, + value1 = function (d, i) { + return __data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter(d.id)(d.value); + }; + + area = __axis_rotated ? area.x0(value0).x1(value1).y(xx) : area.x(xx).y0(value0).y1(value1); + + return function (d) { + var data = filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + + if (isAreaType(d)) { + path = area.interpolate(getInterpolate(d))(data); + } else { + if (data[0]) { + x0 = x(data[0].x); + y0 = getYScale(d.id)(data[0].value); + } + path = __axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; + } + + function generateDrawLine(lineIndices, isSub) { + var line = d3.svg.line(), + getPoint = generateGetLinePoint(lineIndices, isSub), + yScaleGetter = isSub ? getSubYScale : getYScale, + xValue = isSub ? subxx : xx, + yValue = function (d, i) { + return __data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter(d.id)(d.value); + }; + + line = __axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!__line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } + return function (d) { + var data = __line_connect_null ? filterRemoveNull(d.values) : d.values, + x = isSub ? x : subX, y = yScaleGetter(d.id), x0 = 0, y0 = 0, path; + if (isLineType(d)) { + if (__data_regions[d.id]) { + path = lineWithRegions(data, x, y, __data_regions[d.id]); + } else { + path = line.interpolate(getInterpolate(d))(data); + } + } else { + if (data[0]) { + x0 = x(data[0].x); + y0 = y(data[0].value); + } + path = __axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; + } + + function generateDrawBar(barIndices, isSub) { + var getPoints = generateGetBarPoints(barIndices, isSub); + return function (d, i) { + // 4 points that make a bar + var points = getPoints(d, i); + + // switch points if axis is rotated, not applicable for sub chart + var indexX = __axis_rotated ? 1 : 0; + var indexY = __axis_rotated ? 0 : 1; + + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + + 'z'; + + return path; + }; + } + function generateXYForText(barIndices, forX) { + var getPoints = generateGetBarPoints(barIndices, false), + getter = forX ? getXForText : getYForText; + return function (d, i) { + return getter(getPoints(d, i), d, this); + }; + } + function getXForText(points, d, textElement) { + var box = textElement.getBoundingClientRect(), xPos, padding; + if (__axis_rotated) { + padding = isBarType(d) ? 4 : 6; + xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); + } else { + xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + } + return xPos > width ? width - box.width : xPos; + } + function getYForText(points, d, textElement) { + var box = textElement.getBoundingClientRect(), yPos; + if (__axis_rotated) { + yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; + } else { + yPos = points[2][1] + (d.value < 0 ? box.height : isBarType(d) ? -3 : -6); + } + return yPos < box.height ? box.height : yPos; + } + + function generateGetAreaPoint(areaIndices, isSub) { // partial duplication of generateGetBarPoints + var areaTargetsNum = areaIndices.__max__ + 1, + x = getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = getShapeY(!!isSub), + areaOffset = getShapeOffset(isAreaType, areaIndices, !!isSub), + yScale = isSub ? getSubYScale : getYScale; + return function (d, i) { + var y0 = yScale(d.id)(0), + offset = areaOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the area position + return [ + [posX, offset], + [posX, posY - (y0 - offset)] + ]; + }; + } + + function generateGetBarPoints(barIndices, isSub) { + var barTargetsNum = barIndices.__max__ + 1, + barW = getBarW(xAxis, barTargetsNum), + barX = getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = getShapeY(!!isSub), + barOffset = getShapeOffset(isBarType, barIndices, !!isSub), + yScale = isSub ? getSubYScale : getYScale; + return function (d, i) { + var y0 = yScale(d.id)(0), + offset = barOffset(d, i) || y0, // offset is for stacked bar chart + posX = barX(d), posY = barY(d); + // fix posY not to overflow opposite quadrant + if (__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 4 points that make a bar + return [ + [posX, offset], + [posX, posY - (y0 - offset)], + [posX + barW, posY - (y0 - offset)], + [posX + barW, offset] + ]; + }; + } + + function generateGetLinePoint(lineIndices, isSub) { // partial duplication of generateGetBarPoints + var lineTargetsNum = lineIndices.__max__ + 1, + x = getShapeX(0, lineTargetsNum, lineIndices, !!isSub), + y = getShapeY(!!isSub), + lineOffset = getShapeOffset(isLineType, lineIndices, !!isSub), + yScale = isSub ? getSubYScale : getYScale; + return function (d, i) { + var y0 = yScale(d.id)(0), + offset = lineOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (__axis_rotated) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the line position + return [ + [posX, posY - (y0 - offset)] + ]; + }; + } + + function lineWithRegions(d, x, y, _regions) { + var prev = -1, i, j; + var s = "M", sWithRegion; + var xp, yp, dx, dy, dd, diff, diffx2; + var xValue, yValue; + var regions = []; + + // Check start/end of regions + if (isDefined(_regions)) { + for (i = 0; i < _regions.length; i++) { + regions[i] = {}; + if (isUndefined(_regions[i].start)) { + regions[i].start = d[0].x; + } else { + regions[i].start = isTimeSeries ? parseDate(_regions[i].start) : _regions[i].start; + } + if (isUndefined(_regions[i].end)) { + regions[i].end = d[d.length - 1].x; + } else { + regions[i].end = isTimeSeries ? parseDate(_regions[i].end) : _regions[i].end; + } + } + } + + // Set scales + xValue = __axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); }; + yValue = __axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; + + // Define svg generator function for region + if (isTimeSeries) { + sWithRegion = function (d0, d1, j, diff) { + var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, + xv0 = new Date(x0 + x_diff * j), + xv1 = new Date(x0 + x_diff * (j + diff)); + return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); + }; + } else { + sWithRegion = function (d0, d1, j, diff) { + return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); + }; + } + + // Generate + for (i = 0; i < d.length; i++) { + + // Draw as normal + if (isUndefined(regions) || ! isWithinRegions(d[i].x, regions)) { + s += " " + xValue(d[i]) + " " + yValue(d[i]); + } + // Draw with region // TODO: Fix for horizotal charts + else { + xp = getScale(d[i - 1].x, d[i].x, isTimeSeries); + yp = getScale(d[i - 1].value, d[i].value); + + dx = x(d[i].x) - x(d[i - 1].x); + dy = y(d[i].value) - y(d[i - 1].value); + dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + diff = 2 / dd; + diffx2 = diff * 2; + + for (j = diff; j <= 1; j += diffx2) { + s += sWithRegion(d[i - 1], d[i], j, diff); + } + } + prev = d[i].x; + } + + return s; + } + + //-- Define brush/zoom -// + + var brush, zoom = function () {}; + + brush = d3.svg.brush().on("brush", redrawForBrush); + brush.update = function () { + if (context) { context.select('.' + CLASS.brush).call(this); } + return this; + }; + brush.scale = function (scale) { + return __axis_rotated ? this.y(scale) : this.x(scale); + }; + + zoom = d3.behavior.zoom() + .on("zoomstart", function () { zoom.altDomain = d3.event.sourceEvent.altKey ? x.orgDomain() : null; }) + .on("zoom", redrawForZoom); + zoom.scale = function (scale) { + return __axis_rotated ? this.y(scale) : this.x(scale); + }; + zoom.orgScaleExtent = function () { + var extent = __zoom_extent ? __zoom_extent : [1, 10]; + return [extent[0], Math.max(getMaxDataCount() / extent[1], extent[1])]; + }; + zoom.updateScaleExtent = function () { + var ratio = diffDomain(x.orgDomain()) / diffDomain(orgXDomain), extent = this.orgScaleExtent(); + this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + return this; + }; + + function updateZoom() { + var z = __zoom_enabled ? zoom : function () {}; + main.select('.' + CLASS.zoomRect).call(z); + main.selectAll('.' + CLASS.eventRect).call(z); + } + + /*-- Draw Chart --*/ + + // for svg elements + var svg, defs, main, context, legend, tooltip, selectChart; + + // for brush area culculation + var orgXDomain; + + // for save value + var orgAreaOpacity, withoutFadeIn = {}; + + function updateDimension() { + if (__axis_rotated) { + axes.x.call(xAxis); + axes.subx.call(subXAxis); + } else { + axes.y.call(yAxis); + axes.y2.call(y2Axis); + } + updateSizes(); + updateScales(); + updateSvgSize(); + transformAll(false); + } + + function observeInserted(selection) { + var 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 + var interval = window.setInterval(function () { + // parentNode will NOT be null when completed + if (selection.node().parentNode) { + window.clearInterval(interval); + updateDimension(); + 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}); + } + + function init(data) { + var arcs, eventRect, grid, i, binding = true; + + selectChart = d3.select(__bindto); + if (selectChart.empty()) { + selectChart = d3.select(document.createElement('div')).style('opacity', 0); + observeInserted(selectChart); + binding = false; + } + selectChart.html("").classed("c3", true); + + // Init data as targets + c3.data.xs = {}; + c3.data.targets = convertDataToTargets(data); + + if (__data_filter) { + c3.data.targets = c3.data.targets.filter(__data_filter); + } + + // Set targets to hide if needed + if (__data_hide) { + addHiddenTargetIds(__data_hide === true ? mapToIds(c3.data.targets) : __data_hide); + } + + // when gauge, hide legend // TODO: fix + if (hasGaugeType(c3.data.targets)) { + __legend_show = false; + } + + // Init sizes and scales + updateSizes(); + updateScales(); + + // Set domains for each scale + x.domain(d3.extent(getXDomain(c3.data.targets))); + y.domain(getYDomain(c3.data.targets, 'y')); + y2.domain(getYDomain(c3.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 + brush.scale(subX); + if (__zoom_enabled) { zoom.scale(x); } + + /*-- Basic Elements --*/ + + // Define svgs + svg = selectChart.append("svg") + .style("overflow", "hidden") + .on('mouseenter', function () { return __onmouseover.call(c3); }) + .on('mouseleave', function () { return __onmouseout.call(c3); }); + + // Define defs + defs = svg.append("defs"); + defs.append("clipPath").attr("id", clipId).append("rect"); + defs.append("clipPath").attr("id", clipIdForXAxis).append("rect"); + defs.append("clipPath").attr("id", clipIdForYAxis).append("rect"); + updateSvgSize(); + + // Define regions + main = svg.append("g").attr("transform", translate.main); + context = svg.append("g").attr("transform", translate.context); + legend = svg.append("g").attr("transform", translate.legend); + + if (!__subchart_show) { + context.style('visibility', 'hidden'); + } + + if (!__legend_show) { + legend.style('visibility', 'hidden'); + hiddenLegendIds = mapToIds(c3.data.targets); + } + + // Define tooltip + tooltip = selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + + // MEMO: call here to update legend box and tranlate for all + // MEMO: translate will be upated by this, so transform not needed in updateLegend() + updateLegend(mapToIds(c3.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + + /*-- 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 + main.append('g') + .attr("clip-path", clipPath) + .attr("class", CLASS.regions); + + // Grids + grid = main.append('g') + .attr("clip-path", clipPath) + .attr('class', CLASS.grid); + if (__grid_x_show) { + grid.append("g").attr("class", CLASS.xgrids); + } + if (__grid_y_show) { + grid.append('g').attr('class', CLASS.ygrids); + } + grid.append('g').attr("class", CLASS.xgridLines); + grid.append('g').attr('class', CLASS.ygridLines); + if (__grid_focus_show) { + grid.append('g') + .attr("class", CLASS.xgridFocus) + .append('line') + .attr('class', CLASS.xgridFocus); + } + + // Define g for chart area + main.append('g') + .attr("clip-path", clipPath) + .attr('class', CLASS.chart); + + // Cover whole with rects for events + eventRect = main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.eventRects) + .style('fill-opacity', 0); + + // Define g for bar chart area + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); + + // Define g for line chart area + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); + + // Define g for arc chart area + arcs = main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartArcs) + .attr("transform", translate.arc); + arcs.append('text') + .attr('class', CLASS.chartArcsTitle) + .style("text-anchor", "middle") + .text(getArcTitle()); + if (hasGaugeType(c3.data.targets)) { + arcs.append('path') + .attr("class", CLASS.chartArcsBackground) + .attr("d", function () { + var d = { + data: [{value: __gauge_max}], + startAngle: -1 * (Math.PI / 2), + endAngle: Math.PI / 2 + }; + return getArc(d, true, true); + }); + arcs.append("text") + .attr("dy", ".75em") + .attr("class", CLASS.chartArcsGaugeUnit) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(__gauge_label_show ? __gauge_units : ''); + arcs.append("text") + .attr("dx", -1 * (innerRadius + ((radius - innerRadius) / 2)) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS.chartArcsGaugeMin) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(__gauge_label_show ? __gauge_min : ''); + arcs.append("text") + .attr("dx", innerRadius + ((radius - innerRadius) / 2) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS.chartArcsGaugeMax) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(__gauge_label_show ? __gauge_max : ''); + } + + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartTexts); + + // if zoom privileged, insert rect to forefront + main.insert('rect', __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 (__axis_x_default) { + brush.extent(typeof __axis_x_default !== 'function' ? __axis_x_default : __axis_x_default(getXDomain())); + } + + // Add Axis + axes.x = main.append("g") + .attr("class", CLASS.axis + ' ' + CLASS.axisX) + .attr("clip-path", clipPathForXAxis) + .attr("transform", translate.x) + .style("visibility", __axis_x_show ? 'visible' : 'hidden'); + axes.x.append("text") + .attr("class", CLASS.axisXLabel) + .attr("transform", __axis_rotated ? "rotate(-90)" : "") + .style("text-anchor", textAnchorForXAxisLabel); + + axes.y = main.append("g") + .attr("class", CLASS.axis + ' ' + CLASS.axisY) + .attr("clip-path", clipPathForYAxis) + .attr("transform", translate.y) + .style("visibility", __axis_y_show ? 'visible' : 'hidden'); + axes.y.append("text") + .attr("class", CLASS.axisYLabel) + .attr("transform", __axis_rotated ? "" : "rotate(-90)") + .style("text-anchor", textAnchorForYAxisLabel); + + axes.y2 = main.append("g") + .attr("class", CLASS.axis + ' ' + CLASS.axisY2) + // clip-path? + .attr("transform", translate.y2) + .style("visibility", __axis_y2_show ? 'visible' : 'hidden'); + axes.y2.append("text") + .attr("class", CLASS.axisY2Label) + .attr("transform", __axis_rotated ? "" : "rotate(-90)") + .style("text-anchor", textAnchorForY2AxisLabel); + + /*-- Context Region --*/ + + // Define g for chart area + context.append('g') + .attr("clip-path", clipPath) + .attr('class', CLASS.chart); + + // Define g for bar chart area + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); + + // Define g for line chart area + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); + + // Add extent rect for Brush + context.append("g") + .attr("clip-path", clipPath) + .attr("class", CLASS.brush) + .call(brush) + .selectAll("rect") + .attr(__axis_rotated ? "width" : "height", __axis_rotated ? width2 : height2); + + // ATTENTION: This must be called AFTER chart added + // Add Axis + axes.subx = context.append("g") + .attr("class", CLASS.axisX) + .attr("transform", translate.subx) + .attr("clip-path", __axis_rotated ? "" : clipPathForXAxis); + + // Set targets + updateTargets(c3.data.targets); + + // Draw with targets + if (binding) { + updateDimension(); + redraw({ + withTransform: true, + withUpdateXDomain: true, + withUpdateOrgXDomain: true, + withTransitionForAxis: false, + }); + } + + // Show tooltip if needed + if (__tooltip_init_show) { + if (isTimeSeries && typeof __tooltip_init_x === 'string') { + __tooltip_init_x = parseDate(__tooltip_init_x); + for (i = 0; i < c3.data.targets[0].values.length; i++) { + if ((c3.data.targets[0].values[i].x - __tooltip_init_x) === 0) { break; } + } + __tooltip_init_x = i; + } + tooltip.html(__tooltip_contents(c3.data.targets.map(function (d) { + return addName(d.values[__tooltip_init_x]); + }), getXAxisTickFormat(), getYFormat(hasArcType(c3.data.targets)), color)); + tooltip.style("top", __tooltip_init_position.top) + .style("left", __tooltip_init_position.left) + .style("display", "block"); + } + + // Bind resize event + if (window.onresize == null) { + window.onresize = generateResize(); + } + if (window.onresize.add) { + window.onresize.add(function () { + __onresize.call(c3); + }); + window.onresize.add(function () { + c3.flush(); + }); + window.onresize.add(function () { + __onresized.call(c3); + }); + } + + // export element of the chart + c3.element = selectChart.node(); + } + + function generateEventRectsForSingleX(eventRectEnter) { + eventRectEnter.append("rect") + .attr("class", classEvent) + .style("cursor", __data_selection_enabled && __data_selection_grouped ? "pointer" : null) + .on('mouseover', function (d) { + var index = d.index, selectedData, newData; + + if (dragging) { return; } // do nothing if dragging + if (hasArcType(c3.data.targets)) { return; } + + selectedData = c3.data.targets.map(function (t) { + return addName(getValueOnIndex(t.values, index)); + }); + + // Sort selectedData as names order + newData = []; + Object.keys(__data_names).forEach(function (id) { + for (var j = 0; j < selectedData.length; j++) { + if (selectedData[j] && selectedData[j].id === id) { + newData.push(selectedData[j]); + selectedData.shift(j); + break; + } + } + }); + selectedData = newData.concat(selectedData); // Add remained + + // Expand shapes for selection + if (__point_focus_expand_enabled) { expandCircles(index); } + expandBars(index); + + // Call event handler + main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + __data_onmouseover.call(c3, d); + }); + }) + .on('mouseout', function (d) { + var index = d.index; + if (hasArcType(c3.data.targets)) { return; } + hideXGridFocus(); + hideTooltip(); + // Undo expanded shapes + unexpandCircles(index); + unexpandBars(); + // Call event handler + main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + __data_onmouseout.call(c3, d); + }); + }) + .on('mousemove', function (d) { + var selectedData, index = d.index, eventRect = svg.select('.' + CLASS.eventRect + '-' + index); + + if (dragging) { return; } // do nothing when dragging + if (hasArcType(c3.data.targets)) { return; } + + // Show tooltip + selectedData = filterTargetsToShow(c3.data.targets).map(function (t) { + return addName(getValueOnIndex(t.values, index)); + }); + + if (__tooltip_grouped) { + showTooltip(selectedData, d3.mouse(this)); + showXGridFocus(selectedData); + } + + if (__tooltip_grouped && (!__data_selection_enabled || __data_selection_grouped)) { + return; + } + + main.selectAll('.' + CLASS.shape + '-' + index) + .each(function () { + d3.select(this).classed(CLASS.EXPANDED, true); + if (__data_selection_enabled) { + eventRect.style('cursor', __data_selection_grouped ? 'pointer' : null); + } + if (!__tooltip_grouped) { + hideXGridFocus(); + hideTooltip(); + if (!__data_selection_grouped) { + unexpandCircles(index); + unexpandBars(); + } + } + }) + .filter(function (d) { + if (this.nodeName === 'circle') { + return isWithinCircle(this, pointSelectR(d)); + } + else if (this.nodeName === 'path') { + return isWithinBar(this); + } + }) + .each(function (d) { + if (__data_selection_enabled && (__data_selection_grouped || __data_selection_isselectable(d))) { + eventRect.style('cursor', 'pointer'); + } + if (!__tooltip_grouped) { + showTooltip([d], d3.mouse(this)); + showXGridFocus([d]); + if (__point_focus_expand_enabled) { expandCircles(index, d.id); } + expandBars(index, d.id); + } + }); + }) + .on('click', function (d) { + var index = d.index; + if (hasArcType(c3.data.targets)) { return; } + if (cancelClick) { + cancelClick = false; + return; + } + main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { toggleShape(this, d, index); }); + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { drag(d3.mouse(this)); }) + .on('dragstart', function () { dragstart(d3.mouse(this)); }) + .on('dragend', function () { dragend(); }) + ) + .on("dblclick.zoom", null); + } + + function generateEventRectsForMultipleXs(eventRectEnter) { + eventRectEnter.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', width) + .attr('height', height) + .attr('class', CLASS.eventRect) + .on('mouseout', function () { + if (hasArcType(c3.data.targets)) { return; } + hideXGridFocus(); + hideTooltip(); + unexpandCircles(); + }) + .on('mousemove', function () { + var targetsToShow = filterTargetsToShow(c3.data.targets); + var mouse, closest, sameXData, selectedData; + + if (dragging) { return; } // do nothing when dragging + if (hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + if (isScatterType(closest)) { + sameXData = [closest]; + } else { + sameXData = filterSameX(targetsToShow, closest.x); + } + + // show tooltip when cursor is close to some point + selectedData = sameXData.map(function (d) { + return addName(d); + }); + showTooltip(selectedData, mouse); + + // expand points + if (__point_focus_expand_enabled) { + unexpandCircles(); + expandCircles(closest.index, closest.id); + } + + // Show xgrid focus line + showXGridFocus(selectedData); + + // Show cursor as pointer if point is close to mouse position + if (dist(closest, mouse) < 100) { + svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); + if (!mouseover) { + __data_onmouseover.call(c3, closest); + mouseover = true; + } + } else { + svg.select('.' + CLASS.eventRect).style('cursor', null); + __data_onmouseout.call(c3, closest); + mouseover = false; + } + }) + .on('click', function () { + var targetsToShow = filterTargetsToShow(c3.data.targets); + var mouse, closest; + + if (hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + // select if selection enabled + if (dist(closest, mouse) < 100) { + main.select('.' + CLASS.circles + '-' + getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + toggleShape(this, closest, closest.index); + }); + } + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { drag(d3.mouse(this)); }) + .on('dragstart', function () { dragstart(d3.mouse(this)); }) + .on('dragend', function () { dragend(); }) + ) + .on("dblclick.zoom", null); + } + + function toggleShape(that, d, i) { + var shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; + if (that.nodeName === 'circle') { + isWithin = isWithinCircle(that, pointSelectR(d) * 1.5); + toggle = togglePoint; + } + else if (that.nodeName === 'path') { + if (shape.classed(CLASS.bar)) { + isWithin = isWithinBar(that); + toggle = toggleBar; + } else { // would be arc + isWithin = true; + toggle = toggleArc; + } + } + if (__data_selection_grouped || isWithin) { + if (__data_selection_enabled && __data_selection_isselectable(d)) { + if (!__data_selection_multiple) { + main.selectAll('.' + CLASS.shapes + (__data_selection_grouped ? getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this); + if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } + }); + } + shape.classed(CLASS.SELECTED, !isSelected); + toggle(!isSelected, shape, d, i); + } + __data_onclick.call(c3, d, that); + } + } + + function drag(mouse) { + var sx, sy, mx, my, minX, maxX, minY, maxY; + + if (hasArcType(c3.data.targets)) { return; } + if (! __data_selection_enabled) { return; } // do nothing if not selectable + if (__zoom_enabled && ! zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior + if (!__data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection + + sx = dragStart[0]; + sy = dragStart[1]; + mx = mouse[0]; + my = mouse[1]; + minX = Math.min(sx, mx); + maxX = Math.max(sx, mx); + minY = (__data_selection_grouped) ? margin.top : Math.min(sy, my); + maxY = (__data_selection_grouped) ? height : Math.max(sy, my); + + main.select('.' + CLASS.dragarea) + .attr('x', minX) + .attr('y', minY) + .attr('width', maxX - minX) + .attr('height', maxY - minY); + // TODO: binary search when multiple xs + main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) + .filter(function (d) { return __data_selection_isselectable(d); }) + .each(function (d, i) { + var shape = d3.select(this), + isSelected = shape.classed(CLASS.SELECTED), + isIncluded = shape.classed(CLASS.INCLUDED), + _x, _y, _w, _h, toggle, isWithin = false, box; + if (shape.classed(CLASS.circle)) { + _x = shape.attr("cx") * 1; + _y = shape.attr("cy") * 1; + toggle = togglePoint; + isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; + } + else if (shape.classed(CLASS.bar)) { + box = getPathBox(this); + _x = box.x; + _y = box.y; + _w = box.width; + _h = box.height; + toggle = toggleBar; + isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); + } else { + // line/area selection not supported yet + return; + } + if (isWithin ^ isIncluded) { + shape.classed(CLASS.INCLUDED, !isIncluded); + // TODO: included/unincluded callback here + shape.classed(CLASS.SELECTED, !isSelected); + toggle(!isSelected, shape, d, i); + } + }); + } + + function dragstart(mouse) { + if (hasArcType(c3.data.targets)) { return; } + if (! __data_selection_enabled) { return; } // do nothing if not selectable + dragStart = mouse; + main.select('.' + CLASS.chart).append('rect') + .attr('class', CLASS.dragarea) + .style('opacity', 0.1); + dragging = true; + __data_ondragstart.call(c3); + } + + function dragend() { + if (hasArcType(c3.data.targets)) { return; } + if (! __data_selection_enabled) { return; } // do nothing if not selectable + main.select('.' + CLASS.dragarea) + .transition().duration(100) + .style('opacity', 0) + .remove(); + main.selectAll('.' + CLASS.shape) + .classed(CLASS.INCLUDED, false); + dragging = false; + __data_ondragend.call(c3); + } + + function smoothLines(el, type) { + 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), + }); + }); + } + } + + function redraw(options, transitions) { + var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; + var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; + var areaIndices = getShapeIndices(isAreaType), barIndices = getShapeIndices(isBarType), lineIndices = getShapeIndices(isLineType), maxDataCountTarget, tickOffset; + var rectX, rectW; + var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; + var hideAxis = hasArcType(c3.data.targets); + var drawArea, drawAreaOnSub, drawBar, drawBarOnSub, drawLine, drawLineOnSub, xForText, yForText; + var duration, durationForExit, durationForAxis, waitForDraw; + var targetsToShow = filterTargetsToShow(c3.data.targets), tickValues, i, intervalForCulling; + + xgrid = xgridLines = mainCircle = mainText = getEmptySelection(); + + 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); + withLegend = getOption(options, "withLegend", false); + withTransitionForExit = getOption(options, "withTransitionForExit", withTransition); + withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition); + + duration = withTransition ? __transition_duration : 0; + durationForExit = withTransitionForExit ? duration : 0; + durationForAxis = withTransitionForAxis ? duration : 0; + + transitions = transitions || generateAxisTransitions(durationForAxis); + + // update legend and transform each g + if (withLegend && __legend_show) { + updateLegend(mapToIds(c3.data.targets), options, transitions); + } + + // 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); + // update axis tick values according to options + if (!__axis_x_tick_values && (__axis_x_tick_fit || __axis_x_tick_count)) { + tickValues = generateTickValues(mapTargetsToUniqueXs(targetsToShow), __axis_x_tick_count); + xAxis.tickValues(tickValues); + subXAxis.tickValues(tickValues); + } + } else { + xAxis.tickValues([]); + subXAxis.tickValues([]); + } + + y.domain(getYDomain(targetsToShow, 'y')); + y2.domain(getYDomain(targetsToShow, 'y2')); + + // axes + axes.x.style("opacity", hideAxis ? 0 : 1); + axes.y.style("opacity", hideAxis ? 0 : 1); + axes.y2.style("opacity", hideAxis ? 0 : 1); + axes.subx.style("opacity", hideAxis ? 0 : 1); + transitions.axisX.call(xAxis); + transitions.axisY.call(yAxis); + transitions.axisY2.call(y2Axis); + transitions.axisSubX.call(subXAxis); + + // Update axis label + updateAxisLabels(withTransition); + + // show/hide if manual culling needed + if (withUpdateXDomain && targetsToShow.length) { + if (__axis_x_tick_culling && tickValues) { + for (i = 1; i < tickValues.length; i++) { + if (tickValues.length / i < __axis_x_tick_culling_max) { + intervalForCulling = i; + break; + } + } + svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { + var index = tickValues.indexOf(e); + if (index >= 0) { + d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); + } + }); + } else { + svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); + } + } + + // rotate tick text if needed + if (!__axis_rotated && __axis_x_tick_rotate) { + rotateTickText(axes.x, transitions.axisX, __axis_x_tick_rotate); + } + + // setup drawer - MEMO: these must be called after axis updated + drawArea = generateDrawArea(areaIndices, false); + drawBar = generateDrawBar(barIndices); + drawLine = generateDrawLine(lineIndices, false); + xForText = generateXYForText(barIndices, true); + yForText = generateXYForText(barIndices, false); + + // Update sub domain + subY.domain(y.domain()); + subY2.domain(y2.domain()); + + // tooltip + tooltip.style("display", "none"); + + // 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(__data_empty_label_text) + .transition() + .style('opacity', targetsToShow.length ? 0 : 1); + + // grid + main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + if (__grid_x_show) { + xgridAttr = __axis_rotated ? { + 'x1': 0, + 'x2': width, + 'y1': function (d) { return x(d) - tickOffset; }, + 'y2': function (d) { return x(d) - tickOffset; } + } : { + 'x1': function (d) { return x(d) + tickOffset; }, + 'x2': function (d) { return x(d) + tickOffset; }, + 'y1': 0, + 'y2': height + }; + // this is used to flow + flushXGrid = function (withoutUpdate) { + xgridData = generateGridData(__grid_x_type, x); + tickOffset = isCategorized ? xAxis.tickOffset() : 0; + xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) + .data(xgridData); + xgrid.enter().append('line').attr("class", CLASS.xgrid); + if (!withoutUpdate) { + xgrid.attr(xgridAttr) + .style("opacity", function () { return +d3.select(this).attr(__axis_rotated ? 'y1' : 'x1') === (__axis_rotated ? height : 0) ? 0 : 1; }); + } + xgrid.exit().remove(); + }; + flushXGrid(); + } + xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) + .data(__grid_x_lines); + // enter + xgridLine = xgridLines.enter().append('g') + .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); + xgridLine.append('line') + .style("opacity", 0); + xgridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", __axis_rotated ? "" : "rotate(-90)") + .attr('dx', __axis_rotated ? 0 : -margin.top) + .attr('dy', -5) + .style("opacity", 0); + // udpate + // done in d3.transition() of the end of this function + // exit + xgridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + // Y-Grid + if (withY && __grid_y_show) { + ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) + .data(y.ticks(__grid_y_ticks)); + ygrid.enter().append('line') + .attr('class', CLASS.ygrid); + ygrid.attr("x1", __axis_rotated ? y : 0) + .attr("x2", __axis_rotated ? y : width) + .attr("y1", __axis_rotated ? 0 : y) + .attr("y2", __axis_rotated ? height : y); + ygrid.exit().remove(); + smoothLines(ygrid, 'grid'); + } + if (withY) { + ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) + .data(__grid_y_lines); + // enter + ygridLine = ygridLines.enter().append('g') + .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); + ygridLine.append('line') + .style("opacity", 0); + ygridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", __axis_rotated ? "rotate(-90)" : "") + .attr('dx', __axis_rotated ? 0 : -margin.top) + .attr('dy', -5) + .style("opacity", 0); + // update + ygridLines.select('line') + .transition().duration(duration) + .attr("x1", __axis_rotated ? yv : 0) + .attr("x2", __axis_rotated ? yv : width) + .attr("y1", __axis_rotated ? 0 : yv) + .attr("y2", __axis_rotated ? height : yv) + .style("opacity", 1); + ygridLines.select('text') + .transition().duration(duration) + .attr("x", __axis_rotated ? 0 : width) + .attr("y", yv) + .text(function (d) { return d.text; }) + .style("opacity", 1); + // exit + ygridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + } + + // rect for regions + mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) + .data(__regions); + mainRegion.enter().append('g') + .attr('class', classRegion) + .append('rect') + .style("fill-opacity", 0); + mainRegion.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + + // bars + mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(barData); + mainBar.enter().append('path') + .attr("class", classBar) + .style("stroke", function (d) { return color(d.id); }) + .style("fill", function (d) { return color(d.id); }); + mainBar + .style("opacity", initialOpacity); + mainBar.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + // lines, areas and cricles + mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(lineData); + mainLine.enter().append('path') + .attr('class', classLine) + .style("stroke", color); + mainLine + .style("opacity", initialOpacity) + .attr('transform', null); + mainLine.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(lineData); + mainArea.enter().append('path') + .attr("class", classArea) + .style("fill", color) + .style("opacity", function () { orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + mainArea + .style("opacity", orgAreaOpacity); + mainArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + if (__point_show) { + mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) + .data(lineOrScatterData); + mainCircle.enter().append("circle") + .attr("class", classCircle) + .attr("r", pointR) + .style("fill", color); + mainCircle + .style("opacity", initialOpacity); + mainCircle.exit().remove(); + } + + if (hasDataLabel()) { + mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) + .data(barOrLineData); + mainText.enter().append('text') + .attr("class", classText) + .attr('text-anchor', function (d) { return __axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .style("stroke", 'none') + .style("fill", color) + .style("fill-opacity", 0); + mainText + .text(function (d) { return formatByAxisId(getAxisId(d.id))(d.value, d.id); }); + mainText.exit() + .transition().duration(durationForExit) + .style('fill-opacity', 0) + .remove(); + } + + // arc + mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) + .data(arcData); + mainArc.enter().append('path') + .attr("class", classArc) + .style("fill", function (d) { return color(d.data); }) + .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }) + .style("opacity", 0) + .each(function (d) { + if (isGaugeType(d.data)) { + d.startAngle = d.endAngle = -1 * (Math.PI / 2); + } + this._current = d; + }) + .on('mouseover', function (d) { + var updated, arcData; + if (transiting) { // skip while transiting + return; + } + updated = updateAngle(d); + arcData = convertToArcData(updated); + // transitions + expandArc(updated.data.id); + toggleFocusLegend(updated.data.id, true); + __data_onmouseover.call(c3, arcData, this); + }) + .on('mousemove', function (d) { + var updated = updateAngle(d), arcData = convertToArcData(updated), selectedData = [arcData]; + showTooltip(selectedData, d3.mouse(this)); + }) + .on('mouseout', function (d) { + var updated, arcData; + if (transiting) { // skip while transiting + return; + } + updated = updateAngle(d); + arcData = convertToArcData(updated); + // transitions + unexpandArc(updated.data.id); + revertLegend(); + hideTooltip(); + __data_onmouseout.call(c3, arcData, this); + }) + .on('click', function (d, i) { + var updated = updateAngle(d), arcData = convertToArcData(updated); + toggleShape(this, arcData, i); // onclick called in toogleShape() + }); + mainArc + .attr("transform", function (d) { return !isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .style("opacity", function (d) { return d === this._current ? 0 : 1; }) + .each(function () { transiting = true; }) + .transition().duration(duration) + .attrTween("d", function (d) { + var updated = updateAngle(d), interpolate; + + if (! updated) { + return function () { return "M 0 0"; }; + } +/* + if (this._current === d) { + this._current = { + startAngle: Math.PI*2, + endAngle: Math.PI*2, + }; + } +*/ + if (isNaN(this._current.endAngle)) { + this._current.endAngle = this._current.startAngle; + } + interpolate = d3.interpolate(this._current, updated); + this._current = interpolate(0); + return function (t) { return getArc(interpolate(t), true); }; + }) + .attr("transform", withTransform ? "scale(1)" : "") + .style("fill", function (d) { + return levelColor ? levelColor(d.data.values[0].value) : color(d.data.id); + }) // Where gauge reading color would receive customization. + .style("opacity", 1) + .call(endall, function () { + transiting = false; + }); + mainArc.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + main.selectAll('.' + CLASS.chartArc).select('text') + .style("opacity", 0) + .attr('class', function (d) { return isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .text(textForArcLabel) + .attr("transform", transformForArcLabel) + .transition().duration(duration) + .style("opacity", function (d) { return isTargetToShow(d.data.id) && isArcType(d.data) ? 1 : 0; }); + main.select('.' + CLASS.chartArcsTitle) + .style("opacity", hasDonutType(c3.data.targets) || hasGaugeType(c3.data.targets) ? 1 : 0); + + // subchart + if (__subchart_show) { + // reflect main chart to extent on subchart if zoomed + if (d3.event && d3.event.type === 'zoom') { + brush.extent(x.orgDomain()).update(); + } + // update subchart elements if needed + if (withSubchart) { + + // rotate tick text if needed + if (!__axis_rotated && __axis_x_tick_rotate) { + rotateTickText(axes.subx, transitions.axisSubX, __axis_x_tick_rotate); + } + + // extent rect + if (!brush.empty()) { + brush.extent(x.orgDomain()).update(); + } + // setup drawer - MEMO: this must be called after axis updated + drawAreaOnSub = generateDrawArea(areaIndices, true); + drawBarOnSub = generateDrawBar(barIndices, true); + drawLineOnSub = generateDrawLine(lineIndices, true); + // bars + contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(barData); + contextBar.enter().append('path') + .attr("class", classBar) + .style("stroke", 'none') + .style("fill", color); + contextBar + .style("opacity", initialOpacity) + .transition().duration(duration) + .attr('d', drawBarOnSub) + .style('opacity', 1); + contextBar.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // lines + contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(lineData); + contextLine.enter().append('path') + .attr('class', classLine) + .style('stroke', color); + contextLine + .style("opacity", initialOpacity) + .transition().duration(duration) + .attr("d", drawLineOnSub) + .style('opacity', 1); + contextLine.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // area + contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(lineData); + contextArea.enter().append('path') + .attr("class", classArea) + .style("fill", color) + .style("opacity", function () { orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + contextArea + .style("opacity", 0) + .transition().duration(duration) + .attr("d", drawAreaOnSub) + .style("fill", color) + .style("opacity", orgAreaOpacity); + contextArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + } + } + + // circles for select + main.selectAll('.' + CLASS.selectedCircles) + .filter(function (d) { return isBarType(d); }) + .selectAll('circle') + .remove(); + + if (__interaction_enabled) { + // rect for mouseover + eventRect = main.select('.' + CLASS.eventRects) + .style('cursor', __zoom_enabled ? __axis_rotated ? 'ns-resize' : 'ew-resize' : null); + if (notEmpty(__data_xs) && !isSingleX(__data_xs)) { + + if (!eventRect.classed(CLASS.eventRectsMultiple)) { + eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) + .selectAll('.' + CLASS.eventRect).remove(); + } + + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + .data([0]); + // enter : only one rect will be added + generateEventRectsForMultipleXs(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('x', 0) + .attr('y', 0) + .attr('width', width) + .attr('height', height); + // exit : not needed because always only one rect exists + } else { + + if (!eventRect.classed(CLASS.eventRectsSingle)) { + eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) + .selectAll('.' + CLASS.eventRect).remove(); + } + + if ((isCustomX() || isTimeSeries) && !isCategorized) { + rectW = function (d) { + var prevX = getPrevX(d.index), nextX = getNextX(d.index), dx = c3.data.xs[d.id][d.index], + w = (x(nextX ? nextX : dx) - x(prevX ? prevX : dx)) / 2; + return w < 0 ? 0 : w; + }; + rectX = function (d) { + var prevX = getPrevX(d.index), dx = c3.data.xs[d.id][d.index]; + return (x(dx) + x(prevX ? prevX : dx)) / 2; + }; + } else { + rectW = getEventRectWidth(); + rectX = function (d) { + return x(d.x) - (rectW / 2); + }; + } + // Set data + maxDataCountTarget = getMaxDataCountTarget(c3.data.targets); + main.select('.' + CLASS.eventRects) + .datum(maxDataCountTarget ? maxDataCountTarget.values : []); + // Update rects + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + .data(function (d) { return d; }); + // enter + generateEventRectsForSingleX(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('class', classEvent) + .attr("x", __axis_rotated ? 0 : rectX) + .attr("y", __axis_rotated ? rectX : 0) + .attr("width", __axis_rotated ? width : rectW) + .attr("height", __axis_rotated ? rectW : height); + // exit + eventRectUpdate.exit().remove(); + } + } + + // transition should be derived from one transition + d3.transition().duration(duration).each(function () { + var transitions = []; + + transitions.push(mainBar.transition() + .attr('d', drawBar) + .style("fill", color) + .style("opacity", 1)); + transitions.push(mainLine.transition() + .attr("d", drawLine) + .style("stroke", color) + .style("opacity", 1)); + transitions.push(mainArea.transition() + .attr("d", drawArea) + .style("fill", color) + .style("opacity", orgAreaOpacity)); + transitions.push(mainCircle.transition() + .style('opacity', opacityForCircle) + .style("fill", color) + .attr("cx", __axis_rotated ? circleY : circleX) + .attr("cy", __axis_rotated ? circleX : circleY)); + transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() + .attr("cx", __axis_rotated ? circleY : circleX) + .attr("cy", __axis_rotated ? circleX : circleY)); + transitions.push(mainText.transition() + .attr('x', xForText) + .attr('y', yForText) + .style("fill", color) + .style("fill-opacity", options.flow ? 0 : opacityForText)); + transitions.push(mainRegion.selectAll('rect').transition() + .attr("x", regionX) + .attr("y", regionY) + .attr("width", regionWidth) + .attr("height", regionHeight) + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + transitions.push(xgridLines.select('line').transition() + .attr("x1", __axis_rotated ? 0 : xv) + .attr("x2", __axis_rotated ? width : xv) + .attr("y1", __axis_rotated ? xv : margin.top) + .attr("y2", __axis_rotated ? xv : height) + .style("opacity", 1)); + transitions.push(xgridLines.select('text').transition() + .attr("x", __axis_rotated ? width : 0) + .attr("y", xv) + .text(function (d) { return d.text; }) + .style("opacity", 1)); + // Wait for end of transitions if called from flow API + if (options.flow) { + waitForDraw = generateWait(); + transitions.forEach(function (t) { + waitForDraw.add(t); + }); + } + }) + .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow + var translateX, scaleX = 1, transform, + flowIndex = options.flow.index, + flowLength = options.flow.length, + flowStart = getValueOnIndex(c3.data.targets[0].values, flowIndex), + flowEnd = getValueOnIndex(c3.data.targets[0].values, flowIndex + flowLength), + orgDomain = x.domain(), domain, + durationForFlow = options.flow.duration || duration, + done = options.flow.done || function () {}, + wait = generateWait(); + + // remove head data after rendered + c3.data.targets.forEach(function (d) { + d.values.splice(0, flowLength); + }); + + // update x domain to generate axis elements for flow + domain = updateXDomain(targetsToShow, true, true); + // update elements related to x scale + if (flushXGrid) { flushXGrid(true); } + + // generate transform to flow + if (!options.flow.orgDataCount) { // if empty + if (c3.data.targets[0].values.length !== 1) { + translateX = x(orgDomain[0]) - x(domain[0]); + } else { + if (isTimeSeries) { + flowStart = getValueOnIndex(c3.data.targets[0].values, 0); + flowEnd = getValueOnIndex(c3.data.targets[0].values, c3.data.targets[0].values.length - 1); + translateX = x(flowStart.x) - x(flowEnd.x); + } else { + translateX = diffDomain(domain) / 2; + } + } + } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { + translateX = x(orgDomain[0]) - x(domain[0]); + } else { + if (isTimeSeries) { + translateX = (x(orgDomain[0]) - x(domain[0])); + } else { + translateX = (x(flowStart.x) - x(flowEnd.x)); + } + } + scaleX = (diffDomain(orgDomain) / diffDomain(domain)); + transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; + + d3.transition().ease('linear').duration(durationForFlow).each(function () { + wait.add(axes.x.transition().call(xAxis)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter(isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); + }) + .call(wait, function () { + var i, shapes = [], texts = [], eventRects = []; + + // remove flowed elements + if (flowLength) { + for (i = 0; i < flowLength; i++) { + shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); + texts.push('.' + CLASS.text + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); + } + svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); + svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); + svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); + svg.select('.' + CLASS.xgrid).remove(); + } + + // draw again for removing flowed elements and reverting attr + xgrid + .attr('transform', null) + .attr(xgridAttr); + xgridLines + .attr('transform', null); + xgridLines.select('line') + .attr("x1", __axis_rotated ? 0 : xv) + .attr("x2", __axis_rotated ? width : xv); + xgridLines.select('text') + .attr("x", __axis_rotated ? width : 0) + .attr("y", xv); + mainBar + .attr('transform', null) + .attr("d", drawBar); + mainLine + .attr('transform', null) + .attr("d", drawLine); + mainArea + .attr('transform', null) + .attr("d", drawArea); + mainCircle + .attr('transform', null) + .attr("cx", __axis_rotated ? circleY : circleX) + .attr("cy", __axis_rotated ? circleX : circleY); + mainText + .attr('transform', null) + .attr('x', xForText) + .attr('y', yForText) + .style('fill-opacity', opacityForText); + mainRegion + .attr('transform', null); + mainRegion.select('rect').filter(isRegionOnX) + .attr("x", regionX) + .attr("width", regionWidth); + eventRectUpdate + .attr("x", __axis_rotated ? 0 : rectX) + .attr("y", __axis_rotated ? rectX : 0) + .attr("width", __axis_rotated ? width : rectW) + .attr("height", __axis_rotated ? rectW : height); + + // callback for end of flow + done(); + }); + }); + + // update fadein condition + mapToIds(c3.data.targets).forEach(function (id) { + withoutFadeIn[id] = true; + }); + + updateZoom(); + } + function redrawForBrush() { + redraw({ + withTransition: false, + withY: false, + withSubchart: false, + withUpdateXDomain: true + }); + __subchart_onbrush.call(c3, x.orgDomain()); + } + function redrawForZoom() { + if (!__zoom_enabled) { + return; + } + if (filterTargetsToShow(c3.data.targets).length === 0) { + return; + } + if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { + x.domain(zoom.altDomain); + zoom.scale(x).updateScaleExtent(); + return; + } + if (isCategorized && x.orgDomain()[0] === orgXDomain[0]) { + x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); + } + redraw({ + withTransition: false, + withY: false, + withSubchart: false + }); + if (d3.event.sourceEvent.type === 'mousemove') { + cancelClick = true; + } + __zoom_onzoom.call(c3, x.orgDomain()); + } + + function generateResize() { + var resizeFunctions = []; + function callResizeFunctions() { + resizeFunctions.forEach(function (f) { + f(); + }); + } + callResizeFunctions.add = function (f) { + resizeFunctions.push(f); + }; + return callResizeFunctions; + } + + function updateSvgSize() { + svg.attr('width', currentWidth).attr('height', currentHeight); + svg.select('#' + clipId).select('rect') + .attr('width', width) + .attr('height', height); + svg.select('#' + clipIdForXAxis).select('rect') + .attr('x', getXAxisClipX) + .attr('y', getXAxisClipY) + .attr('width', getXAxisClipWidth) + .attr('height', getXAxisClipHeight); + svg.select('#' + clipIdForYAxis).select('rect') + .attr('x', getYAxisClipX) + .attr('y', getYAxisClipY) + .attr('width', getYAxisClipWidth) + .attr('height', getYAxisClipHeight); + 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"); + } + + function generateAxisTransitions(duration) { + 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, + }; + } + + function updateAndRedraw(options) { + var 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 && __legend_show)) { + transitions = generateAxisTransitions(options.withTransitionForAxis ? __transition_duration : 0); + // Update scales + updateScales(); + updateSvgSize(); + // Update g positions + transformAll(options.withTransitionForTransform, transitions); + } + // Draw with new sizes & scales + redraw(options, transitions); + } + + function updateTargets(targets) { + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; + var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + + /*-- Main --*/ + + //-- Text --// + mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) + .data(targets) + .attr('class', classChartText); + mainTextEnter = mainTextUpdate.enter().append('g') + .attr('class', classChartText) + .style('opacity', 0) + .style("pointer-events", "none"); + mainTextEnter.append('g') + .attr('class', classTexts); + + //-- Bar --// + mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + .data(targets) + .attr('class', classChartBar); + mainBarEnter = mainBarUpdate.enter().append('g') + .attr('class', classChartBar) + .style('opacity', 0) + .style("pointer-events", "none"); + // Bars for each data + mainBarEnter.append('g') + .attr("class", classBars) + .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }); + + //-- Line --// + mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + .data(targets) + .attr('class', classChartLine); + mainLineEnter = mainLineUpdate.enter().append('g') + .attr('class', classChartLine) + .style('opacity', 0) + .style("pointer-events", "none"); + // Lines for each data + mainLineEnter.append('g') + .attr("class", classLines); + // Areas + mainLineEnter.append('g') + .attr('class', classAreas); + // Circles for each data point on lines + mainLineEnter.append('g') + .attr("class", function (d) { return generateClass(CLASS.selectedCircles, d.id); }); + mainLineEnter.append('g') + .attr("class", classCircles) + .style("cursor", function (d) { return __data_selection_isselectable(d) ? "pointer" : null; }); + // Update date for selected circles + targets.forEach(function (t) { + main.selectAll('.' + CLASS.selectedCircles + getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + d.value = t.values[d.index].value; + }); + }); + // MEMO: can not keep same color... + //mainLineUpdate.exit().remove(); + + //-- Pie --// + mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) + .data(pie(targets)) + .attr("class", classChartArc); + mainPieEnter = mainPieUpdate.enter().append("g") + .attr("class", classChartArc); + mainPieEnter.append('g') + .attr('class', classArcs); + mainPieEnter.append("text") + .attr("dy", hasGaugeType(c3.data.targets) ? "-0.35em" : ".35em") + .style("opacity", 0) + .style("text-anchor", "middle") + .style("pointer-events", "none"); + // MEMO: can not keep same color..., but not bad to update color in redraw + //mainPieUpdate.exit().remove(); + + /*-- Context --*/ + + if (__subchart_show) { + + contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + .data(targets) + .attr('class', classChartBar); + contextBarEnter = contextBarUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', classChartBar); + // Bars for each data + contextBarEnter.append('g') + .attr("class", classBars); + + //-- Line --// + contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + .data(targets) + .attr('class', classChartLine); + contextLineEnter = contextLineUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', classChartLine); + // Lines for each data + contextLineEnter.append("g") + .attr("class", classLines); + // Area + contextLineEnter.append("g") + .attr("class", classAreas); + } + + /*-- Show --*/ + + // Fade-in each chart + svg.selectAll('.' + CLASS.target).filter(function (d) { return isTargetToShow(d.id); }) + .transition().duration(__transition_duration) + .style("opacity", 1); + } + + function load(targets, args) { + if (targets) { + // filter loading targets if needed + if (args.filter) { + targets = targets.filter(args.filter); + } + // set type if args.types || args.type specified + if (args.type || args.types) { + targets.forEach(function (t) { + args.types ? setTargetType(t.id, args.types[t.id]) : setTargetType(t.id, args.type); + }); + } + // Update/Add data + c3.data.targets.forEach(function (d) { + for (var i = 0; i < targets.length; i++) { + if (d.id === targets[i].id) { + d.values = targets[i].values; + targets.splice(i, 1); + break; + } + } + }); + c3.data.targets = c3.data.targets.concat(targets); // add remained + } + + // Set targets + updateTargets(c3.data.targets); + + // Redraw with new targets + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + + if (typeof args.done === 'function') { + args.done(); + } + } + function loadFromArgs(args) { + if (args.data) { + load(convertDataToTargets(args.data), args); + } + else if (args.url) { + convertUrlToData(args.url, args.mimeType, args.keys, function (data) { + load(convertDataToTargets(data), args); + }); + } + else if (args.json) { + load(convertDataToTargets(convertJsonToData(args.json, args.keys)), args); + } + else if (args.rows) { + load(convertDataToTargets(convertRowsToData(args.rows)), args); + } + else if (args.columns) { + load(convertDataToTargets(convertColumnsToData(args.columns)), args); + } + else { + load(null, args); + } + } + + function unload(targetIds, done) { + if (typeof done !== 'function') { + done = function () {}; + } + // filter existing target + targetIds = targetIds.filter(function (id) { return hasTarget(c3.data.targets, id); }); + // If no target, call done and return + if (!targetIds || targetIds.length === 0) { + done(); + return; + } + svg.selectAll(targetIds.map(function (id) { return selectorTarget(id); })) + .transition() + .style('opacity', 0) + .remove() + .call(endall, done); + targetIds.forEach(function (id) { + // Reset fadein for future load + withoutFadeIn[id] = false; + // Remove target's elements + legend.selectAll('.' + CLASS.legendItem + getTargetSelectorSuffix(id)).remove(); + // Remove target + c3.data.targets = c3.data.targets.filter(function (t) { + return t.id !== id; + }); + }); + } + + /*-- Draw Legend --*/ + + function opacityForLegend(legendItem) { + return legendItem.classed(CLASS.legendItemHidden) ? legendOpacityForHidden : 1; + } + function opacityForUnfocusedLegend(legendItem) { + return legendItem.classed(CLASS.legendItemHidden) ? legendOpacityForHidden : 0.3; + } + function toggleFocusLegend(id, focus) { + legend.selectAll('.' + CLASS.legendItem) + .transition().duration(100) + .style('opacity', function (_id) { + var This = d3.select(this); + if (id && _id !== id) { + return focus ? opacityForUnfocusedLegend(This) : opacityForLegend(This); + } else { + return focus ? opacityForLegend(This) : opacityForUnfocusedLegend(This); + } + }); + } + function revertLegend() { + legend.selectAll('.' + CLASS.legendItem) + .transition().duration(100) + .style('opacity', function () { return opacityForLegend(d3.select(this)); }); + } + function showLegend(targetIds) { + if (!__legend_show) { + __legend_show = true; + legend.style('visibility', 'visible'); + } + removeHiddenLegendIds(targetIds); + legend.selectAll(selectorLegends(targetIds)) + .style('visibility', 'visible') + .transition() + .style('opacity', function () { return opacityForLegend(d3.select(this)); }); + } + function hideLegend(targetIds) { + if (__legend_show && isEmpty(targetIds)) { + __legend_show = false; + legend.style('visibility', 'hidden'); + } + addHiddenLegendIds(targetIds); + legend.selectAll(selectorLegends(targetIds)) + .style('opacity', 0) + .style('visibility', 'hidden'); + } + + function updateLegend(targetIds, options, transitions) { + var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; + var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; + var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; + var withTransition, withTransitionForTransform; + var hasFocused = legend.selectAll('.' + CLASS.legendItemFocused).size(); + var texts, rects, tiles; + + options = options || {}; + withTransition = getOption(options, "withTransition", true); + withTransitionForTransform = getOption(options, "withTransitionForTransform", true); + + function updatePositions(textElement, id, reset) { + var box = getTextRect(textElement.textContent, CLASS.legendItem), + itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, + itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, + itemLength = isLegendRight || isLegendInset ? itemHeight : itemWidth, + areaLength = isLegendRight || isLegendInset ? getLegendHeight() : getLegendWidth(), + margin, maxLength; + + // MEMO: care about condifion of step, totalLength + function updateValues(id, withoutStep) { + if (!withoutStep) { + margin = (areaLength - totalLength - itemLength) / 2; + if (margin < posMin) { + margin = (areaLength - itemLength) / 2; + totalLength = 0; + step++; + } + } + steps[id] = step; + margins[step] = isLegendInset ? 10 : margin; + offsets[id] = totalLength; + totalLength += itemLength; + } + + if (reset) { + totalLength = 0; + step = 0; + maxWidth = 0; + maxHeight = 0; + } + + if (__legend_show && !isLegendToShow(id)) { + widths[id] = heights[id] = steps[id] = offsets[id] = 0; + return; + } + + widths[id] = itemWidth; + heights[id] = itemHeight; + + if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } + if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } + maxLength = isLegendRight || isLegendInset ? maxHeight : maxWidth; + + if (__legend_equally) { + Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); + Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); + margin = (areaLength - maxLength * targetIds.length) / 2; + if (margin < posMin) { + totalLength = 0; + step = 0; + targetIds.forEach(function (id) { updateValues(id); }); + } + else { + updateValues(id, true); + } + } else { + updateValues(id); + } + } + + if (isLegendRight) { + xForLegend = function (id) { return maxWidth * steps[id]; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else if (isLegendInset) { + xForLegend = function (id) { return maxWidth * steps[id] + 10; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else { + xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + yForLegend = function (id) { return maxHeight * steps[id]; }; + } + xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; + yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; + xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; + yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; + + // Define g for legend area + l = legend.selectAll('.' + CLASS.legendItem) + .data(targetIds) + .enter().append('g') + .attr('class', function (id) { return generateClass(CLASS.legendItem, id); }) + .style('visibility', function (id) { return isLegendToShow(id) ? 'visible' : 'hidden'; }) + .style('cursor', 'pointer') + .on('click', function (id) { + typeof __legend_item_onclick === 'function' ? __legend_item_onclick.call(c3, id) : c3.toggle(id); + }) + .on('mouseover', function (id) { + d3.select(this).classed(CLASS.legendItemFocused, true); + if (!transiting) { + c3.focus(id); + } + if (typeof __legend_item_onmouseover === 'function') { + __legend_item_onmouseover.call(c3, id); + } + }) + .on('mouseout', function (id) { + d3.select(this).classed(CLASS.legendItemFocused, false); + if (!transiting) { + c3.revert(); + } + if (typeof __legend_item_onmouseout === 'function') { + __legend_item_onmouseout.call(c3, id); + } + }); + l.append('text') + .text(function (id) { return isDefined(__data_names[id]) ? __data_names[id] : id; }) + .each(function (id, i) { updatePositions(this, id, i === 0); }) + .style("pointer-events", "none") + .attr('x', isLegendRight || isLegendInset ? xForLegendText : -200) + .attr('y', isLegendRight || isLegendInset ? -200 : yForLegendText); + l.append('rect') + .attr("class", CLASS.legendItemEvent) + .style('fill-opacity', 0) + .attr('x', isLegendRight || isLegendInset ? xForLegendRect : -200) + .attr('y', isLegendRight || isLegendInset ? -200 : yForLegendRect); + l.append('rect') + .attr("class", CLASS.legendItemTile) + .style("pointer-events", "none") + .style('fill', color) + .attr('x', isLegendRight || isLegendInset ? xForLegendText : -200) + .attr('y', isLegendRight || isLegendInset ? -200 : yForLegend) + .attr('width', 10) + .attr('height', 10); + // Set background for inset legend + if (isLegendInset && maxWidth !== 0) { + legend.insert('g', '.' + CLASS.legendItem) + .attr("class", CLASS.legendBackground) + .append('rect') + .attr('height', getLegendHeight() - 10) + .attr('width', maxWidth * (step + 1) + 10); + } + + texts = legend.selectAll('text') + .data(targetIds) + .text(function (id) { return isDefined(__data_names[id]) ? __data_names[id] : id; }) // MEMO: needed for update + .each(function (id, i) { updatePositions(this, id, i === 0); }); + (withTransition ? texts.transition() : texts) + .attr('x', xForLegendText) + .attr('y', yForLegendText); + + rects = legend.selectAll('rect.' + CLASS.legendItemEvent) + .data(targetIds); + (withTransition ? rects.transition() : rects) + .attr('width', function (id) { return widths[id]; }) + .attr('height', function (id) { return heights[id]; }) + .attr('x', xForLegendRect) + .attr('y', yForLegendRect); + + tiles = legend.selectAll('rect.' + CLASS.legendItemTile) + .data(targetIds); + (withTransition ? tiles.transition() : tiles) + .style('fill', color) + .attr('x', xForLegend) + .attr('y', yForLegend); + + // toggle legend state + legend.selectAll('.' + CLASS.legendItem) + .classed(CLASS.legendItemHidden, function (id) { return !isTargetToShow(id); }) + .transition() + .style('opacity', function (id) { + var This = d3.select(this); + if (isTargetToShow(id)) { + return !hasFocused || This.classed(CLASS.legendItemFocused) ? opacityForLegend(This) : opacityForUnfocusedLegend(This); + } else { + return legendOpacityForHidden; + } + }); + + // Update all to reflect change of legend + updateLegendItemWidth(maxWidth); + updateLegendItemHeight(maxHeight); + updateLegendStep(step); + // Update size and scale + updateSizes(); + updateScales(); + updateSvgSize(); + // Update g positions + transformAll(withTransitionForTransform, transitions); + } + + /*-- Event Handling --*/ + + function isNoneArc(d) { + return hasTarget(c3.data.targets, d.id); + } + function isArc(d) { + return 'data' in d && hasTarget(c3.data.targets, d.data.id); + } + function getGridFilterToRemove(params) { + return params ? function (line) { + var found = false; + [].concat(params).forEach(function (param) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + found = true; + } + }); + return found; + } : function () { return true; }; + } + function removeGridLines(params, forX) { + var toRemove = getGridFilterToRemove(params), + toShow = function (line) { return !toRemove(line); }, + classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, + classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; + main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) + .transition().duration(__transition_duration) + .style('opacity', 0).remove(); + if (forX) { + __grid_x_lines = __grid_x_lines.filter(toShow); + } else { + __grid_y_lines = __grid_y_lines.filter(toShow); + } + } + function transformTo(targetIds, type, optionsForRedraw) { + var withTransitionForAxis = !hasArcType(c3.data.targets), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + transiting = false; + setTargetType(targetIds, type); + updateAndRedraw(options); + } + + c3.focus = function (targetId) { + var candidates = svg.selectAll(selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(isNoneArc), + candidatesForArc = candidates.filter(isArc); + function focus(targets) { + filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + c3.revert(); + c3.defocus(); + focus(candidatesForNoneArc.classed(CLASS.focused, true)); + focus(candidatesForArc); + if (hasArcType(c3.data.targets)) { + expandArc(targetId, true); + } + toggleFocusLegend(targetId, true); + }; + + c3.defocus = function (targetId) { + var candidates = svg.selectAll(selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(isNoneArc), + candidatesForArc = candidates.filter(isArc); + function defocus(targets) { + filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); + } + c3.revert(); + defocus(candidatesForNoneArc.classed(CLASS.focused, false)); + defocus(candidatesForArc); + if (hasArcType(c3.data.targets)) { + unexpandArc(targetId); + } + toggleFocusLegend(targetId, false); + }; + + c3.revert = function (targetId) { + var candidates = svg.selectAll(selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(isNoneArc), + candidatesForArc = candidates.filter(isArc); + function revert(targets) { + filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + revert(candidatesForNoneArc.classed(CLASS.focused, false)); + revert(candidatesForArc); + if (hasArcType(c3.data.targets)) { + unexpandArc(targetId); + } + revertLegend(); + }; + + c3.show = function (targetIds, options) { + targetIds = mapToTargetIds(targetIds); + options = options || {}; + + removeHiddenTargetIds(targetIds); + svg.selectAll(selectorTargets(targetIds)) + .transition() + .style('opacity', 1); + + if (options.withLegend) { + showLegend(targetIds); + } + + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + }; + + c3.hide = function (targetIds, options) { + targetIds = mapToTargetIds(targetIds); + options = options || {}; + + addHiddenTargetIds(targetIds); + svg.selectAll(selectorTargets(targetIds)) + .transition() + .style('opacity', 0); + + if (options.withLegend) { + hideLegend(targetIds); + } + + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + }; + + c3.toggle = function (targetId) { + isTargetToShow(targetId) ? c3.hide(targetId) : c3.show(targetId); + }; + + c3.unzoom = function () { + brush.clear().update(); + redraw({withUpdateXDomain: true}); + }; + c3.zoom = function () { + }; + c3.zoom.enable = function (enabled) { + __zoom_enabled = enabled; + updateAndRedraw(); + }; + + c3.load = function (args) { + // update xs if specified + if (args.xs) { + addXs(args.xs); + } + // update classes if exists + if ('classes' in args) { + Object.keys(args.classes).forEach(function (id) { + __data_classes[id] = args.classes[id]; + }); + } + // update categories if exists + if ('categories' in args && isCategorized) { + __axis_x_categories = args.categories; + } + // use cache if exists + if ('cacheIds' in args && hasCaches(args.cacheIds)) { + load(getCaches(args.cacheIds), args.done); + return; + } + // unload if needed + if ('unload' in args) { + // TODO: do not unload if target will load (included in url/rows/columns) + unload(mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + loadFromArgs(args); + }); + } else { + loadFromArgs(args); + } + }; + + c3.unload = function (args) { + args = args || {}; + unload(mapToTargetIds(args.ids), function () { + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + if (typeof args.done === 'function') { args.done(); } + }); + }; + + c3.flow = function (args) { + var targets = convertDataToTargets(convertColumnsToData(args.columns), true), notfoundIds = [], + orgDataCount = getMaxDataCount(), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + + // Update/Add data + c3.data.targets.forEach(function (t) { + var found = false, i, j; + for (i = 0; i < targets.length; i++) { + if (t.id === targets[i].id) { + found = true; + + if (t.values[t.values.length - 1]) { + tail = t.values[t.values.length - 1].index + 1; + } + length = targets[i].values.length; + + for (j = 0; j < length; j++) { + targets[i].values[j].index = tail + j; + if (!isTimeSeries) { + targets[i].values[j].x = tail + j; + } + } + t.values = t.values.concat(targets[i].values); + + targets.splice(i, 1); + break; + } + } + if (!found) { notfoundIds.push(t.id); } + }); + + // Append null for not found targets + c3.data.targets.forEach(function (t) { + var i, j; + for (i = 0; i < notfoundIds.length; i++) { + if (t.id === notfoundIds[i]) { + tail = t.values[t.values.length - 1].index + 1; + for (j = 0; j < length; j++) { + t.values.push({ + id: t.id, + index: tail + j, + x: isTimeSeries ? getOtherTargetX(tail + j) : tail + j, + value: null + }); + } + } + } + }); + + // Generate null values for new target + if (c3.data.targets.length) { + targets.forEach(function (t) { + var i, missing = []; + for (i = c3.data.targets[0].values[0].index; i < tail; i++) { + missing.push({ + id: t.id, + index: i, + x: isTimeSeries ? getOtherTargetX(i) : i, + value: null + }); + } + t.values.forEach(function (v) { + v.index += tail; + if (!isTimeSeries) { + v.x += tail; + } + }); + t.values = missing.concat(t.values); + }); + } + c3.data.targets = c3.data.targets.concat(targets); // add remained + + // check data count because behavior needs to change when it's only one + dataCount = getMaxDataCount(); + baseTarget = c3.data.targets[0]; + baseValue = baseTarget.values[0]; + + // Update length to flow if needed + if (isDefined(args.to)) { + length = 0; + to = isTimeSeries ? parseDate(args.to) : args.to; + baseTarget.values.forEach(function (v) { + if (v.x < to) { length++; } + }); + } else if (isDefined(args.length)) { + length = args.length; + } + + // If only one data, update the domain to flow from left edge of the chart + if (!orgDataCount) { + if (isTimeSeries) { + if (baseTarget.values.length > 1) { + diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; + } else { + diff = baseValue.x - getXDomain(c3.data.targets)[0]; + } + } else { + diff = 1; + } + domain = [baseValue.x - diff, baseValue.x]; + updateXDomain(null, true, true, domain); + } else if (orgDataCount === 1) { + if (isTimeSeries) { + diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; + domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; + updateXDomain(null, true, true, domain); + } + } + + // Set targets + updateTargets(c3.data.targets); + + // Redraw with new targets + redraw({ + flow: { + index: baseValue.index, + length: length, + duration: isValue(args.duration) ? args.duration : __transition_duration, + done: args.done, + orgDataCount: orgDataCount, + }, + withLegend: true, + withTransition: orgDataCount > 1, + }); + }; + + c3.selected = function (targetId) { + return d3.merge( + main.selectAll('.' + CLASS.shapes + getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) + .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) + .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) + ); + }; + + c3.select = function (ids, indices, resetOther) { + if (! __data_selection_enabled) { return; } + main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = getToggle(this), + isTargetId = __data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS.SELECTED); + // line/area selection not supported yet + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + return; + } + if (isTargetId && isTargetIndex) { + if (__data_selection_isselectable(d) && !isSelected) { + toggle(true, shape.classed(CLASS.SELECTED, true), d, i); + } + } else if (isDefined(resetOther) && resetOther) { + if (isSelected) { + toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + } + } + }); + }; + + c3.unselect = function (ids, indices) { + if (! __data_selection_enabled) { return; } + main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = getToggle(this), + isTargetId = __data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS.SELECTED); + // line/area selection not supported yet + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + return; + } + if (isTargetId && isTargetIndex) { + if (__data_selection_isselectable(d)) { + if (isSelected) { + toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + } + } + } + }); + }; + + c3.transform = function (type, targetIds) { + var options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; + transformTo(targetIds, type, options); + }; + + c3.groups = function (groups) { + if (isUndefined(groups)) { return __data_groups; } + __data_groups = groups; + redraw(); + return __data_groups; + }; + + c3.xgrids = function (grids) { + if (! grids) { return __grid_x_lines; } + __grid_x_lines = grids; + redraw(); + return __grid_x_lines; + }; + c3.xgrids.add = function (grids) { + if (! grids) { return; } + return c3.xgrids(__grid_x_lines.concat(grids)); + }; + c3.xgrids.remove = function (params) { // TODO: multiple + removeGridLines(params, true); + }; + + c3.ygrids = function (grids) { + if (! grids) { return __grid_y_lines; } + __grid_y_lines = grids; + redraw(); + return __grid_y_lines; + }; + c3.ygrids.add = function (grids) { + if (! grids) { return; } + return c3.ygrids(__grid_y_lines.concat(grids)); + }; + c3.ygrids.remove = function (params) { // TODO: multiple + removeGridLines(params, false); + }; + + c3.regions = function (regions) { + if (!regions) { return __regions; } + __regions = regions; + redraw(); + return __regions; + }; + c3.regions.add = function (regions) { + if (!regions) { return __regions; } + __regions = __regions.concat(regions); + redraw(); + return __regions; + }; + c3.regions.remove = function (options) { + var duration, classes, regions; + + options = options || {}; + duration = getOption(options, "duration", __transition_duration); + classes = getOption(options, "classes", [CLASS.region]); + + regions = main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); + (duration ? regions.transition().duration(duration) : regions) + .style('opacity', 0) + .remove(); + + __regions = __regions.filter(function (region) { + var found = false; + if (!region.class) { + return true; + } + region.class.split(' ').forEach(function (c) { + if (classes.indexOf(c) >= 0) { found = true; } + }); + return !found; + }); + + return __regions; + }; + + c3.data.get = function (targetId) { + var target = c3.data.getAsTarget(targetId); + return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; + }; + c3.data.getAsTarget = function (targetId) { + var targets = c3.data.targets.filter(function (t) { return t.id === targetId; }); + return targets.length > 0 ? targets[0] : undefined; + }; + c3.data.names = function (names) { + if (!arguments.length) { return __data_names; } + Object.keys(names).forEach(function (id) { + __data_names[id] = names[id]; + }); + redraw({withLegend: true}); + return __data_names; + }; + c3.data.colors = function (colors) { + if (!arguments.length) { return __data_colors; } + Object.keys(colors).forEach(function (id) { + __data_colors[id] = colors[id]; + }); + redraw({withLegend: true}); + return __data_colors; + }; + + c3.category = function (i, category) { + if (arguments.length > 1) { + __axis_x_categories[i] = category; + redraw(); + } + return __axis_x_categories[i]; + }; + c3.categories = function (categories) { + if (!arguments.length) { return __axis_x_categories; } + __axis_x_categories = categories; + redraw(); + return __axis_x_categories; + }; + + c3.color = color; + + c3.x = function (x) { + if (arguments.length) { + updateTargetX(c3.data.targets, x); + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return c3.data.xs; + }; + c3.xs = function (xs) { + if (arguments.length) { + updateTargetXs(c3.data.targets, xs); + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return c3.data.xs; + }; + + c3.axis.labels = function (labels) { + if (arguments.length) { + Object.keys(labels).forEach(function (axisId) { + setAxisLabelText(axisId, labels[axisId]); + }); + updateAxisLabels(); + } + // TODO: return some values? + }; + c3.axis.max = function (max) { + if (arguments.length) { + if (typeof max === 'object') { + if (isValue(max.x)) { __axis_x_max = max.x; } + if (isValue(max.y)) { __axis_y_max = max.y; } + if (isValue(max.y2)) { __axis_y2_max = max.y2; } + } else { + __axis_y_max = __axis_y2_max = max; + } + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + }; + c3.axis.min = function (min) { + if (arguments.length) { + if (typeof min === 'object') { + if (isValue(min.x)) { __axis_x_min = min.x; } + if (isValue(min.y)) { __axis_y_min = min.y; } + if (isValue(min.y2)) { __axis_y2_min = min.y2; } + } else { + __axis_y_min = __axis_y2_min = min; + } + redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + }; + c3.axis.range = function (range) { + if (arguments.length) { + if (typeof range.max !== 'undefined') { c3.axis.max(range.max); } + if (typeof range.min !== 'undefined') { c3.axis.min(range.min); } + } + }; + + c3.legend.show = function (targetIds) { + showLegend(mapToTargetIds(targetIds)); + updateAndRedraw({withLegend: true}); + }; + c3.legend.hide = function (targetIds) { + hideLegend(mapToTargetIds(targetIds)); + updateAndRedraw({withLegend: true}); + }; + + c3.resize = function (size) { + __size_width = size ? size.width : null; + __size_height = size ? size.height : null; + c3.flush(); + }; + + c3.flush = function () { + updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); + }; + + c3.destroy = function () { + c3.data.targets = undefined; + c3.data.xs = {}; + selectChart.classed('c3', false).html(""); + window.onresize = null; + }; + + /*-- Load data and init chart with defined functions --*/ + + if (config.data.url) { + convertUrlToData(config.data.url, config.data.mimeType, config.data.keys, init); + } + else if (config.data.json) { + init(convertJsonToData(config.data.json, config.data.keys)); + } + else if (config.data.rows) { + init(convertRowsToData(config.data.rows)); + } + else if (config.data.columns) { + init(convertColumnsToData(config.data.columns)); + } + else { + throw Error('url or json or rows or columns is required.'); + } + + return c3; + }; + + function isValue(v) { + return v || v === 0; + } + function isUndefined(v) { + return typeof v === 'undefined'; + } + function isDefined(v) { + return typeof v !== 'undefined'; + } + + if (typeof define === "function" && define.amd) { + define("c3", ["d3"], c3); + } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { + module.exports = c3; + } else { + window.c3 = c3; + } + + // Features: + // 1. category axis + // 2. ceil values of translate/x/y to int for half pixel antialiasing + function c3_axis(d3, isCategory) { + var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickValues = null, tickFormat, tickArguments; + + var tickOffset = 0, tickCulling = true, tickCentered; + + 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 (isCategory) { + domain = scale.domain(); + newScale.domain([domain[0], domain[1] - 1]); + } + return newScale; + } + function textFormatted(v) { + return tickFormat ? tickFormat(v) : v; + } + function axis(g) { + g.each(function () { + var g = d3.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 = d3.transition(tick).style("opacity", 1), + tickTransform, tickX; + + var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), + path = g.selectAll(".domain").data([ 0 ]), + pathUpdate = (path.enter().append("path").attr("class", "domain"), d3.transition(path)); + tickEnter.append("line"); + tickEnter.append("text"); + + var lineEnter = tickEnter.select("line"), + lineUpdate = tickUpdate.select("line"), + text = tick.select("text").text(textFormatted), + textEnter = tickEnter.select("text"), + textUpdate = tickUpdate.select("text"); + + if (isCategory) { + tickOffset = Math.ceil((scale1(1) - scale1(0)) / 2); + tickX = tickCentered ? 0 : tickOffset; + } else { + tickOffset = tickX = 0; + } + + function tickSize(d) { + var tickPosition = scale(d) + tickOffset; + return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0; + } + + switch (orient) { + case "bottom": + { + tickTransform = axisX; + lineEnter.attr("y2", innerTickSize); + textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding); + lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", tickSize); + textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding); + text.attr("dy", ".71em").style("text-anchor", "middle"); + pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); + break; + } + case "top": + { + tickTransform = axisX; + lineEnter.attr("y2", -innerTickSize); + textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); + lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); + textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); + text.attr("dy", "0em").style("text-anchor", "middle"); + pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); + break; + } + case "left": + { + tickTransform = axisY; + lineEnter.attr("x2", -innerTickSize); + textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)); + lineUpdate.attr("x2", -innerTickSize).attr("y2", 0); + textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", tickOffset); + text.attr("dy", ".32em").style("text-anchor", "end"); + pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); + break; + } + case "right": + { + tickTransform = axisY; + lineEnter.attr("x2", innerTickSize); + textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding); + lineUpdate.attr("x2", innerTickSize).attr("y2", 0); + textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0); + text.attr("dy", ".32em").style("text-anchor", "start"); + 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 (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 () { // This will be overwritten when normal x axis + return tickOffset; + }; + 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 (!arguments.length) { return tickValues; } + tickValues = x; + return axis; + }; + return axis; + } + +})(window); From 566f1e251903610b8a6fe11ffcd68765635c8a60 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 29 Jun 2014 17:28:05 +0900 Subject: [PATCH 02/44] Define concat in grant task --- Gruntfile.coffee | 17 +++++++++++++++++ package.json | 8 +++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 7d387bc..074f379 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -2,6 +2,23 @@ module.exports = (grunt) -> require('load-grunt-tasks') grunt, pattern: 'grunt-contrib-*' grunt.initConfig + watch: + concat: + tasks: 'concat' + files: ['src/*.js'] + + concat: + dist: + src: [ + 'src/head.js', + 'src/c3.core.js', + 'src/c3.render.bar.js', + 'src/c3.draw.bar.js', + 'src/c3.axis.js', + 'src/tail.js' + ] + dest: 'dist/c3.js' + jshint: c3: 'c3.js' spec: 'spec/*.js' diff --git a/package.json b/package.json index 709f2cd..c63fa48 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,11 @@ "readmeFilename": "README.md", "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-jshint": "~0.7.1", + "grunt-contrib-concat": "~0.5.0", "grunt-contrib-jasmine": "~0.5.2", - "load-grunt-tasks": "~0.2.0", - "grunt-contrib-uglify": "~0.4.0" + "grunt-contrib-jshint": "~0.7.1", + "grunt-contrib-uglify": "~0.4.0", + "grunt-contrib-watch": "^0.6.1", + "load-grunt-tasks": "~0.2.0" } } From 7e59cb116ee9a496908be9d99274ec8d3f161c72 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Wed, 23 Jul 2014 00:58:38 +0100 Subject: [PATCH 03/44] Refactor --- c3.js | 2360 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 1184 insertions(+), 1176 deletions(-) diff --git a/c3.js b/c3.js index 21876ab..9ecb5d9 100644 --- a/c3.js +++ b/c3.js @@ -8,38 +8,20 @@ var c3 = { version: "0.3.0" }; - // will be called to generate c3 chart object - c3.generate = function (config) { - return new c3_chart(config); - }; - - // c3.fn.$$ and c3.fn.chart will be defined as prototype interface - c3.fn = {}; - - /*-- HIDDEN VARS AND FUNCTIONS --*/ + function Chart(config) { - // Define solid chart for hiding its functions from chart object scope - var chart = function () {}; - - // Wrap solid chart object and call functions defined through c3.fn.$$ and c3.fn.chart - var c3_chart = function (config) { - - var $$ = this.$$ = new chart(), + var $$ = this.internal = new Chart.Internal(), d3 = $$.d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; - $$.this = this; - $$.config = config; + $$.chart = this; $$.data = {}; $$.cache = {}; /*-- Handle Config --*/ - $$.updateConfig(); - - // TODO: this should be an API - this.config = config; + $$.readConfig(config); - /*-- Set Variables --*/ + /*-- Init Variables --*/ // TODO: some of these should be a function and defined in prototype @@ -51,9 +33,9 @@ $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - $$.isTimeSeries = ($$.__axis_x_type === 'timeseries'); - $$.isCategorized = ($$.__axis_x_type.indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && ($$.__data_x || $$.notEmpty($$.__data_xs)); }; + $$.isTimeSeries = ($$.config.axis_x_type === 'timeseries'); + $$.isCategorized = ($$.config.axis_x_type.indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && ($$.config.data_x || $$.notEmpty($$.config.data_xs)); }; $$.dragStart = null; $$.dragging = false; @@ -62,11 +44,11 @@ $$.transiting = false; $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor($$.__data_colors, $$.notEmpty($$.__color_pattern) ? $$.__color_pattern : $$.defaultColorPattern, $$.__data_color); - $$.levelColor = $$.notEmpty($$.__color_threshold) ? $$.generateLevelColor($$.__color_pattern, $$.__color_threshold) : null; + $$.color = $$.generateColor($$.config.data_colors, $$.notEmpty($$.config.color_pattern) ? $$.config.color_pattern : $$.defaultColorPattern, $$.config.data_color); + $$.levelColor = $$.notEmpty($$.config.color_threshold) ? $$.generateLevelColor($$.config.color_pattern, $$.config.color_threshold) : null; - $$.dataTimeFormat = $$.__data_x_localtime ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = $$.__axis_x_localtime ? d3.time.format : d3.time.format.utc; + $$.dataTimeFormat = $$.config.data_x_localtime ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = $$.config.axis_x_localtime ? d3.time.format : d3.time.format.utc; $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ [".%L", function (d) { return d.getMilliseconds(); }], [":%S", function (d) { return d.getSeconds(); }], @@ -83,26 +65,26 @@ $$.axes = {}; - $$.xOrient = $$.__axis_rotated ? "left" : "bottom"; - $$.yOrient = $$.__axis_rotated ? ($$.__axis_y_inner ? "top" : "bottom") : ($$.__axis_y_inner ? "right" : "left"); - $$.y2Orient = $$.__axis_rotated ? ($$.__axis_y2_inner ? "bottom" : "top") : ($$.__axis_y2_inner ? "left" : "right"); - $$.subXOrient = $$.__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"); + $$.y2Orient = $$.config.axis_rotated ? ($$.config.axis_y2_inner ? "bottom" : "top") : ($$.config.axis_y2_inner ? "left" : "right"); + $$.subXOrient = $$.config.axis_rotated ? "left" : "bottom"; $$.translate = { main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, - x : function () { return "translate(0," + ($$.__axis_rotated ? 0 : $$.height) + ")"; }, - y : function () { return "translate(0," + ($$.__axis_rotated ? $$.height : 0) + ")"; }, - y2 : function () { return "translate(" + ($$.__axis_rotated ? 0 : $$.width) + "," + ($$.__axis_rotated ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + ($$.__axis_rotated ? 0 : $$.height2) + ")"; }, + x : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height) + ")"; }, + y : function () { return "translate(0," + ($$.config.axis_rotated ? $$.height : 0) + ")"; }, + y2 : function () { return "translate(" + ($$.config.axis_rotated ? 0 : $$.width) + "," + ($$.config.axis_rotated ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height2) + ")"; }, arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } }; - $$.isLegendRight = $$.__legend_position === 'right'; - $$.isLegendInset = $$.__legend_position === 'inset'; - $$.isLegendTop = $$.__legend_inset_anchor === 'top-left' || $$.__legend_inset_anchor === 'top-right'; - $$.isLegendLeft = $$.__legend_inset_anchor === 'top-left' || $$.__legend_inset_anchor === 'bottom-left'; + $$.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; @@ -111,7 +93,7 @@ $$.currentMaxTickWidth = 0; $$.rotated_padding_left = 30; - $$.rotated_padding_right = $$.__axis_rotated && !$$.__axis_x_show ? 0 : 30; + $$.rotated_padding_right = $$.config.axis_rotated && !$$.config.axis_x_show ? 0 : 30; $$.rotated_padding_top = 5; $$.withoutFadeIn = {}; @@ -120,7 +102,7 @@ $$.pie = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); }); - if (!$$.__pie_sort || !$$.__donut_sort) { // TODO: this needs to be called by each type + if (!$$.config.pie_sort || !$$.config.donut_sort) { // TODO: this needs to be called by each type $$.pie.sort(null); } @@ -131,7 +113,7 @@ return this; }; $$.brush.scale = function (scale) { - return $$.__axis_rotated ? this.y(scale) : this.x(scale); + return $$.config.axis_rotated ? this.y(scale) : this.x(scale); }; // TODO: this should be pluggable @@ -141,10 +123,10 @@ }) .on("zoom", $$.redrawForZoom); $$.zoom.scale = function (scale) { - return $$.__axis_rotated ? this.y(scale) : this.x(scale); + return $$.config.axis_rotated ? this.y(scale) : this.x(scale); }; $$.zoom.orgScaleExtent = function () { - var extent = $$.__zoom_extent ? $$.__zoom_extent : [1, 10]; + var extent = $$.config.zoom_extent ? $$.config.zoom_extent : [1, 10]; return [extent[0], Math.max(this.getMaxDataCount() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { @@ -170,11 +152,20 @@ else { throw Error('url or json or rows or columns is required.'); } + } + + Chart.Internal = function () {}; + + c3.generate = function (config) { + return new Chart(config); }; - // Open interface for each prototype - c3.fn.chart = c3_chart.prototype = {}; - c3.fn.$$ = chart.prototype = {}; + c3.chart = { + fn: Chart.prototype, + internal: { + fn: Chart.Internal.prototype + } + }; if (typeof define === "function" && define.amd) { define("c3", ["d3"], c3); @@ -195,340 +186,254 @@ /** * c3.config.js */ - c3.fn.$$.getConfig = function (keys, defaultValue) { - var target = this.config, i, isLast, nextTarget; - for (i = 0; i < keys.length; i++) { - // return default if key not found - if (typeof target === 'object' && !(keys[i] in target)) { return defaultValue; } - // Check next key's value - isLast = (i === keys.length - 1); - nextTarget = target[keys[i]]; - if (!isLast && typeof nextTarget !== 'object') { - return defaultValue; - } - target = nextTarget; - } - return target; - }; - c3.fn.$$.updateConfig = function () { - var $$ = this; - - $$.__bindto = $$.getConfig(['bindto'], '#chart'); - - $$.__size_width = $$.getConfig(['size', 'width']); - $$.__size_height = $$.getConfig(['size', 'height']); - - $$.__padding_left = $$.getConfig(['padding', 'left']); - $$.__padding_right = $$.getConfig(['padding', 'right']); - $$.__padding_top = $$.getConfig(['padding', 'top']); - $$.__padding_bottom = $$.getConfig(['padding', 'bottom']); - - $$.__zoom_enabled = $$.getConfig(['zoom', 'enabled'], false); - $$.__zoom_extent = $$.getConfig(['zoom', 'extent']); - $$.__zoom_privileged = $$.getConfig(['zoom', 'privileged'], false); - $$.__zoom_onzoom = $$.getConfig(['zoom', 'onzoom'], function () {}); - - $$.__interaction_enabled = $$.getConfig(['interaction', 'enabled'], true); - - $$.__onmouseover = $$.getConfig(['onmouseover'], function () {}); - $$.__onmouseout = $$.getConfig(['onmouseout'], function () {}); - $$.__onresize = $$.getConfig(['onresize'], function () {}); - $$.__onresized = $$.getConfig(['onresized'], function () {}); - - $$.__transition_duration = $$.getConfig(['transition', 'duration'], 350); - - $$.__data_x = $$.getConfig(['data', 'x']); - $$.__data_xs = $$.getConfig(['data', 'xs'], {}); - $$.__data_x_format = $$.getConfig(['data', 'x_format'], '%Y-%m-%d'); - $$.__data_x_localtime = $$.getConfig(['data', 'x_localtime'], true); - $$.__data_id_converter = $$.getConfig(['data', 'id_converter'], function (id) { return id; }); - $$.__data_names = $$.getConfig(['data', 'names'], {}); - $$.__data_classes = $$.getConfig(['data', 'classes'], {}); - $$.__data_groups = $$.getConfig(['data', 'groups'], []); - $$.__data_axes = $$.getConfig(['data', 'axes'], {}); - $$.__data_type = $$.getConfig(['data', 'type']); - $$.__data_types = $$.getConfig(['data', 'types'], {}); - $$.__data_labels = $$.getConfig(['data', 'labels'], {}); - $$.__data_order = $$.getConfig(['data', 'order']); - $$.__data_regions = $$.getConfig(['data', 'regions'], {}); - $$.__data_color = $$.getConfig(['data', 'color']); - $$.__data_colors = $$.getConfig(['data', 'colors'], {}); - $$.__data_hide = $$.getConfig(['data', 'hide'], false); - $$.__data_filter = $$.getConfig(['data', 'filter']); - $$.__data_selection_enabled = $$.getConfig(['data', 'selection', 'enabled'], false); - $$.__data_selection_grouped = $$.getConfig(['data', 'selection', 'grouped'], false); - $$.__data_selection_isselectable = $$.getConfig(['data', 'selection', 'isselectable'], function () { return true; }); - $$.__data_selection_multiple = $$.getConfig(['data', 'selection', 'multiple'], true); - $$.__data_onclick = $$.getConfig(['data', 'onclick'], function () {}); - $$.__data_onmouseover = $$.getConfig(['data', 'onmouseover'], function () {}); - $$.__data_onmouseout = $$.getConfig(['data', 'onmouseout'], function () {}); - $$.__data_onselected = $$.getConfig(['data', 'onselected'], function () {}); - $$.__data_onunselected = $$.getConfig(['data', 'onunselected'], function () {}); - $$.__data_ondragstart = $$.getConfig(['data', 'ondragstart'], function () {}); - $$.__data_ondragend = $$.getConfig(['data', 'ondragend'], function () {}); + c3.chart.internal.fn.config = { + bindto: '#chart', + size_width: undefined, + size_height: undefined, + + padding_left: undefined, + padding_right: undefined, + padding_top: undefined, + padding_bottom: undefined, + + zoom_enabled: false, + zoom_extent: undefined, + zoom_privileged: false, + zoom_onzoom: function () {}, + + interaction_enabled: true, + + onmouseover: function () {}, + onmouseout: function () {}, + onresize: function () {}, + onresized: function () {}, + + transition_duration: 350, + + data_x: undefined, + data_xs: {}, + data_x_format: '%Y-%m-%d', + data_x_localtime: true, + data_id_converter: function (id) { return id; }, + data_names: {}, + data_classes: {}, + data_groups: [], + data_axes: {}, + data_type: undefined, + data_types: {}, + data_labels: {}, + data_order: 'desc', + data_regions: {}, + data_color: undefined, + data_colors: {}, + data_hide: false, + data_filter: undefined, + data_selection_enabled: false, + data_selection_grouped: false, + data_selection_isselectable: function () { return true; }, + data_selection_multiple: true, + data_onclick: function () {}, + data_onmouseover: function () {}, + data_onmouseout: function () {}, + data_onselected: function () {}, + data_onunselected: function () {}, + data_ondragstart: function () {}, + data_ondragend: function () {}, + data_url: {}, + data_json: {}, + data_rows: {}, + data_columns: {}, // configuration for no plot-able data supplied. - $$.__data_empty_label_text = $$.getConfig(['data', 'empty', 'label', 'text'], ""); - + data_empty_label_text: "", + // subchart - $$.__subchart_show = $$.getConfig(['subchart', 'show'], false); - $$.__subchart_size_height = $$.getConfig(['subchart', 'size', 'height'], 60); - $$.__subchart_onbrush = $$.getConfig(['subchart', 'onbrush'], function () {}); + subchart_show: false, + subchart_size_height: 60, + subchart_onbrush: function () {}, // color - $$.__color_pattern = $$.getConfig(['color', 'pattern'], []); - $$.__color_threshold = $$.getConfig(['color', 'threshold'], {}); + color_pattern: [], + color_threshold : {}, // legend - $$.__legend_show = $$.getConfig(['legend', 'show'], true); - $$.__legend_position = $$.getConfig(['legend', 'position'], 'bottom'); - $$.__legend_inset_anchor = $$.getConfig(['legend', 'inset', 'anchor'], 'top-left'); - $$.__legend_inset_x = $$.getConfig(['legend', 'inset', 'x'], 10); - $$.__legend_inset_y = $$.getConfig(['legend', 'inset', 'y'], 0); - $$.__legend_inset_step = $$.getConfig(['legend', 'inset', 'step']); - $$.__legend_item_onclick = $$.getConfig(['legend', 'item', 'onclick']); - $$.__legend_item_onmouseover = $$.getConfig(['legend', 'item', 'onmouseover']); - $$.__legend_item_onmouseout = $$.getConfig(['legend', 'item', 'onmouseout']); - $$.__legend_equally = $$.getConfig(['legend', 'equally'], false); + legend_show: true, + legend_position: 'bottom', + legend_inset_anchor: 'top-left', + legend_inset_x: 10, + legend_inset_y: 0, + legend_inset_step: undefined, + legend_item_onclick: undefined, + legend_item_onmouseover: undefined, + legend_item_onmouseout: undefined, + legend_equally: false, // axis - $$.__axis_rotated = $$.getConfig(['axis', 'rotated'], false); - $$.__axis_x_show = $$.getConfig(['axis', 'x', 'show'], true); - $$.__axis_x_type = $$.getConfig(['axis', 'x', 'type'], 'indexed'); - $$.__axis_x_localtime = $$.getConfig(['axis', 'x', 'localtime'], true); - $$.__axis_x_categories = $$.getConfig(['axis', 'x', 'categories'], []); - $$.__axis_x_tick_centered = $$.getConfig(['axis', 'x', 'tick', 'centered'], false); - $$.__axis_x_tick_format = $$.getConfig(['axis', 'x', 'tick', 'format']); - $$.__axis_x_tick_culling = $$.getConfig(['axis', 'x', 'tick', 'culling'], {}); - $$.__axis_x_tick_culling_max = $$.getConfig(['axis', 'x', 'tick', 'culling', 'max'], 10); - $$.__axis_x_tick_count = $$.getConfig(['axis', 'x', 'tick', 'count']); - $$.__axis_x_tick_fit = $$.getConfig(['axis', 'x', 'tick', 'fit'], true); - $$.__axis_x_tick_values = $$.getConfig(['axis', 'x', 'tick', 'values'], null); - $$.__axis_x_tick_rotate = $$.getConfig(['axis', 'x', 'tick', 'rotate']); - $$.__axis_x_max = $$.getConfig(['axis', 'x', 'max'], null); - $$.__axis_x_min = $$.getConfig(['axis', 'x', 'min'], null); - $$.__axis_x_padding = $$.getConfig(['axis', 'x', 'padding'], {}); - $$.__axis_x_height = $$.getConfig(['axis', 'x', 'height']); - $$.__axis_x_default = $$.getConfig(['axis', 'x', 'default']); - $$.__axis_x_label = $$.getConfig(['axis', 'x', 'label'], {}); - $$.__axis_y_show = $$.getConfig(['axis', 'y', 'show'], true); - $$.__axis_y_max = $$.getConfig(['axis', 'y', 'max']); - $$.__axis_y_min = $$.getConfig(['axis', 'y', 'min']); - $$.__axis_y_center = $$.getConfig(['axis', 'y', 'center']); - $$.__axis_y_label = $$.getConfig(['axis', 'y', 'label'], {}); - $$.__axis_y_inner = $$.getConfig(['axis', 'y', 'inner'], false); - $$.__axis_y_tick_format = $$.getConfig(['axis', 'y', 'tick', 'format']); - $$.__axis_y_padding = $$.getConfig(['axis', 'y', 'padding']); - $$.__axis_y_ticks = $$.getConfig(['axis', 'y', 'ticks'], 10); - $$.__axis_y2_show = $$.getConfig(['axis', 'y2', 'show'], false); - $$.__axis_y2_max = $$.getConfig(['axis', 'y2', 'max']); - $$.__axis_y2_min = $$.getConfig(['axis', 'y2', 'min']); - $$.__axis_y2_center = $$.getConfig(['axis', 'y2', 'center']); - $$.__axis_y2_label = $$.getConfig(['axis', 'y2', 'label'], {}); - $$.__axis_y2_inner = $$.getConfig(['axis', 'y2', 'inner'], false); - $$.__axis_y2_tick_format = $$.getConfig(['axis', 'y2', 'tick', 'format']); - $$.__axis_y2_padding = $$.getConfig(['axis', 'y2', 'padding']); - $$.__axis_y2_ticks = $$.getConfig(['axis', 'y2', 'ticks'], 10); + axis_rotated: false, + axis_x_show: true, + axis_x_type: 'indexed', + axis_x_localtime: true, + axis_x_categories: [], + axis_x_tick_centered: false, + axis_x_tick_format: undefined, + axis_x_tick_culling: {}, + axis_x_tick_culling_max: 10, + axis_x_tick_count: undefined, + axis_x_tick_fit: true, + axis_x_tick_values: null, + axis_x_tick_rotate: undefined, + axis_x_tick_outer: true, + axis_x_max: null, + axis_x_min: null, + axis_x_padding: {}, + axis_x_height: undefined, + axis_x_default: undefined, + axis_x_label: {}, + axis_y_show: true, + axis_y_max: undefined, + axis_y_min: undefined, + axis_y_center: undefined, + axis_y_label: {}, + axis_y_inner: false, + axis_y_tick_format: undefined, + axis_y_tick_outer: true, + axis_y_padding: undefined, + axis_y_ticks: 10, + axis_y2_show: false, + axis_y2_max: undefined, + axis_y2_min: undefined, + axis_y2_center: undefined, + axis_y2_label: {}, + axis_y2_inner: false, + axis_y2_tick_format: undefined, + axis_y2_tick_outer: true, + axis_y2_padding: undefined, + axis_y2_ticks: 10, // grid - $$.__grid_x_show = $$.getConfig(['grid', 'x', 'show'], false); - $$.__grid_x_type = $$.getConfig(['grid', 'x', 'type'], 'tick'); - $$.__grid_x_lines = $$.getConfig(['grid', 'x', 'lines'], []); - $$.__grid_y_show = $$.getConfig(['grid', 'y', 'show'], false); + grid_x_show: false, + grid_x_type: 'tick', + grid_x_lines: [], + grid_y_show: false, // not used - // __grid_y_type = $$.getConfig(['grid', 'y', 'type'], 'tick'), - $$.__grid_y_lines = $$.getConfig(['grid', 'y', 'lines'], []); - $$.__grid_y_ticks = $$.getConfig(['grid', 'y', 'ticks'], 10); - $$.__grid_focus_show = $$.getConfig(['grid', 'focus', 'show'], true); + // grid_y_type: {}, 'tick'), + grid_y_lines: [], + grid_y_ticks: 10, + grid_focus_show: true, // point - point of each data - $$.__point_show = $$.getConfig(['point', 'show'], true); - $$.__point_r = $$.getConfig(['point', 'r'], 2.5); - $$.__point_focus_expand_enabled = $$.getConfig(['point', 'focus', 'expand', 'enabled'], true); - $$.__point_focus_expand_r = $$.getConfig(['point', 'focus', 'expand', 'r']); - $$.__point_select_r = $$.getConfig(['point', 'focus', 'select', 'r']); + point_show: true, + point_r: 2.5, + point_focus_expand_enabled: true, + point_focus_expand_r: undefined, + point_select_r: undefined, - $$.__line_connect_null = $$.getConfig(['line', 'connect_null'], false); + line_connect_null: false, // bar - $$.__bar_width = $$.getConfig(['bar', 'width']); - $$.__bar_width_ratio = $$.getConfig(['bar', 'width', 'ratio'], 0.6); - $$.__bar_zerobased = $$.getConfig(['bar', 'zerobased'], true); + bar_width: undefined, + bar_width_ratio: 0.6, + bar_width_max: undefined, + bar_zerobased: true, // area - $$.__area_zerobased = $$.getConfig(['area', 'zerobased'], true); + area_zerobased: true, // pie - $$.__pie_label_show = $$.getConfig(['pie', 'label', 'show'], true); - $$.__pie_label_format = $$.getConfig(['pie', 'label', 'format']); - $$.__pie_label_threshold = $$.getConfig(['pie', 'label', 'threshold'], 0.05); - $$.__pie_sort = $$.getConfig(['pie', 'sort'], true); - $$.__pie_expand = $$.getConfig(['pie', 'expand'], true); + pie_label_show: true, + pie_label_format: undefined, + pie_label_threshold: 0.05, + pie_sort: true, + pie_expand: true, // gauge - $$.__gauge_label_show = $$.getConfig(['gauge', 'label', 'show'], true); - $$.__gauge_label_format = $$.getConfig(['gauge', 'label', 'format']); - $$.__gauge_expand = $$.getConfig(['gauge', 'expand'], true); - $$.__gauge_min = $$.getConfig(['gauge', 'min'], 0); - $$.__gauge_max = $$.getConfig(['gauge', 'max'], 100); - $$.__gauge_units = $$.getConfig(['gauge', 'units']); - $$.__gauge_width = $$.getConfig(['gauge', 'width']); + gauge_label_show: true, + gauge_label_format: undefined, + gauge_expand: true, + gauge_min: 0, + gauge_max: 100, + gauge_units: undefined, + gauge_width: undefined, // donut - $$.__donut_label_show = $$.getConfig(['donut', 'label', 'show'], true); - $$.__donut_label_format = $$.getConfig(['donut', 'label', 'format']); - $$.__donut_label_threshold = $$.getConfig(['donut', 'label', 'threshold'], 0.05); - $$.__donut_sort = $$.getConfig(['donut', 'sort'], true); - $$.__donut_expand = $$.getConfig(['donut', 'expand'], true); - $$.__donut_title = $$.getConfig(['donut', 'title'], ""); + donut_label_show: true, + donut_label_format: undefined, + donut_label_threshold: 0.05, + donut_width: undefined, + donut_sort: true, + donut_expand: true, + donut_title: "", // region - region to change style - $$.__regions = $$.getConfig(['regions'], []); + regions: [], // tooltip - show when mouseover on each data - $$.__tooltip_show = $$.getConfig(['tooltip', 'show'], true); - $$.__tooltip_grouped = $$.getConfig(['tooltip', 'grouped'], true); - $$.__tooltip_format_title = $$.getConfig(['tooltip', 'format', 'title']); - $$.__tooltip_format_name = $$.getConfig(['tooltip', 'format', 'name']); - $$.__tooltip_format_value = $$.getConfig(['tooltip', 'format', 'value']); - $$.__tooltip_contents = $$.getConfig(['tooltip', 'contents'], function (d, defaultTitleFormat, defaultValueFormat, color) { - var titleFormat = $$.__tooltip_format_title ? $$.__tooltip_format_title : defaultTitleFormat, - nameFormat = $$.__tooltip_format_name ? $$.__tooltip_format_name : function (name) { return name; }, - valueFormat = $$.__tooltip_format_value ? $$.__tooltip_format_value : defaultValueFormat, + tooltip_show: true, + tooltip_grouped: true, + tooltip_format_title: undefined, + tooltip_format_name: undefined, + tooltip_format_value: undefined, + tooltip_contents: function (d, defaultTitleFormat, defaultValueFormat, color) { + var titleFormat = this.config.tooltip_format_title || defaultTitleFormat, + nameFormat = this.config.tooltip_format_name || function (name) { return name; }, + valueFormat = this.config.tooltip_format_value || defaultValueFormat, text, i, title, value, name, bgcolor; for (i = 0; i < d.length; i++) { if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); + bgcolor = this.levelColor ? this.levelColor(d[i].value) : color(d[i].id); - text += ""; + text += ""; text += ""; text += ""; text += ""; } return text + "
" + title + "
" + name + "" + value + "
"; - }); - $$.__tooltip_init_show = $$.getConfig(['tooltip', 'init', 'show'], false); - $$.__tooltip_init_x = $$.getConfig(['tooltip', 'init', 'x'], 0); - $$.__tooltip_init_position = $$.getConfig(['tooltip', 'init', 'position'], {top: '0px', left: '50px'}); - - }; - - c3.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.fn.$$.updateSizes = function () { - var $$ = this; - var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), - legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = this.hasArcType($$.data.targets), - xAxisHeight = $$.__axis_rotated || hasArc ? 0 : this.getHorizontalAxisHeight('x'), - subchartHeight = $$.__subchart_show && !hasArc ? ($$.__subchart_size_height + xAxisHeight) : 0; - - $$.currentWidth = this.getCurrentWidth(); - $$.currentHeight = this.getCurrentHeight(); - - // for main, context - if ($$.__axis_rotated) { - $$.margin = { - top: this.getHorizontalAxisHeight('y2') + this.getCurrentPaddingTop(), - right: hasArc ? 0 : this.getCurrentPaddingRight(), - bottom: this.getHorizontalAxisHeight('y') + legendHeightForBottom + this.getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : this.getCurrentPaddingLeft()) - }; - $$.margin2 = { - top: $$.margin.top, - right: NaN, - bottom: 20 + legendHeightForBottom, - left: $$.rotated_padding_left - }; - } else { - $$.margin = { - top: 4 + this.getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : this.getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + this.getCurrentPaddingBottom(), - left: hasArc ? 0 : this.getCurrentPaddingLeft() - }; - $$.margin2 = { - top: this.currentHeight - subchartHeight - legendHeightForBottom, - right: NaN, - bottom: xAxisHeight + legendHeightForBottom, - left: $$.margin.left - }; - } - // for legend - var insetLegendPosition = { - top: $$.isLegendTop ? this.getCurrentPaddingTop() + $$.__legend_inset_y + 5.5 : $$.currentHeight - legendHeight - this.getCurrentPaddingBottom() - $$.__legend_inset_y, - left: $$.isLegendLeft ? this.getCurrentPaddingLeft() + $$.__legend_inset_x + 0.5 : $$.currentWidth - legendWidth - this.getCurrentPaddingRight() - $$.__legend_inset_x + 0.5 - }; - $$.margin3 = { - top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, - right: NaN, - bottom: 0, - left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 - }; - - $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; - $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; - if ($$.width < 0) { $$.width = 0; } - if ($$.height < 0) { $$.height = 0; } - - $$.width2 = $$.__axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width; - $$.height2 = $$.__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); - this.updateRadius(); - - if ($$.isLegendRight && hasArc) { - $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; - } - }; - c3.fn.$$.updateRadius = function () { - var $$ = this; - $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; - $$.radius = $$.radiusExpanded * 0.95; - if (this.hasDonutType($$.data.targets) || this.hasGaugeType($$.data.targets)) { - $$.innerRadius = $$.radius * ($$.__gauge_width ? ($$.radius - $$.__gauge_width) / $$.radius : 0.6); - } else { - $$.innerRadius = 0; + }, + tooltip_init_show: false, + tooltip_init_x: 0, + tooltip_init_position: {top: '0px', left: '50px'} + }; + + c3.chart.internal.fn.readConfig = function (config) { + var this_config = this.config, target, keys, read; + function find() { + var key = keys.shift(); +// console.log("key =>", key, ", target =>", target); + if (key && target && key in target) { + target = target[key]; + return find(); + } + else if (!key) { + return target; + } + else { + return undefined; + } } + Object.keys(this_config).forEach(function (key) { + target = config; + keys = key.split('_'); + read = find(); +// console.log("CONFIG : ", key, read); + if (typeof read !== 'undefined') { + this_config[key] = read; + } + }); }; - - - c3.fn.$$.init = function (data) { + c3.chart.internal.fn.init = function (data) { var $$ = this, d3 = this.d3; var arcs, eventRect, grid, i, binding = true; - $$.selectChart = d3.select($$.__bindto); + $$.selectChart = d3.select($$.config.bindto); if ($$.selectChart.empty()) { $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); this.observeInserted($$.selectChart); @@ -540,18 +445,18 @@ $$.data.xs = {}; $$.data.targets = $$.convertDataToTargets(data); - if ($$.__data_filter) { - $$.data.targets = $$.data.targets.filter($$.__data_filter); + if ($$.config.data_filter) { + $$.data.targets = $$.data.targets.filter($$.config.data_filter); } // Set targets to hide if needed - if ($$.__data_hide) { - this.addHiddenTargetIds($$.__data_hide === true ? this.mapToIds($$.data.targets) : $$.__data_hide); + if ($$.config.data_hide) { + this.addHiddenTargetIds($$.config.data_hide === true ? this.mapToIds($$.data.targets) : $$.config.data_hide); } // when gauge, hide legend // TODO: fix if (this.hasGaugeType($$.data.targets)) { - $$.__legend_show = false; + $$.config.legend_show = false; } // Init sizes and scales @@ -571,15 +476,15 @@ // Set initialized scales to brush and zoom $$.brush.scale($$.subX); - if ($$.__zoom_enabled) { $$.zoom.scale($$.x); } + if ($$.config.zoom_enabled) { $$.zoom.scale($$.x); } /*-- Basic Elements --*/ // Define svgs $$.svg = $$.selectChart.append("svg") .style("overflow", "hidden") - .on('mouseenter', function () { return $$.__onmouseover.call(c3); }) - .on('mouseleave', function () { return $$.__onmouseout.call(c3); }); + .on('mouseenter', function () { return $$.config.onmouseover.call(c3); }) + .on('mouseleave', function () { return $$.config.onmouseout.call(c3); }); // Define defs $$.defs = $$.svg.append("defs"); @@ -593,11 +498,11 @@ $$.context = $$.svg.append("g").attr("transform", $$.translate.context); $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); - if (!$$.__subchart_show) { + if (!$$.config.subchart_show) { $$.context.style('visibility', 'hidden'); } - if (!$$.__legend_show) { + if (!$$.config.legend_show) { $$.legend.style('visibility', 'hidden'); $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } @@ -632,15 +537,15 @@ $$.grid = $$.main.append('g') .attr("clip-path", $$.clipPath) .attr('class', this.CLASS.grid); - if ($$.__grid_x_show) { + if ($$.config.grid_x_show) { $$.grid.append("g").attr("class", this.CLASS.xgrids); } - if ($$.__grid_y_show) { + if ($$.config.grid_y_show) { $$.grid.append('g').attr('class', this.CLASS.ygrids); } $$.grid.append('g').attr("class", this.CLASS.xgridLines); $$.grid.append('g').attr('class', this.CLASS.ygridLines); - if ($$.__grid_focus_show) { + if ($$.config.grid_focus_show) { $$.grid.append('g') .attr("class", this.CLASS.xgridFocus) .append('line') @@ -678,7 +583,7 @@ .attr("class", this.CLASS.chartArcsBackground) .attr("d", function () { var d = { - data: [{value: $$.__gauge_max}], + data: [{value: $$.config.gauge_max}], startAngle: -1 * (Math.PI / 2), endAngle: Math.PI / 2 }; @@ -689,28 +594,28 @@ .attr("class", this.CLASS.chartArcsGaugeUnit) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.__gauge_label_show ? $$.__gauge_units : ''); + .text($$.config.gauge_label_show ? $$.config.gauge_units : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") .attr("class", this.CLASS.chartArcsGaugeMin) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.__gauge_label_show ? $$.__gauge_min : ''); + .text($$.config.gauge_label_show ? $$.config.gauge_min : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") .attr("class", this.CLASS.chartArcsGaugeMax) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.__gauge_label_show ? $$.__gauge_max : ''); + .text($$.config.gauge_label_show ? $$.config.gauge_max : ''); } $$.main.select('.' + this.CLASS.chart).append("g") .attr("class", this.CLASS.chartTexts); // if zoom privileged, insert rect to forefront - $$.main.insert('rect', $$.__zoom_privileged ? null : 'g.' + this.CLASS.regions) + $$.main.insert('rect', $$.config.zoom_privileged ? null : 'g.' + this.CLASS.regions) .attr('class', this.CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height) @@ -718,8 +623,8 @@ .on("dblclick.zoom", null); // Set default extent if defined - if ($$.__axis_x_default) { - $$.brush.extent(typeof $$.__axis_x_default !== 'function' ? $$.__axis_x_default : $$.__axis_x_default(this.getXDomain())); + if ($$.config.axis_x_default) { + $$.brush.extent(typeof $$.config.axis_x_default !== 'function' ? $$.config.axis_x_default : $$.config.axis_x_default(this.getXDomain())); } // Add Axis @@ -727,30 +632,30 @@ .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisX) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) - .style("visibility", $$.__axis_x_show ? 'visible' : 'hidden'); + .style("visibility", $$.config.axis_x_show ? 'visible' : 'hidden'); $$.axes.x.append("text") .attr("class", this.CLASS.axisXLabel) - .attr("transform", $$.__axis_rotated ? "rotate(-90)" : "") + .attr("transform", $$.config.axis_rotated ? "rotate(-90)" : "") .style("text-anchor", function () { return $$.textAnchorForXAxisLabel(); }); $$.axes.y = $$.main.append("g") .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) - .style("visibility", $$.__axis_y_show ? 'visible' : 'hidden'); + .style("visibility", $$.config.axis_y_show ? 'visible' : 'hidden'); $$.axes.y.append("text") .attr("class", this.CLASS.axisYLabel) - .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") + .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") .style("text-anchor", function () { return $$.textAnchorForYAxisLabel(); }); $$.axes.y2 = $$.main.append("g") .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY2) // clip-path? .attr("transform", $$.translate.y2) - .style("visibility", $$.__axis_y2_show ? 'visible' : 'hidden'); + .style("visibility", $$.config.axis_y2_show ? 'visible' : 'hidden'); $$.axes.y2.append("text") .attr("class", this.CLASS.axisY2Label) - .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") + .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") .style("text-anchor", function () { return $$.textAnchorForY2AxisLabel(); }); /*-- Context Region --*/ @@ -774,14 +679,14 @@ .attr("class", this.CLASS.brush) .call($$.brush) .selectAll("rect") - .attr($$.__axis_rotated ? "width" : "height", $$.__axis_rotated ? $$.width2 : $$.height2); + .attr($$.config.axis_rotated ? "width" : "height", $$.config.axis_rotated ? $$.width2 : $$.height2); // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = $$.context.append("g") .attr("class", this.CLASS.axisX) .attr("transform", $$.translate.subx) - .attr("clip-path", $$.__axis_rotated ? "" : $$.clipPathForXAxis); + .attr("clip-path", $$.config.axis_rotated ? "" : $$.clipPathForXAxis); // Set targets this.updateTargets($$.data.targets); @@ -798,19 +703,19 @@ } // Show tooltip if needed - if ($$.__tooltip_init_show) { - if ($$.isTimeSeries && typeof $$.__tooltip_init_x === 'string') { - $$.__tooltip_init_x = this.parseDate($$.__tooltip_init_x); + if ($$.config.tooltip_init_show) { + if ($$.isTimeSeries && typeof $$.config.tooltip_init_x === 'string') { + $$.config.tooltip_init_x = this.parseDate($$.config.tooltip_init_x); for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - $$.__tooltip_init_x) === 0) { break; } + if (($$.data.targets[0].values[i].x - $$.config.tooltip_init_x) === 0) { break; } } - $$.__tooltip_init_x = i; + $$.config.tooltip_init_x = i; } - $$.tooltip.html($$.__tooltip_contents($$.data.targets.map(function (d) { - return this.addName(d.values[$$.__tooltip_init_x]); + $$.tooltip.html($$.config.tooltip_contents.call($$, $$.data.targets.map(function (d) { + return this.addName(d.values[$$.config.tooltip_init_x]); }), this.getXAxisTickFormat(), this.getYFormat(this.hasArcType($$.data.targets)), $$.color)); - $$.tooltip.style("top", $$.__tooltip_init_position.top) - .style("left", $$.__tooltip_init_position.left) + $$.tooltip.style("top", $$.config.tooltip_init_position.top) + .style("left", $$.config.tooltip_init_position.left) .style("display", "block"); } @@ -820,22 +725,123 @@ } if (window.onresize.add) { window.onresize.add(function () { - $$.__onresize.call(c3); + $$.config.onresize.call(c3); }); window.onresize.add(function () { - $$.this.flush(); + $$.chart.flush(); }); window.onresize.add(function () { - $$.__onresized.call(c3); + $$.config.onresized.call(c3); }); } // export element of the chart - $$.this.element = $$.selectChart.node(); + $$.chart.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.fn.$$.updateTargets = function (targets) { + c3.chart.internal.fn.updateSizes = function () { + var $$ = this; + var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), + legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, + hasArc = this.hasArcType($$.data.targets), + xAxisHeight = $$.config.axis_rotated || hasArc ? 0 : this.getHorizontalAxisHeight('x'), + subchartHeight = $$.config.subchart_show && !hasArc ? ($$.config.subchart_size_height + xAxisHeight) : 0; + + $$.currentWidth = this.getCurrentWidth(); + $$.currentHeight = this.getCurrentHeight(); + + // for main, context + if ($$.config.axis_rotated) { + $$.margin = { + top: this.getHorizontalAxisHeight('y2') + this.getCurrentPaddingTop(), + right: hasArc ? 0 : this.getCurrentPaddingRight(), + bottom: this.getHorizontalAxisHeight('y') + legendHeightForBottom + this.getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : this.getCurrentPaddingLeft()) + }; + $$.margin2 = { + top: $$.margin.top, + right: NaN, + bottom: 20 + legendHeightForBottom, + left: $$.rotated_padding_left + }; + } else { + $$.margin = { + top: 4 + this.getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : this.getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + this.getCurrentPaddingBottom(), + left: hasArc ? 0 : this.getCurrentPaddingLeft() + }; + $$.margin2 = { + top: this.currentHeight - subchartHeight - legendHeightForBottom, + right: NaN, + bottom: xAxisHeight + legendHeightForBottom, + left: $$.margin.left + }; + } + // for legend + var insetLegendPosition = { + top: $$.isLegendTop ? this.getCurrentPaddingTop() + $$.config.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - this.getCurrentPaddingBottom() - $$.config.legend_inset_y, + left: $$.isLegendLeft ? this.getCurrentPaddingLeft() + $$.config.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - this.getCurrentPaddingRight() - $$.config.legend_inset_x + 0.5 + }; + $$.margin3 = { + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + }; + + $$.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); + this.updateRadius(); + + if ($$.isLegendRight && hasArc) { + $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; + } + }; + c3.chart.internal.fn.updateRadius = function () { + var $$ = this; + $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; + $$.radius = $$.radiusExpanded * 0.95; + if (this.hasDonutType($$.data.targets) || this.hasGaugeType($$.data.targets)) { + $$.innerRadius = $$.radius * ($$.config.gauge_width ? ($$.radius - $$.config.gauge_width) / $$.radius : 0.6); + } else { + $$.innerRadius = 0; + } + }; + + c3.chart.internal.fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS; @@ -864,7 +870,7 @@ // Bars for each data mainBarEnter.append('g') .attr("class", function (d) { return $$.classBars(d); }) - .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }); + .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); //-- Line --// mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) @@ -885,7 +891,7 @@ .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); mainLineEnter.append('g') .attr("class", function (d) { return $$.classCircles(d); }) - .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }); + .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { @@ -913,7 +919,7 @@ /*-- Context --*/ - if ($$.__subchart_show) { + if ($$.config.subchart_show) { contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) @@ -944,11 +950,11 @@ // Fade-in each chart $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) - .transition().duration($$.__transition_duration) + .transition().duration($$.config.transition_duration) .style("opacity", 1); }; - c3.fn.$$.redraw = function (options, transitions) { + c3.chart.internal.fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS, d3 = $$.d3; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; @@ -973,14 +979,14 @@ withTransitionForExit = $$.getOption(options, "withTransitionForExit", withTransition); withTransitionForAxis = $$.getOption(options, "withTransitionForAxis", withTransition); - duration = withTransition ? $$.__transition_duration : 0; + duration = withTransition ? $$.config.transition_duration : 0; durationForExit = withTransitionForExit ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0; transitions = transitions || $$.generateAxisTransitions(durationForAxis); // update legend and transform each g - if (withLegend && $$.__legend_show) { + if (withLegend && $$.config.legend_show) { $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); } @@ -992,8 +998,8 @@ if (targetsToShow.length) { $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); // update axis tick values according to options - if (!$$.__axis_x_tick_values && ($$.__axis_x_tick_fit || $$.__axis_x_tick_count)) { - tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), $$.__axis_x_tick_count); + if (!$$.config.axis_x_tick_values && ($$.config.axis_x_tick_fit || $$.config.axis_x_tick_count)) { + tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), $$.config.axis_x_tick_count); $$.xAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues); } @@ -1020,9 +1026,9 @@ // show/hide if manual culling needed if (withUpdateXDomain && targetsToShow.length) { - if ($$.__axis_x_tick_culling && tickValues) { + if ($$.config.axis_x_tick_culling && tickValues) { for (i = 1; i < tickValues.length; i++) { - if (tickValues.length / i < $$.__axis_x_tick_culling_max) { + if (tickValues.length / i < $$.config.axis_x_tick_culling_max) { intervalForCulling = i; break; } @@ -1039,8 +1045,8 @@ } // rotate tick text if needed - if (!$$.__axis_rotated && $$.__axis_x_tick_rotate) { - $$.rotateTickText($$.axes.x, transitions.axisX, $$.__axis_x_tick_rotate); + if (!$$.config.axis_rotated && $$.config.axis_x_tick_rotate) { + $$.rotateTickText($$.axes.x, transitions.axisX, $$.config.axis_x_tick_rotate); } // setup drawer - MEMO: these must be called after axis updated @@ -1064,14 +1070,14 @@ main.select("text." + CLASS.text + '.' + CLASS.empty) .attr("x", $$.width / 2) .attr("y", $$.height / 2) - .text($$.__data_empty_label_text) + .text($$.config.data_empty_label_text) .transition() .style('opacity', targetsToShow.length ? 0 : 1); // grid main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); - if ($$.__grid_x_show) { - xgridAttr = $$.__axis_rotated ? { + if ($$.config.grid_x_show) { + xgridAttr = $$.config.axis_rotated ? { 'x1': 0, 'x2': $$.width, 'y1': function (d) { return $$.x(d) - tickOffset; }, @@ -1084,21 +1090,21 @@ }; // this is used to flow flushXGrid = function (withoutUpdate) { - xgridData = $$.generateGridData($$.__grid_x_type, $$.x); + xgridData = $$.generateGridData($$.config.grid_x_type, $$.x); tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) .data(xgridData); xgrid.enter().append('line').attr("class", CLASS.xgrid); if (!withoutUpdate) { xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr($$.__axis_rotated ? 'y1' : 'x1') === ($$.__axis_rotated ? $$.height : 0) ? 0 : 1; }); + .style("opacity", function () { return +d3.select(this).attr($$.config.axis_rotated ? 'y1' : 'x1') === ($$.config.axis_rotated ? $$.height : 0) ? 0 : 1; }); } xgrid.exit().remove(); }; flushXGrid(); } xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) - .data($$.__grid_x_lines); + .data($$.config.grid_x_lines); // enter xgridLine = xgridLines.enter().append('g') .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); @@ -1106,8 +1112,8 @@ .style("opacity", 0); xgridLine.append('text') .attr("text-anchor", "end") - .attr("transform", $$.__axis_rotated ? "" : "rotate(-90)") - .attr('dx', $$.__axis_rotated ? 0 : -$$.margin.top) + .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") + .attr('dx', $$.config.axis_rotated ? 0 : -$$.margin.top) .attr('dy', -5) .style("opacity", 0); // udpate @@ -1117,21 +1123,21 @@ .style("opacity", 0) .remove(); // Y-Grid - if (withY && $$.__grid_y_show) { + if (withY && $$.config.grid_y_show) { ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) - .data($$.y.ticks($$.__grid_y_ticks)); + .data($$.y.ticks($$.config.grid_y_ticks)); ygrid.enter().append('line') .attr('class', CLASS.ygrid); - ygrid.attr("x1", $$.__axis_rotated ? $$.y : 0) - .attr("x2", $$.__axis_rotated ? $$.y : $$.width) - .attr("y1", $$.__axis_rotated ? 0 : $$.y) - .attr("y2", $$.__axis_rotated ? $$.height : $$.y); + ygrid.attr("x1", $$.config.axis_rotated ? $$.y : 0) + .attr("x2", $$.config.axis_rotated ? $$.y : $$.width) + .attr("y1", $$.config.axis_rotated ? 0 : $$.y) + .attr("y2", $$.config.axis_rotated ? $$.height : $$.y); ygrid.exit().remove(); $$.smoothLines(ygrid, 'grid'); } if (withY) { ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) - .data($$.__grid_y_lines); + .data($$.config.grid_y_lines); // enter ygridLine = ygridLines.enter().append('g') .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); @@ -1139,22 +1145,22 @@ .style("opacity", 0); ygridLine.append('text') .attr("text-anchor", "end") - .attr("transform", $$.__axis_rotated ? "rotate(-90)" : "") - .attr('dx', $$.__axis_rotated ? 0 : -$$.margin.top) + .attr("transform", $$.config.axis_rotated ? "rotate(-90)" : "") + .attr('dx', $$.config.axis_rotated ? 0 : -$$.margin.top) .attr('dy', -5) .style("opacity", 0); // update var yv = function (d) { return $$.yv.call($$, d); }; ygridLines.select('line') .transition().duration(duration) - .attr("x1", $$.__axis_rotated ? yv : 0) - .attr("x2", $$.__axis_rotated ? yv : $$.width) - .attr("y1", $$.__axis_rotated ? 0 : yv) - .attr("y2", $$.__axis_rotated ? $$.height : yv) + .attr("x1", $$.config.axis_rotated ? yv : 0) + .attr("x2", $$.config.axis_rotated ? yv : $$.width) + .attr("y1", $$.config.axis_rotated ? 0 : yv) + .attr("y2", $$.config.axis_rotated ? $$.height : yv) .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) - .attr("x", $$.__axis_rotated ? 0 : $$.width) + .attr("x", $$.config.axis_rotated ? 0 : $$.width) .attr("y", yv) .text(function (d) { return d.text; }) .style("opacity", 1); @@ -1166,7 +1172,7 @@ // rect for regions mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) - .data($$.__regions); + .data($$.config.regions); mainRegion.enter().append('g') .attr('class', function (d) { return $$.classRegion(d); }) .append('rect') @@ -1213,7 +1219,7 @@ .style('opacity', 0) .remove(); - if ($$.__point_show) { + if ($$.config.point_show) { mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) .data(function (d) { return $$.lineOrScatterData(d); }); mainCircle.enter().append("circle") @@ -1230,7 +1236,7 @@ .data($$.barOrLineData); mainText.enter().append('text') .attr("class", function (d) { return $$.classText(d); }) - .attr('text-anchor', function (d) { return $$.__axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .attr('text-anchor', function (d) { return $$.config.axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) .style("fill-opacity", 0); @@ -1248,7 +1254,7 @@ mainArc.enter().append('path') .attr("class", function (d) { return $$.classArc(d); }) .style("fill", function (d) { return $$.color(d.data); }) - .style("cursor", function (d) { return $$.__data_selection_isselectable(d) ? "pointer" : null; }) + .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) .style("opacity", 0) .each(function (d) { if ($$.isGaugeType(d.data)) { @@ -1266,7 +1272,7 @@ // transitions $$.expandArc(updated.data.id); $$.toggleFocusLegend(updated.data.id, true); - $$.__data_onmouseover.call(c3, arcData, this); + $$.config.data_onmouseover.call(c3, arcData, this); }) .on('mousemove', function (d) { var updated = $$.updateAngle(d), @@ -1285,7 +1291,7 @@ $$.unexpandArc(updated.data.id); $$.revertLegend(); $$.hideTooltip(); - $$.__data_onmouseout.call(c3, arcData, this); + $$.config.data_onmouseout.call(c3, arcData, this); }) .on('click', function (d, i) { var updated = $$.updateAngle(d), @@ -1339,7 +1345,7 @@ .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); // subchart - if ($$.__subchart_show) { + if ($$.config.subchart_show) { // reflect main chart to extent on subchart if zoomed if (d3.event && d3.event.type === 'zoom') { $$.brush.extent($$.x.orgDomain()).update(); @@ -1348,8 +1354,8 @@ if (withSubchart) { // rotate tick text if needed - if (!$$.__axis_rotated && $$.__axis_x_tick_rotate) { - $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.__axis_x_tick_rotate); + if (!$$.config.axis_rotated && $$.config.axis_x_tick_rotate) { + $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.config.axis_x_tick_rotate); } // extent rect @@ -1414,11 +1420,11 @@ .selectAll('circle') .remove(); - if ($$.__interaction_enabled) { + if ($$.config.interaction_enabled) { // rect for mouseover eventRect = main.select('.' + CLASS.eventRects) - .style('cursor', $$.__zoom_enabled ? $$.__axis_rotated ? 'ns-resize' : 'ew-resize' : null); - if ($$.notEmpty($$.__data_xs) && !$$.isSingleX($$.__data_xs)) { + .style('cursor', $$.config.zoom_enabled ? $$.config.axis_rotated ? 'ns-resize' : 'ew-resize' : null); + if ($$.notEmpty($$.config.data_xs) && !$$.isSingleX($$.config.data_xs)) { if (!eventRect.classed(CLASS.eventRectsMultiple)) { eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) @@ -1471,10 +1477,10 @@ // update eventRectUpdate .attr('class', function (d) { return $$.classEvent(d); }) - .attr("x", $$.__axis_rotated ? 0 : rectX) - .attr("y", $$.__axis_rotated ? rectX : 0) - .attr("width", $$.__axis_rotated ? $$.width : rectW) - .attr("height", $$.__axis_rotated ? rectW : $$.height); + .attr("x", $$.config.axis_rotated ? 0 : rectX) + .attr("y", $$.config.axis_rotated ? rectX : 0) + .attr("width", $$.config.axis_rotated ? $$.width : rectW) + .attr("height", $$.config.axis_rotated ? rectW : $$.height); // exit eventRectUpdate.exit().remove(); } @@ -1483,8 +1489,8 @@ // transition should be derived from one transition d3.transition().duration(duration).each(function () { var transitions = [], - cx = $$.__axis_rotated ? $$.circleY : $$.circleX, - cy = $$.__axis_rotated ? $$.circleX : $$.circleY; + cx = $$.config.axis_rotated ? $$.circleY : $$.circleX, + cy = $$.config.axis_rotated ? $$.circleX : $$.circleY; transitions.push(mainBar.transition() .attr('d', drawBar) @@ -1518,13 +1524,13 @@ .attr("height", $$.regionHeight) .style("fill-opacity", function (d) { return $$.isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() - .attr("x1", $$.__axis_rotated ? 0 : $$.xv) - .attr("x2", $$.__axis_rotated ? $$.width : $$.xv) - .attr("y1", $$.__axis_rotated ? $$.xv : $$.margin.top) - .attr("y2", $$.__axis_rotated ? $$.xv : $$.height) + .attr("x1", $$.config.axis_rotated ? 0 : $$.xv) + .attr("x2", $$.config.axis_rotated ? $$.width : $$.xv) + .attr("y1", $$.config.axis_rotated ? $$.xv : $$.margin.top) + .attr("y2", $$.config.axis_rotated ? $$.xv : $$.height) .style("opacity", 1)); transitions.push(xgridLines.select('text').transition() - .attr("x", $$.__axis_rotated ? $$.width : 0) + .attr("x", $$.config.axis_rotated ? $$.width : 0) .attr("y", $$.xv) .text(function (d) { return d.text; }) .style("opacity", 1)); @@ -1616,10 +1622,10 @@ xgridLines .attr('transform', null); xgridLines.select('line') - .attr("x1", $$.__axis_rotated ? 0 : $$.xv) - .attr("x2", $$.__axis_rotated ? $$.width : $$.xv); + .attr("x1", $$.config.axis_rotated ? 0 : $$.xv) + .attr("x2", $$.config.axis_rotated ? $$.width : $$.xv); xgridLines.select('text') - .attr("x", $$.__axis_rotated ? $$.width : 0) + .attr("x", $$.config.axis_rotated ? $$.width : 0) .attr("y", $$.xv); mainBar .attr('transform', null) @@ -1632,8 +1638,8 @@ .attr("d", drawArea); mainCircle .attr('transform', null) - .attr("cx", $$.__axis_rotated ? $$.circleY : $$.circleX) - .attr("cy", $$.__axis_rotated ? $$.circleX : $$.circleY); + .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) + .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY); mainText .attr('transform', null) .attr('x', xForText) @@ -1645,10 +1651,10 @@ .attr("x", $$.regionX) .attr("width", $$.regionWidth); eventRectUpdate - .attr("x", $$.__axis_rotated ? 0 : rectX) - .attr("y", $$.__axis_rotated ? rectX : 0) - .attr("width", $$.__axis_rotated ? $$.width : rectW) - .attr("height", $$.__axis_rotated ? rectW : $$.height); + .attr("x", $$.config.axis_rotated ? 0 : rectX) + .attr("y", $$.config.axis_rotated ? rectX : 0) + .attr("width", $$.config.axis_rotated ? $$.width : rectW) + .attr("height", $$.config.axis_rotated ? rectW : $$.height); // callback for end of flow done(); @@ -1662,7 +1668,7 @@ $$.updateZoom(); }; - c3.fn.$$.redrawForBrush = function () { + c3.chart.internal.fn.redrawForBrush = function () { var $$ = this, x = $$.x; $$.redraw({ withTransition: false, @@ -1670,11 +1676,11 @@ withSubchart: false, withUpdateXDomain: true }); - $$.__subchart_onbrush.call(c3, x.orgDomain()); + $$.config.subchart_onbrush.call(c3, x.orgDomain()); }; - c3.fn.$$.redrawForZoom = function () { - var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain;; - if (!$$.__zoom_enabled) { + c3.chart.internal.fn.redrawForZoom = function () { + var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; + if (!$$.config.zoom_enabled) { return; } if ($$.filterTargetsToShow($$.data.targets).length === 0) { @@ -1696,9 +1702,9 @@ if (d3.event.sourceEvent.type === 'mousemove') { $$.cancelClick = true; } - $$.__zoom_onzoom.call(c3, x.orgDomain()); + $$.config.zoom_onzoom.call(c3, x.orgDomain()); }; - c3.fn.$$.updateAndRedraw = function (options) { + c3.chart.internal.fn.updateAndRedraw = function (options) { var $$ = this, transitions; options = options || {}; // same with redraw @@ -1713,8 +1719,8 @@ // MEMO: this needs to be called before updateLegend and it means this ALWAYS needs to be called) this.updateSizes(); // MEMO: called in updateLegend in redraw if withLegend - if (!(options.withLegend && $$.__legend_show)) { - transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.__transition_duration : 0); + if (!(options.withLegend && $$.config.legend_show)) { + transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.config.transition_duration : 0); // Update scales $$.updateScales(); $$.updateSvgSize(); @@ -1725,11 +1731,11 @@ $$.redraw(options, transitions); }; - c3.fn.$$.generateEventRectsForSingleX = function (eventRectEnter) { + c3.chart.internal.fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, CLASS = $$.CLASS; eventRectEnter.append("rect") .attr("class", function (d) { return $$.classEvent(d); }) - .style("cursor", $$.__data_selection_enabled && $$.__data_selection_grouped ? "pointer" : null) + .style("cursor", $$.config.data_selection_enabled && $$.config.data_selection_grouped ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; @@ -1742,7 +1748,7 @@ // Sort selectedData as names order newData = []; - Object.keys($$.__data_names).forEach(function (id) { + Object.keys($$.config.data_names).forEach(function (id) { for (var j = 0; j < selectedData.length; j++) { if (selectedData[j] && selectedData[j].id === id) { newData.push(selectedData[j]); @@ -1754,12 +1760,12 @@ selectedData = newData.concat(selectedData); // Add remained // Expand shapes for selection - if ($$.__point_focus_expand_enabled) { $$.expandCircles(index); } + if ($$.config.point_focus_expand_enabled) { $$.expandCircles(index); } $$.expandBars(index); // Call event handler $$.main.selectAll('.' + $$.CLASS.shape + '-' + index).each(function (d) { - $$.__data_onmouseover.call(c3, d); + $$.config.data_onmouseover.call(c3, d); }); }) .on('mouseout', function (d) { @@ -1772,7 +1778,7 @@ $$.unexpandBars(); // Call event handler $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - $$.__data_onmouseout.call(c3, d); + $$.config.data_onmouseout.call(c3, d); }); }) .on('mousemove', function (d) { @@ -1787,25 +1793,25 @@ return $$.addName($$.getValueOnIndex(t.values, index)); }); - if ($$.__tooltip_grouped) { + if ($$.config.tooltip_grouped) { $$.showTooltip(selectedData, d3.mouse(this)); $$.showXGridFocus(selectedData); } - if ($$.__tooltip_grouped && (!$$.__data_selection_enabled || $$.__data_selection_grouped)) { + if ($$.config.tooltip_grouped && (!$$.config.data_selection_enabled || $$.config.data_selection_grouped)) { return; } $$.main.selectAll('.' + CLASS.shape + '-' + index) .each(function () { d3.select(this).classed(CLASS.EXPANDED, true); - if ($$.__data_selection_enabled) { - eventRect.style('cursor', $$.__data_selection_grouped ? 'pointer' : null); + if ($$.config.data_selection_enabled) { + eventRect.style('cursor', $$.config.data_selection_grouped ? 'pointer' : null); } - if (!$$.__tooltip_grouped) { + if (!$$.config.tooltip_grouped) { $$.hideXGridFocus(); $$.hideTooltip(); - if (!$$.__data_selection_grouped) { + if (!$$.config.data_selection_grouped) { $$.unexpandCircles(index); $$.unexpandBars(); } @@ -1820,13 +1826,13 @@ } }) .each(function (d) { - if ($$.__data_selection_enabled && ($$.__data_selection_grouped || $$.__data_selection_isselectable(d))) { + if ($$.config.data_selection_enabled && ($$.config.data_selection_grouped || $$.config.data_selection_isselectable(d))) { eventRect.style('cursor', 'pointer'); } - if (!$$.__tooltip_grouped) { + if (!$$.config.tooltip_grouped) { $$.showTooltip([d], d3.mouse(this)); $$.showXGridFocus([d]); - if ($$.__point_focus_expand_enabled) { $$.expandCircles(index, d.id); } + if ($$.config.point_focus_expand_enabled) { $$.expandCircles(index, d.id); } $$.expandBars(index, d.id); } }); @@ -1849,7 +1855,7 @@ .on("dblclick.zoom", null); }; - c3.fn.$$.generateEventRectsForMultipleXs = function (eventRectEnter) { + c3.chart.internal.fn.generateEventRectsForMultipleXs = function (eventRectEnter) { var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; eventRectEnter.append('rect') .attr('x', 0) @@ -1888,7 +1894,7 @@ $$.showTooltip(selectedData, mouse); // expand points - if ($$.__point_focus_expand_enabled) { + if ($$.config.point_focus_expand_enabled) { $$.unexpandCircles(); $$.expandCircles(closest.index, closest.id); } @@ -1900,12 +1906,12 @@ if ($$.dist(closest, mouse) < 100) { $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); if (!$$.mouseover) { - $$.__data_onmouseover.call(c3, closest); + $$.config.data_onmouseover.call(c3, closest); $$.mouseover = true; } } else { $$.svg.select('.' + CLASS.eventRect).style('cursor', null); - $$.__data_onmouseout.call(c3, closest); + $$.config.data_onmouseout.call(c3, closest); $$.mouseover = false; } }) @@ -1943,35 +1949,35 @@ - c3.fn.$$.initialOpacity = function (d) { + c3.chart.internal.fn.initialOpacity = function (d) { var $$ = this; return d.value !== null && $$.withoutFadeIn[d.id] ? 1 : 0; }; - c3.fn.$$.opacityForCircle = function (d) { + c3.chart.internal.fn.opacityForCircle = function (d) { return this.isValue(d.value) ? this.isScatterType(d) ? 0.5 : 1 : 0; }; - c3.fn.$$.opacityForText = function () { + c3.chart.internal.fn.opacityForText = function () { return this.hasDataLabel() ? 1 : 0; }; - c3.fn.$$.xx = function (d) { + c3.chart.internal.fn.xx = function (d) { var $$ = this; return d ? $$.x(d.x) : null; }; - c3.fn.$$.xv = function (d) { + c3.chart.internal.fn.xv = function (d) { return Math.ceil($$.x($$.isTimeSeries ? this.parseDate(d.value) : d.value)); }; - c3.fn.$$.yv = function (d) { + c3.chart.internal.fn.yv = function (d) { var $$ = this, yScale = d.axis && d.axis === 'y2' ? $$.y2 : $$.y; return Math.ceil(yScale(d.value)); }; - c3.fn.$$.subxx = function (d) { + c3.chart.internal.fn.subxx = function (d) { return d ? $$.subX(d.x) : null; }; - c3.fn.$$.transformMain = function (withTransition, transitions) { + c3.chart.internal.fn.transformMain = function (withTransition, transitions) { var $$ = this, xAxis, yAxis, y2Axis; if (transitions && transitions.axisX) { xAxis = transitions.axisX; @@ -1997,8 +2003,8 @@ y2Axis.attr("transform", $$.translate.y2); $$.main.select('.' + this.CLASS.chartArcs).attr("transform", $$.translate.arc); }; - c3.fn.$$.transformContext = function (withTransition, transitions) { - var $$ = this.$$, subXAxis; + c3.chart.internal.fn.transformContext = function (withTransition, transitions) { + var $$ = this.internal, subXAxis; if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { @@ -2008,19 +2014,19 @@ $$.context.attr("transform", $$.translate.context); subXAxis.attr("transform", $$.translate.subx); }; - c3.fn.$$.transformLegend = function (withTransition) { + c3.chart.internal.fn.transformLegend = function (withTransition) { var $$ = this; (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); }; - c3.fn.$$.transformAll = function (withTransition, transitions) { + c3.chart.internal.fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); - if ($$.__subchart_show) { $$.transformContext(withTransition, transitions); } + if ($$.config.subchart_show) { $$.transformContext(withTransition, transitions); } $$.transformLegend(withTransition); }; - c3.fn.$$.updateSvgSize = function () { + c3.chart.internal.fn.updateSvgSize = function () { var $$ = this; $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); $$.svg.select('#' + $$.clipId).select('rect') @@ -2044,9 +2050,9 @@ }; - c3.fn.$$.updateDimension = function () { + c3.chart.internal.fn.updateDimension = function () { var $$ = this; - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { $$.axes.x.call($$.xAxis); $$.axes.subx.call($$.subXAxis); } else { @@ -2059,7 +2065,7 @@ this.transformAll(false); }; - c3.fn.$$.observeInserted = function (selection) { + c3.chart.internal.fn.observeInserted = function (selection) { var observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' && mutation.previousSibling) { @@ -2088,7 +2094,7 @@ }; - c3.fn.$$.generateResize = function () { + c3.chart.internal.fn.generateResize = function () { var resizeFunctions = []; function callResizeFunctions() { resizeFunctions.forEach(function (f) { @@ -2103,44 +2109,44 @@ - c3.fn.$$.getCurrentWidth = function () { + c3.chart.internal.fn.getCurrentWidth = function () { var $$ = this; - return $$.__size_width ? $$.__size_width : $$.getParentWidth(); + return $$.config.size_width ? $$.config.size_width : $$.getParentWidth(); }; - c3.fn.$$.getCurrentHeight = function () { - var $$ = this, h = $$.__size_height ? $$.__size_height : this.getParentHeight(); + c3.chart.internal.fn.getCurrentHeight = function () { + var $$ = this, h = $$.config.size_height ? $$.config.size_height : this.getParentHeight(); return h > 0 ? h : 320; }; - c3.fn.$$.getCurrentPaddingTop = function () { + c3.chart.internal.fn.getCurrentPaddingTop = function () { var $$ = this; - return this.isValue($$.__padding_top) ? $$.__padding_top : 0; + return this.isValue($$.config.padding_top) ? $$.config.padding_top : 0; }; - c3.fn.$$.getCurrentPaddingBottom = function () { + c3.chart.internal.fn.getCurrentPaddingBottom = function () { var $$ = this; - return this.isValue($$.__padding_bottom) ? $$.__padding_bottom : 0; + return this.isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; }; - c3.fn.$$.getCurrentPaddingLeft = function () { + c3.chart.internal.fn.getCurrentPaddingLeft = function () { var $$ = this; - if (this.isValue($$.__padding_left)) { - return $$.__padding_left; - } else if ($$.__axis_rotated) { - return !$$.__axis_x_show ? 1 : Math.max(this.ceil10(this.getAxisWidthByAxisId('x')), 40); + if (this.isValue($$.config.padding_left)) { + return $$.config.padding_left; + } else if ($$.config.axis_rotated) { + return !$$.config.axis_x_show ? 1 : Math.max(this.ceil10(this.getAxisWidthByAxisId('x')), 40); } else { - return !$$.__axis_y_show || $$.__axis_y_inner ? 1 : this.ceil10(this.getAxisWidthByAxisId('y')); + return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : this.ceil10(this.getAxisWidthByAxisId('y')); } }; - c3.fn.$$.getCurrentPaddingRight = function () { + c3.chart.internal.fn.getCurrentPaddingRight = function () { var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? this.getLegendWidth() + 20 : 0; - if (this.isValue($$.__padding_right)) { - return $$.__padding_right + 1; // 1 is needed not to hide tick line - } else if ($$.__axis_rotated) { + if (this.isValue($$.config.padding_right)) { + return $$.config.padding_right + 1; // 1 is needed not to hide tick line + } else if ($$.config.axis_rotated) { return defaultPadding + legendWidthOnRight; } else { - return (!$$.__axis_y2_show || $$.__axis_y2_inner ? defaultPadding : this.ceil10(this.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : this.ceil10(this.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; - c3.fn.$$.getParentRectValue = function (key) { + c3.chart.internal.fn.getParentRectValue = function (key) { var $$ = this, parent = $$.selectChart.node(), v; while (parent && parent.tagName !== 'BODY') { v = parent.getBoundingClientRect()[key]; @@ -2151,18 +2157,18 @@ } return v; }; - c3.fn.$$.getParentWidth = function () { + c3.chart.internal.fn.getParentWidth = function () { return this.getParentRectValue('width'); }; - c3.fn.$$.getParentHeight = function () { + c3.chart.internal.fn.getParentHeight = function () { var h = this.selectChart.style('height'); return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; }; - c3.fn.$$.getSvgLeft = function () { + c3.chart.internal.fn.getSvgLeft = function () { var $$ = this, - leftAxisClass = $$.__axis_rotated ? $$.CLASS.axisX : $$.CLASS.axisY, + leftAxisClass = $$.config.axis_rotated ? $$.CLASS.axisX : $$.CLASS.axisY, leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), @@ -2172,20 +2178,20 @@ }; - c3.fn.$$.getAxisWidthByAxisId = function (id) { + c3.chart.internal.fn.getAxisWidthByAxisId = function (id) { var position = this.getAxisLabelPositionById(id); return position.isInner ? 20 + this.getMaxTickWidth(id) : 40 + this.getMaxTickWidth(id); }; - c3.fn.$$.getHorizontalAxisHeight = function (axisId) { + c3.chart.internal.fn.getHorizontalAxisHeight = function (axisId) { var $$ = this; - if (axisId === 'x' && !$$.__axis_x_show) { return 0; } - if (axisId === 'x' && $$.__axis_x_height) { return $$.__axis_x_height; } - if (axisId === 'y' && !$$.__axis_y_show) { return $$.__legend_show && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } - if (axisId === 'y2' && !$$.__axis_y2_show) { return $$.rotated_padding_top; } + if (axisId === 'x' && !$$.config.axis_x_show) { return 0; } + if (axisId === 'x' && $$.config.axis_x_height) { return $$.config.axis_x_height; } + if (axisId === 'y' && !$$.config.axis_y_show) { return $$.config.legend_show && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !$$.config.axis_y2_show) { return $$.rotated_padding_top; } return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; - c3.fn.$$.getEventRectWidth = function () { + c3.chart.internal.fn.getEventRectWidth = function () { var $$ = this; var target = this.getMaxDataCountTarget($$.data.targets), firstData, lastData, base, maxDataCount, ratio, w; @@ -2195,7 +2201,7 @@ firstData = target.values[0], lastData = target.values[target.values.length - 1]; base = $$.x(lastData.x) - $$.x(firstData.x); if (base === 0) { - return $$.__axis_rotated ? $$.height : $$.width; + return $$.config.axis_rotated ? $$.height : $$.width; } maxDataCount = this.getMaxDataCount(); ratio = (this.hasBarType($$.data.targets) ? (maxDataCount - (this.isCategorized ? 0.25 : 1)) / maxDataCount : 1); @@ -2207,15 +2213,15 @@ /** * c3.tooltip.js */ - c3.fn.$$.showTooltip = function (selectedData, mouse) { + c3.chart.internal.fn.showTooltip = function (selectedData, mouse) { var $$ = this; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; var forArc = $$.hasArcType($$.data.targets), dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); - if (dataToShow.length === 0 || !$$.__tooltip_show) { + if (dataToShow.length === 0 || !$$.config.tooltip_show) { return; } - $$.tooltip.html($$.__tooltip_contents(selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + $$.tooltip.html($$.config.tooltip_contents.call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); // Get tooltip dimensions tWidth = $$.tooltip.property('offsetWidth'); @@ -2225,7 +2231,7 @@ tooltipLeft = ($$.width / 2) + mouse[0]; tooltipTop = ($$.height / 2) + mouse[1] + 20; } else { - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { svgLeft = $$.getSvgLeft(); tooltipLeft = svgLeft + mouse[0] + 100; tooltipRight = tooltipLeft + tWidth; @@ -2251,7 +2257,7 @@ .style("top", tooltipTop + "px") .style("left", tooltipLeft + 'px'); }; - c3.fn.$$.hideTooltip = function () { + c3.chart.internal.fn.hideTooltip = function () { var $$ = this; $$.tooltip.style("display", "none"); }; @@ -2260,32 +2266,32 @@ /** * c3.grid.js */ - c3.fn.$$.showXGridFocus = function (selectedData) { + c3.chart.internal.fn.showXGridFocus = function (selectedData) { var $$ = this, dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); - if (! $$.__tooltip_show) { return; } + if (! $$.config.tooltip_show) { return; } // Hide when scatter plot exists if (this.hasScatterType($$.data.targets) || this.hasArcType($$.data.targets)) { return; } var focusEl = $$.main.selectAll('line.' + this.CLASS.xgridFocus); focusEl .style("visibility", "visible") .data([dataToShow[0]]) - .attr($$.__axis_rotated ? 'y1' : 'x1', function (d) { return $$.xx(d); }) - .attr($$.__axis_rotated ? 'y2' : 'x2', function (d) { return $$.xx(d); }); + .attr($$.config.axis_rotated ? 'y1' : 'x1', function (d) { return $$.xx(d); }) + .attr($$.config.axis_rotated ? 'y2' : 'x2', function (d) { return $$.xx(d); }); this.smoothLines(focusEl, 'grid'); }; - c3.fn.$$.hideXGridFocus = function () { + c3.chart.internal.fn.hideXGridFocus = function () { var $$ = this; $$.main.select('line.' + $$.CLASS.xgridFocus).style("visibility", "hidden"); }; - c3.fn.$$.updateXgridFocus = function () { + c3.chart.internal.fn.updateXgridFocus = function () { var $$ = this; $$.main.select('line.' + this.CLASS.xgridFocus) - .attr("x1", $$.__axis_rotated ? 0 : -10) - .attr("x2", $$.__axis_rotated ? $$.width : -10) - .attr("y1", $$.__axis_rotated ? -10 : 0) - .attr("y2", $$.__axis_rotated ? -10 : $$.height); + .attr("x1", $$.config.axis_rotated ? 0 : -10) + .attr("x2", $$.config.axis_rotated ? $$.width : -10) + .attr("y1", $$.config.axis_rotated ? -10 : 0) + .attr("y2", $$.config.axis_rotated ? -10 : $$.height); }; - c3.fn.$$.generateGridData = function (type, scale) { + c3.chart.internal.fn.generateGridData = function (type, scale) { var gridData = [], xDomain, firstYear, lastYear, i, tickNum = $$.main.select("." + this.CLASS.axisX).selectAll('.tick').size(); if (type === 'year') { @@ -2303,7 +2309,7 @@ } return gridData; }; - c3.fn.$$.getGridFilterToRemove = function (params) { + c3.chart.internal.fn.getGridFilterToRemove = function (params) { return params ? function (line) { var found = false; [].concat(params).forEach(function (param) { @@ -2314,19 +2320,19 @@ return found; } : function () { return true; }; }; - c3.fn.$$.removeGridLines = function (params, forX) { + c3.chart.internal.fn.removeGridLines = function (params, forX) { var $$ = this, CLASS = $$.CLASS, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) - .transition().duration($$.__transition_duration) + .transition().duration($$.config.transition_duration) .style('opacity', 0).remove(); if (forX) { - $$.__grid_x_lines = $$.__grid_x_lines.filter(toShow); + $$.config.grid_x_lines = $$.config.grid_x_lines.filter(toShow); } else { - $$.__grid_y_lines = $$.__grid_y_lines.filter(toShow); + $$.config.grid_y_lines = $$.config.grid_y_lines.filter(toShow); } }; @@ -2334,44 +2340,44 @@ /** * c3.legend.js */ - c3.fn.$$.updateLegendStep = function (step) { + c3.chart.internal.fn.updateLegendStep = function (step) { var $$ = this; $$.legendStep = step; }; - c3.fn.$$.updateLegendItemWidth = function (w) { + c3.chart.internal.fn.updateLegendItemWidth = function (w) { var $$ = this; $$.legendItemWidth = w; }; - c3.fn.$$.updateLegendItemHeight = function (h) { + c3.chart.internal.fn.updateLegendItemHeight = function (h) { var $$ = this; $$.legendItemHeight = h; }; - c3.fn.$$.getLegendWidth = function () { + c3.chart.internal.fn.getLegendWidth = function () { var $$ = this; - return $$.__legend_show ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; + return $$.config.legend_show ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; }; - c3.fn.$$.getLegendHeight = function () { + c3.chart.internal.fn.getLegendHeight = function () { var $$ = this, h = 0; - if ($$.__legend_show) { + if ($$.config.legend_show) { if ($$.isLegendRight) { h = $$.currentHeight; } else if ($$.isLegendInset) { - h = $$.__legend_inset_step ? Math.max(20, $$.legendItemHeight) * ($$.__legend_inset_step + 1) : $$.height; + h = $$.config.legend_inset_step ? Math.max(20, $$.legendItemHeight) * ($$.config.legend_inset_step + 1) : $$.height; } else { h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); } } return h; }; - c3.fn.$$.opacityForLegend = function (legendItem) { + c3.chart.internal.fn.opacityForLegend = function (legendItem) { var $$ = this; return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; }; - c3.fn.$$.opacityForUnfocusedLegend = function (legendItem) { + c3.chart.internal.fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; }; - c3.fn.$$.toggleFocusLegend = function (id, focus) { + c3.chart.internal.fn.toggleFocusLegend = function (id, focus) { var $$ = this; $$.legend.selectAll('.' + $$.CLASS.legendItem) .transition().duration(100) @@ -2384,16 +2390,16 @@ } }); }; - c3.fn.$$.revertLegend = function () { + c3.chart.internal.fn.revertLegend = function () { var $$ = this, d3 = $$.d3; $$.legend.selectAll('.' + $$.CLASS.legendItem) .transition().duration(100) .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; - c3.fn.$$.showLegend = function (targetIds) { + c3.chart.internal.fn.showLegend = function (targetIds) { var $$ = this; - if (!$$.__legend_show) { - $$.__legend_show = true; + if (!$$.config.legend_show) { + $$.config.legend_show = true; $$.legend.style('visibility', 'visible'); } $$.removeHiddenLegendIds(targetIds); @@ -2402,10 +2408,10 @@ .transition() .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); }; - c3.fn.$$.hideLegend = function (targetIds) { + c3.chart.internal.fn.hideLegend = function (targetIds) { var $$ = this; - if ($$.__legend_show && $$.isEmpty(targetIds)) { - $$.__legend_show = false; + if ($$.config.legend_show && $$.isEmpty(targetIds)) { + $$.config.legend_show = false; $$.legend.style('visibility', 'hidden'); } $$.addHiddenLegendIds(targetIds); @@ -2413,7 +2419,7 @@ .style('opacity', 0) .style('visibility', 'hidden'); }; - c3.fn.$$.updateLegend = function (targetIds, options, transitions) { + c3.chart.internal.fn.updateLegend = function (targetIds, options, transitions) { var $$ = this; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; @@ -2457,7 +2463,7 @@ maxHeight = 0; } - if ($$.__legend_show && !$$.isLegendToShow(id)) { + if ($$.config.legend_show && !$$.isLegendToShow(id)) { widths[id] = heights[id] = steps[id] = offsets[id] = 0; return; } @@ -2469,7 +2475,7 @@ if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; - if ($$.__legend_equally) { + if ($$.config.legend_equally) { Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); margin = (areaLength - maxLength * targetIds.length) / 2; @@ -2509,28 +2515,28 @@ .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - typeof $$.__legend_item_onclick === 'function' ? $$.__legend_item_onclick.call(c3, id) : $$.this.toggle(id); + typeof $$.config.legend_item_onclick === 'function' ? $$.config.legend_item_onclick.call(c3, id) : $$.chart.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed($$.CLASS.legendItemFocused, true); if (!$$.transiting) { - $$.this.focus(id); + $$.chart.focus(id); } - if (typeof $$.__legend_item_onmouseover === 'function') { - $$.__legend_item_onmouseover.call(c3, id); + if (typeof $$.config.legend_item_onmouseover === 'function') { + $$.config.legend_item_onmouseover.call(c3, id); } }) .on('mouseout', function (id) { $$.d3.select(this).classed($$.CLASS.legendItemFocused, false); if (!$$.transiting) { - $$.this.revert(); + $$.chart.revert(); } - if (typeof $$.__legend_item_onmouseout === 'function') { - $$.__legend_item_onmouseout.call(c3, id); + if (typeof $$.config.legend_item_onmouseout === 'function') { + $$.config.legend_item_onmouseout.call(c3, id); } }); l.append('text') - .text(function (id) { return $$.isDefined($$.__data_names[id]) ? $$.__data_names[id] : id; }) + .text(function (id) { return $$.isDefined($$.config.data_names[id]) ? $$.config.data_names[id] : id; }) .each(function (id, i) { updatePositions(this, id, i === 0); }) .style("pointer-events", "none") .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2559,7 +2565,7 @@ texts = $$.legend.selectAll('text') .data(targetIds) - .text(function (id) { return $$.isDefined($$.__data_names[id]) ? $$.__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 .each(function (id, i) { updatePositions(this, id, i === 0); }); (withTransition ? texts.transition() : texts) .attr('x', xForLegendText) @@ -2608,76 +2614,76 @@ - c3.fn.$$.getClipPath = function (id) { + c3.chart.internal.fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; }; - c3.fn.$$.getAxisClipX = function (forHorizontal) { + c3.chart.internal.fn.getAxisClipX = function (forHorizontal) { var $$ = this; // axis line width + padding for left return forHorizontal ? -(1 + 30) : -($$.margin.left - 1); }; - c3.fn.$$.getAxisClipY = function (forHorizontal) { + c3.chart.internal.fn.getAxisClipY = function (forHorizontal) { return forHorizontal ? -20 : -4; }; - c3.fn.$$.getXAxisClipX = function () { + c3.chart.internal.fn.getXAxisClipX = function () { var $$ = this; - return $$.getAxisClipX(!$$.__axis_rotated); + return $$.getAxisClipX(!$$.config.axis_rotated); }; - c3.fn.$$.getXAxisClipY = function () { + c3.chart.internal.fn.getXAxisClipY = function () { var $$ = this; - return this.getAxisClipY(!$$.__axis_rotated); + return this.getAxisClipY(!$$.config.axis_rotated); }; - c3.fn.$$.getYAxisClipX = function () { + c3.chart.internal.fn.getYAxisClipX = function () { var $$ = this; - return this.getAxisClipX($$.__axis_rotated); + return this.getAxisClipX($$.config.axis_rotated); }; - c3.fn.$$.getYAxisClipY = function () { + c3.chart.internal.fn.getYAxisClipY = function () { var $$ = this; - return this.getAxisClipY($$.__axis_rotated); + return this.getAxisClipY($$.config.axis_rotated); }; - c3.fn.$$.getAxisClipWidth = function (forHorizontal) { + c3.chart.internal.fn.getAxisClipWidth = function (forHorizontal) { var $$ = this; // width + axis line width + padding for left/right return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; - c3.fn.$$.getAxisClipHeight = function (forHorizontal) { + c3.chart.internal.fn.getAxisClipHeight = function (forHorizontal) { var $$ = this; - return forHorizontal ? ($$.__axis_x_height ? $$.__axis_x_height : 0) + 80 : $$.height + 8; + return forHorizontal ? ($$.config.axis_x_height ? $$.config.axis_x_height : 0) + 80 : $$.height + 8; }; - c3.fn.$$.getXAxisClipWidth = function () { + c3.chart.internal.fn.getXAxisClipWidth = function () { var $$ = this; - return this.getAxisClipWidth(!$$.__axis_rotated); + return this.getAxisClipWidth(!$$.config.axis_rotated); }; - c3.fn.$$.getXAxisClipHeight = function () { + c3.chart.internal.fn.getXAxisClipHeight = function () { var $$ = this; - return this.getAxisClipHeight(!$$.__axis_rotated); + return this.getAxisClipHeight(!$$.config.axis_rotated); }; - c3.fn.$$.getYAxisClipWidth = function () { + c3.chart.internal.fn.getYAxisClipWidth = function () { var $$ = this; - return this.getAxisClipWidth($$.__axis_rotated); + return this.getAxisClipWidth($$.config.axis_rotated); }; - c3.fn.$$.getYAxisClipHeight = function () { + c3.chart.internal.fn.getYAxisClipHeight = function () { var $$ = this; - return this.getAxisClipHeight($$.__axis_rotated); + return this.getAxisClipHeight($$.config.axis_rotated); }; /** * $$.data.js */ - c3.fn.$$.isX = function (key) { + c3.chart.internal.fn.isX = function (key) { var $$ = this; - return ($$.__data_x && key === $$.__data_x) || (this.notEmpty($$.__data_xs) && this.hasValue($$.__data_xs, key)); + return ($$.config.data_x && key === $$.config.data_x) || (this.notEmpty($$.config.data_xs) && this.hasValue($$.config.data_xs, key)); }; - c3.fn.$$.isNotX = function (key) { + c3.chart.internal.fn.isNotX = function (key) { return !this.isX(key); }; - c3.fn.$$.getXKey = function (id) { + c3.chart.internal.fn.getXKey = function (id) { var $$ = this; - return $$.__data_x ? $$.__data_x : this.notEmpty($$.__data_xs) ? $$.__data_xs[id] : null; + return $$.config.data_x ? $$.config.data_x : this.notEmpty($$.config.data_xs) ? $$.config.data_xs[id] : null; }; - c3.fn.$$.getXValuesOfXKey = function (key, targets) { + c3.chart.internal.fn.getXValuesOfXKey = function (key, targets) { var xValues, ids = targets && this.notEmpty(targets) ? mapToIds(targets) : []; ids.forEach(function (id) { if (this.getXKey(id) === key) { @@ -2686,38 +2692,38 @@ }); return xValues; }; - c3.fn.$$.getXValue = function (id, i) { + c3.chart.internal.fn.getXValue = function (id, i) { return id in $$.data.xs && $$.data.xs[id] && this.isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; }; - c3.fn.$$.getOtherTargetXs = function () { + c3.chart.internal.fn.getOtherTargetXs = function () { var idsForX = Object.keys($$.data.xs); return idsForX.length ? $$.data.xs[idsForX[0]] : null; }; - c3.fn.$$.getOtherTargetX = function (index) { + c3.chart.internal.fn.getOtherTargetX = function (index) { var xs = this.getOtherTargetXs(); return xs && index < xs.length ? xs[index] : null; }; - c3.fn.$$.addXs = function (xs) { + c3.chart.internal.fn.addXs = function (xs) { Object.keys(xs).forEach(function (id) { - $$.__data_xs[id] = xs[id]; + $$.config.data_xs[id] = xs[id]; }); }; - c3.fn.$$.isSingleX = function (xs) { + c3.chart.internal.fn.isSingleX = function (xs) { return $$.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; }; - c3.fn.$$.addName = function (data) { + c3.chart.internal.fn.addName = function (data) { var $$ = this, name; if (data) { - name = $$.__data_names[data.id]; + name = $$.config.data_names[data.id]; data.name = name ? name : data.id; } return data; }; - c3.fn.$$.getValueOnIndex = function (values, index) { + c3.chart.internal.fn.getValueOnIndex = function (values, index) { var valueOnIndex = values.filter(function (v) { return v.index === index; }); return valueOnIndex.length ? valueOnIndex[0] : null; }; - c3.fn.$$.updateTargetX = function (targets, x) { + c3.chart.internal.fn.updateTargetX = function (targets, x) { targets.forEach(function (t) { t.values.forEach(function (v, i) { v.x = generateTargetX(x[i], t.id, i); @@ -2725,14 +2731,14 @@ $$.data.xs[t.id] = x; }); }; - c3.fn.$$.updateTargetXs = function (targets, xs) { + c3.chart.internal.fn.updateTargetXs = function (targets, xs) { targets.forEach(function (t) { if (xs[t.id]) { this.updateTargetX([t], xs[t.id]); } }); }; - c3.fn.$$.generateTargetX = function (rawX, id, index) { + c3.chart.internal.fn.generateTargetX = function (rawX, id, index) { var $$ = this, x; if ($$.isTimeSeries) { x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); @@ -2745,7 +2751,7 @@ } return x; }; - c3.fn.$$.convertUrlToData = function (url, mimeType, keys, done) { + c3.chart.internal.fn.convertUrlToData = function (url, mimeType, keys, done) { var type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; @@ -2757,7 +2763,7 @@ done(d); }); }; - c3.fn.$$.cloneTarget = function (target) { + c3.chart.internal.fn.cloneTarget = function (target) { return { id : target.id, id_org : target.id_org, @@ -2766,19 +2772,19 @@ }) }; }; - c3.fn.$$.getPrevX = function (i) { + c3.chart.internal.fn.getPrevX = function (i) { var value = this.getValueOnIndex($$.data.targets[0].values, i - 1); return value ? value.x : null; }; - c3.fn.$$.getNextX = function (i) { + c3.chart.internal.fn.getNextX = function (i) { var value = this.getValueOnIndex($$.data.targets[0].values, i + 1); return value ? value.x : null; }; - c3.fn.$$.getMaxDataCount = function () { + c3.chart.internal.fn.getMaxDataCount = function () { var $$ = this; return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); }; - c3.fn.$$.getMaxDataCountTarget = function (targets) { + c3.chart.internal.fn.getMaxDataCountTarget = function (targets) { var length = targets.length, max = 0, maxTarget; if (length > 1) { targets.forEach(function (t) { @@ -2792,7 +2798,7 @@ } return maxTarget; }; - c3.fn.$$.getEdgeX = function (targets) { + c3.chart.internal.fn.getEdgeX = function (targets) { var target = this.getMaxDataCountTarget(targets), firstData, lastData; if (!target) { return [0, 0]; @@ -2800,13 +2806,13 @@ firstData = target.values[0], lastData = target.values[target.values.length - 1]; return [firstData.x, lastData.x]; }; - c3.fn.$$.mapToIds = function (targets) { + c3.chart.internal.fn.mapToIds = function (targets) { return targets.map(function (d) { return d.id; }); }; - c3.fn.$$.mapToTargetIds = function (ids) { + c3.chart.internal.fn.mapToTargetIds = function (ids) { return ids ? (typeof ids === 'string' ? [ids] : ids) : mapToIds($$.data.targets); }; - c3.fn.$$.hasTarget = function (targets, id) { + c3.chart.internal.fn.hasTarget = function (targets, id) { var ids = this.mapToIds(targets), i; for (i = 0; i < ids.length; i++) { if (ids[i] === id) { @@ -2815,38 +2821,38 @@ } return false; }; - c3.fn.$$.isTargetToShow = function (targetId) { + c3.chart.internal.fn.isTargetToShow = function (targetId) { return this.hiddenTargetIds.indexOf(targetId) < 0; }; - c3.fn.$$.isLegendToShow = function (targetId) { + c3.chart.internal.fn.isLegendToShow = function (targetId) { return this.hiddenLegendIds.indexOf(targetId) < 0; }; - c3.fn.$$.filterTargetsToShow = function (targets) { + c3.chart.internal.fn.filterTargetsToShow = function (targets) { var $$ = this; return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); }; - c3.fn.$$.mapTargetsToUniqueXs = function (targets) { + c3.chart.internal.fn.mapTargetsToUniqueXs = function (targets) { var $$ = this; var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); }; - c3.fn.$$.addHiddenTargetIds = function (targetIds) { + c3.chart.internal.fn.addHiddenTargetIds = function (targetIds) { var $$ = this; $$.hiddenTargetIds = $$.hiddenTargetIds.concat(targetIds); }; - c3.fn.$$.removeHiddenTargetIds = function (targetIds) { + c3.chart.internal.fn.removeHiddenTargetIds = function (targetIds) { var $$ = this; $$.hiddenTargetIds = $$.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3.fn.$$.addHiddenLegendIds = function (targetIds) { + c3.chart.internal.fn.addHiddenLegendIds = function (targetIds) { var $$ = this; $$.hiddenLegendIds = $$.hiddenLegendIds.concat(targetIds); }; - c3.fn.$$.removeHiddenLegendIds = function (targetIds) { + c3.chart.internal.fn.removeHiddenLegendIds = function (targetIds) { var $$ = this; $$.hiddenLegendIds = $$.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3.fn.$$.getValuesAsIdKeyed = function (targets) { + c3.chart.internal.fn.getValuesAsIdKeyed = function (targets) { var ys = {}; targets.forEach(function (t) { ys[t.id] = []; @@ -2856,7 +2862,7 @@ }); return ys; }; - c3.fn.$$.checkValueInTargets = function (targets, checker) { + c3.chart.internal.fn.checkValueInTargets = function (targets, checker) { var ids = Object.keys(targets), i, j, values; for (i = 0; i < ids.length; i++) { values = targets[ids[i]].values; @@ -2868,21 +2874,21 @@ } return false; }; - c3.fn.$$.hasNegativeValueInTargets = function (targets) { + c3.chart.internal.fn.hasNegativeValueInTargets = function (targets) { return this.checkValueInTargets(targets, function (v) { return v < 0; }); }; - c3.fn.$$.hasPositiveValueInTargets = function (targets) { + c3.chart.internal.fn.hasPositiveValueInTargets = function (targets) { return this.checkValueInTargets(targets, function (v) { return v > 0; }); }; - c3.fn.$$.isOrderDesc = function () { + c3.chart.internal.fn.isOrderDesc = function () { var $$ = this; - return $$.__data_order && $$.__data_order.toLowerCase() === 'desc'; + return $$.config.data_order && $$.config.data_order.toLowerCase() === 'desc'; }; - c3.fn.$$.isOrderAsc = function () { + c3.chart.internal.fn.isOrderAsc = function () { var $$ = this; - return $$.__data_order && $$.__data_order.toLowerCase() === 'asc'; + return $$.config.data_order && $$.config.data_order.toLowerCase() === 'asc'; }; - c3.fn.$$.orderTargets = function (targets) { + c3.chart.internal.fn.orderTargets = function (targets) { var $$ = this, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); if (orderAsc || orderDesc) { targets.sort(function (t1, t2) { @@ -2891,28 +2897,28 @@ t2Sum = t2.values.reduce(reducer, 0); return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; }); - } else if (typeof $$.__data_order === 'function') { - targets.sort($$.__data_order); + } else if (typeof $$.config.data_order === 'function') { + targets.sort($$.config.data_order); } // TODO: accept name array for order return targets; }; - c3.fn.$$.filterSameX = function (targets, x) { + c3.chart.internal.fn.filterSameX = function (targets, x) { return $$.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); }; - c3.fn.$$.filterRemoveNull = function (data) { + c3.chart.internal.fn.filterRemoveNull = function (data) { var $$ = this; return data.filter(function (d) { return $$.isValue(d.value); }); }; - c3.fn.$$.hasDataLabel = function () { + c3.chart.internal.fn.hasDataLabel = function () { var $$ = this; - if (typeof $$.__data_labels === 'boolean' && $$.__data_labels) { + if (typeof $$.config.data_labels === 'boolean' && $$.config.data_labels) { return true; - } else if (typeof $$.__data_labels === 'object' && this.notEmpty($$.__data_labels)) { + } else if (typeof $$.config.data_labels === 'object' && this.notEmpty($$.config.data_labels)) { return true; } return false; }; - c3.fn.$$.getDataLabelLength = function (min, max, axisId, key) { + c3.chart.internal.fn.getDataLabelLength = function (min, max, axisId, key) { var lengths = [0, 0], paddingCoef = 1.3; $$.selectChart.select('svg').selectAll('.dummy') .data([min, max]) @@ -2924,11 +2930,11 @@ .remove(); return lengths; }; - c3.fn.$$.isNoneArc = function (d) { + c3.chart.internal.fn.isNoneArc = function (d) { var $$ = this; return $$.hasTarget($$.data.targets, d.id); }; - c3.fn.$$.isArc = function (d) { + c3.chart.internal.fn.isArc = function (d) { var $$ = this; return 'data' in d && $$.hasTarget($$.data.targets, d.data.id); }; @@ -2937,7 +2943,7 @@ /** * c3.data.convert.js */ - c3.fn.$$.convertCsvToData = function (csv) { + c3.chart.internal.fn.convertCsvToData = function (csv) { var rows = $$.d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; @@ -2949,13 +2955,13 @@ } return d; }; - c3.fn.$$.convertJsonToData = function (json, keys) { + c3.chart.internal.fn.convertJsonToData = function (json, keys) { var new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects targetKeys = keys.value; if (keys.x) { targetKeys.push(keys.x); - $$.__data_x = keys.x; + $$.config.data_x = keys.x; } new_rows.push(targetKeys); json.forEach(function (o) { @@ -2976,7 +2982,7 @@ } return data; }; - c3.fn.$$.convertRowsToData = function (rows) { + c3.chart.internal.fn.convertRowsToData = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; @@ -2987,7 +2993,7 @@ } return new_rows; }; - c3.fn.$$.convertColumnsToData = function (columns) { + c3.chart.internal.fn.convertColumnsToData = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; @@ -3000,7 +3006,7 @@ } return new_rows; }; - c3.fn.$$.convertDataToTargets = function (data, appendXs) { + c3.chart.internal.fn.convertDataToTargets = function (data, appendXs) { var $$ = this; var ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), @@ -3020,11 +3026,11 @@ ); } // if not included in input data, find from preloaded data of other id's x - else if ($$.__data_x) { + else if ($$.config.data_x) { $$.data.xs[id] = this.getOtherTargetXs(); } // if not included in input data, find from preloaded data - else if (this.notEmpty($$.__data_xs)) { + else if (this.notEmpty($$.config.data_xs)) { $$.data.xs[id] = this.getXValuesOfXKey(xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used @@ -3042,7 +3048,7 @@ // convert to target targets = ids.map(function (id, index) { - var convertedId = $$.__data_id_converter(id); + var convertedId = $$.config.data_id_converter(id); return { id: convertedId, id_org: id, @@ -3050,8 +3056,8 @@ var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); // use x as categories if custom x and categorized if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { - if (i === 0) { $$.__axis_x_categories = []; } - $$.__axis_x_categories.push(rawX); + if (i === 0) { $$.config.axis_x_categories = []; } + $$.config.axis_x_categories.push(rawX); } // mark as x = undefined if value is undefined and filter to remove after mapped if (typeof d[id] === 'undefined' || $$.data.xs[id].length <= i) { @@ -3083,8 +3089,8 @@ }); // set target types - if ($$.__data_type) { - this.setTargetType(this.mapToIds(targets).filter(function (id) { return ! (id in $$.__data_types); }), $$.__data_type); + if ($$.config.data_type) { + this.setTargetType(this.mapToIds(targets).filter(function (id) { return ! (id in $$.config.data_types); }), $$.config.data_type); } // cache as original id keyed @@ -3098,7 +3104,7 @@ /** * c3.data.load.js */ - c3.fn.$$.load = function (targets, args) { + c3.chart.internal.fn.load = function (targets, args) { var $$ = this; if (targets) { // filter loading targets if needed @@ -3134,7 +3140,7 @@ args.done(); } }; - c3.fn.$$.loadFromArgs = function (args) { + c3.chart.internal.fn.loadFromArgs = function (args) { var $$ = this; if (args.data) { $$.load($$.convertDataToTargets(args.data), args); @@ -3157,7 +3163,7 @@ $$.load(null, args); } }; - c3.fn.$$.unload = function (targetIds, done) { + c3.chart.internal.fn.unload = function (targetIds, done) { var $$ = this; if (typeof done !== 'function') { done = function () {}; @@ -3190,28 +3196,26 @@ /** * c3.data.category.js */ - c3.fn.$$.categoryName = function (i) { + c3.chart.internal.fn.categoryName = function (i) { var $$ = this; - return i < $$.__axis_x_categories.length ? $$.__axis_x_categories[i] : i; + return i < $$.config.axis_x_categories.length ? $$.config.axis_x_categories[i] : i; }; - - /** * c3.shape.js */ - c3.fn.$$.getShapeIndices = function (typeFilter) { + c3.chart.internal.fn.getShapeIndices = function (typeFilter) { var $$ = this; var indices = {}, i = 0, j, k; $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { - for (j = 0; j < $$.__data_groups.length; j++) { - if ($$.__data_groups[j].indexOf(d.id) < 0) { continue; } - for (k = 0; k < $$.__data_groups[j].length; k++) { - if ($$.__data_groups[j][k] in indices) { - indices[d.id] = indices[$$.__data_groups[j][k]]; + for (j = 0; j < $$.config.data_groups.length; j++) { + if ($$.config.data_groups[j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < $$.config.data_groups[j].length; k++) { + if ($$.config.data_groups[j][k] in indices) { + indices[d.id] = indices[$$.config.data_groups[j][k]]; break; - } + } } } if ($$.isUndefined(indices[d.id])) { indices[d.id] = i++; } @@ -3219,21 +3223,21 @@ indices.__max__ = i - 1; return indices; }; - c3.fn.$$.getShapeX = function (offset, targetsNum, indices, isSub) { + c3.chart.internal.fn.getShapeX = function (offset, targetsNum, indices, isSub) { var $$ = this, scale = isSub ? $$.subX : $$.x; return function (d) { var index = d.id in indices ? indices[d.id] : 0; return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; }; }; - c3.fn.$$.getShapeY = function (isSub) { + c3.chart.internal.fn.getShapeY = function (isSub) { var $$ = this; return function (d) { var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); return scale(d.value); }; }; - c3.fn.$$.getShapeOffset = function (typeFilter, indices, isSub) { + c3.chart.internal.fn.getShapeOffset = function (typeFilter, indices, isSub) { var $$ = this, targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), targetIds = targets.map(function (t) { return t.id; }); @@ -3250,75 +3254,75 @@ }; }; - c3.fn.$$.getInterpolate = function (d) { + c3.chart.internal.fn.getInterpolate = function (d) { var $$ = this; return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; - c3.fn.$$.circleX = function (d) { + c3.chart.internal.fn.circleX = function (d) { var $$ = this; return d.x || d.x === 0 ? $$.x(d.x) : null; }; - c3.fn.$$.circleY = function (d, i) { + c3.chart.internal.fn.circleY = function (d, i) { var $$ = this, lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); - return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; - c3.fn.$$.getCircles = function (i, id) { + c3.chart.internal.fn.getCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); }; - c3.fn.$$.expandCircles = function (i, id) { + c3.chart.internal.fn.expandCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; $$.getCircles(i, id) .classed(CLASS.EXPANDED, true) .attr('r', function (d) { return $$.pointExpandedR(d); }); }; - c3.fn.$$.unexpandCircles = function (i) { + c3.chart.internal.fn.unexpandCircles = function (i) { var $$ = this, CLASS = $$.CLASS; $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) .classed(CLASS.EXPANDED, false) .attr('r', function (d) { return $$.pointR(d); }); }; - c3.fn.$$.pointR = function (d) { + c3.chart.internal.fn.pointR = function (d) { var $$ = this; - return $$.__point_show && !$$.isStepType(d) ? (typeof $$.__point_r === 'function' ? $$.__point_r(d) : $$.__point_r) : 0; + return $$.config.point_show && !$$.isStepType(d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; }; - c3.fn.$$.pointExpandedR = function (d) { + c3.chart.internal.fn.pointExpandedR = function (d) { var $$ = this; - return $$.__point_focus_expand_enabled ? ($$.__point_focus_expand_r ? $$.__point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); + return $$.config.point_focus_expand_enabled ? ($$.config.point_focus_expand_r ? $$.config.point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); }; - c3.fn.$$.pointSelectR = function (d) { + c3.chart.internal.fn.pointSelectR = function (d) { var $$ = this; - return $$.__point_select_r ? $$.__point_select_r : $$.pointR(d) * 4; + return $$.config.point_select_r ? $$.config.point_select_r : $$.pointR(d) * 4; }; - c3.fn.$$.getBarW = function (axis, barTargetsNum) { + c3.chart.internal.fn.getBarW = function (axis, barTargetsNum) { var $$ = this; - return typeof $$.__bar_width === 'number' ? $$.__bar_width : barTargetsNum ? (axis.tickOffset() * 2 * $$.__bar_width_ratio) / barTargetsNum : 0; + return typeof $$.config.bar_width === 'number' ? $$.config.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * $$.config.bar_width_ratio) / barTargetsNum : 0; }; - c3.fn.$$.getBars = function (i) { + c3.chart.internal.fn.getBars = function (i) { var $$ = this; return $$.main.selectAll('.' + this.CLASS.bar + (this.isValue(i) ? '-' + i : '')); }; - c3.fn.$$.expandBars = function (i) { + c3.chart.internal.fn.expandBars = function (i) { this.getBars(i).classed(this.CLASS.EXPANDED, true); }; - c3.fn.$$.unexpandBars = function (i) { + c3.chart.internal.fn.unexpandBars = function (i) { this.getBars(i).classed(this.CLASS.EXPANDED, false); }; - c3.fn.$$.generateDrawBar = function (barIndices, isSub) { + c3.chart.internal.fn.generateDrawBar = function (barIndices, isSub) { var $$ = this, getPoints = this.generateGetBarPoints(barIndices, isSub); return function (d, i) { // 4 points that make a bar var points = getPoints(d, i); // switch points if axis is rotated, not applicable for sub chart - var indexX = $$.__axis_rotated ? 1 : 0; - var indexY = $$.__axis_rotated ? 0 : 1; + var indexX = $$.config.axis_rotated ? 1 : 0; + var indexY = $$.config.axis_rotated ? 0 : 1; var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + @@ -3329,7 +3333,7 @@ return path; }; }; - c3.fn.$$.generateGetBarPoints = function (barIndices, isSub) { + c3.chart.internal.fn.generateGetBarPoints = function (barIndices, isSub) { var $$ = this, barTargetsNum = barIndices.__max__ + 1, barW = $$.getBarW($$.xAxis, barTargetsNum), @@ -3342,7 +3346,7 @@ offset = barOffset(d, i) || y0, // offset is for stacked bar chart posX = barX(d), posY = barY(d); // fix posY not to overflow opposite quadrant - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 4 points that make a bar @@ -3355,19 +3359,19 @@ }; }; - c3.fn.$$.generateDrawArea = function (areaIndices, isSub) { + c3.chart.internal.fn.generateDrawArea = function (areaIndices, isSub) { var $$ = this, area = $$.d3.svg.area(), getPoint = $$.generateGetAreaPoint(areaIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, value0 = function (d, i) { - return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); }, value1 = function (d, i) { - return $$.__data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value); + return $$.config.data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value); }; - area = $$.__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); return function (d) { var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; @@ -3378,29 +3382,29 @@ x0 = $$.x(data[0].x); y0 = $$.getYScale(d.id)(data[0].value); } - path = $$.__axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + path = $$.config.axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } return path ? path : "M 0 0"; }; }; - c3.fn.$$.generateDrawLine = function (lineIndices, isSub) { + c3.chart.internal.fn.generateDrawLine = function (lineIndices, isSub) { var $$ = this, line = $$.d3.svg.line(), getPoint = $$.generateGetLinePoint(lineIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, yValue = function (d, i) { - return $$.__data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); + return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); }; - line = $$.__axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); - if (!$$.__line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } + line = $$.config.axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!$$.config.line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } return function (d) { - var data = $$.__line_connect_null ? $$.filterRemoveNull(d.values) : d.values, + var data = $$.config.line_connect_null ? $$.filterRemoveNull(d.values) : d.values, x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; if ($$.isLineType(d)) { - if ($$.__data_regions[d.id]) { - path = $$.lineWithRegions(data, x, y, $$.__data_regions[d.id]); + if ($$.config.data_regions[d.id]) { + path = $$.lineWithRegions(data, x, y, $$.config.data_regions[d.id]); } else { path = line.interpolate($$.getInterpolate(d))(data); } @@ -3409,22 +3413,22 @@ x0 = x(data[0].x); y0 = y(data[0].value); } - path = $$.__axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + path = $$.config.axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } return path ? path : "M 0 0"; }; }; - c3.fn.$$.generateXYForText = function (barIndices, forX) { + c3.chart.internal.fn.generateXYForText = function (barIndices, forX) { var getPoints = this.generateGetBarPoints(barIndices, false), getter = forX ? this.getXForText : this.getYForText; return function (d, i) { return getter(getPoints(d, i), d, this); }; }; - c3.fn.$$.getXForText = function (points, d, textElement) { + c3.chart.internal.fn.getXForText = function (points, d, textElement) { var box = textElement.getBoundingClientRect(), xPos, padding; - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { padding = this.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { @@ -3432,9 +3436,9 @@ } return xPos > $$.width ? $$.width - box.width : xPos; }; - c3.fn.$$.getYForText = function (points, d, textElement) { + c3.chart.internal.fn.getYForText = function (points, d, textElement) { var box = textElement.getBoundingClientRect(), yPos; - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { yPos = points[2][1] + (d.value < 0 ? box.height : this.isBarType(d) ? -3 : -6); @@ -3442,7 +3446,7 @@ return yPos < box.height ? box.height : yPos; }; - c3.fn.$$.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + c3.chart.internal.fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, areaTargetsNum = areaIndices.__max__ + 1, x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), @@ -3454,7 +3458,7 @@ offset = areaOffset(d, i) || y0, // offset is for stacked area chart posX = x(d), posY = y(d); // fix posY not to overflow opposite quadrant - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 1 point that marks the area position @@ -3465,7 +3469,7 @@ }; }; - c3.fn.$$.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + c3.chart.internal.fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, lineTargetsNum = lineIndices.__max__ + 1, x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), @@ -3477,7 +3481,7 @@ offset = lineOffset(d, i) || y0, // offset is for stacked area chart posX = x(d), posY = y(d); // fix posY not to overflow opposite quadrant - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 1 point that marks the line position @@ -3488,7 +3492,7 @@ }; - c3.fn.$$.lineWithRegions = function (d, x, y, _regions) { + c3.chart.internal.fn.lineWithRegions = function (d, x, y, _regions) { var prev = -1, i, j; var s = "M", sWithRegion; var xp, yp, dx, dy, dd, diff, diffx2; @@ -3513,8 +3517,8 @@ } // Set scales - xValue = $$.__axis_rotated ? function (d) { return y(d.value); } : function (d) { return x(d.x); }; - yValue = $$.__axis_rotated ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; + 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); }; // Define svg generator function for region if ($$.isTimeSeries) { @@ -3560,19 +3564,19 @@ - c3.fn.$$.isWithinCircle = function (_this, _r) { + c3.chart.internal.fn.isWithinCircle = function (_this, _r) { var mouse = $$.d3.mouse(_this), d3_this = $$.d3.select(_this); var cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; - c3.fn.$$.isWithinBar = function (_this) { + c3.chart.internal.fn.isWithinBar = function (_this) { var mouse = $$.d3.mouse(_this), box = _this.getBoundingClientRect(), seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1); var x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2; var sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; }; - c3.fn.$$.isWithinRegions = function (x, regions) { + c3.chart.internal.fn.isWithinRegions = function (x, regions) { var i; for (i = 0; i < regions.length; i++) { if (regions[i].start < x && x <= regions[i].end) { return true; } @@ -3583,7 +3587,7 @@ - c3.fn.$$.findSameXOfValues = function (values, index) { + c3.chart.internal.fn.findSameXOfValues = function (values, index) { var i, targetX = values[index].x, sames = []; for (i = index - 1; i >= 0; i--) { if (targetX !== values[i].x) { break; } @@ -3596,12 +3600,12 @@ return sames; }; - c3.fn.$$.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + c3.chart.internal.fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x var min = _min ? _min : 0, max = _max ? _max : values.length - 1, med = Math.floor((max - min) / 2) + min, value = values[med], - diff = $$.x(value.x) - pos[$$.__axis_rotated ? 1 : 0], + diff = $$.x(value.x) - pos[$$.config.axis_rotated ? 1 : 0], candidates; // Update range for search @@ -3625,7 +3629,7 @@ return this.findClosestOfValues(values, pos, min, max); }; - c3.fn.$$.findClosestFromTargets = function (targets, pos) { + c3.chart.internal.fn.findClosestFromTargets = function (targets, pos) { var candidates; // map to array of closest points of each target @@ -3636,7 +3640,7 @@ // decide closest point and return return this.findClosest(candidates, pos); }; - c3.fn.$$.findClosest = function (values, pos) { + c3.chart.internal.fn.findClosest = function (values, pos) { var minDist, closest; values.forEach(function (v) { var d = this.dist(v, pos); @@ -3647,29 +3651,29 @@ }); return closest; }; - c3.fn.$$.dist = function (data, pos) { + c3.chart.internal.fn.dist = function (data, pos) { var yScale = this.getAxisId(data.id) === 'y' ? $$.y : $$.y2, - xIndex = $$.__axis_rotated ? 1 : 0, - yIndex = $$.__axis_rotated ? 0 : 1; + xIndex = $$.config.axis_rotated ? 1 : 0, + yIndex = $$.config.axis_rotated ? 0 : 1; return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); }; - c3.fn.$$.setTargetType = function (targetIds, type) { + c3.chart.internal.fn.setTargetType = function (targetIds, type) { var $$ = this; $$.mapToTargetIds(targetIds).forEach(function (id) { - $$.withoutFadeIn[id] = (type === $$.__data_types[id]); - $$.__data_types[id] = type; + $$.withoutFadeIn[id] = (type === $$.config.data_types[id]); + $$.config.data_types[id] = type; }); if (!targetIds) { - $$.__data_type = type; + $$.config.data_type = type; } }; - c3.fn.$$.hasType = function (targets, type) { + c3.chart.internal.fn.hasType = function (targets, type) { var $$ = this, has = false; targets.forEach(function (t) { - if ($$.__data_types[t.id] === type) { has = true; } - if (!(t.id in $$.__data_types) && type === 'line') { has = true; } + if ($$.config.data_types[t.id] === type) { has = true; } + if (!(t.id in $$.config.data_types) && type === 'line') { has = true; } }); return has; }; @@ -3679,72 +3683,72 @@ return hasType(targets, 'line'); } */ - c3.fn.$$.hasAreaType = function (targets) { + c3.chart.internal.fn.hasAreaType = function (targets) { return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); }; - c3.fn.$$.hasBarType = function (targets) { + c3.chart.internal.fn.hasBarType = function (targets) { return this.hasType(targets, 'bar'); }; - c3.fn.$$.hasScatterType = function (targets) { + c3.chart.internal.fn.hasScatterType = function (targets) { return this.hasType(targets, 'scatter'); }; - c3.fn.$$.hasPieType = function (targets) { + c3.chart.internal.fn.hasPieType = function (targets) { var $$ = this; - return $$.__data_type === 'pie' || $$.hasType(targets, 'pie'); + return $$.config.data_type === 'pie' || $$.hasType(targets, 'pie'); }; - c3.fn.$$.hasGaugeType = function (targets) { + c3.chart.internal.fn.hasGaugeType = function (targets) { return this.hasType(targets, 'gauge'); }; - c3.fn.$$.hasDonutType = function (targets) { + c3.chart.internal.fn.hasDonutType = function (targets) { var $$ = this; - return $$.__data_type === 'donut' || $$.hasType(targets, 'donut'); + return $$.config.data_type === 'donut' || $$.hasType(targets, 'donut'); }; - c3.fn.$$.hasArcType = function (targets) { + c3.chart.internal.fn.hasArcType = function (targets) { return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); }; - c3.fn.$$.isLineType = function (d) { + c3.chart.internal.fn.isLineType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return !$$.__data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf($$.__data_types[id]) >= 0; + return !$$.config.data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf($$.config.data_types[id]) >= 0; }; - c3.fn.$$.isStepType = function (d) { + c3.chart.internal.fn.isStepType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['step', 'area-step'].indexOf($$.__data_types[id]) >= 0; + return ['step', 'area-step'].indexOf($$.config.data_types[id]) >= 0; }; - c3.fn.$$.isSplineType = function (d) { + c3.chart.internal.fn.isSplineType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['spline', 'area-spline'].indexOf($$.__data_types[id]) >= 0; + return ['spline', 'area-spline'].indexOf($$.config.data_types[id]) >= 0; }; - c3.fn.$$.isAreaType = function (d) { + c3.chart.internal.fn.isAreaType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['area', 'area-spline', 'area-step'].indexOf($$.__data_types[id]) >= 0; + return ['area', 'area-spline', 'area-step'].indexOf($$.config.data_types[id]) >= 0; }; - c3.fn.$$.isBarType = function (d) { + c3.chart.internal.fn.isBarType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.__data_types[id] === 'bar'; + return $$.config.data_types[id] === 'bar'; }; - c3.fn.$$.isScatterType = function (d) { + c3.chart.internal.fn.isScatterType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.__data_types[id] === 'scatter'; + return $$.config.data_types[id] === 'scatter'; }; - c3.fn.$$.isPieType = function (d) { + c3.chart.internal.fn.isPieType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.__data_types[id] === 'pie'; + return $$.config.data_types[id] === 'pie'; }; - c3.fn.$$.isGaugeType = function (d) { + c3.chart.internal.fn.isGaugeType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.__data_types[id] === 'gauge'; + return $$.config.data_types[id] === 'gauge'; }; - c3.fn.$$.isDonutType = function (d) { + c3.chart.internal.fn.isDonutType = function (d) { var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.__data_types[id] === 'donut'; + return $$.config.data_types[id] === 'donut'; }; - c3.fn.$$.isArcType = function (d) { + c3.chart.internal.fn.isArcType = function (d) { return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); }; - c3.fn.$$.lineData = function (d) { + c3.chart.internal.fn.lineData = function (d) { return this.isLineType(d) ? [d] : []; }; - c3.fn.$$.arcData = function (d) { + c3.chart.internal.fn.arcData = function (d) { return this.isArcType(d.data) ? [d] : []; }; /* not used @@ -3752,13 +3756,13 @@ return isScatterType(d) ? d.values : []; } */ - c3.fn.$$.barData = function (d) { + c3.chart.internal.fn.barData = function (d) { return this.isBarType(d) ? d.values : []; }; - c3.fn.$$.lineOrScatterData = function (d) { + c3.chart.internal.fn.lineOrScatterData = function (d) { return this.isLineType(d) || this.isScatterType(d) ? d.values : []; }; - c3.fn.$$.barOrLineData = function (d) { + c3.chart.internal.fn.barOrLineData = function (d) { return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; @@ -3767,14 +3771,14 @@ /** * c3.date.js */ - c3.fn.$$.parseDate = function (date) { + c3.chart.internal.fn.parseDate = function (date) { var parsedDate; if (date instanceof Date) { parsedDate = date; } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = this.dataTimeFormat($$.__data_x_format).parse(date); + parsedDate = this.dataTimeFormat($$.config.data_x_format).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -3786,7 +3790,7 @@ /** * c3.color.js */ - c3.fn.$$.generateColor = function (colors, pattern, callback) { + c3.chart.internal.fn.generateColor = function (colors, pattern, callback) { var ids = []; return function (d) { @@ -3809,7 +3813,7 @@ return callback instanceof Function ? callback(color, d) : color; }; }; - c3.fn.$$.generateLevelColor = function (colors, threshold) { + c3.chart.internal.fn.generateLevelColor = function (colors, threshold) { var asValue = threshold.unit === 'value', values = threshold.values && threshold.values.length ? threshold.values : [], max = threshold.max || 100; @@ -3830,10 +3834,10 @@ /** * c3.scale.js */ - c3.fn.$$.getScale = function (min, max, forTimeseries) { + c3.chart.internal.fn.getScale = function (min, max, forTimeseries) { return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); }; - c3.fn.$$.getX = function (min, max, domain, offset) { + c3.chart.internal.fn.getX = function (min, max, domain, offset) { var $$ = this; var scale = this.getScale(min, max, $$.isTimeSeries), _scale = domain ? scale.domain(domain) : scale, key; @@ -3870,30 +3874,30 @@ } return scale; }; - c3.fn.$$.getY = function (min, max, domain) { + c3.chart.internal.fn.getY = function (min, max, domain) { var scale = this.getScale(min, max); if (domain) { scale.domain(domain); } return scale; }; - c3.fn.$$.getYScale = function (id) { + c3.chart.internal.fn.getYScale = function (id) { var $$ = this; return $$.getAxisId(id) === 'y2' ? $$.y2 : $$.y; }; - c3.fn.$$.getSubYScale = function (id) { + c3.chart.internal.fn.getSubYScale = function (id) { var $$ = this; return $$.getAxisId(id) === 'y2' ? $$.subY2 : $$.subY; }; - c3.fn.$$.updateScales = function () { + c3.chart.internal.fn.updateScales = function () { var $$ = this, xAxisTickFormat, xAxisTickValues, forInit = !$$.x; // update edges - $$.xMin = $$.__axis_rotated ? 1 : 0; - $$.xMax = $$.__axis_rotated ? $$.height : $$.width; - $$.yMin = $$.__axis_rotated ? 0 : $$.height; - $$.yMax = $$.__axis_rotated ? $$.width : 1; + $$.xMin = $$.config.axis_rotated ? 1 : 0; + $$.xMax = $$.config.axis_rotated ? $$.height : $$.width; + $$.yMin = $$.config.axis_rotated ? 0 : $$.height; + $$.yMax = $$.config.axis_rotated ? $$.width : 1; $$.subXMin = $$.xMin; $$.subXMax = $$.xMax; - $$.subYMin = $$.__axis_rotated ? 0 : $$.height2; - $$.subYMax = $$.__axis_rotated ? $$.width2 : 1; + $$.subYMin = $$.config.axis_rotated ? 0 : $$.height2; + $$.subYMax = $$.config.axis_rotated ? $$.width2 : 1; // update scales $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); @@ -3903,20 +3907,20 @@ $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes $$.xAxisTickFormat = $$.getXAxisTickFormat(); - $$.xAxisTickValues = $$.__axis_x_tick_values ? $$.__axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxisTickValues = $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$.getYAxis($$.y, $$.yOrient, $$.__axis_y_tick_format, $$.__axis_y_ticks); - $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, $$.__axis_y2_tick_format, $$.__axis_y2_ticks); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); // Set initialized scales to brush and zoom if (!forInit) { $$.brush.scale($$.subX); - if ($$.__zoom_enabled) { $$.zoom.scale($$.x); } + if ($$.config.zoom_enabled) { $$.zoom.scale($$.x); } } // update for arc this.updateArc(); }; - c3.fn.$$.updateArc = function () { + c3.chart.internal.fn.updateArc = function () { var $$ = this; $$.svgArc = this.getSvgArc(); $$.svgArcExpanded = this.getSvgArcExpanded(); @@ -3927,15 +3931,15 @@ /** * c3.domain.js */ - c3.fn.$$.getYDomainMin = function (targets) { + c3.chart.internal.fn.getYDomainMin = function (targets) { var $$ = this, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; - if ($$.__data_groups.length > 0) { + if ($$.config.data_groups.length > 0) { hasNegativeValue = $$.hasNegativeValueInTargets(targets); - for (j = 0; j < $$.__data_groups.length; j++) { + for (j = 0; j < $$.config.data_groups.length; j++) { // Determine baseId - idsInGroup = $$.__data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + idsInGroup = $$.config.data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); if (idsInGroup.length === 0) { continue; } baseId = idsInGroup[0]; // Consider negative values @@ -3958,15 +3962,15 @@ } return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); }; - c3.fn.$$.getYDomainMax = function (targets) { + c3.chart.internal.fn.getYDomainMax = function (targets) { var $$ = this, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; - if ($$.__data_groups.length > 0) { + if ($$.config.data_groups.length > 0) { hasPositiveValue = $$.hasPositiveValueInTargets(targets); - for (j = 0; j < $$.__data_groups.length; j++) { + for (j = 0; j < $$.config.data_groups.length; j++) { // Determine baseId - idsInGroup = $$.__data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + idsInGroup = $$.config.data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); if (idsInGroup.length === 0) { continue; } baseId = idsInGroup[0]; // Consider positive values @@ -3989,19 +3993,19 @@ } return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - c3.fn.$$.getYDomain = function (targets, axisId) { + c3.chart.internal.fn.getYDomain = function (targets, axisId) { var $$ = this; var yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), - yMin = axisId === 'y2' ? $$.__axis_y2_min : $$.__axis_y_min, - yMax = axisId === 'y2' ? $$.__axis_y2_max : $$.__axis_y_max, + yMin = axisId === 'y2' ? $$.config.axis_y2_min : $$.config.axis_y_min, + yMax = axisId === 'y2' ? $$.config.axis_y2_max : $$.config.axis_y_max, yDomainMin = this.isValue(yMin) ? yMin : this.getYDomainMin(yTargets), yDomainMax = this.isValue(yMax) ? yMax : this.getYDomainMax(yTargets), domainLength, padding, padding_top, padding_bottom, - center = axisId === 'y2' ? $$.__axis_y2_center : $$.__axis_y_center, + center = axisId === 'y2' ? $$.config.axis_y2_center : $$.config.axis_y_center, yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = (this.hasBarType(yTargets) && $$.__bar_zerobased) || (this.hasAreaType(yTargets) && $$.__area_zerobased), - showHorizontalDataLabel = this.hasDataLabel() && $$.__axis_rotated, - showVerticalDataLabel = this.hasDataLabel() && !$$.__axis_rotated; + isZeroBased = (this.hasBarType(yTargets) && $$.config.bar_zerobased) || (this.hasAreaType(yTargets) && $$.config.area_zerobased), + showHorizontalDataLabel = this.hasDataLabel() && $$.config.axis_rotated, + showVerticalDataLabel = this.hasDataLabel() && !$$.config.axis_rotated; if (yTargets.length === 0) { // use current domain if target of axisId is none return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } @@ -4037,13 +4041,13 @@ padding_top += lengths[1]; padding_bottom += lengths[0]; } - if (axisId === 'y' && $$.__axis_y_padding) { - padding_top = this.getAxisPadding($$.__axis_y_padding, 'top', padding, domainLength); - padding_bottom = this.getAxisPadding($$.__axis_y_padding, 'bottom', padding, domainLength); + if (axisId === 'y' && $$.config.axis_y_padding) { + padding_top = this.getAxisPadding($$.config.axis_y_padding, 'top', padding, domainLength); + padding_bottom = this.getAxisPadding($$.config.axis_y_padding, 'bottom', padding, domainLength); } - if (axisId === 'y2' && $$.__axis_y2_padding) { - padding_top = this.getAxisPadding($$.__axis_y2_padding, 'top', padding, domainLength); - padding_bottom = this.getAxisPadding($$.__axis_y2_padding, 'bottom', padding, domainLength); + if (axisId === 'y2' && $$.config.axis_y2_padding) { + padding_top = this.getAxisPadding($$.config.axis_y2_padding, 'top', padding, domainLength); + padding_bottom = this.getAxisPadding($$.config.axis_y2_padding, 'bottom', padding, domainLength); } // Bar/Area chart should be 0-based if all positive|negative if (isZeroBased) { @@ -4052,15 +4056,15 @@ } return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; - c3.fn.$$.getXDomainMin = function (targets) { + c3.chart.internal.fn.getXDomainMin = function (targets) { var $$ = this; - return $$.__axis_x_min ? ($$.isTimeSeries ? this.parseDate($$.__axis_x_min) : $$.__axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); + return $$.config.axis_x_min ? ($$.isTimeSeries ? this.parseDate($$.config.axis_x_min) : $$.config.axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; - c3.fn.$$.getXDomainMax = function (targets) { + c3.chart.internal.fn.getXDomainMax = function (targets) { var $$ = this; - return $$.__axis_x_max ? ($$.isTimeSeries ? this.parseDate($$.__axis_x_max) : $$.__axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); + return $$.config.axis_x_max ? ($$.isTimeSeries ? this.parseDate($$.config.axis_x_max) : $$.config.axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; - c3.fn.$$.getXDomainPadding = function (targets) { + c3.chart.internal.fn.getXDomainPadding = function (targets) { var $$ = this; var edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; @@ -4072,17 +4076,17 @@ } else { padding = diff * 0.01; } - if (typeof $$.__axis_x_padding === 'object' && this.notEmpty($$.__axis_x_padding)) { - paddingLeft = this.isValue($$.__axis_x_padding.left) ? $$.__axis_x_padding.left : padding; - paddingRight = this.isValue($$.__axis_x_padding.right) ? $$.__axis_x_padding.right : padding; - } else if (typeof $$.__axis_x_padding === 'number') { - paddingLeft = paddingRight = $$.__axis_x_padding; + if (typeof $$.config.axis_x_padding === 'object' && this.notEmpty($$.config.axis_x_padding)) { + paddingLeft = this.isValue($$.config.axis_x_padding.left) ? $$.config.axis_x_padding.left : padding; + paddingRight = this.isValue($$.config.axis_x_padding.right) ? $$.config.axis_x_padding.right : padding; + } else if (typeof $$.config.axis_x_padding === 'number') { + paddingLeft = paddingRight = $$.config.axis_x_padding; } else { paddingLeft = paddingRight = padding; } return {left: paddingLeft, right: paddingRight}; }; - c3.fn.$$.getXDomain = function (targets) { + c3.chart.internal.fn.getXDomain = function (targets) { var $$ = this; var xDomain = [this.getXDomainMin(targets), this.getXDomainMax(targets)], firstX = xDomain[0], lastX = xDomain[1], @@ -4101,18 +4105,18 @@ } return [min, max]; }; - c3.fn.$$.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + c3.chart.internal.fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { var $$ = this; if (withUpdateOrgXDomain) { $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); $$.orgXDomain = $$.x.domain(); - if ($$.__zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } + if ($$.config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } $$.subX.domain($$.x.domain()); $$.brush.scale($$.subX); } if (withUpdateXDomain) { $$.x.domain(domain ? domain : $$.brush.empty() ? $$.orgXDomain : $$.brush.extent()); - if ($$.__zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } + if ($$.config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } } return $$.x.domain(); }; @@ -4120,80 +4124,80 @@ - c3.fn.$$.getXAxis = function (scale, orient, tickFormat, tickValues) { + c3.chart.internal.fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); // Set tick axis.tickFormat(tickFormat).tickValues(tickValues); if ($$.isCategorized) { - axis.tickCentered($$.__axis_x_tick_centered); - if ($$.isEmpty($$.__axis_x_tick_culling)) { - $$.__axis_x_tick_culling = false; + axis.tickCentered($$.config.axis_x_tick_centered); + if ($$.isEmpty($$.config.axis_x_tick_culling)) { + $$.config.axis_x_tick_culling = false; } } else { // TODO: move this to c3_axis axis.tickOffset = function () { var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), - base = diff ? diff : ($$.__axis_rotated ? $$.height : $$.width); + base = diff ? diff : ($$.config.axis_rotated ? $$.height : $$.width); return (base / $$.getMaxDataCount()) / 2; }; } return axis; }; - c3.fn.$$.getYAxis = function (scale, orient, tickFormat, ticks) { + c3.chart.internal.fn.getYAxis = function (scale, orient, tickFormat, ticks) { var $$ = this; return c3_axis($$.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); }; - c3.fn.$$.getAxisId = function (id) { + c3.chart.internal.fn.getAxisId = function (id) { var $$ = this; - return id in $$.__data_axes ? $$.__data_axes[id] : 'y'; + return id in $$.config.data_axes ? $$.config.data_axes[id] : 'y'; }; - c3.fn.$$.getXAxisTickFormat = function () { + c3.chart.internal.fn.getXAxisTickFormat = function () { var $$ = this; var format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; - if ($$.__axis_x_tick_format) { - if (typeof $$.__axis_x_tick_format === 'function') { - format = $$.__axis_x_tick_format; + if ($$.config.axis_x_tick_format) { + if (typeof $$.config.axis_x_tick_format === 'function') { + format = $$.config.axis_x_tick_format; } else if ($$.isTimeSeries) { format = function (date) { - return date ? $$.axisTimeFormat($$.__axis_x_tick_format)(date) : ""; + return date ? $$.axisTimeFormat($$.config.axis_x_tick_format)(date) : ""; }; } } return function (v) { return format.call($$, v); }; }; - c3.fn.$$.getAxisLabelOptionByAxisId = function (axisId) { + c3.chart.internal.fn.getAxisLabelOptionByAxisId = function (axisId) { var $$ = this, option; if (axisId === 'y') { - option = $$.__axis_y_label; + option = $$.config.axis_y_label; } else if (axisId === 'y2') { - option = $$.__axis_y2_label; + option = $$.config.axis_y2_label; } else if (axisId === 'x') { - option = $$.__axis_x_label; + option = $$.config.axis_x_label; } return option; }; - c3.fn.$$.getAxisLabelText = function (axisId) { + c3.chart.internal.fn.getAxisLabelText = function (axisId) { var option = this.getAxisLabelOptionByAxisId(axisId); return typeof option === 'string' ? option : option ? option.text : null; }; - c3.fn.$$.setAxisLabelText = function (axisId, text) { + c3.chart.internal.fn.setAxisLabelText = function (axisId, text) { var option = this.getAxisLabelOptionByAxisId(axisId); if (typeof option === 'string') { if (axisId === 'y') { - $$.__axis_y_label = text; + $$.config.axis_y_label = text; } else if (axisId === 'y2') { - $$.__axis_y2_label = text; + $$.config.axis_y2_label = text; } else if (axisId === 'x') { - $$.__axis_x_label = text; + $$.config.axis_x_label = text; } } else if (option) { option.text = text; } }; - c3.fn.$$.getAxisLabelPosition = function (axisId, defaultPosition) { + c3.chart.internal.fn.getAxisLabelPosition = function (axisId, defaultPosition) { var option = this.getAxisLabelOptionByAxisId(axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { @@ -4207,32 +4211,32 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - c3.fn.$$.getXAxisLabelPosition = function () { + c3.chart.internal.fn.getXAxisLabelPosition = function () { var $$ = this; - return this.getAxisLabelPosition('x', $$.__axis_rotated ? 'inner-top' : 'inner-right'); + return this.getAxisLabelPosition('x', $$.config.axis_rotated ? 'inner-top' : 'inner-right'); }; - c3.fn.$$.getYAxisLabelPosition = function () { + c3.chart.internal.fn.getYAxisLabelPosition = function () { var $$ = this; - return this.getAxisLabelPosition('y', $$.__axis_rotated ? 'inner-right' : 'inner-top'); + return this.getAxisLabelPosition('y', $$.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3.fn.$$.getY2AxisLabelPosition = function () { + c3.chart.internal.fn.getY2AxisLabelPosition = function () { var $$ = this; - return this.getAxisLabelPosition('y2', $$.__axis_rotated ? 'inner-right' : 'inner-top'); + return this.getAxisLabelPosition('y2', $$.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3.fn.$$.getAxisLabelPositionById = function (id) { + c3.chart.internal.fn.getAxisLabelPositionById = function (id) { var $$ = this; return id === 'y2' ? $$.getY2AxisLabelPosition() : id === 'y' ? $$.getYAxisLabelPosition() : $$.getXAxisLabelPosition(); }; - c3.fn.$$.textForXAxisLabel = function () { + c3.chart.internal.fn.textForXAxisLabel = function () { return this.getAxisLabelText('x'); }; - c3.fn.$$.textForYAxisLabel = function () { + c3.chart.internal.fn.textForYAxisLabel = function () { return this.getAxisLabelText('y'); }; - c3.fn.$$.textForY2AxisLabel = function () { + c3.chart.internal.fn.textForY2AxisLabel = function () { return this.getAxisLabelText('y2'); }; - c3.fn.$$.xForAxisLabel = function (forHorizontal, position) { + c3.chart.internal.fn.xForAxisLabel = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -4240,83 +4244,83 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - c3.fn.$$.dxForAxisLabel = function (forHorizontal, position) { + c3.chart.internal.fn.dxForAxisLabel = function (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"; } }; - c3.fn.$$.textAnchorForAxisLabel = function (forHorizontal, position) { + c3.chart.internal.fn.textAnchorForAxisLabel = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - c3.fn.$$.xForXAxisLabel = function () { + c3.chart.internal.fn.xForXAxisLabel = function () { var $$ = this; - return $$.xForAxisLabel(!$$.__axis_rotated, $$.getXAxisLabelPosition()); + return $$.xForAxisLabel(!$$.config.axis_rotated, $$.getXAxisLabelPosition()); }; - c3.fn.$$.xForYAxisLabel = function () { + c3.chart.internal.fn.xForYAxisLabel = function () { return this.xForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); }; - c3.fn.$$.xForY2AxisLabel = function () { + c3.chart.internal.fn.xForY2AxisLabel = function () { return this.xForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); }; - c3.fn.$$.dxForXAxisLabel = function () { + c3.chart.internal.fn.dxForXAxisLabel = function () { return this.dxForAxisLabel(!this.__axis_rotated, this.getXAxisLabelPosition()); }; - c3.fn.$$.dxForYAxisLabel = function () { + c3.chart.internal.fn.dxForYAxisLabel = function () { return this.dxForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); }; - c3.fn.$$.dxForY2AxisLabel = function () { + c3.chart.internal.fn.dxForY2AxisLabel = function () { return this.dxForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); }; - c3.fn.$$.dyForXAxisLabel = function () { + c3.chart.internal.fn.dyForXAxisLabel = function () { var $$ = this, position = $$.getXAxisLabelPosition(); - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); } else { - return position.isInner ? "-0.5em" : $$.__axis_x_height ? $$.__axis_x_height - 10 : "3em"; + return position.isInner ? "-0.5em" : $$.config.axis_x_height ? $$.config.axis_x_height - 10 : "3em"; } }; - c3.fn.$$.dyForYAxisLabel = function () { + c3.chart.internal.fn.dyForYAxisLabel = function () { var $$ = this, position = $$.getYAxisLabelPosition(); - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { return position.isInner ? "-0.5em" : "3em"; } else { return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); } }; - c3.fn.$$.dyForY2AxisLabel = function () { + c3.chart.internal.fn.dyForY2AxisLabel = function () { var $$ = this, position = $$.getY2AxisLabelPosition(); - if ($$.__axis_rotated) { + if ($$.config.axis_rotated) { return position.isInner ? "1.2em" : "-2.2em"; } else { return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); } }; - c3.fn.$$.textAnchorForXAxisLabel = function () { + c3.chart.internal.fn.textAnchorForXAxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel(!$$.__axis_rotated, $$.getXAxisLabelPosition()); + return $$.textAnchorForAxisLabel(!$$.config.axis_rotated, $$.getXAxisLabelPosition()); }; - c3.fn.$$.textAnchorForYAxisLabel = function () { + c3.chart.internal.fn.textAnchorForYAxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.__axis_rotated, $$.getYAxisLabelPosition()); + return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getYAxisLabelPosition()); }; - c3.fn.$$.textAnchorForY2AxisLabel = function () { + c3.chart.internal.fn.textAnchorForY2AxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.__axis_rotated, $$.getY2AxisLabelPosition()); + return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getY2AxisLabelPosition()); }; - c3.fn.$$.xForRotatedTickText = function (r) { + c3.chart.internal.fn.xForRotatedTickText = function (r) { return 10 * Math.sin(Math.PI * (r / 180)); }; - c3.fn.$$.yForRotatedTickText = function (r) { + c3.chart.internal.fn.yForRotatedTickText = function (r) { return 11.5 - 2.5 * (r / 15); }; - c3.fn.$$.rotateTickText = function (axis, transition, rotate) { + c3.chart.internal.fn.rotateTickText = function (axis, transition, rotate) { axis.selectAll('.tick text') .style("text-anchor", "start"); transition.selectAll('.tick text') @@ -4325,20 +4329,20 @@ .attr("transform", "rotate(" + rotate + ")"); }; - c3.fn.$$.getMaxTickWidth = function (id) { + c3.chart.internal.fn.getMaxTickWidth = function (id) { var $$ = this; var maxWidth = 0, targetsToShow, scale, axis; if ($$.svg) { targetsToShow = this.filterTargetsToShow($$.data.targets); if (id === 'y') { scale = $$.y.copy().domain(this.getYDomain(targetsToShow, 'y')); - axis = this.getYAxis(scale, $$.yOrient, $$.__axis_y_tick_format, $$.__axis_y_ticks); + axis = this.getYAxis(scale, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); } else if (id === 'y2') { scale = $$.y2.copy().domain(this.getYDomain(targetsToShow, 'y2')); - axis = this.getYAxis(scale, $$.y2Orient, $$.__axis_y2_tick_format, $$.__axis_y2_ticks); + axis = this.getYAxis(scale, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); } else { scale = $$.x.copy().domain(this.getXDomain(targetsToShow)); - axis = this.getXAxis(scale, $$.xOrient, this.getXAxisTickFormat(), $$.__axis_x_tick_values ? $$.__axis_x_tick_values : $$.xAxis.tickValues()); + axis = this.getXAxis(scale, $$.xOrient, this.getXAxisTickFormat(), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4351,7 +4355,7 @@ return $$.currentMaxTickWidth; }; - c3.fn.$$.updateAxisLabels = function (withTransition) { + c3.chart.internal.fn.updateAxisLabels = function (withTransition) { var $$ = this; var axisXLabel = $$.main.select('.' + this.CLASS.axisX + ' .' + this.CLASS.axisXLabel), axisYLabel = $$.main.select('.' + this.CLASS.axisY + ' .' + this.CLASS.axisYLabel), @@ -4374,17 +4378,17 @@ .text(function () { return $$.textForY2AxisLabel(); }); }; - c3.fn.$$.getAxisPadding = function (padding, key, defaultValue, all) { + c3.chart.internal.fn.getAxisPadding = function (padding, key, defaultValue, all) { var ratio = padding.unit === 'ratio' ? all : 1; return this.isValue(padding[key]) ? padding[key] * ratio : defaultValue; }; - c3.fn.$$.generateTickValues = function (xs, tickCount) { + c3.chart.internal.fn.generateTickValues = function (xs, tickCount) { var $$ = this; var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { targetCount = typeof tickCount === 'function' ? tickCount() : tickCount; - // compute ticks according to $$.__axis_x_tick_count + // compute ticks according to $$.config.axis_x_tick_count if (targetCount === 1) { tickValues = [xs[0]]; } else if (targetCount === 2) { @@ -4411,43 +4415,43 @@ /** * c3.region.js */ - c3.fn.$$.regionX = function (d) { + c3.chart.internal.fn.regionX = function (d) { var xPos, yScale = d.axis === 'y' ? y : y2; if (d.axis === 'y' || d.axis === 'y2') { - xPos = $$.__axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; + xPos = $$.config.axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = $$.__axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0); + xPos = $$.config.axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0); } return xPos; }; - c3.fn.$$.regionY = function (d) { + c3.chart.internal.fn.regionY = function (d) { var yPos, yScale = d.axis === 'y' ? y : y2; if (d.axis === 'y' || d.axis === 'y2') { - yPos = $$.__axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); + yPos = $$.config.axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = $$.__axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0) : 0; + yPos = $$.config.axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0) : 0; } return yPos; }; - c3.fn.$$.regionWidth = function (d) { + c3.chart.internal.fn.regionWidth = function (d) { var start = this.regionX(d), end, yScale = d.axis === 'y' ? y : y2; if (d.axis === 'y' || d.axis === 'y2') { - end = $$.__axis_rotated ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; + end = $$.config.axis_rotated ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = $$.__axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.width); + end = $$.config.axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; - c3.fn.$$.regionHeight = function (d) { + c3.chart.internal.fn.regionHeight = function (d) { var start = this.regionY(d), end, yScale = d.axis === 'y' ? y : y2; if (d.axis === 'y' || d.axis === 'y2') { - end = $$.__axis_rotated ? $$.height : ('start' in d ? yScale(d.start) : $$.height); + end = $$.config.axis_rotated ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = $$.__axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.height) : $$.height; + end = $$.config.axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; - c3.fn.$$.isRegionOnX = function (d) { + c3.chart.internal.fn.isRegionOnX = function (d) { return !d.axis || d.axis === 'x'; }; @@ -4457,7 +4461,7 @@ /** * c3.arc.js */ - c3.fn.$$.updateAngle = function (d) { + c3.chart.internal.fn.updateAngle = function (d) { var $$ = this, found = false, index = 0; $$.pie($$.filterTargetsToShow($$.data.targets)).sort(this.descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { @@ -4471,7 +4475,7 @@ d.endAngle = d.startAngle; } if (this.isGaugeType(d.data)) { - var gMin = $$.__gauge_min, gMax = $$.__gauge_max, + var gMin = $$.config.gauge_min, gMax = $$.config.gauge_max, gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); @@ -4479,7 +4483,7 @@ } return found ? d : null; }; - c3.fn.$$.getSvgArc = function () { + c3.chart.internal.fn.getSvgArc = function () { var $$ = this; var arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { @@ -4492,7 +4496,7 @@ newArc.centroid = arc.centroid; return newArc; }; - c3.fn.$$.getSvgArcExpanded = function (rate) { + c3.chart.internal.fn.getSvgArcExpanded = function (rate) { var $$ = this; var arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { @@ -4500,10 +4504,10 @@ return updated ? arc(updated) : "M 0 0"; }; }; - c3.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"; }; - c3.fn.$$.transformForArcLabel = function (d) { + c3.chart.internal.fn.transformForArcLabel = function (d) { var $$ = this, updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; if (updated && !this.hasGaugeType($$.data.targets)) { c = this.svgArc.centroid(updated); @@ -4516,11 +4520,11 @@ } return translate; }; - c3.fn.$$.getArcRatio = function (d) { + c3.chart.internal.fn.getArcRatio = function (d) { var $$ = this, whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; - c3.fn.$$.convertToArcData = function (d) { + c3.chart.internal.fn.convertToArcData = function (d) { return this.addName({ id: d.data.id, value: d.value, @@ -4528,7 +4532,7 @@ index: d.index }); }; - c3.fn.$$.textForArcLabel = function (d) { + c3.chart.internal.fn.textForArcLabel = function (d) { var $$ = this, updated, value, ratio, format; if (! $$.shouldShowArcLabel()) { return ""; } updated = $$.updateAngle(d); @@ -4538,7 +4542,7 @@ format = $$.getArcLabelFormat(); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; - c3.fn.$$.expandArc = function (id, withoutFadeOut) { + c3.chart.internal.fn.expandArc = function (id, withoutFadeOut) { var $$ = this, CLASS= $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); @@ -4559,7 +4563,7 @@ noneTargets.style("opacity", 0.3); } }; - c3.fn.$$.unexpandArc = function (id) { + c3.chart.internal.fn.unexpandArc = function (id) { var $$ = this, CLASS = $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); target.selectAll('path.' + CLASS.arc) @@ -4568,38 +4572,38 @@ $$.svg.selectAll('.' + CLASS.arc) .style("opacity", 1); }; - c3.fn.$$.shouldExpand = function (id) { + c3.chart.internal.fn.shouldExpand = function (id) { var $$ = this; - return ($$.isDonutType(id) && $$.__donut_expand) || ($$.isGaugeType(id) && $$.__gauge_expand) || ($$.isPieType(id) && $$.__pie_expand); + return ($$.isDonutType(id) && $$.config.donut_expand) || ($$.isGaugeType(id) && $$.config.gauge_expand) || ($$.isPieType(id) && $$.config.pie_expand); }; - c3.fn.$$.shouldShowArcLabel = function () { + c3.chart.internal.fn.shouldShowArcLabel = function () { var $$ = this, shouldShow = true; if (this.hasDonutType($$.data.targets)) { - shouldShow = $$.__donut_label_show; + shouldShow = $$.config.donut_label_show; } else if (this.hasPieType($$.data.targets)) { - shouldShow = $$.__pie_label_show; + shouldShow = $$.config.pie_label_show; } // when gauge, always true return shouldShow; }; - c3.fn.$$.meetsArcLabelThreshold = function (ratio) { - var $$ = this, threshold = this.hasDonutType($$.data.targets) ? $$.__donut_label_threshold : $$.__pie_label_threshold; + c3.chart.internal.fn.meetsArcLabelThreshold = function (ratio) { + var $$ = this, threshold = this.hasDonutType($$.data.targets) ? $$.config.donut_label_threshold : $$.config.pie_label_threshold; return ratio >= threshold; }; - c3.fn.$$.getArcLabelFormat = function () { - var $$ = this, format = $$.__pie_label_format; + c3.chart.internal.fn.getArcLabelFormat = function () { + var $$ = this, format = $$.config.pie_label_format; if (this.hasGaugeType($$.data.targets)) { - format = $$.__gauge_label_format; + format = $$.config.gauge_label_format; } else if (this.hasDonutType($$.data.targets)) { - format = $$.__donut_label_format; + format = $$.config.donut_label_format; } return format; }; - c3.fn.$$.getArcTitle = function () { + c3.chart.internal.fn.getArcTitle = function () { var $$ = this; - return $$.hasDonutType($$.data.targets) ? $$.__donut_title : ""; + return $$.hasDonutType($$.data.targets) ? $$.config.donut_title : ""; }; - c3.fn.$$.descByStartAngle = function (a, b) { + c3.chart.internal.fn.descByStartAngle = function (a, b) { return a.startAngle - b.startAngle; }; @@ -4608,17 +4612,17 @@ /** * c3.cache.js */ - c3.fn.$$.hasCaches = function (ids) { + c3.chart.internal.fn.hasCaches = function (ids) { for (var i = 0; i < ids.length; i++) { if (! (ids[i] in $$.cache)) { return false; } } return true; }; - c3.fn.$$.addCache = function (id, target) { + c3.chart.internal.fn.addCache = function (id, target) { var $$ = this; $$.cache[id] = $$.cloneTarget(target); }; - c3.fn.$$.getCaches = function (ids) { + c3.chart.internal.fn.getCaches = function (ids) { var targets = [], i; for (i = 0; i < ids.length; i++) { if (ids[i] in $$.cache) { targets.push(this.cloneTarget($$.cache[ids[i]])); } @@ -4630,8 +4634,8 @@ /** * c3.zoom.js */ - c3.fn.$$.updateZoom = function () { - var $$ = this, z = $$.__zoom_enabled ? $$.zoom : function () {}; + c3.chart.internal.fn.updateZoom = function () { + var $$ = this, z = $$.config.zoom_enabled ? $$.zoom : function () {}; $$.main.select('.' + this.CLASS.zoomRect).call(z); $$.main.selectAll('.' + this.CLASS.eventRect).call(z); }; @@ -4642,47 +4646,47 @@ /** * c3.util.js */ - c3.fn.$$.isValue = function (v) { + c3.chart.internal.fn.isValue = function (v) { return v || v === 0; }; - c3.fn.$$.isUndefined = function (v) { + c3.chart.internal.fn.isUndefined = function (v) { return typeof v === 'undefined'; }; - c3.fn.$$.isDefined = function (v) { + c3.chart.internal.fn.isDefined = function (v) { return typeof v !== 'undefined'; }; - c3.fn.$$.ceil10 = function (v) { + c3.chart.internal.fn.ceil10 = function (v) { return Math.ceil(v / 10) * 10; }; - c3.fn.$$.asHalfPixel = function (n) { + c3.chart.internal.fn.asHalfPixel = function (n) { return Math.ceil(n) + 0.5; }; - c3.fn.$$.diffDomain = function (d) { + c3.chart.internal.fn.diffDomain = function (d) { return d[1] - d[0]; }; - c3.fn.$$.isEmpty = function (o) { + c3.chart.internal.fn.isEmpty = function (o) { return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); }; - c3.fn.$$.notEmpty = function (o) { + c3.chart.internal.fn.notEmpty = function (o) { return Object.keys(o).length > 0; }; - c3.fn.$$.getOption = function (options, key, defaultValue) { + c3.chart.internal.fn.getOption = function (options, key, defaultValue) { return typeof options[key] !== 'undefined' ? options[key] : defaultValue; }; - c3.fn.$$.hasValue = function (dict, value) { + c3.chart.internal.fn.hasValue = function (dict, value) { var found = false; Object.keys(dict).forEach(function (key) { if (dict[key] === value) { found = true; } }); return found; }; - c3.fn.$$.getPathBox = function (path) { + c3.chart.internal.fn.getPathBox = function (path) { var box = path.getBoundingClientRect(), items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; }; - c3.fn.$$.getTextRect = function (text, cls) { + c3.chart.internal.fn.getTextRect = function (text, cls) { var $$ = this, rect; $$.d3.select('body').selectAll('.dummy') .data([text]) @@ -4694,7 +4698,7 @@ return rect; }; - c3.fn.$$.getEmptySelection = function () { + c3.chart.internal.fn.getEmptySelection = function () { var $$ = this; return $$.d3.selectAll([]); }; @@ -4703,51 +4707,51 @@ /** * c3.selection.js */ - c3.fn.$$.selectPoint = function (target, d, i) { + c3.chart.internal.fn.selectPoint = function (target, d, i) { var $$ = this; - $$.__data_onselected.call(c3, d, target.node()); + $$.config.data_onselected.call(c3, d, target.node()); // add selected-circle on low layer g main.select('.' + this.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') .attr("class", function () { return generateClass(this.CLASS.selectedCircle, i); }) - .attr("cx", $$.__axis_rotated ? circleY : circleX) - .attr("cy", $$.__axis_rotated ? circleX : circleY) + .attr("cx", $$.config.axis_rotated ? circleY : circleX) + .attr("cy", $$.config.axis_rotated ? circleX : circleY) .attr("stroke", function () { return color(d); }) .attr("r", pointSelectR(d) * 1.4) .transition().duration(100) .attr("r", pointSelectR); }; - c3.fn.$$.unselectPoint = function (target, d, i) { + c3.chart.internal.fn.unselectPoint = function (target, d, i) { var $$ = this; - $$.__data_onunselected.call(c3, d, target.node()); + $$.config.data_onunselected.call(c3, d, target.node()); // remove selected-circle from low layer g main.select('.' + $$.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; - c3.fn.$$.togglePoint = function (selected, target, d, i) { + c3.chart.internal.fn.togglePoint = function (selected, target, d, i) { selected ? selectPoint(target, d, i) : unselectPoint(target, d, i); }; - c3.fn.$$.selectBar = function (target, d) { - $$.__data_onselected.call(c3, d, target.node()); + c3.chart.internal.fn.selectBar = function (target, d) { + $$.config.data_onselected.call(c3, d, target.node()); target.transition().duration(100).style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); }; - c3.fn.$$.unselectBar = function (target, d) { - $$.__data_onunselected.call(c3, d, target.node()); + c3.chart.internal.fn.unselectBar = function (target, d) { + $$.config.data_onunselected.call(c3, d, target.node()); target.transition().duration(100).style("fill", function () { return $$.color(d); }); }; - c3.fn.$$.toggleBar = function (selected, target, d, i) { + c3.chart.internal.fn.toggleBar = function (selected, target, d, i) { selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); }; - c3.fn.$$.toggleArc = function (selected, target, d, i) { + c3.chart.internal.fn.toggleArc = function (selected, target, d, i) { this.toggleBar(selected, target, d.data, i); }; - c3.fn.$$.getToggle = function (that) { + c3.chart.internal.fn.getToggle = function (that) { // path selection not supported yet return that.nodeName === 'circle' ? this.togglePoint : ($$.d3.select(that).classed(this.CLASS.bar) ? this.toggleBar : this.toggleArc); }; - c3.fn.$$.toggleShape = function (that, d, i) { + c3.chart.internal.fn.toggleShape = function (that, d, i) { var $$ = this, CLASS = $$.CLASS, d3 = $$.d3, shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; if (that.nodeName === 'circle') { @@ -4763,10 +4767,10 @@ toggle = $$.toggleArc; } } - if ($$.__data_selection_grouped || isWithin) { - if ($$.__data_selection_enabled && $$.__data_selection_isselectable(d)) { - if (!$$.__data_selection_multiple) { - $$.main.selectAll('.' + CLASS.shapes + ($$.__data_selection_grouped ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { + if ($$.config.data_selection_grouped || isWithin) { + if ($$.config.data_selection_enabled && $$.config.data_selection_isselectable(d)) { + if (!$$.config.data_selection_multiple) { + $$.main.selectAll('.' + CLASS.shapes + ($$.config.data_selection_grouped ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this); if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } }); @@ -4774,7 +4778,7 @@ shape.classed(CLASS.SELECTED, !isSelected); toggle(!isSelected, shape, d, i); } - $$.__data_onclick.call(c3, d, that); + $$.config.data_onclick.call(c3, d, that); } }; @@ -4782,7 +4786,7 @@ /** * c3.transition.js */ - c3.fn.$$.generateAxisTransitions = function (duration) { + c3.chart.internal.fn.generateAxisTransitions = function (duration) { var $$ = this, axes = $$.axes; return { axisX: duration ? axes.x.transition().duration(duration) : axes.x, @@ -4791,7 +4795,7 @@ axisSubX: duration ? axes.subx.transition().duration(duration) : axes.subx }; }; - c3.fn.$$.endall = function (transition, callback) { + c3.chart.internal.fn.endall = function (transition, callback) { var n = 0; transition .each(function () { ++n; }) @@ -4799,7 +4803,7 @@ if (!--n) { callback.apply(this, arguments); } }); }; - c3.fn.$$.generateWait = function () { + c3.chart.internal.fn.generateWait = function () { var transitionsToWait = [], f = function (transition, callback) { var timer = setInterval(function () { @@ -4831,7 +4835,7 @@ /** * c3.transform.js */ - c3.fn.$$.transformTo = function (targetIds, type, optionsForRedraw) { + c3.chart.internal.fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, withTransitionForAxis = !$$.hasArcType($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; @@ -4845,7 +4849,7 @@ /** * c3.class.js */ - c3.fn.$$.CLASS = { + c3.chart.internal.fn.CLASS = { target: 'c3-target', chart : 'c3-chart', chartLine: 'c3-chart-line', @@ -4918,94 +4922,94 @@ SELECTED: '_selected_', INCLUDED: '_included_' }; - c3.fn.$$.generateClass = function (prefix, targetId) { + c3.chart.internal.fn.generateClass = function (prefix, targetId) { var $$ = this; return " " + prefix + " " + prefix + $$.getTargetSelectorSuffix(targetId); }; - c3.fn.$$.classText = function (d) { + c3.chart.internal.fn.classText = function (d) { return this.generateClass(this.CLASS.text, d.index); }; - c3.fn.$$.classTexts = function (d) { + c3.chart.internal.fn.classTexts = function (d) { return this.generateClass(this.CLASS.texts, d.id); }; - c3.fn.$$.classShape = function (d) { + c3.chart.internal.fn.classShape = function (d) { return this.generateClass(this.CLASS.shape, d.index); }; - c3.fn.$$.classShapes = function (d) { + c3.chart.internal.fn.classShapes = function (d) { return this.generateClass(this.CLASS.shapes, d.id); }; - c3.fn.$$.classLine = function (d) { + c3.chart.internal.fn.classLine = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.line, d.id); }; - c3.fn.$$.classLines = function (d) { + c3.chart.internal.fn.classLines = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.lines, d.id); }; - c3.fn.$$.classCircle = function (d) { + c3.chart.internal.fn.classCircle = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.circle, d.index); }; - c3.fn.$$.classCircles = function (d) { + c3.chart.internal.fn.classCircles = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.circles, d.id); }; - c3.fn.$$.classBar = function (d) { + c3.chart.internal.fn.classBar = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.bar, d.index); }; - c3.fn.$$.classBars = function (d) { + c3.chart.internal.fn.classBars = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.bars, d.id); }; - c3.fn.$$.classArc = function (d) { + c3.chart.internal.fn.classArc = function (d) { return this.classShape(d.data) + this.generateClass(this.CLASS.arc, d.data.id); }; - c3.fn.$$.classArcs = function (d) { + c3.chart.internal.fn.classArcs = function (d) { return this.classShapes(d.data) + this.generateClass(this.CLASS.arcs, d.data.id); }; - c3.fn.$$.classArea = function (d) { + c3.chart.internal.fn.classArea = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.area, d.id); }; - c3.fn.$$.classAreas = function (d) { + c3.chart.internal.fn.classAreas = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.areas, d.id); }; - c3.fn.$$.classRegion = function (d, i) { + c3.chart.internal.fn.classRegion = function (d, i) { return this.generateClass(this.CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); }; - c3.fn.$$.classEvent = function (d) { + c3.chart.internal.fn.classEvent = function (d) { return this.generateClass(this.CLASS.eventRect, d.index); }; - c3.fn.$$.classTarget = function (id) { + c3.chart.internal.fn.classTarget = function (id) { var $$ = this; - var additionalClassSuffix = $$.__data_classes[id], additionalClass = ''; + var additionalClassSuffix = $$.config.data_classes[id], additionalClass = ''; if (additionalClassSuffix) { additionalClass = ' ' + $$.CLASS.target + '-' + additionalClassSuffix; } return $$.generateClass($$.CLASS.target, id) + additionalClass; }; - c3.fn.$$.classChartText = function (d) { + c3.chart.internal.fn.classChartText = function (d) { return this.CLASS.chartText + this.classTarget(d.id); }; - c3.fn.$$.classChartLine = function (d) { + c3.chart.internal.fn.classChartLine = function (d) { return this.CLASS.chartLine + this.classTarget(d.id); }; - c3.fn.$$.classChartBar = function (d) { + c3.chart.internal.fn.classChartBar = function (d) { return this.CLASS.chartBar + this.classTarget(d.id); }; - c3.fn.$$.classChartArc = function (d) { + c3.chart.internal.fn.classChartArc = function (d) { return this.CLASS.chartArc + this.classTarget(d.data.id); }; - c3.fn.$$.getTargetSelectorSuffix = function (targetId) { + c3.chart.internal.fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; - c3.fn.$$.selectorTarget = function (id) { + c3.chart.internal.fn.selectorTarget = function (id) { var $$ = this; return '.' + $$.CLASS.target + $$.getTargetSelectorSuffix(id); }; - c3.fn.$$.selectorTargets = function (ids) { + c3.chart.internal.fn.selectorTargets = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; }; - c3.fn.$$.selectorLegend = function (id) { + c3.chart.internal.fn.selectorLegend = function (id) { var $$ = this; return '.' + $$.CLASS.legendItem + $$.getTargetSelectorSuffix(id); }; - c3.fn.$$.selectorLegends = function (ids) { + c3.chart.internal.fn.selectorLegends = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; }; @@ -5015,7 +5019,7 @@ /** * c3.format.js */ - c3.fn.$$.getYFormat = function (forArc) { + c3.chart.internal.fn.getYFormat = function (forArc) { var $$ = this, formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; @@ -5024,28 +5028,28 @@ return format.call($$, v, ratio); }; }; - c3.fn.$$.yFormat = function (v) { - var $$ = this, format = $$.__axis_y_tick_format ? $$.__axis_y_tick_format : $$.defaultValueFormat; + c3.chart.internal.fn.yFormat = function (v) { + var $$ = this, format = $$.config.axis_y_tick_format ? $$.config.axis_y_tick_format : $$.defaultValueFormat; return format.call($$, v); }; - c3.fn.$$.y2Format = function (v) { - var $$ = this, format = $$.__axis_y2_tick_format ? $$.__axis_y2_tick_format : $$.defaultValueFormat; + c3.chart.internal.fn.y2Format = function (v) { + var $$ = this, format = $$.config.axis_y2_tick_format ? $$.config.axis_y2_tick_format : $$.defaultValueFormat; return format.call($$, v); }; - c3.fn.$$.defaultValueFormat = function (v) { + c3.chart.internal.fn.defaultValueFormat = function (v) { return this.isValue(v) ? +v : ""; }; - c3.fn.$$.defaultArcValueFormat = function (v, ratio) { + c3.chart.internal.fn.defaultArcValueFormat = function (v, ratio) { return (ratio * 100).toFixed(1) + '%'; }; - c3.fn.$$.formatByAxisId = function (axisId) { - var $$ = this.$$, format = function (v) { return this.isValue(v) ? +v : ""; }; + c3.chart.internal.fn.formatByAxisId = function (axisId) { + var $$ = this.internal, format = function (v) { return this.isValue(v) ? +v : ""; }; // find format according to axis id - if (typeof $$.__data_labels.format === 'function') { - format = $$.__data_labels.format; - } else if (typeof $$.__data_labels.format === 'object') { - if (typeof $$.__data_labels.format[axisId] === 'function') { - format = $$.__data_labels.format[axisId]; + if (typeof $$.config.data_labels.format === 'function') { + format = $$.config.data_labels.format; + } else if (typeof $$.config.data_labels.format === 'object') { + if (typeof $$.config.data_labels.format[axisId] === 'function') { + format = $$.config.data_labels.format[axisId]; } } return format; @@ -5056,14 +5060,14 @@ /** * c3.drag.js */ - c3.fn.$$.drag = function (mouse) { + c3.chart.internal.fn.drag = function (mouse) { var $$ = this, main = $$.main, CLASS = $$.CLASS, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; if ($$.hasArcType($$.data.targets)) { return; } - if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable - if ($$.__zoom_enabled && ! $$.zoom.altDomain) { return; } // skip if zoomable because of conflict drag dehavior - if (!$$.__data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection + 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.data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection sx = $$.dragStart[0]; sy = $$.dragStart[1]; @@ -5071,8 +5075,8 @@ my = mouse[1]; minX = Math.min(sx, mx); maxX = Math.max(sx, mx); - minY = ($$.__data_selection_grouped) ? $$.margin.top : Math.min(sy, my); - maxY = ($$.__data_selection_grouped) ? $$.height : Math.max(sy, my); + minY = ($$.config.data_selection_grouped) ? $$.margin.top : Math.min(sy, my); + maxY = ($$.config.data_selection_grouped) ? $$.height : Math.max(sy, my); main.select('.' + CLASS.dragarea) .attr('x', minX) @@ -5081,7 +5085,7 @@ .attr('height', maxY - minY); // TODO: binary search when multiple xs main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) - .filter(function (d) { return $$.__data_selection_isselectable(d); }) + .filter(function (d) { return $$.config.data_selection_isselectable(d); }) .each(function (d, i) { var shape = d3.select(this), isSelected = shape.classed(CLASS.SELECTED), @@ -5114,22 +5118,22 @@ }); }; - c3.fn.$$.dragstart = function (mouse) { + c3.chart.internal.fn.dragstart = function (mouse) { var $$ = this; if ($$.hasArcType($$.data.targets)) { return; } - if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable + if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable $$.dragStart = mouse; $$.main.select('.' + $$.CLASS.chart).append('rect') .attr('class', $$.CLASS.dragarea) .style('opacity', 0.1); $$.dragging = true; - $$.__data_ondragstart.call(c3); + $$.config.data_ondragstart.call(c3); }; - c3.fn.$$.dragend = function () { + c3.chart.internal.fn.dragend = function () { var $$ = this; if ($$.hasArcType($$.data.targets)) { return; } - if (! $$.__data_selection_enabled) { return; } // do nothing if not selectable + if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable $$.main.select('.' + $$.CLASS.dragarea) .transition().duration(100) .style('opacity', 0) @@ -5137,7 +5141,7 @@ $$.main.selectAll('.' + $$.CLASS.shape) .classed($$.CLASS.INCLUDED, false); $$.dragging = false; - $$.__data_ondragend.call(c3); + $$.config.data_ondragend.call(c3); }; @@ -5147,8 +5151,8 @@ /** * c3.api.js (or c3.api.focus.js, etc?) */ - c3.fn.chart.focus = function (targetId) { - var $$ = this.$$, + c3.chart.fn.focus = function (targetId) { + var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); @@ -5165,8 +5169,8 @@ $$.toggleFocusLegend(targetId, true); }; - c3.fn.chart.defocus = function (targetId) { - var $$ = this.$$, + c3.chart.fn.defocus = function (targetId) { + var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); @@ -5182,8 +5186,8 @@ $$.toggleFocusLegend(targetId, false); }; - c3.fn.chart.revert = function (targetId) { - var $$ = this.$$, + c3.chart.fn.revert = function (targetId) { + var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); @@ -5198,8 +5202,8 @@ $$.revertLegend(); }; - c3.fn.chart.show = function (targetIds, options) { - var $$ = this.$$; + c3.chart.fn.show = function (targetIds, options) { + var $$ = this.internal; targetIds = $$.mapToTargetIds(targetIds); options = options || {}; @@ -5216,8 +5220,8 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); }; - c3.fn.chart.hide = function (targetIds, options) { - var $$ = this.$$; + c3.chart.fn.hide = function (targetIds, options) { + var $$ = this.internal; targetIds = $$.mapToTargetIds(targetIds); options = options || {}; @@ -5234,26 +5238,26 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); }; - c3.fn.chart.toggle = function (targetId) { - var $$ = this.$$; + c3.chart.fn.toggle = function (targetId) { + var $$ = this.internal; $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); }; - c3.fn.chart.zoom = function () { + c3.chart.fn.zoom = function () { }; - c3.fn.chart.zoom.enable = function (enabled) { - var $$ = this.$$; - $$.__zoom_enabled = enabled; + c3.chart.fn.zoom.enable = function (enabled) { + var $$ = this.internal; + $$.config.zoom_enabled = enabled; $$.updateAndRedraw(); }; - c3.fn.chart.unzoom = function () { - var $$ = this.$$; + c3.chart.fn.unzoom = function () { + var $$ = this.internal; $$.brush.clear().update(); $$.redraw({withUpdateXDomain: true}); }; - c3.fn.chart.load = function (args) { - var $$ = this.$$; + c3.chart.fn.load = function (args) { + var $$ = this.internal; // update xs if specified if (args.xs) { $$.addXs(args.xs); @@ -5261,12 +5265,12 @@ // update classes if exists if ('classes' in args) { Object.keys(args.classes).forEach(function (id) { - $$.__data_classes[id] = args.classes[id]; + $$.config.data_classes[id] = args.classes[id]; }); } // update categories if exists if ('categories' in args && $$.isCategorized) { - $$.__axis_x_categories = args.categories; + $$.config.axis_x_categories = args.categories; } // use cache if exists if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { @@ -5284,8 +5288,8 @@ } }; - c3.fn.chart.unload = function (args) { - var $$ = this.$$; + c3.chart.fn.unload = function (args) { + var $$ = this.internal; args = args || {}; $$.unload($$.mapToTargetIds(args.ids), function () { $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); @@ -5293,8 +5297,8 @@ }); }; - c3.fn.chart.flow = function (args) { - var $$ = this.$$, + c3.chart.fn.flow = function (args) { + var $$ = this.internal, targets = $$.convertDataToTargets($$.convertColumnsToData(args.columns), true), notfoundIds = [], orgDataCount = $$.getMaxDataCount(), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; @@ -5412,7 +5416,7 @@ flow: { index: baseValue.index, length: length, - duration: $$.isValue(args.duration) ? args.duration : $$.__transition_duration, + duration: $$.isValue(args.duration) ? args.duration : $$.config.transition_duration, done: args.done, orgDataCount: orgDataCount, }, @@ -5421,20 +5425,20 @@ }); }; - c3.fn.chart.selected = function (targetId) { - var $$ = this.$$, d3 = $$.d3, CLASS = $$.CLASS; + c3.chart.fn.selected = function (targetId) { + var $$ = this.internal, d3 = $$.d3, CLASS = $$.CLASS; return d3.merge( $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; - c3.fn.chart.select = function (ids, indices, resetOther) { - var $$ = this.$$, CLASS = $$.CLASS, d3 = $$.d3; - if (! $$.__data_selection_enabled) { return; } + c3.chart.fn.select = function (ids, indices, resetOther) { + var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; + if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = $$.__data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetId = $$.config.data_selection_grouped || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet @@ -5442,7 +5446,7 @@ return; } if (isTargetId && isTargetIndex) { - if ($$.__data_selection_isselectable(d) && !isSelected) { + if ($$.config.data_selection_isselectable(d) && !isSelected) { toggle(true, shape.classed(CLASS.SELECTED, true), d, i); } } else if ($$.isDefined(resetOther) && resetOther) { @@ -5452,12 +5456,12 @@ } }); }; - c3.fn.chart.unselect = function (ids, indices) { - var $$ = this.$$, CLASS = $$.CLASS, d3 = $$.d3; - if (! $$.__data_selection_enabled) { return; } + c3.chart.fn.unselect = function (ids, indices) { + var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; + if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = $$.__data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetId = $$.config.data_selection_grouped || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet @@ -5465,7 +5469,7 @@ return; } if (isTargetId && isTargetIndex) { - if ($$.__data_selection_isselectable(d)) { + if ($$.config.data_selection_isselectable(d)) { if (isSelected) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } @@ -5474,72 +5478,72 @@ }); }; - c3.fn.chart.transform = function (type, targetIds) { - var $$ = this.$$, + c3.chart.fn.transform = function (type, targetIds) { + var $$ = this.internal, options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; $$.transformTo(targetIds, type, options); }; - c3.fn.chart.groups = function (groups) { - var $$ = this.$$; - if ($$.isUndefined(groups)) { return $$.__data_groups; } - $$.__data_groups = groups; + c3.chart.fn.groups = function (groups) { + var $$ = this.internal; + if ($$.isUndefined(groups)) { return $$.config.data_groups; } + $$.config.data_groups = groups; $$.redraw(); - return $$.__data_groups; + return $$.config.data_groups; }; - c3.fn.chart.xgrids = function (grids) { - var $$ = this.$$; - if (! grids) { return $$.__grid_x_lines; } - $$.__grid_x_lines = grids; + c3.chart.fn.xgrids = function (grids) { + var $$ = this.internal; + if (! grids) { return $$.config.grid_x_lines; } + $$.config.grid_x_lines = grids; $$.redraw(); - return $$.__grid_x_lines; + return $$.config.grid_x_lines; }; - c3.fn.chart.xgrids.add = function (grids) { - var $$ = this.$$; - return this.xgrids($$.__grid_x_lines.concat(grids ? grids : [])); + c3.chart.fn.xgrids.add = function (grids) { + var $$ = this.internal; + return this.xgrids($$.config.grid_x_lines.concat(grids ? grids : [])); }; - c3.fn.chart.xgrids.remove = function (params) { // TODO: multiple - var $$ = this.$$; + c3.chart.fn.xgrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; $$.removeGridLines(params, true); }; - c3.fn.chart.ygrids = function (grids) { - var $$ = this.$$; - if (! grids) { return $$.__grid_y_lines; } - $$.__grid_y_lines = grids; + c3.chart.fn.ygrids = function (grids) { + var $$ = this.internal; + if (! grids) { return $$.config.grid_y_lines; } + $$.config.grid_y_lines = grids; $$.redraw(); - return $$.__grid_y_lines; + return $$.config.grid_y_lines; }; - c3.fn.chart.ygrids.add = function (grids) { - var $$ = this.$$; - return c3.ygrids($$.__grid_y_lines.concat(grids ? grids : [])); + c3.chart.fn.ygrids.add = function (grids) { + var $$ = this.internal; + return c3.ygrids($$.config.grid_y_lines.concat(grids ? grids : [])); }; - c3.fn.chart.ygrids.remove = function (params) { // TODO: multiple - var $$ = this.$$; + c3.chart.fn.ygrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; $$.removeGridLines(params, false); }; - c3.fn.chart.regions = function (regions) { - var $$ = this.$$; - if (!regions) { return $$.__regions; } - $$.__regions = regions; + c3.chart.fn.regions = function (regions) { + var $$ = this.internal; + if (!regions) { return $$.config.regions; } + $$.config.regions = regions; $$.redraw(); - return $$.__regions; + return $$.config.regions; }; - c3.fn.chart.regions.add = function (regions) { - var $$ = this.$$; - if (!regions) { return $$.__regions; } - $$.__regions = $$.__regions.concat(regions); + c3.chart.fn.regions.add = function (regions) { + var $$ = this.internal; + if (!regions) { return $$.config.regions; } + $$.config.regions = $$.config.regions.concat(regions); $$.redraw(); - return $$.__regions; + return $$.config.regions; }; - c3.fn.chart.regions.remove = function (options) { - var $$ = this.$$, CLASS = $$.CLASS, + c3.chart.fn.regions.remove = function (options) { + var $$ = this.internal, CLASS = $$.CLASS, duration, classes, regions; options = options || {}; - duration = $$.getOption(options, "duration", $$.__transition_duration); + duration = $$.getOption(options, "duration", $$.config.transition_duration); classes = $$.getOption(options, "classes", [CLASS.region]); regions = $$.main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); @@ -5547,7 +5551,7 @@ .style('opacity', 0) .remove(); - $$.__regions = $$.__regions.filter(function (region) { + $$.config.regions = $$.config.regions.filter(function (region) { var found = false; if (!region.class) { return true; @@ -5558,70 +5562,70 @@ return !found; }); - return $$.__regions; + return $$.config.regions; }; - c3.fn.chart.data = function () { + c3.chart.fn.data = function () { }; - c3.fn.chart.data.get = function (targetId) { - var $$ = this.$$, + c3.chart.fn.data.get = function (targetId) { + var $$ = this.internal, target = this.data.getAsTarget(targetId); return $$.isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; }; - c3.fn.chart.data.getAsTarget = function (targetId) { + c3.chart.fn.data.getAsTarget = function (targetId) { var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); return targets.length > 0 ? targets[0] : undefined; }; - c3.fn.chart.data.names = function (names) { - var $$ = this.$$; - if (!arguments.length) { return $$.__data_names; } + c3.chart.fn.data.names = function (names) { + var $$ = this.internal; + if (!arguments.length) { return $$.config.data_names; } Object.keys(names).forEach(function (id) { - $$.__data_names[id] = names[id]; + $$.config.data_names[id] = names[id]; }); $$.redraw({withLegend: true}); - return $$.__data_names; + return $$.config.data_names; }; - c3.fn.chart.data.colors = function (colors) { - var $$ = this.$$; - if (!arguments.length) { return $$.__data_colors; } + c3.chart.fn.data.colors = function (colors) { + var $$ = this.internal; + if (!arguments.length) { return $$.config.data_colors; } Object.keys(colors).forEach(function (id) { - $$.__data_colors[id] = colors[id]; + $$.config.data_colors[id] = colors[id]; }); $$.redraw({withLegend: true}); - return $$.__data_colors; + return $$.config.data_colors; }; - c3.fn.chart.category = function (i, category) { - var $$ = this.$$; + c3.chart.fn.category = function (i, category) { + var $$ = this.internal; if (arguments.length > 1) { - $$.__axis_x_categories[i] = category; + $$.config.axis_x_categories[i] = category; $$.redraw(); } - return $$.__axis_x_categories[i]; + return $$.config.axis_x_categories[i]; }; - c3.fn.chart.categories = function (categories) { - var $$ = this.$$; - if (!arguments.length) { return $$.__axis_x_categories; } - $$.__axis_x_categories = categories; + c3.chart.fn.categories = function (categories) { + var $$ = this.internal; + if (!arguments.length) { return $$.config.axis_x_categories; } + $$.config.axis_x_categories = categories; $$.redraw(); - return $$.__axis_x_categories; + return $$.config.axis_x_categories; }; // TODO: fix - c3.fn.chart.color = function (id) { - var $$ = this.$$; + c3.chart.fn.color = function (id) { + var $$ = this.internal; return $$.color(id); // more patterns }; - c3.fn.chart.x = function (x) { - var $$ = this.$$; + c3.chart.fn.x = function (x) { + var $$ = this.internal; if (arguments.length) { $$.updateTargetX($$.data.targets, x); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } return $$.data.xs; }; - c3.fn.chart.xs = function (xs) { - var $$ = this.$$; + c3.chart.fn.xs = function (xs) { + var $$ = this.internal; if (arguments.length) { $$.updateTargetXs($$.data.targets, xs); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); @@ -5630,10 +5634,10 @@ }; - c3.fn.chart.axis = function () { + c3.chart.fn.axis = function () { }; - c3.fn.chart.axis.labels = function (labels) { - var $$ = this.$$; + c3.chart.fn.axis.labels = function (labels) { + var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { $$.setAxisLabelText(axisId, labels[axisId]); @@ -5642,34 +5646,34 @@ } // TODO: return some values? }; - c3.fn.chart.axis.max = function (max) { - var $$ = this.$$; + c3.chart.fn.axis.max = function (max) { + var $$ = this.internal; if (arguments.length) { if (typeof max === 'object') { - if ($$.isValue(max.x)) { $$.__axis_x_max = max.x; } - if ($$.isValue(max.y)) { $$.__axis_y_max = max.y; } - if ($$.isValue(max.y2)) { $$.__axis_y2_max = max.y2; } + if ($$.isValue(max.x)) { $$.config.axis_x_max = max.x; } + if ($$.isValue(max.y)) { $$.config.axis_y_max = max.y; } + if ($$.isValue(max.y2)) { $$.config.axis_y2_max = max.y2; } } else { - $$.__axis_y_max = $$.__axis_y2_max = max; + $$.config.axis_y_max = $$.config.axis_y2_max = max; } $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; - c3.fn.chart.axis.min = function (min) { - var $$ = this.$$; + c3.chart.fn.axis.min = function (min) { + var $$ = this.internal; if (arguments.length) { if (typeof min === 'object') { - if ($$.isValue(min.x)) { $$.__axis_x_min = min.x; } - if ($$.isValue(min.y)) { $$.__axis_y_min = min.y; } - if ($$.isValue(min.y2)) { $$.__axis_y2_min = min.y2; } + if ($$.isValue(min.x)) { $$.config.axis_x_min = min.x; } + if ($$.isValue(min.y)) { $$.config.axis_y_min = min.y; } + if ($$.isValue(min.y2)) { $$.config.axis_y2_min = min.y2; } } else { - $$.__axis_y_min = $$.__axis_y2_min = min; + $$.config.axis_y_min = $$.config.axis_y2_min = min; } $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; - c3.fn.chart.axis.range = function (range) { - var $$ = this.$$; + c3.chart.fn.axis.range = function (range) { + var $$ = this.internal; if (arguments.length) { if (typeof range.max !== 'undefined') { this.axis.max(range.max); } if (typeof range.min !== 'undefined') { this.axis.min(range.min); } @@ -5677,33 +5681,33 @@ }; - c3.fn.chart.legend = function () { + c3.chart.fn.legend = function () { }; - c3.fn.chart.legend.show = function (targetIds) { - var $$ = this.$$; + c3.chart.fn.legend.show = function (targetIds) { + var $$ = this.internal; $$.showLegend($$.mapToTargetIds(targetIds)); $$.updateAndRedraw({withLegend: true}); }; - c3.fn.chart.legend.hide = function (targetIds) { - var $$ = this.$$; + c3.chart.fn.legend.hide = function (targetIds) { + var $$ = this.internal; $$.hideLegend($$.mapToTargetIds(targetIds)); $$.updateAndRedraw({withLegend: true}); }; - c3.fn.chart.resize = function (size) { - var $$ = this.$$; - $$.__size_width = size ? size.width : null; - $$.__size_height = size ? size.height : null; + c3.chart.fn.resize = function (size) { + var $$ = this.internal; + $$.config.size_width = size ? size.width : null; + $$.config.size_height = size ? size.height : null; this.flush(); }; - c3.fn.chart.flush = function () { - var $$ = this.$$; + c3.chart.fn.flush = function () { + var $$ = this.internal; $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); }; - c3.fn.chart.destroy = function () { - var $$ = this.$$; + c3.chart.fn.destroy = function () { + var $$ = this.internal; $$.data.targets = undefined; $$.data.xs = {}; $$.selectChart.classed('c3', false).html(""); @@ -5901,4 +5905,8 @@ } + c3.chart.fn.hoge = function () { + console.log(this, this.internal.isTimeSeries); + }; + })(window.c3); From c770dade0202bb0fc052dda8c19ca88f4730d5e1 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 26 Jul 2014 11:43:57 +0100 Subject: [PATCH 04/44] Refactor --- c3.js | 364 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 192 insertions(+), 172 deletions(-) diff --git a/c3.js b/c3.js index 9ecb5d9..ad99551 100644 --- a/c3.js +++ b/c3.js @@ -8,153 +8,22 @@ var c3 = { version: "0.3.0" }; - function Chart(config) { + var c3_chart_fn, c3_chart_internal_fn; - var $$ = this.internal = new Chart.Internal(), - d3 = $$.d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + function Chart(config) { + this.internal = new ChartInternal(config, this); + this.internal.loadConfig(config); + this.internal.init(); + } - $$.chart = this; + function ChartInternal(config, api) { + var $$ = this; + $$.d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + $$.api = api; $$.data = {}; $$.cache = {}; - - /*-- Handle Config --*/ - - $$.readConfig(config); - - /*-- Init Variables --*/ - - // TODO: some of these should be a function and defined in prototype - - // MEMO: clipId needs to be unique because it conflicts when multiple charts exist - $$.clipId = "c3-" + (+new Date()) + '-clip', - $$.clipIdForXAxis = $$.clipId + '-xaxis', - $$.clipIdForYAxis = $$.clipId + '-yaxis', - $$.clipPath = $$.getClipPath($$.clipId), - $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), - $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - - $$.isTimeSeries = ($$.config.axis_x_type === 'timeseries'); - $$.isCategorized = ($$.config.axis_x_type.indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && ($$.config.data_x || $$.notEmpty($$.config.data_xs)); }; - - $$.dragStart = null; - $$.dragging = false; - $$.cancelClick = false; - $$.mouseover = false; - $$.transiting = false; - - $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor($$.config.data_colors, $$.notEmpty($$.config.color_pattern) ? $$.config.color_pattern : $$.defaultColorPattern, $$.config.data_color); - $$.levelColor = $$.notEmpty($$.config.color_threshold) ? $$.generateLevelColor($$.config.color_pattern, $$.config.color_threshold) : null; - - $$.dataTimeFormat = $$.config.data_x_localtime ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = $$.config.axis_x_localtime ? d3.time.format : d3.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 = []; - $$.axes = {}; - - $$.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"; - - $$.translate = { - main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, - context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, - legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, - x : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height) + ")"; }, - y : function () { return "translate(0," + ($$.config.axis_rotated ? $$.height : 0) + ")"; }, - y2 : function () { return "translate(" + ($$.config.axis_rotated ? 0 : $$.width) + "," + ($$.config.axis_rotated ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height2) + ")"; }, - arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } - }; - - $$.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; - $$.legendOpacityForHidden = 0.15; - - $$.currentMaxTickWidth = 0; - - $$.rotated_padding_left = 30; - $$.rotated_padding_right = $$.config.axis_rotated && !$$.config.axis_x_show ? 0 : 30; - $$.rotated_padding_top = 5; - - $$.withoutFadeIn = {}; - - // TODO: this should be pluggable - $$.pie = d3.layout.pie().value(function (d) { - return d.values.reduce(function (a, b) { return a + b.value; }, 0); - }); - if (!$$.config.pie_sort || !$$.config.donut_sort) { // TODO: this needs to be called by each type - $$.pie.sort(null); - } - - // TODO: this should be pluggable - $$.brush = d3.svg.brush().on("brush", $$.redrawForBrush); - $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + this.CLASS.brush).call(this); } - return this; - }; - $$.brush.scale = function (scale) { - return $$.config.axis_rotated ? this.y(scale) : this.x(scale); - }; - - // TODO: this should be pluggable - $$.zoom = d3.behavior.zoom() - .on("zoomstart", function () { - $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; - }) - .on("zoom", $$.redrawForZoom); - $$.zoom.scale = function (scale) { - return $$.config.axis_rotated ? this.y(scale) : this.x(scale); - }; - $$.zoom.orgScaleExtent = function () { - var extent = $$.config.zoom_extent ? $$.config.zoom_extent : [1, 10]; - return [extent[0], Math.max(this.getMaxDataCount() / extent[1], extent[1])]; - }; - $$.zoom.updateScaleExtent = function () { - var ratio = this.diffDomain($$.x.orgDomain()) / this.diffDomain(this.orgXDomain), extent = this.orgScaleExtent(); - this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); - return this; - }; - - /*-- Load data and init chart with defined functions --*/ - - if (config.data.url) { - $$.convertUrlToData(config.data.url, config.data.mimeType, config.data.keys, $$.init); - } - else if (config.data.json) { - $$.init($$.convertJsonToData(config.data.json, config.data.keys)); - } - else if (config.data.rows) { - $$.init($$.convertRowsToData(config.data.rows)); - } - else if (config.data.columns) { - $$.init($$.convertColumnsToData(config.data.columns)); - } - else { - throw Error('url or json or rows or columns is required.'); - } - } - - Chart.Internal = function () {}; + }; c3.generate = function (config) { return new Chart(config); @@ -163,25 +32,12 @@ c3.chart = { fn: Chart.prototype, internal: { - fn: Chart.Internal.prototype + fn: ChartInternal.prototype } }; + c3_chart_fn = c3.chart.fn; + c3_chart_internal_fn = c3.chart.internal.fn; - if (typeof define === "function" && define.amd) { - define("c3", ["d3"], c3); - } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { - module.exports = c3; - } else { - window.c3 = c3; - } - -})(window); - - - -// TODO: these should be separated into each file -(function (c3) { - 'use strict'; /** * c3.config.js @@ -239,10 +95,12 @@ data_onunselected: function () {}, data_ondragstart: function () {}, data_ondragend: function () {}, - data_url: {}, - data_json: {}, - data_rows: {}, - data_columns: {}, + data_url: undefined, + data_json: undefined, + data_rows: undefined, + data_columns: undefined, + data_mimeType: undefined, + data_keys: undefined, // configuration for no plot-able data supplied. data_empty_label_text: "", @@ -402,7 +260,7 @@ tooltip_init_position: {top: '0px', left: '50px'} }; - c3.chart.internal.fn.readConfig = function (config) { + c3.chart.internal.fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -429,10 +287,156 @@ }); }; - c3.chart.internal.fn.init = function (data) { + + + + // should be define in c3.arc.js + c3.chart.internal.fn.initPie = function () { + var $$ = this, d3 = $$.d3; + $$.pie = d3.layout.pie().value(function (d) { + return d.values.reduce(function (a, b) { return a + b.value; }, 0); + }); + if (!$$.config.pie_sort || !$$.config.donut_sort) { // TODO: this needs to be called by each type + $$.pie.sort(null); + } + }; + + // should be define in c3.brush.js (c3.subchart.js?) + c3.chart.internal.fn.initBrush = function () { + var $$ = this, d3 = $$.d3; + // TODO: this should be pluggable + $$.brush = d3.svg.brush().on("brush", $$.redrawForBrush); + $$.brush.update = function () { + if ($$.context) { $$.context.select('.' + this.CLASS.brush).call(this); } + return this; + }; + $$.brush.scale = function (scale) { + return $$.config.axis_rotated ? this.y(scale) : this.x(scale); + }; + }; + + // should be define in c3.zoom.js + c3.chart.internal.fn.initZoom = function () { + var $$ = this, d3 = $$.d3; + $$.zoom = d3.behavior.zoom() + .on("zoomstart", function () { + $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; + }) + .on("zoom", $$.redrawForZoom); + $$.zoom.scale = function (scale) { + return $$.config.axis_rotated ? this.y(scale) : this.x(scale); + }; + $$.zoom.orgScaleExtent = function () { + var extent = $$.config.zoom_extent ? $$.config.zoom_extent : [1, 10]; + return [extent[0], Math.max(this.getMaxDataCount() / extent[1], extent[1])]; + }; + $$.zoom.updateScaleExtent = function () { + var ratio = this.diffDomain($$.x.orgDomain()) / this.diffDomain(this.orgXDomain), + extent = this.orgScaleExtent(); + this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + return this; + }; + }; + + + c3.chart.internal.fn.init = function () { + var $$ = this; + if ($$.config.data_url) { + $$.convertUrlToData($$.config.data_url, $$.config.data_mimeType, $$.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.initWithData = function (data) { var $$ = this, d3 = this.d3; var arcs, eventRect, grid, i, binding = true; + // MEMO: clipId needs to be unique because it conflicts when multiple charts exist + $$.clipId = "c3-" + (+new Date()) + '-clip', + $$.clipIdForXAxis = $$.clipId + '-xaxis', + $$.clipIdForYAxis = $$.clipId + '-yaxis', + $$.clipPath = $$.getClipPath($$.clipId), + $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), + $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); + + $$.isTimeSeries = ($$.config.axis_x_type === 'timeseries'); + $$.isCategorized = ($$.config.axis_x_type.indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && ($$.config.data_x || $$.notEmpty($$.config.data_xs)); }; + + $$.dragStart = null; + $$.dragging = false; + $$.cancelClick = false; + $$.mouseover = false; + $$.transiting = false; + + $$.defaultColorPattern = d3.scale.category10().range(); + $$.color = $$.generateColor($$.config.data_colors, $$.notEmpty($$.config.color_pattern) ? $$.config.color_pattern : $$.defaultColorPattern, $$.config.data_color); + $$.levelColor = $$.notEmpty($$.config.color_threshold) ? $$.generateLevelColor($$.config.color_pattern, $$.config.color_threshold) : null; + + $$.dataTimeFormat = $$.config.data_x_localtime ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = $$.config.axis_x_localtime ? d3.time.format : d3.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 = []; + + $$.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"; + + $$.translate = { + main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, + context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, + legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, + x : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height) + ")"; }, + y : function () { return "translate(0," + ($$.config.axis_rotated ? $$.height : 0) + ")"; }, + y2 : function () { return "translate(" + ($$.config.axis_rotated ? 0 : $$.width) + "," + ($$.config.axis_rotated ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height2) + ")"; }, + arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } + }; + + $$.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; + $$.legendOpacityForHidden = 0.15; + + $$.currentMaxTickWidth = 0; + + $$.rotated_padding_left = 30; + $$.rotated_padding_right = $$.config.axis_rotated && !$$.config.axis_x_show ? 0 : 30; + $$.rotated_padding_top = 5; + + $$.withoutFadeIn = {}; + + if ($$.initPie) { $$.initPie(); } + if ($$.initBrush) { $$.initBrush(); } + if ($$.initZoom) { $$.initZoom(); } + $$.selectChart = d3.select($$.config.bindto); if ($$.selectChart.empty()) { $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); @@ -728,7 +732,7 @@ $$.config.onresize.call(c3); }); window.onresize.add(function () { - $$.chart.flush(); + $$.api.flush(); }); window.onresize.add(function () { $$.config.onresized.call(c3); @@ -736,7 +740,7 @@ } // export element of the chart - $$.chart.element = $$.selectChart.node(); + $$.api.element = $$.selectChart.node(); }; @@ -2515,12 +2519,12 @@ .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - typeof $$.config.legend_item_onclick === 'function' ? $$.config.legend_item_onclick.call(c3, id) : $$.chart.toggle(id); + typeof $$.config.legend_item_onclick === 'function' ? $$.config.legend_item_onclick.call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed($$.CLASS.legendItemFocused, true); if (!$$.transiting) { - $$.chart.focus(id); + $$.api.focus(id); } if (typeof $$.config.legend_item_onmouseover === 'function') { $$.config.legend_item_onmouseover.call(c3, id); @@ -2529,7 +2533,7 @@ .on('mouseout', function (id) { $$.d3.select(this).classed($$.CLASS.legendItemFocused, false); if (!$$.transiting) { - $$.chart.revert(); + $$.api.revert(); } if (typeof $$.config.legend_item_onmouseout === 'function') { $$.config.legend_item_onmouseout.call(c3, id); @@ -5904,9 +5908,25 @@ return axis; } + if (typeof define === "function" && define.amd) { + define("c3", ["d3"], c3); + } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { + module.exports = c3; + } else { + window.c3 = c3; + } + +})(window); + + +/** + * c3.plugin.js + */ +(function(fn) { - c3.chart.fn.hoge = function () { - console.log(this, this.internal.isTimeSeries); + fn.myapi = function () { + // we can do something with internal variables + // e.g. this.internal.isTimeseries, this.internal.svg, this.focus, etc }; -})(window.c3); +})(window.c3.chart.fn); From d5d85c740bce7382c536a45397efd44ab0f7d895 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 26 Jul 2014 17:45:40 +0100 Subject: [PATCH 05/44] Fix jshint --- c3.js | 1869 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 937 insertions(+), 932 deletions(-) diff --git a/c3.js b/c3.js index ad99551..c784b61 100644 --- a/c3.js +++ b/c3.js @@ -1,6 +1,3 @@ -/** - * c3.core.js - */ (function (window) { 'use strict'; @@ -23,7 +20,7 @@ $$.data = {}; $$.cache = {}; $$.axes = {}; - }; + } c3.generate = function (config) { return new Chart(config); @@ -42,7 +39,7 @@ /** * c3.config.js */ - c3.chart.internal.fn.config = { + c3_chart_internal_fn.config = { bindto: '#chart', size_width: undefined, size_height: undefined, @@ -232,23 +229,24 @@ tooltip_format_name: undefined, tooltip_format_value: undefined, tooltip_contents: function (d, defaultTitleFormat, defaultValueFormat, color) { - var titleFormat = this.config.tooltip_format_title || defaultTitleFormat, - nameFormat = this.config.tooltip_format_name || function (name) { return name; }, - valueFormat = this.config.tooltip_format_value || defaultValueFormat, + var $$ = this, + titleFormat = $$.config.tooltip_format_title || defaultTitleFormat, + nameFormat = $$.config.tooltip_format_name || function (name) { return name; }, + valueFormat = $$.config.tooltip_format_value || defaultValueFormat, text, i, title, value, name, bgcolor; for (i = 0; i < d.length; i++) { if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = this.levelColor ? this.levelColor(d[i].value) : color(d[i].id); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - text += ""; + text += ""; text += ""; text += ""; text += ""; @@ -260,7 +258,7 @@ tooltip_init_position: {top: '0px', left: '50px'} }; - c3.chart.internal.fn.loadConfig = function (config) { + c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -291,7 +289,7 @@ // should be define in c3.arc.js - c3.chart.internal.fn.initPie = function () { + c3_chart_internal_fn.initPie = function () { var $$ = this, d3 = $$.d3; $$.pie = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); @@ -302,12 +300,12 @@ }; // should be define in c3.brush.js (c3.subchart.js?) - c3.chart.internal.fn.initBrush = function () { + c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; // TODO: this should be pluggable $$.brush = d3.svg.brush().on("brush", $$.redrawForBrush); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + this.CLASS.brush).call(this); } + if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } return this; }; $$.brush.scale = function (scale) { @@ -316,7 +314,7 @@ }; // should be define in c3.zoom.js - c3.chart.internal.fn.initZoom = function () { + c3_chart_internal_fn.initZoom = function () { var $$ = this, d3 = $$.d3; $$.zoom = d3.behavior.zoom() .on("zoomstart", function () { @@ -328,39 +326,39 @@ }; $$.zoom.orgScaleExtent = function () { var extent = $$.config.zoom_extent ? $$.config.zoom_extent : [1, 10]; - return [extent[0], Math.max(this.getMaxDataCount() / extent[1], extent[1])]; + return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { - var ratio = this.diffDomain($$.x.orgDomain()) / this.diffDomain(this.orgXDomain), - extent = this.orgScaleExtent(); - this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + var ratio = $$.diffDomain($$.x.orgDomain()) / $$.diffDomain($$.orgXDomain), + extent = $$.orgScaleExtent(); + $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); return this; }; }; - c3.chart.internal.fn.init = function () { - var $$ = this; - if ($$.config.data_url) { - $$.convertUrlToData($$.config.data_url, $$.config.data_mimeType, $$.config.data_keys, $$.initWithData); + c3_chart_internal_fn.init = function () { + var $$ = this, c = $$.config; + if (c.data_url) { + $$.convertUrlToData(c.data_url, c.data_mimeType, c.data_keys, $$.initWithData); } - else if ($$.config.data_json) { - $$.initWithData($$.convertJsonToData($$.config.data_json, $$.config.data_keys)); + else if (c.data_json) { + $$.initWithData($$.convertJsonToData(c.data_json, c.data_keys)); } - else if ($$.config.data_rows) { - $$.initWithData($$.convertRowsToData($$.config.data_rows)); + else if (c.data_rows) { + $$.initWithData($$.convertRowsToData(c.data_rows)); } - else if ($$.config.data_columns) { - $$.initWithData($$.convertColumnsToData($$.config.data_columns)); + else if (c.data_columns) { + $$.initWithData($$.convertColumnsToData(c.data_columns)); } else { throw Error('url or json or rows or columns is required.'); } }; - c3.chart.internal.fn.initWithData = function (data) { - var $$ = this, d3 = this.d3; - var arcs, eventRect, grid, i, binding = true; + c3_chart_internal_fn.initWithData = function (data) { + var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, c = $$.config; + var arcs, eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId = "c3-" + (+new Date()) + '-clip', @@ -370,9 +368,9 @@ $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - $$.isTimeSeries = ($$.config.axis_x_type === 'timeseries'); - $$.isCategorized = ($$.config.axis_x_type.indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && ($$.config.data_x || $$.notEmpty($$.config.data_xs)); }; + $$.isTimeSeries = (c.axis_x_type === 'timeseries'); + $$.isCategorized = (c.axis_x_type.indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && (c.data_x || $$.notEmpty(c.data_xs)); }; $$.dragStart = null; $$.dragging = false; @@ -381,11 +379,11 @@ $$.transiting = false; $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor($$.config.data_colors, $$.notEmpty($$.config.color_pattern) ? $$.config.color_pattern : $$.defaultColorPattern, $$.config.data_color); - $$.levelColor = $$.notEmpty($$.config.color_threshold) ? $$.generateLevelColor($$.config.color_pattern, $$.config.color_threshold) : null; + $$.color = $$.generateColor(c.data_colors, $$.notEmpty(c.color_pattern) ? c.color_pattern : $$.defaultColorPattern, c.data_color); + $$.levelColor = $$.notEmpty(c.color_threshold) ? $$.generateLevelColor(c.color_pattern, c.color_threshold) : null; - $$.dataTimeFormat = $$.config.data_x_localtime ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = $$.config.axis_x_localtime ? d3.time.format : d3.time.format.utc; + $$.dataTimeFormat = c.data_x_localtime ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = c.axis_x_localtime ? d3.time.format : d3.time.format.utc; $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ [".%L", function (d) { return d.getMilliseconds(); }], [":%S", function (d) { return d.getSeconds(); }], @@ -400,26 +398,26 @@ $$.hiddenTargetIds = []; $$.hiddenLegendIds = []; - $$.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"; + $$.xOrient = c.axis_rotated ? "left" : "bottom"; + $$.yOrient = c.axis_rotated ? (c.axis_y_inner ? "top" : "bottom") : (c.axis_y_inner ? "right" : "left"); + $$.y2Orient = c.axis_rotated ? (c.axis_y2_inner ? "bottom" : "top") : (c.axis_y2_inner ? "left" : "right"); + $$.subXOrient = c.axis_rotated ? "left" : "bottom"; $$.translate = { main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, - x : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height) + ")"; }, - y : function () { return "translate(0," + ($$.config.axis_rotated ? $$.height : 0) + ")"; }, - y2 : function () { return "translate(" + ($$.config.axis_rotated ? 0 : $$.width) + "," + ($$.config.axis_rotated ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + ($$.config.axis_rotated ? 0 : $$.height2) + ")"; }, + x : function () { return "translate(0," + (c.axis_rotated ? 0 : $$.height) + ")"; }, + y : function () { return "translate(0," + (c.axis_rotated ? $$.height : 0) + ")"; }, + y2 : function () { return "translate(" + (c.axis_rotated ? 0 : $$.width) + "," + (c.axis_rotated ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + (c.axis_rotated ? 0 : $$.height2) + ")"; }, arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } }; - $$.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'; + $$.isLegendRight = c.legend_position === 'right'; + $$.isLegendInset = c.legend_position === 'inset'; + $$.isLegendTop = c.legend_inset_anchor === 'top-left' || c.legend_inset_anchor === 'top-right'; + $$.isLegendLeft = c.legend_inset_anchor === 'top-left' || c.legend_inset_anchor === 'bottom-left'; $$.legendStep = 0; $$.legendItemWidth = 0; $$.legendItemHeight = 0; @@ -428,7 +426,7 @@ $$.currentMaxTickWidth = 0; $$.rotated_padding_left = 30; - $$.rotated_padding_right = $$.config.axis_rotated && !$$.config.axis_x_show ? 0 : 30; + $$.rotated_padding_right = c.axis_rotated && !c.axis_x_show ? 0 : 30; $$.rotated_padding_top = 5; $$.withoutFadeIn = {}; @@ -437,10 +435,10 @@ if ($$.initBrush) { $$.initBrush(); } if ($$.initZoom) { $$.initZoom(); } - $$.selectChart = d3.select($$.config.bindto); + $$.selectChart = d3.select(c.bindto); if ($$.selectChart.empty()) { $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); - this.observeInserted($$.selectChart); + $$.observeInserted($$.selectChart); binding = false; } $$.selectChart.html("").classed("c3", true); @@ -449,28 +447,28 @@ $$.data.xs = {}; $$.data.targets = $$.convertDataToTargets(data); - if ($$.config.data_filter) { - $$.data.targets = $$.data.targets.filter($$.config.data_filter); + if (c.data_filter) { + $$.data.targets = $$.data.targets.filter(c.data_filter); } // Set targets to hide if needed - if ($$.config.data_hide) { - this.addHiddenTargetIds($$.config.data_hide === true ? this.mapToIds($$.data.targets) : $$.config.data_hide); + if (c.data_hide) { + $$.addHiddenTargetIds(c.data_hide === true ? $$.mapToIds($$.data.targets) : c.data_hide); } // when gauge, hide legend // TODO: fix - if (this.hasGaugeType($$.data.targets)) { - $$.config.legend_show = false; + if ($$.hasGaugeType($$.data.targets)) { + c.legend_show = false; } // Init sizes and scales - this.updateSizes(); - this.updateScales(); + $$.updateSizes(); + $$.updateScales(); // Set domains for each scale - $$.x.domain(d3.extent(this.getXDomain($$.data.targets))); - $$.y.domain(this.getYDomain($$.data.targets, 'y')); - $$.y2.domain(this.getYDomain($$.data.targets, 'y2')); + $$.x.domain(d3.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()); @@ -480,15 +478,15 @@ // Set initialized scales to brush and zoom $$.brush.scale($$.subX); - if ($$.config.zoom_enabled) { $$.zoom.scale($$.x); } + if (c.zoom_enabled) { $$.zoom.scale($$.x); } /*-- Basic Elements --*/ // Define svgs $$.svg = $$.selectChart.append("svg") .style("overflow", "hidden") - .on('mouseenter', function () { return $$.config.onmouseover.call(c3); }) - .on('mouseleave', function () { return $$.config.onmouseout.call(c3); }); + .on('mouseenter', function () { return c.onmouseover.call(c3); }) + .on('mouseleave', function () { return c.onmouseout.call(c3); }); // Define defs $$.defs = $$.svg.append("defs"); @@ -502,11 +500,11 @@ $$.context = $$.svg.append("g").attr("transform", $$.translate.context); $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); - if (!$$.config.subchart_show) { + if (!c.subchart_show) { $$.context.style('visibility', 'hidden'); } - if (!$$.config.legend_show) { + if (!c.legend_show) { $$.legend.style('visibility', 'hidden'); $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } @@ -528,138 +526,138 @@ // text when empty $$.main.append("text") - .attr("class", this.CLASS.text + ' ' + this.CLASS.empty) + .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 $$.main.append('g') .attr("clip-path", $$.clipPath) - .attr("class", this.CLASS.regions); + .attr("class", CLASS.regions); // Grids $$.grid = $$.main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', this.CLASS.grid); - if ($$.config.grid_x_show) { - $$.grid.append("g").attr("class", this.CLASS.xgrids); + .attr('class', CLASS.grid); + if (c.grid_x_show) { + $$.grid.append("g").attr("class", CLASS.xgrids); } - if ($$.config.grid_y_show) { - $$.grid.append('g').attr('class', this.CLASS.ygrids); + if (c.grid_y_show) { + $$.grid.append('g').attr('class', CLASS.ygrids); } - $$.grid.append('g').attr("class", this.CLASS.xgridLines); - $$.grid.append('g').attr('class', this.CLASS.ygridLines); - if ($$.config.grid_focus_show) { + $$.grid.append('g').attr("class", CLASS.xgridLines); + $$.grid.append('g').attr('class', CLASS.ygridLines); + if (c.grid_focus_show) { $$.grid.append('g') - .attr("class", this.CLASS.xgridFocus) + .attr("class", CLASS.xgridFocus) .append('line') - .attr('class', this.CLASS.xgridFocus); + .attr('class', CLASS.xgridFocus); } // Define g for chart area $$.main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', this.CLASS.chart); + .attr('class', CLASS.chart); // Cover whole with rects for events - eventRect = $$.main.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.eventRects) + eventRect = $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.eventRects) .style('fill-opacity', 0); // Define g for bar chart area - $$.main.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartBars); + $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); // Define g for line chart area - $$.main.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartLines); + $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); // Define g for arc chart area - arcs = $$.main.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartArcs) + arcs = $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartArcs) .attr("transform", $$.translate.arc); arcs.append('text') - .attr('class', this.CLASS.chartArcsTitle) + .attr('class', CLASS.chartArcsTitle) .style("text-anchor", "middle") - .text(this.getArcTitle()); - if (this.hasGaugeType($$.data.targets)) { + .text($$.getArcTitle()); + if ($$.hasGaugeType($$.data.targets)) { arcs.append('path') - .attr("class", this.CLASS.chartArcsBackground) + .attr("class", CLASS.chartArcsBackground) .attr("d", function () { var d = { - data: [{value: $$.config.gauge_max}], + data: [{value: c.gauge_max}], startAngle: -1 * (Math.PI / 2), endAngle: Math.PI / 2 }; - return this.getArc(d, true, true); + return $$.getArc(d, true, true); }); arcs.append("text") .attr("dy", ".75em") - .attr("class", this.CLASS.chartArcsGaugeUnit) + .attr("class", CLASS.chartArcsGaugeUnit) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.config.gauge_label_show ? $$.config.gauge_units : ''); + .text(c.gauge_label_show ? c.gauge_units : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") - .attr("class", this.CLASS.chartArcsGaugeMin) + .attr("class", CLASS.chartArcsGaugeMin) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.config.gauge_label_show ? $$.config.gauge_min : ''); + .text(c.gauge_label_show ? c.gauge_min : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") - .attr("class", this.CLASS.chartArcsGaugeMax) + .attr("class", CLASS.chartArcsGaugeMax) .style("text-anchor", "middle") .style("pointer-events", "none") - .text($$.config.gauge_label_show ? $$.config.gauge_max : ''); + .text(c.gauge_label_show ? c.gauge_max : ''); } - $$.main.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartTexts); + $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartTexts); // if zoom privileged, insert rect to forefront - $$.main.insert('rect', $$.config.zoom_privileged ? null : 'g.' + this.CLASS.regions) - .attr('class', this.CLASS.zoomRect) + $$.main.insert('rect', c.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_default) { - $$.brush.extent(typeof $$.config.axis_x_default !== 'function' ? $$.config.axis_x_default : $$.config.axis_x_default(this.getXDomain())); + if (c.axis_x_default) { + $$.brush.extent(typeof c.axis_x_default !== 'function' ? c.axis_x_default : c.axis_x_default($$.getXDomain())); } // Add Axis $$.axes.x = $$.main.append("g") - .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisX) + .attr("class", CLASS.axis + ' ' + CLASS.axisX) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) - .style("visibility", $$.config.axis_x_show ? 'visible' : 'hidden'); + .style("visibility", c.axis_x_show ? 'visible' : 'hidden'); $$.axes.x.append("text") - .attr("class", this.CLASS.axisXLabel) - .attr("transform", $$.config.axis_rotated ? "rotate(-90)" : "") + .attr("class", CLASS.axisXLabel) + .attr("transform", c.axis_rotated ? "rotate(-90)" : "") .style("text-anchor", function () { return $$.textAnchorForXAxisLabel(); }); $$.axes.y = $$.main.append("g") - .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY) + .attr("class", CLASS.axis + ' ' + CLASS.axisY) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) - .style("visibility", $$.config.axis_y_show ? 'visible' : 'hidden'); + .style("visibility", c.axis_y_show ? 'visible' : 'hidden'); $$.axes.y.append("text") - .attr("class", this.CLASS.axisYLabel) - .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") + .attr("class", CLASS.axisYLabel) + .attr("transform", c.axis_rotated ? "" : "rotate(-90)") .style("text-anchor", function () { return $$.textAnchorForYAxisLabel(); }); $$.axes.y2 = $$.main.append("g") - .attr("class", this.CLASS.axis + ' ' + this.CLASS.axisY2) + .attr("class", CLASS.axis + ' ' + CLASS.axisY2) // clip-path? .attr("transform", $$.translate.y2) - .style("visibility", $$.config.axis_y2_show ? 'visible' : 'hidden'); + .style("visibility", c.axis_y2_show ? 'visible' : 'hidden'); $$.axes.y2.append("text") - .attr("class", this.CLASS.axisY2Label) - .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") + .attr("class", CLASS.axisY2Label) + .attr("transform", c.axis_rotated ? "" : "rotate(-90)") .style("text-anchor", function () { return $$.textAnchorForY2AxisLabel(); }); /*-- Context Region --*/ @@ -667,38 +665,38 @@ // Define g for chart area $$.context.append('g') .attr("clip-path", $$.clipPath) - .attr('class', this.CLASS.chart); + .attr('class', CLASS.chart); // Define g for bar chart area - $$.context.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartBars); + $$.context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); // Define g for line chart area - $$.context.select('.' + this.CLASS.chart).append("g") - .attr("class", this.CLASS.chartLines); + $$.context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); // Add extent rect for Brush $$.context.append("g") .attr("clip-path", $$.clipPath) - .attr("class", this.CLASS.brush) + .attr("class", CLASS.brush) .call($$.brush) .selectAll("rect") - .attr($$.config.axis_rotated ? "width" : "height", $$.config.axis_rotated ? $$.width2 : $$.height2); + .attr(c.axis_rotated ? "width" : "height", c.axis_rotated ? $$.width2 : $$.height2); // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = $$.context.append("g") - .attr("class", this.CLASS.axisX) + .attr("class", CLASS.axisX) .attr("transform", $$.translate.subx) - .attr("clip-path", $$.config.axis_rotated ? "" : $$.clipPathForXAxis); + .attr("clip-path", c.axis_rotated ? "" : $$.clipPathForXAxis); // Set targets - this.updateTargets($$.data.targets); + $$.updateTargets($$.data.targets); // Draw with targets if (binding) { - this.updateDimension(); - this.redraw({ + $$.updateDimension(); + $$.redraw({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -707,35 +705,35 @@ } // Show tooltip if needed - if ($$.config.tooltip_init_show) { - if ($$.isTimeSeries && typeof $$.config.tooltip_init_x === 'string') { - $$.config.tooltip_init_x = this.parseDate($$.config.tooltip_init_x); + if (c.tooltip_init_show) { + if ($$.isTimeSeries && typeof c.tooltip_init_x === 'string') { + c.tooltip_init_x = $$.parseDate(c.tooltip_init_x); for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - $$.config.tooltip_init_x) === 0) { break; } + if (($$.data.targets[0].values[i].x - c.tooltip_init_x) === 0) { break; } } - $$.config.tooltip_init_x = i; + c.tooltip_init_x = i; } - $$.tooltip.html($$.config.tooltip_contents.call($$, $$.data.targets.map(function (d) { - return this.addName(d.values[$$.config.tooltip_init_x]); - }), this.getXAxisTickFormat(), this.getYFormat(this.hasArcType($$.data.targets)), $$.color)); - $$.tooltip.style("top", $$.config.tooltip_init_position.top) - .style("left", $$.config.tooltip_init_position.left) + $$.tooltip.html(c.tooltip_contents.call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[c.tooltip_init_x]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); + $$.tooltip.style("top", c.tooltip_init_position.top) + .style("left", c.tooltip_init_position.left) .style("display", "block"); } // Bind resize event if (window.onresize == null) { - window.onresize = this.generateResize(); + window.onresize = $$.generateResize(); } if (window.onresize.add) { window.onresize.add(function () { - $$.config.onresize.call(c3); + c.onresize.call(c3); }); window.onresize.add(function () { $$.api.flush(); }); window.onresize.add(function () { - $$.config.onresized.call(c3); + c.onresized.call(c3); }); } @@ -744,7 +742,7 @@ }; - c3.chart.internal.fn.smoothLines = function (el, type) { + c3_chart_internal_fn.smoothLines = function (el, type) { var $$ = this; if (type === 'grid') { el.each(function () { @@ -764,24 +762,24 @@ }; - c3.chart.internal.fn.updateSizes = function () { - var $$ = this; + c3_chart_internal_fn.updateSizes = function () { + var $$ = this, c = $$.config; var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = this.hasArcType($$.data.targets), - xAxisHeight = $$.config.axis_rotated || hasArc ? 0 : this.getHorizontalAxisHeight('x'), - subchartHeight = $$.config.subchart_show && !hasArc ? ($$.config.subchart_size_height + xAxisHeight) : 0; + hasArc = $$.hasArcType($$.data.targets), + xAxisHeight = c.axis_rotated || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), + subchartHeight = c.subchart_show && !hasArc ? (c.subchart_size_height + xAxisHeight) : 0; - $$.currentWidth = this.getCurrentWidth(); - $$.currentHeight = this.getCurrentHeight(); + $$.currentWidth = $$.getCurrentWidth(); + $$.currentHeight = $$.getCurrentHeight(); // for main, context - if ($$.config.axis_rotated) { + if (c.axis_rotated) { $$.margin = { - top: this.getHorizontalAxisHeight('y2') + this.getCurrentPaddingTop(), - right: hasArc ? 0 : this.getCurrentPaddingRight(), - bottom: this.getHorizontalAxisHeight('y') + legendHeightForBottom + this.getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : this.getCurrentPaddingLeft()) + top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) }; $$.margin2 = { top: $$.margin.top, @@ -791,13 +789,13 @@ }; } else { $$.margin = { - top: 4 + this.getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : this.getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + this.getCurrentPaddingBottom(), - left: hasArc ? 0 : this.getCurrentPaddingLeft() + top: 4 + $$.getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: hasArc ? 0 : $$.getCurrentPaddingLeft() }; $$.margin2 = { - top: this.currentHeight - subchartHeight - legendHeightForBottom, + top: $$.currentHeight - subchartHeight - legendHeightForBottom, right: NaN, bottom: xAxisHeight + legendHeightForBottom, left: $$.margin.left @@ -805,8 +803,8 @@ } // for legend var insetLegendPosition = { - top: $$.isLegendTop ? this.getCurrentPaddingTop() + $$.config.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - this.getCurrentPaddingBottom() - $$.config.legend_inset_y, - left: $$.isLegendLeft ? this.getCurrentPaddingLeft() + $$.config.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - this.getCurrentPaddingRight() - $$.config.legend_inset_x + 0.5 + top: $$.isLegendTop ? $$.getCurrentPaddingTop() + c.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - $$.getCurrentPaddingBottom() - c.legend_inset_y, + left: $$.isLegendLeft ? $$.getCurrentPaddingLeft() + c.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - $$.getCurrentPaddingRight() - c.legend_inset_x + 0.5 }; $$.margin3 = { top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, @@ -820,32 +818,32 @@ 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; + $$.width2 = c.axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width; + $$.height2 = c.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); - this.updateRadius(); + $$.updateRadius(); if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } }; - c3.chart.internal.fn.updateRadius = function () { + c3_chart_internal_fn.updateRadius = function () { var $$ = this; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; - if (this.hasDonutType($$.data.targets) || this.hasGaugeType($$.data.targets)) { + if ($$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets)) { $$.innerRadius = $$.radius * ($$.config.gauge_width ? ($$.radius - $$.config.gauge_width) / $$.radius : 0.6); } else { $$.innerRadius = 0; } }; - c3.chart.internal.fn.updateTargets = function (targets) { + c3_chart_internal_fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS; @@ -958,7 +956,7 @@ .style("opacity", 1); }; - c3.chart.internal.fn.redraw = function (options, transitions) { + c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS, d3 = $$.d3; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; @@ -1672,7 +1670,7 @@ $$.updateZoom(); }; - c3.chart.internal.fn.redrawForBrush = function () { + c3_chart_internal_fn.redrawForBrush = function () { var $$ = this, x = $$.x; $$.redraw({ withTransition: false, @@ -1682,7 +1680,7 @@ }); $$.config.subchart_onbrush.call(c3, x.orgDomain()); }; - c3.chart.internal.fn.redrawForZoom = function () { + c3_chart_internal_fn.redrawForZoom = function () { var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; if (!$$.config.zoom_enabled) { return; @@ -1708,7 +1706,7 @@ } $$.config.zoom_onzoom.call(c3, x.orgDomain()); }; - c3.chart.internal.fn.updateAndRedraw = function (options) { + c3_chart_internal_fn.updateAndRedraw = function (options) { var $$ = this, transitions; options = options || {}; // same with redraw @@ -1721,7 +1719,7 @@ 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) - this.updateSizes(); + $$.updateSizes(); // MEMO: called in updateLegend in redraw if withLegend if (!(options.withLegend && $$.config.legend_show)) { transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.config.transition_duration : 0); @@ -1735,7 +1733,7 @@ $$.redraw(options, transitions); }; - c3.chart.internal.fn.generateEventRectsForSingleX = function (eventRectEnter) { + c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, CLASS = $$.CLASS; eventRectEnter.append("rect") .attr("class", function (d) { return $$.classEvent(d); }) @@ -1859,7 +1857,7 @@ .on("dblclick.zoom", null); }; - c3.chart.internal.fn.generateEventRectsForMultipleXs = function (eventRectEnter) { + c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; eventRectEnter.append('rect') .attr('x', 0) @@ -1953,76 +1951,78 @@ - c3.chart.internal.fn.initialOpacity = function (d) { + c3_chart_internal_fn.initialOpacity = function (d) { var $$ = this; return d.value !== null && $$.withoutFadeIn[d.id] ? 1 : 0; }; - c3.chart.internal.fn.opacityForCircle = function (d) { - return this.isValue(d.value) ? this.isScatterType(d) ? 0.5 : 1 : 0; + c3_chart_internal_fn.opacityForCircle = function (d) { + var $$ = this; + return $$.isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 0; }; - c3.chart.internal.fn.opacityForText = function () { + c3_chart_internal_fn.opacityForText = function () { return this.hasDataLabel() ? 1 : 0; }; - c3.chart.internal.fn.xx = function (d) { - var $$ = this; - return d ? $$.x(d.x) : null; + c3_chart_internal_fn.xx = function (d) { + return d ? this.x(d.x) : null; }; - c3.chart.internal.fn.xv = function (d) { - return Math.ceil($$.x($$.isTimeSeries ? this.parseDate(d.value) : d.value)); + c3_chart_internal_fn.xv = function (d) { + var $$ = this; + return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); }; - c3.chart.internal.fn.yv = function (d) { + 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 ? $$.subX(d.x) : null; + 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; + c3_chart_internal_fn.transformMain = function (withTransition, transitions) { + var $$ = this, CLASS = $$.CLASS, + xAxis, yAxis, y2Axis; if (transitions && transitions.axisX) { xAxis = transitions.axisX; } else { - xAxis = $$.main.select('.' + this.CLASS.axisX); + xAxis = $$.main.select('.' + CLASS.axisX); if (withTransition) { xAxis = xAxis.transition(); } } if (transitions && transitions.axisY) { yAxis = transitions.axisY; } else { - yAxis = $$.main.select('.' + this.CLASS.axisY); + yAxis = $$.main.select('.' + CLASS.axisY); if (withTransition) { yAxis = yAxis.transition(); } } if (transitions && transitions.axisY2) { y2Axis = transitions.axisY2; } else { - y2Axis = $$.main.select('.' + this.CLASS.axisY2); + y2Axis = $$.main.select('.' + CLASS.axisY2); if (withTransition) { y2Axis = y2Axis.transition(); } } (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); xAxis.attr("transform", $$.translate.x); yAxis.attr("transform", $$.translate.y); y2Axis.attr("transform", $$.translate.y2); - $$.main.select('.' + this.CLASS.chartArcs).attr("transform", $$.translate.arc); + $$.main.select('.' + CLASS.chartArcs).attr("transform", $$.translate.arc); }; - c3.chart.internal.fn.transformContext = function (withTransition, transitions) { - var $$ = this.internal, subXAxis; + c3_chart_internal_fn.transformContext = function (withTransition, transitions) { + var $$ = this, subXAxis; if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + this.CLASS.axisX); + subXAxis = $$.context.select('.' + $$.CLASS.axisX); if (withTransition) { subXAxis = subXAxis.transition(); } } $$.context.attr("transform", $$.translate.context); subXAxis.attr("transform", $$.translate.subx); }; - c3.chart.internal.fn.transformLegend = function (withTransition) { + c3_chart_internal_fn.transformLegend = function (withTransition) { var $$ = this; (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); }; - c3.chart.internal.fn.transformAll = function (withTransition, transitions) { + c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); if ($$.config.subchart_show) { $$.transformContext(withTransition, transitions); } @@ -2030,7 +2030,7 @@ }; - c3.chart.internal.fn.updateSvgSize = function () { + c3_chart_internal_fn.updateSvgSize = function () { var $$ = this; $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); $$.svg.select('#' + $$.clipId).select('rect') @@ -2054,7 +2054,7 @@ }; - c3.chart.internal.fn.updateDimension = function () { + c3_chart_internal_fn.updateDimension = function () { var $$ = this; if ($$.config.axis_rotated) { $$.axes.x.call($$.xAxis); @@ -2063,14 +2063,14 @@ $$.axes.y.call($$.yAxis); $$.axes.y2.call($$.y2Axis); } - this.updateSizes(); - this.updateScales(); - this.updateSvgSize(); - this.transformAll(false); + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); + $$.transformAll(false); }; - c3.chart.internal.fn.observeInserted = function (selection) { - var observer = new MutationObserver(function (mutations) { + c3_chart_internal_fn.observeInserted = function (selection) { + var $$ = this, observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' && mutation.previousSibling) { observer.disconnect(); @@ -2079,8 +2079,8 @@ // parentNode will NOT be null when completed if (selection.node().parentNode) { window.clearInterval(interval); - this.updateDimension(); - this.redraw({ + $$.updateDimension(); + $$.redraw({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -2098,7 +2098,7 @@ }; - c3.chart.internal.fn.generateResize = function () { + c3_chart_internal_fn.generateResize = function () { var resizeFunctions = []; function callResizeFunctions() { resizeFunctions.forEach(function (f) { @@ -2113,44 +2113,44 @@ - c3.chart.internal.fn.getCurrentWidth = function () { + c3_chart_internal_fn.getCurrentWidth = function () { var $$ = this; return $$.config.size_width ? $$.config.size_width : $$.getParentWidth(); }; - c3.chart.internal.fn.getCurrentHeight = function () { - var $$ = this, h = $$.config.size_height ? $$.config.size_height : this.getParentHeight(); + c3_chart_internal_fn.getCurrentHeight = function () { + var $$ = this, h = $$.config.size_height ? $$.config.size_height : $$.getParentHeight(); return h > 0 ? h : 320; }; - c3.chart.internal.fn.getCurrentPaddingTop = function () { + c3_chart_internal_fn.getCurrentPaddingTop = function () { var $$ = this; - return this.isValue($$.config.padding_top) ? $$.config.padding_top : 0; + return $$.isValue($$.config.padding_top) ? $$.config.padding_top : 0; }; - c3.chart.internal.fn.getCurrentPaddingBottom = function () { + c3_chart_internal_fn.getCurrentPaddingBottom = function () { var $$ = this; - return this.isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; + return $$.isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; }; - c3.chart.internal.fn.getCurrentPaddingLeft = function () { + c3_chart_internal_fn.getCurrentPaddingLeft = function () { var $$ = this; - if (this.isValue($$.config.padding_left)) { + if ($$.isValue($$.config.padding_left)) { return $$.config.padding_left; } else if ($$.config.axis_rotated) { - return !$$.config.axis_x_show ? 1 : Math.max(this.ceil10(this.getAxisWidthByAxisId('x')), 40); + return !$$.config.axis_x_show ? 1 : Math.max($$.ceil10($$.getAxisWidthByAxisId('x')), 40); } else { - return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : this.ceil10(this.getAxisWidthByAxisId('y')); + return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : $$.ceil10($$.getAxisWidthByAxisId('y')); } }; - c3.chart.internal.fn.getCurrentPaddingRight = function () { - var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? this.getLegendWidth() + 20 : 0; - if (this.isValue($$.config.padding_right)) { + c3_chart_internal_fn.getCurrentPaddingRight = function () { + var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; + if ($$.isValue($$.config.padding_right)) { return $$.config.padding_right + 1; // 1 is needed not to hide tick line } else if ($$.config.axis_rotated) { return defaultPadding + legendWidthOnRight; } else { - return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : this.ceil10(this.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : $$.ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; - c3.chart.internal.fn.getParentRectValue = function (key) { + c3_chart_internal_fn.getParentRectValue = function (key) { var $$ = this, parent = $$.selectChart.node(), v; while (parent && parent.tagName !== 'BODY') { v = parent.getBoundingClientRect()[key]; @@ -2161,16 +2161,16 @@ } return v; }; - c3.chart.internal.fn.getParentWidth = function () { + c3_chart_internal_fn.getParentWidth = function () { return this.getParentRectValue('width'); }; - c3.chart.internal.fn.getParentHeight = function () { + c3_chart_internal_fn.getParentHeight = function () { var h = this.selectChart.style('height'); return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; }; - c3.chart.internal.fn.getSvgLeft = function () { + c3_chart_internal_fn.getSvgLeft = function () { var $$ = this, leftAxisClass = $$.config.axis_rotated ? $$.CLASS.axisX : $$.CLASS.axisY, leftAxis = $$.main.select('.' + leftAxisClass).node(), @@ -2182,11 +2182,11 @@ }; - c3.chart.internal.fn.getAxisWidthByAxisId = function (id) { - var position = this.getAxisLabelPositionById(id); - return position.isInner ? 20 + this.getMaxTickWidth(id) : 40 + this.getMaxTickWidth(id); + c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { + var $$ = this, position = $$.getAxisLabelPositionById(id); + return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); }; - c3.chart.internal.fn.getHorizontalAxisHeight = function (axisId) { + c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { var $$ = this; if (axisId === 'x' && !$$.config.axis_x_show) { return 0; } if (axisId === 'x' && $$.config.axis_x_height) { return $$.config.axis_x_height; } @@ -2195,9 +2195,9 @@ return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; - c3.chart.internal.fn.getEventRectWidth = function () { + c3_chart_internal_fn.getEventRectWidth = function () { var $$ = this; - var target = this.getMaxDataCountTarget($$.data.targets), + var target = $$.getMaxDataCountTarget($$.data.targets), firstData, lastData, base, maxDataCount, ratio, w; if (!target) { return 0; @@ -2207,8 +2207,8 @@ if (base === 0) { return $$.config.axis_rotated ? $$.height : $$.width; } - maxDataCount = this.getMaxDataCount(); - ratio = (this.hasBarType($$.data.targets) ? (maxDataCount - (this.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + maxDataCount = $$.getMaxDataCount(); + ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2217,7 +2217,7 @@ /** * c3.tooltip.js */ - c3.chart.internal.fn.showTooltip = function (selectedData, mouse) { + c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { var $$ = this; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; var forArc = $$.hasArcType($$.data.targets), @@ -2261,45 +2261,45 @@ .style("top", tooltipTop + "px") .style("left", tooltipLeft + 'px'); }; - c3.chart.internal.fn.hideTooltip = function () { - var $$ = this; - $$.tooltip.style("display", "none"); + c3_chart_internal_fn.hideTooltip = function () { + this.tooltip.style("display", "none"); }; /** * c3.grid.js */ - c3.chart.internal.fn.showXGridFocus = function (selectedData) { + c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); if (! $$.config.tooltip_show) { return; } // Hide when scatter plot exists - if (this.hasScatterType($$.data.targets) || this.hasArcType($$.data.targets)) { return; } - var focusEl = $$.main.selectAll('line.' + this.CLASS.xgridFocus); + if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } + var focusEl = $$.main.selectAll('line.' + $$.CLASS.xgridFocus); focusEl .style("visibility", "visible") .data([dataToShow[0]]) .attr($$.config.axis_rotated ? 'y1' : 'x1', function (d) { return $$.xx(d); }) .attr($$.config.axis_rotated ? 'y2' : 'x2', function (d) { return $$.xx(d); }); - this.smoothLines(focusEl, 'grid'); + $$.smoothLines(focusEl, 'grid'); }; - c3.chart.internal.fn.hideXGridFocus = function () { + c3_chart_internal_fn.hideXGridFocus = function () { var $$ = this; $$.main.select('line.' + $$.CLASS.xgridFocus).style("visibility", "hidden"); }; - c3.chart.internal.fn.updateXgridFocus = function () { - var $$ = this; - $$.main.select('line.' + this.CLASS.xgridFocus) - .attr("x1", $$.config.axis_rotated ? 0 : -10) - .attr("x2", $$.config.axis_rotated ? $$.width : -10) - .attr("y1", $$.config.axis_rotated ? -10 : 0) - .attr("y2", $$.config.axis_rotated ? -10 : $$.height); - }; - c3.chart.internal.fn.generateGridData = function (type, scale) { - var gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + this.CLASS.axisX).selectAll('.tick').size(); + c3_chart_internal_fn.updateXgridFocus = function () { + var $$ = this, config = $$.config; + $$.main.select('line.' + $$.CLASS.xgridFocus) + .attr("x1", config.axis_rotated ? 0 : -10) + .attr("x2", config.axis_rotated ? $$.width : -10) + .attr("y1", config.axis_rotated ? -10 : 0) + .attr("y2", config.axis_rotated ? -10 : $$.height); + }; + c3_chart_internal_fn.generateGridData = function (type, scale) { + var $$ = this, + gridData = [], xDomain, firstYear, lastYear, i, + tickNum = $$.main.select("." + $$.CLASS.axisX).selectAll('.tick').size(); if (type === 'year') { - xDomain = this.getXDomain(); + xDomain = $$.getXDomain(); firstYear = xDomain[0].getFullYear(); lastYear = xDomain[1].getFullYear(); for (i = firstYear; i <= lastYear; i++) { @@ -2313,7 +2313,7 @@ } return gridData; }; - c3.chart.internal.fn.getGridFilterToRemove = function (params) { + c3_chart_internal_fn.getGridFilterToRemove = function (params) { return params ? function (line) { var found = false; [].concat(params).forEach(function (param) { @@ -2324,7 +2324,7 @@ return found; } : function () { return true; }; }; - c3.chart.internal.fn.removeGridLines = function (params, forX) { + c3_chart_internal_fn.removeGridLines = function (params, forX) { var $$ = this, CLASS = $$.CLASS, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, @@ -2344,23 +2344,20 @@ /** * c3.legend.js */ - c3.chart.internal.fn.updateLegendStep = function (step) { - var $$ = this; - $$.legendStep = step; + c3_chart_internal_fn.updateLegendStep = function (step) { + this.legendStep = step; }; - c3.chart.internal.fn.updateLegendItemWidth = function (w) { - var $$ = this; - $$.legendItemWidth = w; + c3_chart_internal_fn.updateLegendItemWidth = function (w) { + this.legendItemWidth = w; }; - c3.chart.internal.fn.updateLegendItemHeight = function (h) { - var $$ = this; - $$.legendItemHeight = h; + c3_chart_internal_fn.updateLegendItemHeight = function (h) { + this.legendItemHeight = h; }; - c3.chart.internal.fn.getLegendWidth = function () { + c3_chart_internal_fn.getLegendWidth = function () { var $$ = this; return $$.config.legend_show ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; }; - c3.chart.internal.fn.getLegendHeight = function () { + c3_chart_internal_fn.getLegendHeight = function () { var $$ = this, h = 0; if ($$.config.legend_show) { if ($$.isLegendRight) { @@ -2373,15 +2370,15 @@ } return h; }; - c3.chart.internal.fn.opacityForLegend = function (legendItem) { + c3_chart_internal_fn.opacityForLegend = function (legendItem) { var $$ = this; return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; }; - c3.chart.internal.fn.opacityForUnfocusedLegend = function (legendItem) { + c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; }; - c3.chart.internal.fn.toggleFocusLegend = function (id, focus) { + c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { var $$ = this; $$.legend.selectAll('.' + $$.CLASS.legendItem) .transition().duration(100) @@ -2394,13 +2391,13 @@ } }); }; - c3.chart.internal.fn.revertLegend = function () { + c3_chart_internal_fn.revertLegend = function () { var $$ = this, d3 = $$.d3; $$.legend.selectAll('.' + $$.CLASS.legendItem) .transition().duration(100) .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; - c3.chart.internal.fn.showLegend = function (targetIds) { + c3_chart_internal_fn.showLegend = function (targetIds) { var $$ = this; if (!$$.config.legend_show) { $$.config.legend_show = true; @@ -2412,7 +2409,7 @@ .transition() .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); }; - c3.chart.internal.fn.hideLegend = function (targetIds) { + c3_chart_internal_fn.hideLegend = function (targetIds) { var $$ = this; if ($$.config.legend_show && $$.isEmpty(targetIds)) { $$.config.legend_show = false; @@ -2423,13 +2420,13 @@ .style('opacity', 0) .style('visibility', 'hidden'); }; - c3.chart.internal.fn.updateLegend = function (targetIds, options, transitions) { - var $$ = this; + c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { + var $$ = this, CLASS = $$.CLASS; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + $$.CLASS.legendItemFocused).size(); + var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); var texts, rects, tiles; options = options || {}; @@ -2437,7 +2434,7 @@ withTransitionForTransform = $$.getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, $$.CLASS.legendItem), + var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, @@ -2512,17 +2509,17 @@ yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; // Define g for legend area - l = $$.legend.selectAll('.' + $$.CLASS.legendItem) + l = $$.legend.selectAll('.' + CLASS.legendItem) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return $$.generateClass($$.CLASS.legendItem, id); }) + .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { typeof $$.config.legend_item_onclick === 'function' ? $$.config.legend_item_onclick.call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { - $$.d3.select(this).classed($$.CLASS.legendItemFocused, true); + $$.d3.select(this).classed(CLASS.legendItemFocused, true); if (!$$.transiting) { $$.api.focus(id); } @@ -2531,7 +2528,7 @@ } }) .on('mouseout', function (id) { - $$.d3.select(this).classed($$.CLASS.legendItemFocused, false); + $$.d3.select(this).classed(CLASS.legendItemFocused, false); if (!$$.transiting) { $$.api.revert(); } @@ -2546,12 +2543,12 @@ .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); l.append('rect') - .attr("class", $$.CLASS.legendItemEvent) + .attr("class", CLASS.legendItemEvent) .style('fill-opacity', 0) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); l.append('rect') - .attr("class", $$.CLASS.legendItemTile) + .attr("class", CLASS.legendItemTile) .style("pointer-events", "none") .style('fill', $$.color) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2560,8 +2557,8 @@ .attr('height', 10); // Set background for inset legend if ($$.isLegendInset && maxWidth !== 0) { - $$.legend.insert('g', '.' + $$.CLASS.legendItem) - .attr("class", $$.CLASS.legendBackground) + $$.legend.insert('g', '.' + CLASS.legendItem) + .attr("class", CLASS.legendBackground) .append('rect') .attr('height', $$.getLegendHeight() - 10) .attr('width', maxWidth * (step + 1) + 10); @@ -2575,7 +2572,7 @@ .attr('x', xForLegendText) .attr('y', yForLegendText); - rects = $$.legend.selectAll('rect.' + $$.CLASS.legendItemEvent) + rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent) .data(targetIds); (withTransition ? rects.transition() : rects) .attr('width', function (id) { return widths[id]; }) @@ -2583,7 +2580,7 @@ .attr('x', xForLegendRect) .attr('y', yForLegendRect); - tiles = $$.legend.selectAll('rect.' + $$.CLASS.legendItemTile) + tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) .data(targetIds); (withTransition ? tiles.transition() : tiles) .style('fill', $$.color) @@ -2591,13 +2588,13 @@ .attr('y', yForLegend); // toggle legend state - $$.legend.selectAll('.' + $$.CLASS.legendItem) - .classed($$.CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) + $$.legend.selectAll('.' + CLASS.legendItem) + .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) .transition() .style('opacity', function (id) { var This = $$.d3.select(this); if ($$.isTargetToShow(id)) { - return !hasFocused || This.classed($$.CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + return !hasFocused || This.classed(CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); } else { return $$.legendOpacityForHidden; } @@ -2618,104 +2615,107 @@ - c3.chart.internal.fn.getClipPath = function (id) { + c3_chart_internal_fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; }; - c3.chart.internal.fn.getAxisClipX = function (forHorizontal) { - var $$ = this; + c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { // axis line width + padding for left - return forHorizontal ? -(1 + 30) : -($$.margin.left - 1); + return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); }; - c3.chart.internal.fn.getAxisClipY = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { return forHorizontal ? -20 : -4; }; - c3.chart.internal.fn.getXAxisClipX = function () { + c3_chart_internal_fn.getXAxisClipX = function () { var $$ = this; return $$.getAxisClipX(!$$.config.axis_rotated); }; - c3.chart.internal.fn.getXAxisClipY = function () { + c3_chart_internal_fn.getXAxisClipY = function () { var $$ = this; - return this.getAxisClipY(!$$.config.axis_rotated); + return $$.getAxisClipY(!$$.config.axis_rotated); }; - c3.chart.internal.fn.getYAxisClipX = function () { + c3_chart_internal_fn.getYAxisClipX = function () { var $$ = this; - return this.getAxisClipX($$.config.axis_rotated); + return $$.getAxisClipX($$.config.axis_rotated); }; - c3.chart.internal.fn.getYAxisClipY = function () { + c3_chart_internal_fn.getYAxisClipY = function () { var $$ = this; - return this.getAxisClipY($$.config.axis_rotated); + return $$.getAxisClipY($$.config.axis_rotated); }; - c3.chart.internal.fn.getAxisClipWidth = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { var $$ = this; // width + axis line width + padding for left/right return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; - c3.chart.internal.fn.getAxisClipHeight = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { var $$ = this; return forHorizontal ? ($$.config.axis_x_height ? $$.config.axis_x_height : 0) + 80 : $$.height + 8; }; - c3.chart.internal.fn.getXAxisClipWidth = function () { + c3_chart_internal_fn.getXAxisClipWidth = function () { var $$ = this; - return this.getAxisClipWidth(!$$.config.axis_rotated); + return $$.getAxisClipWidth(!$$.config.axis_rotated); }; - c3.chart.internal.fn.getXAxisClipHeight = function () { + c3_chart_internal_fn.getXAxisClipHeight = function () { var $$ = this; - return this.getAxisClipHeight(!$$.config.axis_rotated); + return $$.getAxisClipHeight(!$$.config.axis_rotated); }; - c3.chart.internal.fn.getYAxisClipWidth = function () { + c3_chart_internal_fn.getYAxisClipWidth = function () { var $$ = this; - return this.getAxisClipWidth($$.config.axis_rotated); + return $$.getAxisClipWidth($$.config.axis_rotated); }; - c3.chart.internal.fn.getYAxisClipHeight = function () { + c3_chart_internal_fn.getYAxisClipHeight = function () { var $$ = this; - return this.getAxisClipHeight($$.config.axis_rotated); + return $$.getAxisClipHeight($$.config.axis_rotated); }; /** * $$.data.js */ - c3.chart.internal.fn.isX = function (key) { - var $$ = this; - return ($$.config.data_x && key === $$.config.data_x) || (this.notEmpty($$.config.data_xs) && this.hasValue($$.config.data_xs, key)); + c3_chart_internal_fn.isX = function (key) { + var $$ = this, c = $$.config; + return (c.data_x && key === c.data_x) || ($$.notEmpty(c.data_xs) && $$.hasValue(c.data_xs, key)); }; - c3.chart.internal.fn.isNotX = function (key) { + c3_chart_internal_fn.isNotX = function (key) { return !this.isX(key); }; - c3.chart.internal.fn.getXKey = function (id) { - var $$ = this; - return $$.config.data_x ? $$.config.data_x : this.notEmpty($$.config.data_xs) ? $$.config.data_xs[id] : null; + c3_chart_internal_fn.getXKey = function (id) { + var $$ = this, c = $$.config; + return c.data_x ? c.data_x : this.notEmpty(c.data_xs) ? c.data_xs[id] : null; }; - c3.chart.internal.fn.getXValuesOfXKey = function (key, targets) { - var xValues, ids = targets && this.notEmpty(targets) ? mapToIds(targets) : []; + c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { + var $$ = this, + xValues, ids = targets && $$.notEmpty(targets) ? $$.mapToIds(targets) : []; ids.forEach(function (id) { - if (this.getXKey(id) === key) { + if ($$.getXKey(id) === key) { xValues = $$.data.xs[id]; } }); return xValues; }; - c3.chart.internal.fn.getXValue = function (id, i) { - return id in $$.data.xs && $$.data.xs[id] && this.isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; + c3_chart_internal_fn.getXValue = function (id, i) { + var $$ = this; + return id in $$.data.xs && $$.data.xs[id] && $$.isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; }; - c3.chart.internal.fn.getOtherTargetXs = function () { - var idsForX = Object.keys($$.data.xs); + c3_chart_internal_fn.getOtherTargetXs = function () { + var $$ = this, + idsForX = Object.keys($$.data.xs); return idsForX.length ? $$.data.xs[idsForX[0]] : null; }; - c3.chart.internal.fn.getOtherTargetX = function (index) { + c3_chart_internal_fn.getOtherTargetX = function (index) { var xs = this.getOtherTargetXs(); return xs && index < xs.length ? xs[index] : null; }; - c3.chart.internal.fn.addXs = function (xs) { + c3_chart_internal_fn.addXs = function (xs) { + var $$ = this; Object.keys(xs).forEach(function (id) { $$.config.data_xs[id] = xs[id]; }); }; - c3.chart.internal.fn.isSingleX = function (xs) { - return $$.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; + c3_chart_internal_fn.isSingleX = function (xs) { + return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; }; - c3.chart.internal.fn.addName = function (data) { + c3_chart_internal_fn.addName = function (data) { var $$ = this, name; if (data) { name = $$.config.data_names[data.id]; @@ -2723,26 +2723,28 @@ } return data; }; - c3.chart.internal.fn.getValueOnIndex = function (values, index) { + c3_chart_internal_fn.getValueOnIndex = function (values, index) { var valueOnIndex = values.filter(function (v) { return v.index === index; }); return valueOnIndex.length ? valueOnIndex[0] : null; }; - c3.chart.internal.fn.updateTargetX = function (targets, x) { + c3_chart_internal_fn.updateTargetX = function (targets, x) { + var $$ = this; targets.forEach(function (t) { t.values.forEach(function (v, i) { - v.x = generateTargetX(x[i], t.id, i); + v.x = $$.generateTargetX(x[i], t.id, i); }); $$.data.xs[t.id] = x; }); }; - c3.chart.internal.fn.updateTargetXs = function (targets, xs) { + c3_chart_internal_fn.updateTargetXs = function (targets, xs) { + var $$ = this; targets.forEach(function (t) { if (xs[t.id]) { - this.updateTargetX([t], xs[t.id]); + $$.updateTargetX([t], xs[t.id]); } }); }; - c3.chart.internal.fn.generateTargetX = function (rawX, id, index) { + c3_chart_internal_fn.generateTargetX = function (rawX, id, index) { var $$ = this, x; if ($$.isTimeSeries) { x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); @@ -2755,19 +2757,19 @@ } return x; }; - c3.chart.internal.fn.convertUrlToData = function (url, mimeType, keys, done) { - var type = mimeType ? mimeType : 'csv'; + c3_chart_internal_fn.convertUrlToData = function convertUrlToData(url, mimeType, keys, done) { + var $$ = this, type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; if (type === 'json') { - d = this.convertJsonToData(JSON.parse(data.response), keys); + d = $$.convertJsonToData(JSON.parse(data.response), keys); } else { - d = this.convertCsvToData(data.response); + d = $$.convertCsvToData(data.response); } done(d); }); }; - c3.chart.internal.fn.cloneTarget = function (target) { + c3_chart_internal_fn.cloneTarget = function (target) { return { id : target.id, id_org : target.id_org, @@ -2776,19 +2778,19 @@ }) }; }; - c3.chart.internal.fn.getPrevX = function (i) { - var value = this.getValueOnIndex($$.data.targets[0].values, i - 1); + c3_chart_internal_fn.getPrevX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); return value ? value.x : null; }; - c3.chart.internal.fn.getNextX = function (i) { - var value = this.getValueOnIndex($$.data.targets[0].values, i + 1); + c3_chart_internal_fn.getNextX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); return value ? value.x : null; }; - c3.chart.internal.fn.getMaxDataCount = function () { + c3_chart_internal_fn.getMaxDataCount = function () { var $$ = this; return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); }; - c3.chart.internal.fn.getMaxDataCountTarget = function (targets) { + c3_chart_internal_fn.getMaxDataCountTarget = function (targets) { var length = targets.length, max = 0, maxTarget; if (length > 1) { targets.forEach(function (t) { @@ -2802,7 +2804,7 @@ } return maxTarget; }; - c3.chart.internal.fn.getEdgeX = function (targets) { + c3_chart_internal_fn.getEdgeX = function (targets) { var target = this.getMaxDataCountTarget(targets), firstData, lastData; if (!target) { return [0, 0]; @@ -2810,13 +2812,14 @@ firstData = target.values[0], lastData = target.values[target.values.length - 1]; return [firstData.x, lastData.x]; }; - c3.chart.internal.fn.mapToIds = function (targets) { + c3_chart_internal_fn.mapToIds = function (targets) { return targets.map(function (d) { return d.id; }); }; - c3.chart.internal.fn.mapToTargetIds = function (ids) { - return ids ? (typeof ids === 'string' ? [ids] : ids) : mapToIds($$.data.targets); + c3_chart_internal_fn.mapToTargetIds = function (ids) { + var $$ = this; + return ids ? (typeof ids === 'string' ? [ids] : ids) : $$.mapToIds($$.data.targets); }; - c3.chart.internal.fn.hasTarget = function (targets, id) { + c3_chart_internal_fn.hasTarget = function (targets, id) { var ids = this.mapToIds(targets), i; for (i = 0; i < ids.length; i++) { if (ids[i] === id) { @@ -2825,38 +2828,34 @@ } return false; }; - c3.chart.internal.fn.isTargetToShow = function (targetId) { + c3_chart_internal_fn.isTargetToShow = function (targetId) { return this.hiddenTargetIds.indexOf(targetId) < 0; }; - c3.chart.internal.fn.isLegendToShow = function (targetId) { + c3_chart_internal_fn.isLegendToShow = function (targetId) { return this.hiddenLegendIds.indexOf(targetId) < 0; }; - c3.chart.internal.fn.filterTargetsToShow = function (targets) { + c3_chart_internal_fn.filterTargetsToShow = function (targets) { var $$ = this; return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); }; - c3.chart.internal.fn.mapTargetsToUniqueXs = function (targets) { + c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { var $$ = this; var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); }; - c3.chart.internal.fn.addHiddenTargetIds = function (targetIds) { - var $$ = this; - $$.hiddenTargetIds = $$.hiddenTargetIds.concat(targetIds); + c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); }; - c3.chart.internal.fn.removeHiddenTargetIds = function (targetIds) { - var $$ = this; - $$.hiddenTargetIds = $$.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3.chart.internal.fn.addHiddenLegendIds = function (targetIds) { - var $$ = this; - $$.hiddenLegendIds = $$.hiddenLegendIds.concat(targetIds); + c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); }; - c3.chart.internal.fn.removeHiddenLegendIds = function (targetIds) { - var $$ = this; - $$.hiddenLegendIds = $$.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3.chart.internal.fn.getValuesAsIdKeyed = function (targets) { + c3_chart_internal_fn.getValuesAsIdKeyed = function (targets) { var ys = {}; targets.forEach(function (t) { ys[t.id] = []; @@ -2866,7 +2865,7 @@ }); return ys; }; - c3.chart.internal.fn.checkValueInTargets = function (targets, checker) { + c3_chart_internal_fn.checkValueInTargets = function (targets, checker) { var ids = Object.keys(targets), i, j, values; for (i = 0; i < ids.length; i++) { values = targets[ids[i]].values; @@ -2878,21 +2877,21 @@ } return false; }; - c3.chart.internal.fn.hasNegativeValueInTargets = function (targets) { + c3_chart_internal_fn.hasNegativeValueInTargets = function (targets) { return this.checkValueInTargets(targets, function (v) { return v < 0; }); }; - c3.chart.internal.fn.hasPositiveValueInTargets = function (targets) { + c3_chart_internal_fn.hasPositiveValueInTargets = function (targets) { return this.checkValueInTargets(targets, function (v) { return v > 0; }); }; - c3.chart.internal.fn.isOrderDesc = function () { - var $$ = this; - return $$.config.data_order && $$.config.data_order.toLowerCase() === 'desc'; + c3_chart_internal_fn.isOrderDesc = function () { + var c = this.config; + return c.data_order && c.data_order.toLowerCase() === 'desc'; }; - c3.chart.internal.fn.isOrderAsc = function () { - var $$ = this; - return $$.config.data_order && $$.config.data_order.toLowerCase() === 'asc'; + c3_chart_internal_fn.isOrderAsc = function () { + var c = this.config; + return c.data_order && c.data_order.toLowerCase() === 'asc'; }; - c3.chart.internal.fn.orderTargets = function (targets) { + c3_chart_internal_fn.orderTargets = function (targets) { var $$ = this, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); if (orderAsc || orderDesc) { targets.sort(function (t1, t2) { @@ -2906,61 +2905,61 @@ } // TODO: accept name array for order return targets; }; - c3.chart.internal.fn.filterSameX = function (targets, x) { - return $$.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); + c3_chart_internal_fn.filterSameX = function (targets, x) { + return this.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); }; - c3.chart.internal.fn.filterRemoveNull = function (data) { + c3_chart_internal_fn.filterRemoveNull = function (data) { var $$ = this; return data.filter(function (d) { return $$.isValue(d.value); }); }; - c3.chart.internal.fn.hasDataLabel = function () { - var $$ = this; - if (typeof $$.config.data_labels === 'boolean' && $$.config.data_labels) { + c3_chart_internal_fn.hasDataLabel = function () { + var $$ = this, c = $$.config; + if (typeof c.data_labels === 'boolean' && c.data_labels) { return true; - } else if (typeof $$.config.data_labels === 'object' && this.notEmpty($$.config.data_labels)) { + } else if (typeof c.data_labels === 'object' && $$.notEmpty(c.data_labels)) { return true; } return false; }; - c3.chart.internal.fn.getDataLabelLength = function (min, max, axisId, key) { - var lengths = [0, 0], paddingCoef = 1.3; + c3_chart_internal_fn.getDataLabelLength = function (min, max, axisId, key) { + var $$ = this, + lengths = [0, 0], paddingCoef = 1.3; $$.selectChart.select('svg').selectAll('.dummy') .data([min, max]) .enter().append('text') - .text(function (d) { return this.formatByAxisId(axisId)(d); }) + .text(function (d) { return $$.formatByAxisId(axisId)(d); }) .each(function (d, i) { lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; }) .remove(); return lengths; }; - c3.chart.internal.fn.isNoneArc = function (d) { - var $$ = this; - return $$.hasTarget($$.data.targets, d.id); + c3_chart_internal_fn.isNoneArc = function (d) { + return this.hasTarget(this.data.targets, d.id); }; - c3.chart.internal.fn.isArc = function (d) { - var $$ = this; - return 'data' in d && $$.hasTarget($$.data.targets, d.data.id); + c3_chart_internal_fn.isArc = function (d) { + return 'data' in d && this.hasTarget(this.data.targets, d.data.id); }; /** * c3.data.convert.js */ - c3.chart.internal.fn.convertCsvToData = function (csv) { - var rows = $$.d3.csv.parseRows(csv), d; + c3_chart_internal_fn.convertCsvToData = function (csv) { + var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; rows[0].forEach(function (id) { d[0][id] = null; }); } else { - d = $$.d3.csv.parse(csv); + d = d3.csv.parse(csv); } return d; }; - c3.chart.internal.fn.convertJsonToData = function (json, keys) { - var new_rows = [], targetKeys, data; + c3_chart_internal_fn.convertJsonToData = function (json, keys) { + var $$ = this, + new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects targetKeys = keys.value; if (keys.x) { @@ -2977,16 +2976,16 @@ }); new_rows.push(new_row); }); - data = this.convertRowsToData(new_rows); + data = $$.convertRowsToData(new_rows); } else { Object.keys(json).forEach(function (key) { new_rows.push([key].concat(json[key])); }); - data = this.convertColumnsToData(new_rows); + data = $$.convertColumnsToData(new_rows); } return data; }; - c3.chart.internal.fn.convertRowsToData = function (rows) { + c3_chart_internal_fn.convertRowsToData = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; @@ -2997,12 +2996,12 @@ } return new_rows; }; - c3.chart.internal.fn.convertColumnsToData = function (columns) { + c3_chart_internal_fn.convertColumnsToData = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; for (j = 1; j < columns[i].length; j++) { - if (this.isUndefined(new_rows[j - 1])) { + if (typeof new_rows[j - 1] === 'undefined') { new_rows[j - 1] = {}; } new_rows[j - 1][key] = columns[i][j]; @@ -3010,9 +3009,9 @@ } return new_rows; }; - c3.chart.internal.fn.convertDataToTargets = function (data, appendXs) { - var $$ = this; - var ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), + c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { + var $$ = this, c = $$.config, + ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), targets; @@ -3025,23 +3024,23 @@ if (xs.indexOf(xKey) >= 0) { $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( data.map(function (d) { return d[xKey]; }) - .filter(this.isValue) - .map(function (rawX, i) { return this.generateTargetX(rawX, id, i); }) + .filter($$.isValue) + .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }) ); } // if not included in input data, find from preloaded data of other id's x - else if ($$.config.data_x) { - $$.data.xs[id] = this.getOtherTargetXs(); + else if (c.data_x) { + $$.data.xs[id] = $$.getOtherTargetXs(); } // if not included in input data, find from preloaded data - else if (this.notEmpty($$.config.data_xs)) { - $$.data.xs[id] = this.getXValuesOfXKey(xKey, $$.data.targets); + else if ($$.notEmpty(c.data_xs)) { + $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used } else { $$.data.xs[id] = data.map(function (d, i) { return i; }); } - }, this); + }); // check x is defined ids.forEach(function (id) { @@ -3052,7 +3051,7 @@ // convert to target targets = ids.map(function (id, index) { - var convertedId = $$.config.data_id_converter(id); + var convertedId = c.data_id_converter(id); return { id: convertedId, id_org: id, @@ -3060,8 +3059,8 @@ var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); // use x as categories if custom x and categorized if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { - if (i === 0) { $$.config.axis_x_categories = []; } - $$.config.axis_x_categories.push(rawX); + if (i === 0) { c.axis_x_categories = []; } + c.axis_x_categories.push(rawX); } // mark as x = undefined if value is undefined and filter to remove after mapped if (typeof d[id] === 'undefined' || $$.data.xs[id].length <= i) { @@ -3093,8 +3092,8 @@ }); // set target types - if ($$.config.data_type) { - this.setTargetType(this.mapToIds(targets).filter(function (id) { return ! (id in $$.config.data_types); }), $$.config.data_type); + if (c.data_type) { + $$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in c.data_types); }), c.data_type); } // cache as original id keyed @@ -3108,7 +3107,7 @@ /** * c3.data.load.js */ - c3.chart.internal.fn.load = function (targets, args) { + c3_chart_internal_fn.load = function (targets, args) { var $$ = this; if (targets) { // filter loading targets if needed @@ -3144,7 +3143,7 @@ args.done(); } }; - c3.chart.internal.fn.loadFromArgs = function (args) { + c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; if (args.data) { $$.load($$.convertDataToTargets(args.data), args); @@ -3167,7 +3166,7 @@ $$.load(null, args); } }; - c3.chart.internal.fn.unload = function (targetIds, done) { + c3_chart_internal_fn.unload = function (targetIds, done) { var $$ = this; if (typeof done !== 'function') { done = function () {}; @@ -3200,24 +3199,24 @@ /** * c3.data.category.js */ - c3.chart.internal.fn.categoryName = function (i) { - var $$ = this; - return i < $$.config.axis_x_categories.length ? $$.config.axis_x_categories[i] : i; + c3_chart_internal_fn.categoryName = function (i) { + var c = this.config; + return i < c.axis_x_categories.length ? c.axis_x_categories[i] : i; }; /** * c3.shape.js */ - c3.chart.internal.fn.getShapeIndices = function (typeFilter) { - var $$ = this; - var indices = {}, i = 0, j, k; + c3_chart_internal_fn.getShapeIndices = function (typeFilter) { + var $$ = this, c = $$.config, + indices = {}, i = 0, j, k; $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { - for (j = 0; j < $$.config.data_groups.length; j++) { - if ($$.config.data_groups[j].indexOf(d.id) < 0) { continue; } - for (k = 0; k < $$.config.data_groups[j].length; k++) { - if ($$.config.data_groups[j][k] in indices) { - indices[d.id] = indices[$$.config.data_groups[j][k]]; + for (j = 0; j < c.data_groups.length; j++) { + if (c.data_groups[j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < c.data_groups[j].length; k++) { + if (c.data_groups[j][k] in indices) { + indices[d.id] = indices[c.data_groups[j][k]]; break; } } @@ -3227,21 +3226,21 @@ indices.__max__ = i - 1; return indices; }; - c3.chart.internal.fn.getShapeX = function (offset, targetsNum, indices, isSub) { + c3_chart_internal_fn.getShapeX = function (offset, targetsNum, indices, isSub) { var $$ = this, scale = isSub ? $$.subX : $$.x; return function (d) { var index = d.id in indices ? indices[d.id] : 0; return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; }; }; - c3.chart.internal.fn.getShapeY = function (isSub) { + c3_chart_internal_fn.getShapeY = function (isSub) { var $$ = this; return function (d) { var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); return scale(d.value); }; }; - c3.chart.internal.fn.getShapeOffset = function (typeFilter, indices, isSub) { + c3_chart_internal_fn.getShapeOffset = function (typeFilter, indices, isSub) { var $$ = this, targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), targetIds = targets.map(function (t) { return t.id; }); @@ -3258,68 +3257,70 @@ }; }; - c3.chart.internal.fn.getInterpolate = function (d) { + c3_chart_internal_fn.getInterpolate = function (d) { var $$ = this; return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; - c3.chart.internal.fn.circleX = function (d) { - var $$ = this; - return d.x || d.x === 0 ? $$.x(d.x) : null; + c3_chart_internal_fn.circleX = function (d) { + return d.x || d.x === 0 ? this.x(d.x) : null; }; - c3.chart.internal.fn.circleY = function (d, i) { - var $$ = this, lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + c3_chart_internal_fn.circleY = function (d, i) { + var $$ = this, + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; - c3.chart.internal.fn.getCircles = function (i, id) { + c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); }; - c3.chart.internal.fn.expandCircles = function (i, id) { + c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; $$.getCircles(i, id) .classed(CLASS.EXPANDED, true) .attr('r', function (d) { return $$.pointExpandedR(d); }); }; - c3.chart.internal.fn.unexpandCircles = function (i) { + c3_chart_internal_fn.unexpandCircles = function (i) { var $$ = this, CLASS = $$.CLASS; $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) .classed(CLASS.EXPANDED, false) .attr('r', function (d) { return $$.pointR(d); }); }; - c3.chart.internal.fn.pointR = function (d) { + c3_chart_internal_fn.pointR = function (d) { var $$ = this; return $$.config.point_show && !$$.isStepType(d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; }; - c3.chart.internal.fn.pointExpandedR = function (d) { - var $$ = this; - return $$.config.point_focus_expand_enabled ? ($$.config.point_focus_expand_r ? $$.config.point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); + c3_chart_internal_fn.pointExpandedR = function (d) { + var $$ = this, c = $$.config; + return c.point_focus_expand_enabled ? (c.point_focus_expand_r ? c.point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); }; - c3.chart.internal.fn.pointSelectR = function (d) { - var $$ = this; - return $$.config.point_select_r ? $$.config.point_select_r : $$.pointR(d) * 4; + c3_chart_internal_fn.pointSelectR = function (d) { + var $$ = this, c = $$.config; + return c.point_select_r ? c.point_select_r : $$.pointR(d) * 4; }; - c3.chart.internal.fn.getBarW = function (axis, barTargetsNum) { - var $$ = this; - return typeof $$.config.bar_width === 'number' ? $$.config.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * $$.config.bar_width_ratio) / barTargetsNum : 0; + c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { + var $$ = this, c = $$.config; + return typeof c.bar_width === 'number' ? c.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * c.bar_width_ratio) / barTargetsNum : 0; }; - c3.chart.internal.fn.getBars = function (i) { + c3_chart_internal_fn.getBars = function (i) { var $$ = this; - return $$.main.selectAll('.' + this.CLASS.bar + (this.isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + $$.CLASS.bar + ($$.isValue(i) ? '-' + i : '')); }; - c3.chart.internal.fn.expandBars = function (i) { - this.getBars(i).classed(this.CLASS.EXPANDED, true); + c3_chart_internal_fn.expandBars = function (i) { + var $$ = this; + $$.getBars(i).classed($$.CLASS.EXPANDED, true); }; - c3.chart.internal.fn.unexpandBars = function (i) { - this.getBars(i).classed(this.CLASS.EXPANDED, false); + c3_chart_internal_fn.unexpandBars = function (i) { + var $$ = this; + $$.getBars(i).classed($$.CLASS.EXPANDED, false); }; - c3.chart.internal.fn.generateDrawBar = function (barIndices, isSub) { - var $$ = this, getPoints = this.generateGetBarPoints(barIndices, isSub); + c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { + var $$ = this, getPoints = $$.generateGetBarPoints(barIndices, isSub); return function (d, i) { // 4 points that make a bar var points = getPoints(d, i); @@ -3337,7 +3338,7 @@ return path; }; }; - c3.chart.internal.fn.generateGetBarPoints = function (barIndices, isSub) { + c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { var $$ = this, barTargetsNum = barIndices.__max__ + 1, barW = $$.getBarW($$.xAxis, barTargetsNum), @@ -3363,7 +3364,7 @@ }; }; - c3.chart.internal.fn.generateDrawArea = function (areaIndices, isSub) { + c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { var $$ = this, area = $$.d3.svg.area(), getPoint = $$.generateGetAreaPoint(areaIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, @@ -3392,8 +3393,9 @@ }; }; - c3.chart.internal.fn.generateDrawLine = function (lineIndices, isSub) { - var $$ = this, line = $$.d3.svg.line(), + c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { + var $$ = this, + line = $$.d3.svg.line(), getPoint = $$.generateGetLinePoint(lineIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, @@ -3423,34 +3425,37 @@ }; }; - c3.chart.internal.fn.generateXYForText = function (barIndices, forX) { - var getPoints = this.generateGetBarPoints(barIndices, false), - getter = forX ? this.getXForText : this.getYForText; + c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { + var $$ = this, + getPoints = $$.generateGetBarPoints(barIndices, false), + getter = forX ? $$.getXForText : $$.getYForText; return function (d, i) { return getter(getPoints(d, i), d, this); }; }; - c3.chart.internal.fn.getXForText = function (points, d, textElement) { - var box = textElement.getBoundingClientRect(), xPos, padding; + c3_chart_internal_fn.getXForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), xPos, padding; if ($$.config.axis_rotated) { - padding = this.isBarType(d) ? 4 : 6; + padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; } return xPos > $$.width ? $$.width - box.width : xPos; }; - c3.chart.internal.fn.getYForText = function (points, d, textElement) { - var box = textElement.getBoundingClientRect(), yPos; + c3_chart_internal_fn.getYForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), yPos; if ($$.config.axis_rotated) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { - yPos = points[2][1] + (d.value < 0 ? box.height : this.isBarType(d) ? -3 : -6); + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); } return yPos < box.height ? box.height : yPos; }; - c3.chart.internal.fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, areaTargetsNum = areaIndices.__max__ + 1, x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), @@ -3473,7 +3478,7 @@ }; }; - c3.chart.internal.fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, lineTargetsNum = lineIndices.__max__ + 1, x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), @@ -3496,26 +3501,27 @@ }; - c3.chart.internal.fn.lineWithRegions = function (d, x, y, _regions) { - var prev = -1, i, j; - var s = "M", sWithRegion; - var xp, yp, dx, dy, dd, diff, diffx2; - var xValue, yValue; - var regions = []; + c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { + var $$ = this, + prev = -1, i, j, + s = "M", sWithRegion, + xp, yp, dx, dy, dd, diff, diffx2, + xValue, yValue, + regions = []; // Check start/end of regions - if (this.isDefined(_regions)) { + if ($$.isDefined(_regions)) { for (i = 0; i < _regions.length; i++) { regions[i] = {}; - if (this.isUndefined(_regions[i].start)) { + if ($$.isUndefined(_regions[i].start)) { regions[i].start = d[0].x; } else { - regions[i].start = $$.isTimeSeries ? this.parseDate(_regions[i].start) : _regions[i].start; + regions[i].start = $$.isTimeSeries ? $$.parseDate(_regions[i].start) : _regions[i].start; } - if (this.isUndefined(_regions[i].end)) { + if ($$.isUndefined(_regions[i].end)) { regions[i].end = d[d.length - 1].x; } else { - regions[i].end = $$.isTimeSeries ? this.parseDate(_regions[i].end) : _regions[i].end; + regions[i].end = $$.isTimeSeries ? $$.parseDate(_regions[i].end) : _regions[i].end; } } } @@ -3542,13 +3548,13 @@ for (i = 0; i < d.length; i++) { // Draw as normal - if (this.isUndefined(regions) || ! this.isWithinRegions(d[i].x, regions)) { + if ($$.isUndefined(regions) || ! $$.isWithinRegions(d[i].x, regions)) { s += " " + xValue(d[i]) + " " + yValue(d[i]); } // Draw with region // TODO: Fix for horizotal charts else { - xp = this.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); - yp = this.getScale(d[i - 1].value, d[i].value); + xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); + yp = $$.getScale(d[i - 1].value, d[i].value); dx = x(d[i].x) - x(d[i - 1].x); dy = y(d[i].value) - y(d[i - 1].value); @@ -3568,19 +3574,21 @@ - c3.chart.internal.fn.isWithinCircle = function (_this, _r) { - var mouse = $$.d3.mouse(_this), d3_this = $$.d3.select(_this); - var cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; + c3_chart_internal_fn.isWithinCircle = function (_this, _r) { + var d3 = this.d3, + mouse = d3.mouse(_this), d3_this = d3.select(_this), + cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; - c3.chart.internal.fn.isWithinBar = function (_this) { - var mouse = $$.d3.mouse(_this), box = _this.getBoundingClientRect(), - seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1); - var x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2; - var sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; + c3_chart_internal_fn.isWithinBar = function (_this) { + var d3 = this.d3, + mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), + seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), + x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, + sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; }; - c3.chart.internal.fn.isWithinRegions = function (x, regions) { + c3_chart_internal_fn.isWithinRegions = function (x, regions) { var i; for (i = 0; i < regions.length; i++) { if (regions[i].start < x && x <= regions[i].end) { return true; } @@ -3591,7 +3599,7 @@ - c3.chart.internal.fn.findSameXOfValues = function (values, index) { + c3_chart_internal_fn.findSameXOfValues = function (values, index) { var i, targetX = values[index].x, sames = []; for (i = index - 1; i >= 0; i--) { if (targetX !== values[i].x) { break; } @@ -3604,8 +3612,9 @@ return sames; }; - c3.chart.internal.fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x - var min = _min ? _min : 0, + c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + var $$ = this, + min = _min ? _min : 0, max = _max ? _max : values.length - 1, med = Math.floor((max - min) / 2) + min, value = values[med], @@ -3621,33 +3630,33 @@ // Get candidates that has same min and max index candidates = []; if (values[min].x || values[min].x === 0) { - candidates = candidates.concat(this.findSameXOfValues(values, min)); + candidates = candidates.concat($$.findSameXOfValues(values, min)); } if (values[max].x || values[max].x === 0) { - candidates = candidates.concat(this.findSameXOfValues(values, max)); + candidates = candidates.concat($$.findSameXOfValues(values, max)); } // Determine the closest and return - return this.findClosest(candidates, pos); + return $$.findClosest(candidates, pos); } - return this.findClosestOfValues(values, pos, min, max); + return $$.findClosestOfValues(values, pos, min, max); }; - c3.chart.internal.fn.findClosestFromTargets = function (targets, pos) { - var candidates; + c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { + var $$ = this, candidates; // map to array of closest points of each target candidates = targets.map(function (target) { - return this.findClosestOfValues(target.values, pos); + return $$.findClosestOfValues(target.values, pos); }); // decide closest point and return - return this.findClosest(candidates, pos); + return $$.findClosest(candidates, pos); }; - c3.chart.internal.fn.findClosest = function (values, pos) { - var minDist, closest; + c3_chart_internal_fn.findClosest = function (values, pos) { + var $$ = this, minDist, closest; values.forEach(function (v) { - var d = this.dist(v, pos); + var d = $$.dist(v, pos); if (d < minDist || ! minDist) { minDist = d; closest = v; @@ -3655,15 +3664,16 @@ }); return closest; }; - c3.chart.internal.fn.dist = function (data, pos) { - var yScale = this.getAxisId(data.id) === 'y' ? $$.y : $$.y2, + c3_chart_internal_fn.dist = function (data, pos) { + var $$ = this, + yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, xIndex = $$.config.axis_rotated ? 1 : 0, yIndex = $$.config.axis_rotated ? 0 : 1; return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); }; - c3.chart.internal.fn.setTargetType = function (targetIds, type) { + c3_chart_internal_fn.setTargetType = function (targetIds, type) { var $$ = this; $$.mapToTargetIds(targetIds).forEach(function (id) { $$.withoutFadeIn[id] = (type === $$.config.data_types[id]); @@ -3673,7 +3683,7 @@ $$.config.data_type = type; } }; - c3.chart.internal.fn.hasType = function (targets, type) { + c3_chart_internal_fn.hasType = function (targets, type) { var $$ = this, has = false; targets.forEach(function (t) { if ($$.config.data_types[t.id] === type) { has = true; } @@ -3687,72 +3697,70 @@ return hasType(targets, 'line'); } */ - c3.chart.internal.fn.hasAreaType = function (targets) { + c3_chart_internal_fn.hasAreaType = function (targets) { return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); }; - c3.chart.internal.fn.hasBarType = function (targets) { + c3_chart_internal_fn.hasBarType = function (targets) { return this.hasType(targets, 'bar'); }; - c3.chart.internal.fn.hasScatterType = function (targets) { + c3_chart_internal_fn.hasScatterType = function (targets) { return this.hasType(targets, 'scatter'); }; - c3.chart.internal.fn.hasPieType = function (targets) { - var $$ = this; - return $$.config.data_type === 'pie' || $$.hasType(targets, 'pie'); + c3_chart_internal_fn.hasPieType = function (targets) { + return this.config.data_type === 'pie' || this.hasType(targets, 'pie'); }; - c3.chart.internal.fn.hasGaugeType = function (targets) { + c3_chart_internal_fn.hasGaugeType = function (targets) { return this.hasType(targets, 'gauge'); }; - c3.chart.internal.fn.hasDonutType = function (targets) { - var $$ = this; - return $$.config.data_type === 'donut' || $$.hasType(targets, 'donut'); + c3_chart_internal_fn.hasDonutType = function (targets) { + return this.config.data_type === 'donut' || this.hasType(targets, 'donut'); }; - c3.chart.internal.fn.hasArcType = function (targets) { + c3_chart_internal_fn.hasArcType = function (targets) { return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); }; - c3.chart.internal.fn.isLineType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return !$$.config.data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf($$.config.data_types[id]) >= 0; + c3_chart_internal_fn.isLineType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return !this.config.data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3.chart.internal.fn.isStepType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['step', 'area-step'].indexOf($$.config.data_types[id]) >= 0; + c3_chart_internal_fn.isStepType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return ['step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3.chart.internal.fn.isSplineType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['spline', 'area-spline'].indexOf($$.config.data_types[id]) >= 0; + c3_chart_internal_fn.isSplineType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return ['spline', 'area-spline'].indexOf(this.config.data_types[id]) >= 0; }; - c3.chart.internal.fn.isAreaType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return ['area', 'area-spline', 'area-step'].indexOf($$.config.data_types[id]) >= 0; + c3_chart_internal_fn.isAreaType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return ['area', 'area-spline', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3.chart.internal.fn.isBarType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.config.data_types[id] === 'bar'; + c3_chart_internal_fn.isBarType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return this.config.data_types[id] === 'bar'; }; - c3.chart.internal.fn.isScatterType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.config.data_types[id] === 'scatter'; + c3_chart_internal_fn.isScatterType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return this.config.data_types[id] === 'scatter'; }; - c3.chart.internal.fn.isPieType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.config.data_types[id] === 'pie'; + c3_chart_internal_fn.isPieType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return this.config.data_types[id] === 'pie'; }; - c3.chart.internal.fn.isGaugeType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.config.data_types[id] === 'gauge'; + c3_chart_internal_fn.isGaugeType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return this.config.data_types[id] === 'gauge'; }; - c3.chart.internal.fn.isDonutType = function (d) { - var $$ = this, id = (typeof d === 'string') ? d : d.id; - return $$.config.data_types[id] === 'donut'; + c3_chart_internal_fn.isDonutType = function (d) { + var id = (typeof d === 'string') ? d : d.id; + return this.config.data_types[id] === 'donut'; }; - c3.chart.internal.fn.isArcType = function (d) { + c3_chart_internal_fn.isArcType = function (d) { return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); }; - c3.chart.internal.fn.lineData = function (d) { + c3_chart_internal_fn.lineData = function (d) { return this.isLineType(d) ? [d] : []; }; - c3.chart.internal.fn.arcData = function (d) { + c3_chart_internal_fn.arcData = function (d) { return this.isArcType(d.data) ? [d] : []; }; /* not used @@ -3760,13 +3768,13 @@ return isScatterType(d) ? d.values : []; } */ - c3.chart.internal.fn.barData = function (d) { + c3_chart_internal_fn.barData = function (d) { return this.isBarType(d) ? d.values : []; }; - c3.chart.internal.fn.lineOrScatterData = function (d) { + c3_chart_internal_fn.lineOrScatterData = function (d) { return this.isLineType(d) || this.isScatterType(d) ? d.values : []; }; - c3.chart.internal.fn.barOrLineData = function (d) { + c3_chart_internal_fn.barOrLineData = function (d) { return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; @@ -3775,14 +3783,14 @@ /** * c3.date.js */ - c3.chart.internal.fn.parseDate = function (date) { - var parsedDate; + c3_chart_internal_fn.parseDate = function (date) { + var $$ = this, parsedDate; if (date instanceof Date) { parsedDate = date; } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = this.dataTimeFormat($$.config.data_x_format).parse(date); + parsedDate = $$.dataTimeFormat($$.config.data_x_format).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -3794,7 +3802,7 @@ /** * c3.color.js */ - c3.chart.internal.fn.generateColor = function (colors, pattern, callback) { + c3_chart_internal_fn.generateColor = function (colors, pattern, callback) { var ids = []; return function (d) { @@ -3817,7 +3825,7 @@ return callback instanceof Function ? callback(color, d) : color; }; }; - c3.chart.internal.fn.generateLevelColor = function (colors, threshold) { + c3_chart_internal_fn.generateLevelColor = function (colors, threshold) { var asValue = threshold.unit === 'value', values = threshold.values && threshold.values.length ? threshold.values : [], max = threshold.max || 100; @@ -3838,12 +3846,12 @@ /** * c3.scale.js */ - c3.chart.internal.fn.getScale = function (min, max, forTimeseries) { + c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); }; - c3.chart.internal.fn.getX = function (min, max, domain, offset) { - var $$ = this; - var scale = this.getScale(min, max, $$.isTimeSeries), + c3_chart_internal_fn.getX = function (min, max, domain, offset) { + var $$ = this, + scale = $$.getScale(min, max, $$.isTimeSeries), _scale = domain ? scale.domain(domain) : scale, key; // Define customized scale if categorized axis if ($$.isCategorized) { @@ -3878,30 +3886,29 @@ } return scale; }; - c3.chart.internal.fn.getY = function (min, max, domain) { + c3_chart_internal_fn.getY = function (min, max, domain) { var scale = this.getScale(min, max); if (domain) { scale.domain(domain); } return scale; }; - c3.chart.internal.fn.getYScale = function (id) { - var $$ = this; - return $$.getAxisId(id) === 'y2' ? $$.y2 : $$.y; + c3_chart_internal_fn.getYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.y2 : this.y; }; - c3.chart.internal.fn.getSubYScale = function (id) { - var $$ = this; - return $$.getAxisId(id) === 'y2' ? $$.subY2 : $$.subY; + c3_chart_internal_fn.getSubYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; }; - c3.chart.internal.fn.updateScales = function () { - var $$ = this, xAxisTickFormat, xAxisTickValues, forInit = !$$.x; + c3_chart_internal_fn.updateScales = function () { + var $$ = this, c = $$.config, + forInit = !$$.x; // update edges - $$.xMin = $$.config.axis_rotated ? 1 : 0; - $$.xMax = $$.config.axis_rotated ? $$.height : $$.width; - $$.yMin = $$.config.axis_rotated ? 0 : $$.height; - $$.yMax = $$.config.axis_rotated ? $$.width : 1; + $$.xMin = c.axis_rotated ? 1 : 0; + $$.xMax = c.axis_rotated ? $$.height : $$.width; + $$.yMin = c.axis_rotated ? 0 : $$.height; + $$.yMax = c.axis_rotated ? $$.width : 1; $$.subXMin = $$.xMin; $$.subXMax = $$.xMax; - $$.subYMin = $$.config.axis_rotated ? 0 : $$.height2; - $$.subYMax = $$.config.axis_rotated ? $$.width2 : 1; + $$.subYMin = c.axis_rotated ? 0 : $$.height2; + $$.subYMax = c.axis_rotated ? $$.width2 : 1; // update scales $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); @@ -3911,31 +3918,31 @@ $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes $$.xAxisTickFormat = $$.getXAxisTickFormat(); - $$.xAxisTickValues = $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxisTickValues = c.axis_x_tick_values ? c.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$.getYAxis($$.y, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); - $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, c.axis_y_tick_format, c.axis_y_ticks); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, c.axis_y2_tick_format, c.axis_y2_ticks); // Set initialized scales to brush and zoom if (!forInit) { $$.brush.scale($$.subX); - if ($$.config.zoom_enabled) { $$.zoom.scale($$.x); } + if (c.zoom_enabled) { $$.zoom.scale($$.x); } } // update for arc this.updateArc(); }; - c3.chart.internal.fn.updateArc = function () { + c3_chart_internal_fn.updateArc = function () { var $$ = this; - $$.svgArc = this.getSvgArc(); - $$.svgArcExpanded = this.getSvgArcExpanded(); - $$.svgArcExpandedSub = this.getSvgArcExpanded(0.98); + $$.svgArc = $$.getSvgArc(); + $$.svgArcExpanded = $$.getSvgArcExpanded(); + $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); }; /** * c3.domain.js */ - c3.chart.internal.fn.getYDomainMin = function (targets) { + c3_chart_internal_fn.getYDomainMin = function (targets) { var $$ = this, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; @@ -3966,7 +3973,7 @@ } return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); }; - c3.chart.internal.fn.getYDomainMax = function (targets) { + c3_chart_internal_fn.getYDomainMax = function (targets) { var $$ = this, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; @@ -3997,19 +4004,19 @@ } return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - c3.chart.internal.fn.getYDomain = function (targets, axisId) { - var $$ = this; - var yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), - yMin = axisId === 'y2' ? $$.config.axis_y2_min : $$.config.axis_y_min, - yMax = axisId === 'y2' ? $$.config.axis_y2_max : $$.config.axis_y_max, - yDomainMin = this.isValue(yMin) ? yMin : this.getYDomainMin(yTargets), - yDomainMax = this.isValue(yMax) ? yMax : this.getYDomainMax(yTargets), + c3_chart_internal_fn.getYDomain = function (targets, axisId) { + var $$ = this, c = $$.config, + yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), + yMin = axisId === 'y2' ? c.axis_y2_min : c.axis_y_min, + yMax = axisId === 'y2' ? c.axis_y2_max : c.axis_y_max, + yDomainMin = $$.isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), + yDomainMax = $$.isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), domainLength, padding, padding_top, padding_bottom, - center = axisId === 'y2' ? $$.config.axis_y2_center : $$.config.axis_y_center, + center = axisId === 'y2' ? c.axis_y2_center : c.axis_y_center, yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = (this.hasBarType(yTargets) && $$.config.bar_zerobased) || (this.hasAreaType(yTargets) && $$.config.area_zerobased), - showHorizontalDataLabel = this.hasDataLabel() && $$.config.axis_rotated, - showVerticalDataLabel = this.hasDataLabel() && !$$.config.axis_rotated; + isZeroBased = ($$.hasBarType(yTargets) && c.bar_zerobased) || ($$.hasAreaType(yTargets) && c.area_zerobased), + showHorizontalDataLabel = $$.hasDataLabel() && c.axis_rotated, + showVerticalDataLabel = $$.hasDataLabel() && !c.axis_rotated; if (yTargets.length === 0) { // use current domain if target of axisId is none return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } @@ -4035,23 +4042,23 @@ } // add padding for data label if (showHorizontalDataLabel) { - lengths = this.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); - diff = this.diffDomain($$.y.range()); + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + diff = $$.diffDomain($$.y.range()); ratio = [lengths[0] / diff, lengths[1] / diff]; padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); } else if (showVerticalDataLabel) { - lengths = this.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); padding_top += lengths[1]; padding_bottom += lengths[0]; } - if (axisId === 'y' && $$.config.axis_y_padding) { - padding_top = this.getAxisPadding($$.config.axis_y_padding, 'top', padding, domainLength); - padding_bottom = this.getAxisPadding($$.config.axis_y_padding, 'bottom', padding, domainLength); + if (axisId === 'y' && c.axis_y_padding) { + padding_top = $$.getAxisPadding(c.axis_y_padding, 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(c.axis_y_padding, 'bottom', padding, domainLength); } - if (axisId === 'y2' && $$.config.axis_y2_padding) { - padding_top = this.getAxisPadding($$.config.axis_y2_padding, 'top', padding, domainLength); - padding_bottom = this.getAxisPadding($$.config.axis_y2_padding, 'bottom', padding, domainLength); + if (axisId === 'y2' && c.axis_y2_padding) { + padding_top = $$.getAxisPadding(c.axis_y2_padding, 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(c.axis_y2_padding, 'bottom', padding, domainLength); } // Bar/Area chart should be 0-based if all positive|negative if (isZeroBased) { @@ -4060,17 +4067,17 @@ } return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; - c3.chart.internal.fn.getXDomainMin = function (targets) { - var $$ = this; - return $$.config.axis_x_min ? ($$.isTimeSeries ? this.parseDate($$.config.axis_x_min) : $$.config.axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); + c3_chart_internal_fn.getXDomainMin = function (targets) { + var $$ = this, c = $$.config; + return c.axis_x_min ? ($$.isTimeSeries ? this.parseDate(c.axis_x_min) : c.axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; - c3.chart.internal.fn.getXDomainMax = function (targets) { - var $$ = this; - return $$.config.axis_x_max ? ($$.isTimeSeries ? this.parseDate($$.config.axis_x_max) : $$.config.axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); + c3_chart_internal_fn.getXDomainMax = function (targets) { + var $$ = this, c = $$.config; + return c.axis_x_max ? ($$.isTimeSeries ? this.parseDate(c.axis_x_max) : c.axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; - c3.chart.internal.fn.getXDomainPadding = function (targets) { - var $$ = this; - var edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], + c3_chart_internal_fn.getXDomainPadding = function (targets) { + var $$ = this, c = $$.config, + edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; if ($$.isCategorized) { padding = 0; @@ -4080,21 +4087,21 @@ } else { padding = diff * 0.01; } - if (typeof $$.config.axis_x_padding === 'object' && this.notEmpty($$.config.axis_x_padding)) { - paddingLeft = this.isValue($$.config.axis_x_padding.left) ? $$.config.axis_x_padding.left : padding; - paddingRight = this.isValue($$.config.axis_x_padding.right) ? $$.config.axis_x_padding.right : padding; - } else if (typeof $$.config.axis_x_padding === 'number') { - paddingLeft = paddingRight = $$.config.axis_x_padding; + if (typeof c.axis_x_padding === 'object' && this.notEmpty(c.axis_x_padding)) { + paddingLeft = this.isValue(c.axis_x_padding.left) ? c.axis_x_padding.left : padding; + paddingRight = this.isValue(c.axis_x_padding.right) ? c.axis_x_padding.right : padding; + } else if (typeof c.axis_x_padding === 'number') { + paddingLeft = paddingRight = c.axis_x_padding; } else { paddingLeft = paddingRight = padding; } return {left: paddingLeft, right: paddingRight}; }; - c3.chart.internal.fn.getXDomain = function (targets) { - var $$ = this; - var xDomain = [this.getXDomainMin(targets), this.getXDomainMax(targets)], + c3_chart_internal_fn.getXDomain = function (targets) { + var $$ = this, + xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], firstX = xDomain[0], lastX = xDomain[1], - padding = this.getXDomainPadding(targets), + padding = $$.getXDomainPadding(targets), min = 0, max = 0; // show center of x domain if min and max are the same if ((firstX - lastX) === 0 && !$$.isCategorized) { @@ -4109,7 +4116,7 @@ } return [min, max]; }; - c3.chart.internal.fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { var $$ = this; if (withUpdateOrgXDomain) { $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); @@ -4128,7 +4135,7 @@ - c3.chart.internal.fn.getXAxis = function (scale, orient, tickFormat, tickValues) { + c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); @@ -4150,58 +4157,58 @@ return axis; }; - c3.chart.internal.fn.getYAxis = function (scale, orient, tickFormat, ticks) { - var $$ = this; - return c3_axis($$.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); + c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks) { + return c3_axis(this.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); }; - c3.chart.internal.fn.getAxisId = function (id) { - var $$ = this; - return id in $$.config.data_axes ? $$.config.data_axes[id] : 'y'; + c3_chart_internal_fn.getAxisId = function (id) { + var c = this.config; + return id in c.data_axes ? c.data_axes[id] : 'y'; }; - c3.chart.internal.fn.getXAxisTickFormat = function () { - var $$ = this; - var format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; - if ($$.config.axis_x_tick_format) { - if (typeof $$.config.axis_x_tick_format === 'function') { - format = $$.config.axis_x_tick_format; + c3_chart_internal_fn.getXAxisTickFormat = function () { + var $$ = this, c = $$.config, + format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + if (c.axis_x_tick_format) { + if (typeof c.axis_x_tick_format === 'function') { + format = c.axis_x_tick_format; } else if ($$.isTimeSeries) { format = function (date) { - return date ? $$.axisTimeFormat($$.config.axis_x_tick_format)(date) : ""; + return date ? $$.axisTimeFormat(c.axis_x_tick_format)(date) : ""; }; } } return function (v) { return format.call($$, v); }; }; - c3.chart.internal.fn.getAxisLabelOptionByAxisId = function (axisId) { - var $$ = this, option; + c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { + var $$ = this, c = $$.config, option; if (axisId === 'y') { - option = $$.config.axis_y_label; + option = c.axis_y_label; } else if (axisId === 'y2') { - option = $$.config.axis_y2_label; + option = c.axis_y2_label; } else if (axisId === 'x') { - option = $$.config.axis_x_label; + option = c.axis_x_label; } return option; }; - c3.chart.internal.fn.getAxisLabelText = function (axisId) { + c3_chart_internal_fn.getAxisLabelText = function (axisId) { var option = this.getAxisLabelOptionByAxisId(axisId); return typeof option === 'string' ? option : option ? option.text : null; }; - c3.chart.internal.fn.setAxisLabelText = function (axisId, text) { - var option = this.getAxisLabelOptionByAxisId(axisId); + c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { + var $$ = this, c = $$.config, + option = $$.getAxisLabelOptionByAxisId(axisId); if (typeof option === 'string') { if (axisId === 'y') { - $$.config.axis_y_label = text; + c.axis_y_label = text; } else if (axisId === 'y2') { - $$.config.axis_y2_label = text; + c.axis_y2_label = text; } else if (axisId === 'x') { - $$.config.axis_x_label = text; + c.axis_x_label = text; } } else if (option) { option.text = text; } }; - c3.chart.internal.fn.getAxisLabelPosition = function (axisId, defaultPosition) { + c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { var option = this.getAxisLabelOptionByAxisId(axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { @@ -4215,32 +4222,28 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - c3.chart.internal.fn.getXAxisLabelPosition = function () { - var $$ = this; - return this.getAxisLabelPosition('x', $$.config.axis_rotated ? 'inner-top' : 'inner-right'); + c3_chart_internal_fn.getXAxisLabelPosition = function () { + return this.getAxisLabelPosition('x', this.config.axis_rotated ? 'inner-top' : 'inner-right'); }; - c3.chart.internal.fn.getYAxisLabelPosition = function () { - var $$ = this; - return this.getAxisLabelPosition('y', $$.config.axis_rotated ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getYAxisLabelPosition = function () { + return this.getAxisLabelPosition('y', this.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3.chart.internal.fn.getY2AxisLabelPosition = function () { - var $$ = this; - return this.getAxisLabelPosition('y2', $$.config.axis_rotated ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getY2AxisLabelPosition = function () { + return this.getAxisLabelPosition('y2', this.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3.chart.internal.fn.getAxisLabelPositionById = function (id) { - var $$ = this; - return id === 'y2' ? $$.getY2AxisLabelPosition() : id === 'y' ? $$.getYAxisLabelPosition() : $$.getXAxisLabelPosition(); + c3_chart_internal_fn.getAxisLabelPositionById = function (id) { + return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); }; - c3.chart.internal.fn.textForXAxisLabel = function () { + c3_chart_internal_fn.textForXAxisLabel = function () { return this.getAxisLabelText('x'); }; - c3.chart.internal.fn.textForYAxisLabel = function () { + c3_chart_internal_fn.textForYAxisLabel = function () { return this.getAxisLabelText('y'); }; - c3.chart.internal.fn.textForY2AxisLabel = function () { + c3_chart_internal_fn.textForY2AxisLabel = function () { return this.getAxisLabelText('y2'); }; - c3.chart.internal.fn.xForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -4248,83 +4251,85 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - c3.chart.internal.fn.dxForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.dxForAxisLabel = function (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"; } }; - c3.chart.internal.fn.textAnchorForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - c3.chart.internal.fn.xForXAxisLabel = function () { - var $$ = this; - return $$.xForAxisLabel(!$$.config.axis_rotated, $$.getXAxisLabelPosition()); + c3_chart_internal_fn.xForXAxisLabel = function () { + return this.xForAxisLabel(!this.config.axis_rotated, this.getXAxisLabelPosition()); }; - c3.chart.internal.fn.xForYAxisLabel = function () { + c3_chart_internal_fn.xForYAxisLabel = function () { return this.xForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); }; - c3.chart.internal.fn.xForY2AxisLabel = function () { + c3_chart_internal_fn.xForY2AxisLabel = function () { return this.xForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); }; - c3.chart.internal.fn.dxForXAxisLabel = function () { + c3_chart_internal_fn.dxForXAxisLabel = function () { return this.dxForAxisLabel(!this.__axis_rotated, this.getXAxisLabelPosition()); }; - c3.chart.internal.fn.dxForYAxisLabel = function () { + c3_chart_internal_fn.dxForYAxisLabel = function () { return this.dxForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); }; - c3.chart.internal.fn.dxForY2AxisLabel = function () { + c3_chart_internal_fn.dxForY2AxisLabel = function () { return this.dxForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); }; - c3.chart.internal.fn.dyForXAxisLabel = function () { - var $$ = this, position = $$.getXAxisLabelPosition(); - if ($$.config.axis_rotated) { + c3_chart_internal_fn.dyForXAxisLabel = function () { + var $$ = this, c = $$.config, + position = $$.getXAxisLabelPosition(); + if (c.axis_rotated) { return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); } else { - return position.isInner ? "-0.5em" : $$.config.axis_x_height ? $$.config.axis_x_height - 10 : "3em"; + return position.isInner ? "-0.5em" : c.axis_x_height ? c.axis_x_height - 10 : "3em"; } }; - c3.chart.internal.fn.dyForYAxisLabel = function () { - var $$ = this, position = $$.getYAxisLabelPosition(); + c3_chart_internal_fn.dyForYAxisLabel = function () { + var $$ = this, + position = $$.getYAxisLabelPosition(); if ($$.config.axis_rotated) { return position.isInner ? "-0.5em" : "3em"; } else { return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); } }; - c3.chart.internal.fn.dyForY2AxisLabel = function () { - var $$ = this, position = $$.getY2AxisLabelPosition(); + c3_chart_internal_fn.dyForY2AxisLabel = function () { + var $$ = this, + position = $$.getY2AxisLabelPosition(); if ($$.config.axis_rotated) { return position.isInner ? "1.2em" : "-2.2em"; } else { return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); } }; - c3.chart.internal.fn.textAnchorForXAxisLabel = function () { + c3_chart_internal_fn.textAnchorForXAxisLabel = function () { var $$ = this; return $$.textAnchorForAxisLabel(!$$.config.axis_rotated, $$.getXAxisLabelPosition()); }; - c3.chart.internal.fn.textAnchorForYAxisLabel = function () { + c3_chart_internal_fn.textAnchorForYAxisLabel = function () { var $$ = this; return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getYAxisLabelPosition()); }; - c3.chart.internal.fn.textAnchorForY2AxisLabel = function () { + c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { var $$ = this; return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getY2AxisLabelPosition()); }; - c3.chart.internal.fn.xForRotatedTickText = function (r) { + c3_chart_internal_fn.xForRotatedTickText = function (r) { return 10 * Math.sin(Math.PI * (r / 180)); }; - c3.chart.internal.fn.yForRotatedTickText = function (r) { + c3_chart_internal_fn.yForRotatedTickText = function (r) { return 11.5 - 2.5 * (r / 15); }; - c3.chart.internal.fn.rotateTickText = function (axis, transition, rotate) { + c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) { axis.selectAll('.tick text') .style("text-anchor", "start"); transition.selectAll('.tick text') @@ -4333,20 +4338,20 @@ .attr("transform", "rotate(" + rotate + ")"); }; - c3.chart.internal.fn.getMaxTickWidth = function (id) { + c3_chart_internal_fn.getMaxTickWidth = function (id) { var $$ = this; var maxWidth = 0, targetsToShow, scale, axis; if ($$.svg) { - targetsToShow = this.filterTargetsToShow($$.data.targets); + targetsToShow = $$.filterTargetsToShow($$.data.targets); if (id === 'y') { - scale = $$.y.copy().domain(this.getYDomain(targetsToShow, 'y')); - axis = this.getYAxis(scale, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); + scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); + axis = $$.getYAxis(scale, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); } else if (id === 'y2') { - scale = $$.y2.copy().domain(this.getYDomain(targetsToShow, 'y2')); - axis = this.getYAxis(scale, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); + scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); + axis = $$.getYAxis(scale, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); } else { - scale = $$.x.copy().domain(this.getXDomain(targetsToShow)); - axis = this.getXAxis(scale, $$.xOrient, this.getXAxisTickFormat(), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); + scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); + axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4359,11 +4364,11 @@ return $$.currentMaxTickWidth; }; - c3.chart.internal.fn.updateAxisLabels = function (withTransition) { - var $$ = this; - var axisXLabel = $$.main.select('.' + this.CLASS.axisX + ' .' + this.CLASS.axisXLabel), - axisYLabel = $$.main.select('.' + this.CLASS.axisY + ' .' + this.CLASS.axisYLabel), - axisY2Label = $$.main.select('.' + this.CLASS.axisY2 + ' .' + this.CLASS.axisY2Label); + c3_chart_internal_fn.updateAxisLabels = function (withTransition) { + var $$ = this, CLASS = $$.CLASS; + 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", function () { return $$.xForXAxisLabel(); }) .attr("dx", function () { return $$.dxForXAxisLabel(); }) @@ -4382,12 +4387,12 @@ .text(function () { return $$.textForY2AxisLabel(); }); }; - c3.chart.internal.fn.getAxisPadding = function (padding, key, defaultValue, all) { + c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { var ratio = padding.unit === 'ratio' ? all : 1; return this.isValue(padding[key]) ? padding[key] * ratio : defaultValue; }; - c3.chart.internal.fn.generateTickValues = function (xs, tickCount) { + c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { var $$ = this; var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { @@ -4419,43 +4424,47 @@ /** * c3.region.js */ - c3.chart.internal.fn.regionX = function (d) { - var xPos, yScale = d.axis === 'y' ? y : y2; + c3_chart_internal_fn.regionX = function (d) { + var $$ = this, + xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { xPos = $$.config.axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = $$.config.axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0); + xPos = $$.config.axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); } return xPos; }; - c3.chart.internal.fn.regionY = function (d) { - var yPos, yScale = d.axis === 'y' ? y : y2; + c3_chart_internal_fn.regionY = function (d) { + var $$ = this, + yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { yPos = $$.config.axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = $$.config.axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.start) : d.start) : 0) : 0; + yPos = $$.config.axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; } return yPos; }; - c3.chart.internal.fn.regionWidth = function (d) { - var start = this.regionX(d), end, yScale = d.axis === 'y' ? y : y2; + c3_chart_internal_fn.regionWidth = function (d) { + var $$ = this, + start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = $$.config.axis_rotated ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = $$.config.axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.width); + end = $$.config.axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; - c3.chart.internal.fn.regionHeight = function (d) { - var start = this.regionY(d), end, yScale = d.axis === 'y' ? y : y2; + c3_chart_internal_fn.regionHeight = function (d) { + var $$ = this, + start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = $$.config.axis_rotated ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = $$.config.axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? this.parseDate(d.end) : d.end) : $$.height) : $$.height; + end = $$.config.axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; - c3.chart.internal.fn.isRegionOnX = function (d) { + c3_chart_internal_fn.isRegionOnX = function (d) { return !d.axis || d.axis === 'x'; }; @@ -4465,8 +4474,9 @@ /** * c3.arc.js */ - c3.chart.internal.fn.updateAngle = function (d) { - var $$ = this, found = false, index = 0; + c3_chart_internal_fn.updateAngle = function (d) { + var $$ = this, + found = false, index = 0; $$.pie($$.filterTargetsToShow($$.data.targets)).sort(this.descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { found = true; @@ -4487,9 +4497,9 @@ } return found ? d : null; }; - c3.chart.internal.fn.getSvgArc = function () { - var $$ = this; - var arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), + c3_chart_internal_fn.getSvgArc = function () { + var $$ = this, + arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { var updated; if (withoutUpdate) { return arc(d); } // for interpolate @@ -4500,20 +4510,21 @@ newArc.centroid = arc.centroid; return newArc; }; - c3.chart.internal.fn.getSvgArcExpanded = function (rate) { - var $$ = this; - var arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); + c3_chart_internal_fn.getSvgArcExpanded = function (rate) { + var $$ = this, + arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { var updated = $$.updateAngle(d); 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"; }; - c3.chart.internal.fn.transformForArcLabel = function (d) { - var $$ = this, updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; - if (updated && !this.hasGaugeType($$.data.targets)) { + c3_chart_internal_fn.transformForArcLabel = function (d) { + var $$ = this, + updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !$$.hasGaugeType($$.data.targets)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4524,11 +4535,12 @@ } return translate; }; - c3.chart.internal.fn.getArcRatio = function (d) { - var $$ = this, whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); + c3_chart_internal_fn.getArcRatio = function (d) { + var $$ = this, + whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); 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({ id: d.data.id, value: d.value, @@ -4536,8 +4548,9 @@ index: d.index }); }; - c3.chart.internal.fn.textForArcLabel = function (d) { - var $$ = this, updated, value, ratio, format; + c3_chart_internal_fn.textForArcLabel = function (d) { + var $$ = this, + updated, value, ratio, format; if (! $$.shouldShowArcLabel()) { return ""; } updated = $$.updateAngle(d); value = updated ? updated.value : null; @@ -4546,8 +4559,8 @@ format = $$.getArcLabelFormat(); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; - c3.chart.internal.fn.expandArc = function (id, withoutFadeOut) { - var $$ = this, CLASS= $$.CLASS, + c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { + var $$ = this, CLASS = $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); @@ -4567,7 +4580,7 @@ noneTargets.style("opacity", 0.3); } }; - c3.chart.internal.fn.unexpandArc = function (id) { + c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, CLASS = $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); target.selectAll('path.' + CLASS.arc) @@ -4576,38 +4589,40 @@ $$.svg.selectAll('.' + CLASS.arc) .style("opacity", 1); }; - c3.chart.internal.fn.shouldExpand = function (id) { + c3_chart_internal_fn.shouldExpand = function (id) { var $$ = this; 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, shouldShow = true; - if (this.hasDonutType($$.data.targets)) { + if ($$.hasDonutType($$.data.targets)) { shouldShow = $$.config.donut_label_show; - } else if (this.hasPieType($$.data.targets)) { + } else if ($$.hasPieType($$.data.targets)) { shouldShow = $$.config.pie_label_show; } // when gauge, always true return shouldShow; }; - c3.chart.internal.fn.meetsArcLabelThreshold = function (ratio) { - var $$ = this, threshold = this.hasDonutType($$.data.targets) ? $$.config.donut_label_threshold : $$.config.pie_label_threshold; + c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { + var $$ = this, c = $$.config, + threshold = this.hasDonutType($$.data.targets) ? c.donut_label_threshold : c.pie_label_threshold; return ratio >= threshold; }; - c3.chart.internal.fn.getArcLabelFormat = function () { - var $$ = this, format = $$.config.pie_label_format; - if (this.hasGaugeType($$.data.targets)) { + c3_chart_internal_fn.getArcLabelFormat = function () { + var $$ = this, + format = $$.config.pie_label_format; + if ($$.hasGaugeType($$.data.targets)) { format = $$.config.gauge_label_format; - } else if (this.hasDonutType($$.data.targets)) { + } else if ($$.hasDonutType($$.data.targets)) { format = $$.config.donut_label_format; } return format; }; - c3.chart.internal.fn.getArcTitle = function () { + c3_chart_internal_fn.getArcTitle = function () { var $$ = this; return $$.hasDonutType($$.data.targets) ? $$.config.donut_title : ""; }; - c3.chart.internal.fn.descByStartAngle = function (a, b) { + c3_chart_internal_fn.descByStartAngle = function (a, b) { return a.startAngle - b.startAngle; }; @@ -4616,20 +4631,19 @@ /** * c3.cache.js */ - c3.chart.internal.fn.hasCaches = function (ids) { + c3_chart_internal_fn.hasCaches = function (ids) { for (var i = 0; i < ids.length; i++) { - if (! (ids[i] in $$.cache)) { return false; } + if (! (ids[i] in this.cache)) { return false; } } return true; }; - c3.chart.internal.fn.addCache = function (id, target) { - var $$ = this; - $$.cache[id] = $$.cloneTarget(target); + c3_chart_internal_fn.addCache = function (id, target) { + this.cache[id] = this.cloneTarget(target); }; - c3.chart.internal.fn.getCaches = function (ids) { + c3_chart_internal_fn.getCaches = function (ids) { var targets = [], i; for (i = 0; i < ids.length; i++) { - if (ids[i] in $$.cache) { targets.push(this.cloneTarget($$.cache[ids[i]])); } + if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } } return targets; }; @@ -4638,10 +4652,10 @@ /** * c3.zoom.js */ - c3.chart.internal.fn.updateZoom = function () { + c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config.zoom_enabled ? $$.zoom : function () {}; - $$.main.select('.' + this.CLASS.zoomRect).call(z); - $$.main.selectAll('.' + this.CLASS.eventRect).call(z); + $$.main.select('.' + $$.CLASS.zoomRect).call(z); + $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); }; @@ -4650,47 +4664,47 @@ /** * c3.util.js */ - c3.chart.internal.fn.isValue = function (v) { + c3_chart_internal_fn.isValue = function (v) { return v || v === 0; }; - c3.chart.internal.fn.isUndefined = function (v) { + c3_chart_internal_fn.isUndefined = function (v) { return typeof v === 'undefined'; }; - c3.chart.internal.fn.isDefined = function (v) { + c3_chart_internal_fn.isDefined = function (v) { return typeof v !== 'undefined'; }; - c3.chart.internal.fn.ceil10 = function (v) { + c3_chart_internal_fn.ceil10 = function (v) { return Math.ceil(v / 10) * 10; }; - c3.chart.internal.fn.asHalfPixel = function (n) { + c3_chart_internal_fn.asHalfPixel = function (n) { return Math.ceil(n) + 0.5; }; - c3.chart.internal.fn.diffDomain = function (d) { + c3_chart_internal_fn.diffDomain = function (d) { return d[1] - d[0]; }; - c3.chart.internal.fn.isEmpty = function (o) { + c3_chart_internal_fn.isEmpty = function (o) { return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); }; - c3.chart.internal.fn.notEmpty = function (o) { + c3_chart_internal_fn.notEmpty = function (o) { return Object.keys(o).length > 0; }; - c3.chart.internal.fn.getOption = function (options, key, defaultValue) { + c3_chart_internal_fn.getOption = function (options, key, defaultValue) { return typeof options[key] !== 'undefined' ? options[key] : defaultValue; }; - c3.chart.internal.fn.hasValue = function (dict, value) { + c3_chart_internal_fn.hasValue = function (dict, value) { var found = false; Object.keys(dict).forEach(function (key) { if (dict[key] === value) { found = true; } }); return found; }; - c3.chart.internal.fn.getPathBox = function (path) { + c3_chart_internal_fn.getPathBox = function (path) { var box = path.getBoundingClientRect(), items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; }; - c3.chart.internal.fn.getTextRect = function (text, cls) { + c3_chart_internal_fn.getTextRect = function (text, cls) { var $$ = this, rect; $$.d3.select('body').selectAll('.dummy') .data([text]) @@ -4702,7 +4716,7 @@ return rect; }; - c3.chart.internal.fn.getEmptySelection = function () { + c3_chart_internal_fn.getEmptySelection = function () { var $$ = this; return $$.d3.selectAll([]); }; @@ -4711,51 +4725,56 @@ /** * c3.selection.js */ - c3.chart.internal.fn.selectPoint = function (target, d, i) { + c3_chart_internal_fn.selectPoint = function (target, d, i) { var $$ = this; $$.config.data_onselected.call(c3, d, target.node()); // add selected-circle on low layer g - main.select('.' + this.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + this.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return generateClass(this.CLASS.selectedCircle, i); }) - .attr("cx", $$.config.axis_rotated ? circleY : circleX) - .attr("cy", $$.config.axis_rotated ? circleX : circleY) - .attr("stroke", function () { return color(d); }) - .attr("r", pointSelectR(d) * 1.4) + .attr("class", function () { return $$.generateClass(this.CLASS.selectedCircle, i); }) + .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) + .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY) + .attr("stroke", function () { return $$.color(d); }) + .attr("r", $$.pointSelectR(d) * 1.4) .transition().duration(100) - .attr("r", pointSelectR); + .attr("r", $$.pointSelectR); }; - c3.chart.internal.fn.unselectPoint = function (target, d, i) { + c3_chart_internal_fn.unselectPoint = function (target, d, i) { var $$ = this; $$.config.data_onunselected.call(c3, d, target.node()); // remove selected-circle from low layer g - main.select('.' + $$.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + $$.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; - c3.chart.internal.fn.togglePoint = function (selected, target, d, i) { - selected ? selectPoint(target, d, i) : unselectPoint(target, d, i); + c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { + selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); }; - c3.chart.internal.fn.selectBar = function (target, d) { + c3_chart_internal_fn.selectBar = function (target, d) { + var $$ = this; $$.config.data_onselected.call(c3, d, target.node()); - target.transition().duration(100).style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + target.transition().duration(100) + .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); }; - c3.chart.internal.fn.unselectBar = function (target, d) { + c3_chart_internal_fn.unselectBar = function (target, d) { + var $$ = this; $$.config.data_onunselected.call(c3, d, target.node()); - target.transition().duration(100).style("fill", function () { return $$.color(d); }); + target.transition().duration(100) + .style("fill", function () { return $$.color(d); }); }; - c3.chart.internal.fn.toggleBar = function (selected, target, d, i) { + c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); }; - c3.chart.internal.fn.toggleArc = function (selected, target, d, i) { + c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { this.toggleBar(selected, target, d.data, i); }; - c3.chart.internal.fn.getToggle = function (that) { + c3_chart_internal_fn.getToggle = function (that) { + var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? this.togglePoint : ($$.d3.select(that).classed(this.CLASS.bar) ? this.toggleBar : this.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed($$.CLASS.bar) ? $$.toggleBar : $$.toggleArc); }; - c3.chart.internal.fn.toggleShape = function (that, d, i) { + c3_chart_internal_fn.toggleShape = function (that, d, i) { var $$ = this, CLASS = $$.CLASS, d3 = $$.d3, shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; if (that.nodeName === 'circle') { @@ -4790,7 +4809,7 @@ /** * c3.transition.js */ - c3.chart.internal.fn.generateAxisTransitions = function (duration) { + c3_chart_internal_fn.generateAxisTransitions = function (duration) { var $$ = this, axes = $$.axes; return { axisX: duration ? axes.x.transition().duration(duration) : axes.x, @@ -4799,7 +4818,7 @@ axisSubX: duration ? axes.subx.transition().duration(duration) : axes.subx }; }; - c3.chart.internal.fn.endall = function (transition, callback) { + c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition .each(function () { ++n; }) @@ -4807,7 +4826,7 @@ if (!--n) { callback.apply(this, arguments); } }); }; - c3.chart.internal.fn.generateWait = function () { + c3_chart_internal_fn.generateWait = function () { var transitionsToWait = [], f = function (transition, callback) { var timer = setInterval(function () { @@ -4839,7 +4858,7 @@ /** * c3.transform.js */ - c3.chart.internal.fn.transformTo = function (targetIds, type, optionsForRedraw) { + c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, withTransitionForAxis = !$$.hasArcType($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; @@ -4853,7 +4872,7 @@ /** * c3.class.js */ - c3.chart.internal.fn.CLASS = { + c3_chart_internal_fn.CLASS = { target: 'c3-target', chart : 'c3-chart', chartLine: 'c3-chart-line', @@ -4926,59 +4945,58 @@ SELECTED: '_selected_', INCLUDED: '_included_' }; - c3.chart.internal.fn.generateClass = function (prefix, targetId) { - var $$ = this; - return " " + prefix + " " + prefix + $$.getTargetSelectorSuffix(targetId); + c3_chart_internal_fn.generateClass = function (prefix, targetId) { + return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); }; - c3.chart.internal.fn.classText = function (d) { + c3_chart_internal_fn.classText = function (d) { return this.generateClass(this.CLASS.text, d.index); }; - c3.chart.internal.fn.classTexts = function (d) { + c3_chart_internal_fn.classTexts = function (d) { return this.generateClass(this.CLASS.texts, d.id); }; - c3.chart.internal.fn.classShape = function (d) { + c3_chart_internal_fn.classShape = function (d) { return this.generateClass(this.CLASS.shape, d.index); }; - c3.chart.internal.fn.classShapes = function (d) { + c3_chart_internal_fn.classShapes = function (d) { return this.generateClass(this.CLASS.shapes, d.id); }; - c3.chart.internal.fn.classLine = function (d) { + c3_chart_internal_fn.classLine = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.line, d.id); }; - c3.chart.internal.fn.classLines = function (d) { + c3_chart_internal_fn.classLines = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.lines, d.id); }; - c3.chart.internal.fn.classCircle = function (d) { + c3_chart_internal_fn.classCircle = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.circle, d.index); }; - c3.chart.internal.fn.classCircles = function (d) { + c3_chart_internal_fn.classCircles = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.circles, d.id); }; - c3.chart.internal.fn.classBar = function (d) { + c3_chart_internal_fn.classBar = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.bar, d.index); }; - c3.chart.internal.fn.classBars = function (d) { + c3_chart_internal_fn.classBars = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.bars, d.id); }; - c3.chart.internal.fn.classArc = function (d) { + c3_chart_internal_fn.classArc = function (d) { return this.classShape(d.data) + this.generateClass(this.CLASS.arc, d.data.id); }; - c3.chart.internal.fn.classArcs = function (d) { + c3_chart_internal_fn.classArcs = function (d) { return this.classShapes(d.data) + this.generateClass(this.CLASS.arcs, d.data.id); }; - c3.chart.internal.fn.classArea = function (d) { + c3_chart_internal_fn.classArea = function (d) { return this.classShape(d) + this.generateClass(this.CLASS.area, d.id); }; - c3.chart.internal.fn.classAreas = function (d) { + c3_chart_internal_fn.classAreas = function (d) { return this.classShapes(d) + this.generateClass(this.CLASS.areas, d.id); }; - c3.chart.internal.fn.classRegion = function (d, i) { + c3_chart_internal_fn.classRegion = function (d, i) { return this.generateClass(this.CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); }; - c3.chart.internal.fn.classEvent = function (d) { + c3_chart_internal_fn.classEvent = function (d) { return this.generateClass(this.CLASS.eventRect, d.index); }; - c3.chart.internal.fn.classTarget = function (id) { + c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config.data_classes[id], additionalClass = ''; if (additionalClassSuffix) { @@ -4986,34 +5004,32 @@ } return $$.generateClass($$.CLASS.target, id) + additionalClass; }; - c3.chart.internal.fn.classChartText = function (d) { + c3_chart_internal_fn.classChartText = function (d) { return this.CLASS.chartText + this.classTarget(d.id); }; - c3.chart.internal.fn.classChartLine = function (d) { + c3_chart_internal_fn.classChartLine = function (d) { return this.CLASS.chartLine + this.classTarget(d.id); }; - c3.chart.internal.fn.classChartBar = function (d) { + c3_chart_internal_fn.classChartBar = function (d) { return this.CLASS.chartBar + this.classTarget(d.id); }; - c3.chart.internal.fn.classChartArc = function (d) { + c3_chart_internal_fn.classChartArc = function (d) { return this.CLASS.chartArc + this.classTarget(d.data.id); }; - c3.chart.internal.fn.getTargetSelectorSuffix = function (targetId) { + c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; - c3.chart.internal.fn.selectorTarget = function (id) { - var $$ = this; - return '.' + $$.CLASS.target + $$.getTargetSelectorSuffix(id); + c3_chart_internal_fn.selectorTarget = function (id) { + return '.' + this.CLASS.target + this.getTargetSelectorSuffix(id); }; - c3.chart.internal.fn.selectorTargets = function (ids) { + c3_chart_internal_fn.selectorTargets = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; }; - c3.chart.internal.fn.selectorLegend = function (id) { - var $$ = this; - return '.' + $$.CLASS.legendItem + $$.getTargetSelectorSuffix(id); + c3_chart_internal_fn.selectorLegend = function (id) { + return '.' + this.CLASS.legendItem + this.getTargetSelectorSuffix(id); }; - c3.chart.internal.fn.selectorLegends = function (ids) { + c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; }; @@ -5023,7 +5039,7 @@ /** * c3.format.js */ - c3.chart.internal.fn.getYFormat = function (forArc) { + c3_chart_internal_fn.getYFormat = function (forArc) { var $$ = this, formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; @@ -5032,28 +5048,31 @@ return format.call($$, v, ratio); }; }; - c3.chart.internal.fn.yFormat = function (v) { - var $$ = this, format = $$.config.axis_y_tick_format ? $$.config.axis_y_tick_format : $$.defaultValueFormat; + c3_chart_internal_fn.yFormat = function (v) { + var $$ = this, + format = $$.config.axis_y_tick_format ? $$.config.axis_y_tick_format : $$.defaultValueFormat; return format.call($$, v); }; - c3.chart.internal.fn.y2Format = function (v) { - var $$ = this, format = $$.config.axis_y2_tick_format ? $$.config.axis_y2_tick_format : $$.defaultValueFormat; + c3_chart_internal_fn.y2Format = function (v) { + var $$ = this, + format = $$.config.axis_y2_tick_format ? $$.config.axis_y2_tick_format : $$.defaultValueFormat; return format.call($$, v); }; - c3.chart.internal.fn.defaultValueFormat = function (v) { + c3_chart_internal_fn.defaultValueFormat = function (v) { return this.isValue(v) ? +v : ""; }; - c3.chart.internal.fn.defaultArcValueFormat = function (v, ratio) { + c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { return (ratio * 100).toFixed(1) + '%'; }; - c3.chart.internal.fn.formatByAxisId = function (axisId) { - var $$ = this.internal, format = function (v) { return this.isValue(v) ? +v : ""; }; + c3_chart_internal_fn.formatByAxisId = function (axisId) { + var $$ = this.internal, data_labels = $$.config.data_labels, + format = function (v) { return this.isValue(v) ? +v : ""; }; // find format according to axis id - if (typeof $$.config.data_labels.format === 'function') { - format = $$.config.data_labels.format; - } else if (typeof $$.config.data_labels.format === 'object') { - if (typeof $$.config.data_labels.format[axisId] === 'function') { - format = $$.config.data_labels.format[axisId]; + if (typeof data_labels.format === 'function') { + format = data_labels.format; + } else if (typeof data_labels.format === 'object') { + if (typeof data_labels.format[axisId] === 'function') { + format = data_labels.format[axisId]; } } return format; @@ -5064,7 +5083,7 @@ /** * c3.drag.js */ - c3.chart.internal.fn.drag = function (mouse) { + c3_chart_internal_fn.drag = function (mouse) { var $$ = this, main = $$.main, CLASS = $$.CLASS, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; @@ -5122,7 +5141,7 @@ }); }; - c3.chart.internal.fn.dragstart = function (mouse) { + c3_chart_internal_fn.dragstart = function (mouse) { var $$ = this; if ($$.hasArcType($$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable @@ -5134,7 +5153,7 @@ $$.config.data_ondragstart.call(c3); }; - c3.chart.internal.fn.dragend = function () { + c3_chart_internal_fn.dragend = function () { var $$ = this; if ($$.hasArcType($$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable @@ -5155,7 +5174,7 @@ /** * c3.api.js (or c3.api.focus.js, etc?) */ - c3.chart.fn.focus = function (targetId) { + c3_chart_fn.focus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), @@ -5173,7 +5192,7 @@ $$.toggleFocusLegend(targetId, true); }; - c3.chart.fn.defocus = function (targetId) { + c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), @@ -5190,7 +5209,7 @@ $$.toggleFocusLegend(targetId, false); }; - c3.chart.fn.revert = function (targetId) { + c3_chart_fn.revert = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), @@ -5206,7 +5225,7 @@ $$.revertLegend(); }; - c3.chart.fn.show = function (targetIds, options) { + c3_chart_fn.show = function (targetIds, options) { var $$ = this.internal; targetIds = $$.mapToTargetIds(targetIds); @@ -5224,7 +5243,7 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); }; - c3.chart.fn.hide = function (targetIds, options) { + c3_chart_fn.hide = function (targetIds, options) { var $$ = this.internal; targetIds = $$.mapToTargetIds(targetIds); @@ -5242,25 +5261,25 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); }; - c3.chart.fn.toggle = function (targetId) { + c3_chart_fn.toggle = function (targetId) { var $$ = this.internal; $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); }; - c3.chart.fn.zoom = function () { + c3_chart_fn.zoom = function () { }; - c3.chart.fn.zoom.enable = function (enabled) { + c3_chart_fn.zoom.enable = function (enabled) { var $$ = this.internal; $$.config.zoom_enabled = enabled; $$.updateAndRedraw(); }; - c3.chart.fn.unzoom = function () { + c3_chart_fn.unzoom = function () { var $$ = this.internal; $$.brush.clear().update(); $$.redraw({withUpdateXDomain: true}); }; - c3.chart.fn.load = function (args) { + c3_chart_fn.load = function (args) { var $$ = this.internal; // update xs if specified if (args.xs) { @@ -5292,7 +5311,7 @@ } }; - c3.chart.fn.unload = function (args) { + c3_chart_fn.unload = function (args) { var $$ = this.internal; args = args || {}; $$.unload($$.mapToTargetIds(args.ids), function () { @@ -5301,7 +5320,7 @@ }); }; - c3.chart.fn.flow = function (args) { + c3_chart_fn.flow = function (args) { var $$ = this.internal, targets = $$.convertDataToTargets($$.convertColumnsToData(args.columns), true), notfoundIds = [], orgDataCount = $$.getMaxDataCount(), @@ -5429,7 +5448,7 @@ }); }; - c3.chart.fn.selected = function (targetId) { + c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3, CLASS = $$.CLASS; return d3.merge( $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) @@ -5437,7 +5456,7 @@ .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; - c3.chart.fn.select = function (ids, indices, resetOther) { + c3_chart_fn.select = function (ids, indices, resetOther) { var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { @@ -5460,7 +5479,7 @@ } }); }; - c3.chart.fn.unselect = function (ids, indices) { + c3_chart_fn.unselect = function (ids, indices) { var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { @@ -5482,13 +5501,13 @@ }); }; - c3.chart.fn.transform = function (type, targetIds) { + c3_chart_fn.transform = function (type, targetIds) { var $$ = this.internal, options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; $$.transformTo(targetIds, type, options); }; - c3.chart.fn.groups = function (groups) { + c3_chart_fn.groups = function (groups) { var $$ = this.internal; if ($$.isUndefined(groups)) { return $$.config.data_groups; } $$.config.data_groups = groups; @@ -5496,53 +5515,53 @@ return $$.config.data_groups; }; - c3.chart.fn.xgrids = function (grids) { + c3_chart_fn.xgrids = function (grids) { var $$ = this.internal; if (! grids) { return $$.config.grid_x_lines; } $$.config.grid_x_lines = grids; $$.redraw(); return $$.config.grid_x_lines; }; - c3.chart.fn.xgrids.add = function (grids) { + c3_chart_fn.xgrids.add = function (grids) { var $$ = this.internal; return this.xgrids($$.config.grid_x_lines.concat(grids ? grids : [])); }; - c3.chart.fn.xgrids.remove = function (params) { // TODO: multiple + c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple var $$ = this.internal; $$.removeGridLines(params, true); }; - c3.chart.fn.ygrids = function (grids) { + c3_chart_fn.ygrids = function (grids) { var $$ = this.internal; if (! grids) { return $$.config.grid_y_lines; } $$.config.grid_y_lines = grids; $$.redraw(); return $$.config.grid_y_lines; }; - c3.chart.fn.ygrids.add = function (grids) { + c3_chart_fn.ygrids.add = function (grids) { var $$ = this.internal; return c3.ygrids($$.config.grid_y_lines.concat(grids ? grids : [])); }; - c3.chart.fn.ygrids.remove = function (params) { // TODO: multiple + c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple var $$ = this.internal; $$.removeGridLines(params, false); }; - c3.chart.fn.regions = function (regions) { + c3_chart_fn.regions = function (regions) { var $$ = this.internal; if (!regions) { return $$.config.regions; } $$.config.regions = regions; $$.redraw(); return $$.config.regions; }; - c3.chart.fn.regions.add = function (regions) { + c3_chart_fn.regions.add = function (regions) { var $$ = this.internal; if (!regions) { return $$.config.regions; } $$.config.regions = $$.config.regions.concat(regions); $$.redraw(); return $$.config.regions; }; - c3.chart.fn.regions.remove = function (options) { + c3_chart_fn.regions.remove = function (options) { var $$ = this.internal, CLASS = $$.CLASS, duration, classes, regions; @@ -5569,18 +5588,18 @@ return $$.config.regions; }; - c3.chart.fn.data = function () { + c3_chart_fn.data = function () { }; - c3.chart.fn.data.get = function (targetId) { + c3_chart_fn.data.get = function (targetId) { var $$ = this.internal, target = this.data.getAsTarget(targetId); return $$.isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; }; - c3.chart.fn.data.getAsTarget = function (targetId) { + c3_chart_fn.data.getAsTarget = function (targetId) { var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); return targets.length > 0 ? targets[0] : undefined; }; - c3.chart.fn.data.names = function (names) { + c3_chart_fn.data.names = function (names) { var $$ = this.internal; if (!arguments.length) { return $$.config.data_names; } Object.keys(names).forEach(function (id) { @@ -5589,7 +5608,7 @@ $$.redraw({withLegend: true}); return $$.config.data_names; }; - c3.chart.fn.data.colors = function (colors) { + c3_chart_fn.data.colors = function (colors) { var $$ = this.internal; if (!arguments.length) { return $$.config.data_colors; } Object.keys(colors).forEach(function (id) { @@ -5598,7 +5617,7 @@ $$.redraw({withLegend: true}); return $$.config.data_colors; }; - c3.chart.fn.category = function (i, category) { + c3_chart_fn.category = function (i, category) { var $$ = this.internal; if (arguments.length > 1) { $$.config.axis_x_categories[i] = category; @@ -5606,7 +5625,7 @@ } return $$.config.axis_x_categories[i]; }; - c3.chart.fn.categories = function (categories) { + c3_chart_fn.categories = function (categories) { var $$ = this.internal; if (!arguments.length) { return $$.config.axis_x_categories; } $$.config.axis_x_categories = categories; @@ -5615,12 +5634,12 @@ }; // TODO: fix - c3.chart.fn.color = function (id) { + c3_chart_fn.color = function (id) { var $$ = this.internal; return $$.color(id); // more patterns }; - c3.chart.fn.x = function (x) { + c3_chart_fn.x = function (x) { var $$ = this.internal; if (arguments.length) { $$.updateTargetX($$.data.targets, x); @@ -5628,7 +5647,7 @@ } return $$.data.xs; }; - c3.chart.fn.xs = function (xs) { + c3_chart_fn.xs = function (xs) { var $$ = this.internal; if (arguments.length) { $$.updateTargetXs($$.data.targets, xs); @@ -5638,9 +5657,9 @@ }; - c3.chart.fn.axis = function () { + c3_chart_fn.axis = function () { }; - c3.chart.fn.axis.labels = function (labels) { + c3_chart_fn.axis.labels = function (labels) { var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { @@ -5650,7 +5669,7 @@ } // TODO: return some values? }; - c3.chart.fn.axis.max = function (max) { + c3_chart_fn.axis.max = function (max) { var $$ = this.internal; if (arguments.length) { if (typeof max === 'object') { @@ -5663,7 +5682,7 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; - c3.chart.fn.axis.min = function (min) { + c3_chart_fn.axis.min = function (min) { var $$ = this.internal; if (arguments.length) { if (typeof min === 'object') { @@ -5676,8 +5695,7 @@ $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; - c3.chart.fn.axis.range = function (range) { - var $$ = this.internal; + c3_chart_fn.axis.range = function (range) { if (arguments.length) { if (typeof range.max !== 'undefined') { this.axis.max(range.max); } if (typeof range.min !== 'undefined') { this.axis.min(range.min); } @@ -5685,32 +5703,32 @@ }; - c3.chart.fn.legend = function () { + c3_chart_fn.legend = function () { }; - c3.chart.fn.legend.show = function (targetIds) { + c3_chart_fn.legend.show = function (targetIds) { var $$ = this.internal; $$.showLegend($$.mapToTargetIds(targetIds)); $$.updateAndRedraw({withLegend: true}); }; - c3.chart.fn.legend.hide = function (targetIds) { + c3_chart_fn.legend.hide = function (targetIds) { var $$ = this.internal; $$.hideLegend($$.mapToTargetIds(targetIds)); $$.updateAndRedraw({withLegend: true}); }; - c3.chart.fn.resize = function (size) { + c3_chart_fn.resize = function (size) { var $$ = this.internal; $$.config.size_width = size ? size.width : null; $$.config.size_height = size ? size.height : null; this.flush(); }; - c3.chart.fn.flush = function () { + c3_chart_fn.flush = function () { var $$ = this.internal; $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); }; - c3.chart.fn.destroy = function () { + c3_chart_fn.destroy = function () { var $$ = this.internal; $$.data.targets = undefined; $$.data.xs = {}; @@ -5917,16 +5935,3 @@ } })(window); - - -/** - * c3.plugin.js - */ -(function(fn) { - - fn.myapi = function () { - // we can do something with internal variables - // e.g. this.internal.isTimeseries, this.internal.svg, this.focus, etc - }; - -})(window.c3.chart.fn); From 2d676fbec75796f76736e502a4144814e5079c8c Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 26 Jul 2014 18:40:05 +0100 Subject: [PATCH 06/44] Merge diff to master --- c3.js | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/c3.js b/c3.js index c784b61..ac33a30 100644 --- a/c3.js +++ b/c3.js @@ -294,7 +294,7 @@ $$.pie = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); }); - if (!$$.config.pie_sort || !$$.config.donut_sort) { // TODO: this needs to be called by each type + if (!$$.config.data_order || !$$.config.pie_sort || !$$.config.donut_sort) { $$.pie.sort(null); } }; @@ -833,14 +833,12 @@ } }; c3_chart_internal_fn.updateRadius = function () { - var $$ = this; + var $$ = this, + w = $$.config.gauge_width || $$.config.donut_width; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; - if ($$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets)) { - $$.innerRadius = $$.radius * ($$.config.gauge_width ? ($$.radius - $$.config.gauge_width) / $$.radius : 0.6); - } else { - $$.innerRadius = 0; - } + $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; + $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; }; c3_chart_internal_fn.updateTargets = function (targets) { @@ -1911,7 +1909,7 @@ $$.config.data_onmouseover.call(c3, closest); $$.mouseover = true; } - } else { + } else if ($$.mouseover) { $$.svg.select('.' + CLASS.eventRect).style('cursor', null); $$.config.data_onmouseout.call(c3, closest); $$.mouseover = false; @@ -1930,7 +1928,7 @@ // select if selection enabled if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS.circles + '-' + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); } @@ -2990,6 +2988,9 @@ for (i = 1; i < rows.length; i++) { new_row = {}; for (j = 0; j < rows[i].length; j++) { + if (typeof rows[i][j] === 'undefined') { + throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); + } new_row[keys[j]] = rows[i][j]; } new_rows.push(new_row); @@ -3004,6 +3005,9 @@ if (typeof new_rows[j - 1] === 'undefined') { new_rows[j - 1] = {}; } + if (typeof columns[i][j] === 'undefined') { + throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); + } new_rows[j - 1][key] = columns[i][j]; } } @@ -3304,8 +3308,9 @@ c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { - var $$ = this, c = $$.config; - return typeof c.bar_width === 'number' ? c.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * c.bar_width_ratio) / barTargetsNum : 0; + var $$ = this, c = $$.config, + w = typeof c.bar_width === 'number' ? c.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * c.bar_width_ratio) / barTargetsNum : 0; + return c.bar_width_ratio && w > c.bar_width_max ? c.bar_width_max : w; }; c3_chart_internal_fn.getBars = function (i) { var $$ = this; @@ -5322,10 +5327,23 @@ c3_chart_fn.flow = function (args) { var $$ = this.internal, - targets = $$.convertDataToTargets($$.convertColumnsToData(args.columns), true), - notfoundIds = [], orgDataCount = $$.getMaxDataCount(), + targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + if (args.json) { + data = $$.convertJsonToData(args.json, args.keys); + } + else if (args.rows) { + data = $$.convertRowsToData(args.rows); + } + else if (args.columns) { + data = $$.convertColumnsToData(args.columns); + } + else { + return; + } + targets = $$.convertDataToTargets(data, true); + // Update/Add data $$.data.targets.forEach(function (t) { var found = false, i, j; From 476aa983efbbe389a9165fe43315910baa98822b Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 27 Jul 2014 15:42:39 +0100 Subject: [PATCH 07/44] Make arc plugable --- .jshintrc | 2 +- c3.js | 466 +++++++++++++++++++++++++++++------------------------- 2 files changed, 254 insertions(+), 214 deletions(-) diff --git a/.jshintrc b/.jshintrc index 5bbc9db..ce3c17b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -6,7 +6,7 @@ "trailing": true, "white": true, "maxlen": 210, - "undef": true, + "undef": false, "unused": true, "indent": 4, diff --git a/c3.js b/c3.js index ac33a30..ac42aa4 100644 --- a/c3.js +++ b/c3.js @@ -288,17 +288,6 @@ - // should be define in c3.arc.js - c3_chart_internal_fn.initPie = function () { - var $$ = this, d3 = $$.d3; - $$.pie = d3.layout.pie().value(function (d) { - return d.values.reduce(function (a, b) { return a + b.value; }, 0); - }); - if (!$$.config.data_order || !$$.config.pie_sort || !$$.config.donut_sort) { - $$.pie.sort(null); - } - }; - // should be define in c3.brush.js (c3.subchart.js?) c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; @@ -358,7 +347,7 @@ c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, c = $$.config; - var arcs, eventRect, i, binding = true; + var eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId = "c3-" + (+new Date()) + '-clip', @@ -431,7 +420,7 @@ $$.withoutFadeIn = {}; - if ($$.initPie) { $$.initPie(); } + if (isFunction(initPie)) { initPie.call($$); } if ($$.initBrush) { $$.initBrush(); } if ($$.initZoom) { $$.initZoom(); } @@ -573,45 +562,8 @@ .attr("class", CLASS.chartLines); // Define g for arc chart area - arcs = $$.main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartArcs) - .attr("transform", $$.translate.arc); - arcs.append('text') - .attr('class', CLASS.chartArcsTitle) - .style("text-anchor", "middle") - .text($$.getArcTitle()); - if ($$.hasGaugeType($$.data.targets)) { - arcs.append('path') - .attr("class", CLASS.chartArcsBackground) - .attr("d", function () { - var d = { - data: [{value: c.gauge_max}], - startAngle: -1 * (Math.PI / 2), - endAngle: Math.PI / 2 - }; - return $$.getArc(d, true, true); - }); - arcs.append("text") - .attr("dy", ".75em") - .attr("class", CLASS.chartArcsGaugeUnit) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_units : ''); - arcs.append("text") - .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") - .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMin) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_min : ''); - arcs.append("text") - .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") - .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMax) - .style("text-anchor", "middle") - .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_max : ''); - } + if (isFunction(initArc)) { initArc.call($$); } + if (isFunction(initGauge)) { initGauge.call($$); } $$.main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartTexts); @@ -826,23 +778,15 @@ // for arc $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); - $$.updateRadius(); + if (isFunction(updateRadius)) { updateRadius.call($$); } if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } }; - c3_chart_internal_fn.updateRadius = function () { - var $$ = this, - w = $$.config.gauge_width || $$.config.donut_width; - $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; - $$.radius = $$.radiusExpanded * 0.95; - $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; - }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainPieEnter, mainPieUpdate, mainTextUpdate, mainTextEnter; + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS; @@ -901,21 +845,7 @@ // MEMO: can not keep same color... //mainLineUpdate.exit().remove(); - //-- Pie --// - mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) - .data($$.pie(targets)) - .attr("class", function (d) { return $$.classChartArc(d); }); - mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", function (d) { return $$.classChartArc(d); }); - mainPieEnter.append('g') - .attr('class', function (d) { return $$.classArcs(d); }); - mainPieEnter.append("text") - .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") - .style("opacity", 0) - .style("text-anchor", "middle") - .style("pointer-events", "none"); - // MEMO: can not keep same color..., but not bad to update color in redraw - //mainPieUpdate.exit().remove(); + if (isFunction(updateTargetsForArc)) { updateTargetsForArc.call($$, targets); } /*-- Context --*/ @@ -957,7 +887,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS, d3 = $$.d3; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; - var mainLine, mainArea, mainCircle, mainBar, mainArc, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -1249,100 +1179,7 @@ } // arc - mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(function (d) { return $$.arcData(d); }); - mainArc.enter().append('path') - .attr("class", function (d) { return $$.classArc(d); }) - .style("fill", function (d) { return $$.color(d.data); }) - .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) - .style("opacity", 0) - .each(function (d) { - if ($$.isGaugeType(d.data)) { - d.startAngle = d.endAngle = -1 * (Math.PI / 2); - } - this._current = d; - }) - .on('mouseover', function (d) { - var updated, arcData; - if ($$.transiting) { // skip while transiting - return; - } - updated = $$.updateAngle(d); - arcData = $$.convertToArcData(updated); - // transitions - $$.expandArc(updated.data.id); - $$.toggleFocusLegend(updated.data.id, true); - $$.config.data_onmouseover.call(c3, arcData, this); - }) - .on('mousemove', function (d) { - var updated = $$.updateAngle(d), - arcData = $$.convertToArcData(updated), - selectedData = [arcData]; - $$.showTooltip(selectedData, d3.mouse(this)); - }) - .on('mouseout', function (d) { - var updated, arcData; - if ($$.transiting) { // skip while transiting - return; - } - updated = $$.updateAngle(d); - arcData = $$.convertToArcData(updated); - // transitions - $$.unexpandArc(updated.data.id); - $$.revertLegend(); - $$.hideTooltip(); - $$.config.data_onmouseout.call(c3, arcData, this); - }) - .on('click', function (d, i) { - var updated = $$.updateAngle(d), - arcData = $$.convertToArcData(updated); - $$.toggleShape(this, arcData, i); // onclick called in toogleShape() - }); - mainArc - .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) - .style("opacity", function (d) { return d === this._current ? 0 : 1; }) - .each(function () { $$.transiting = true; }) - .transition().duration(duration) - .attrTween("d", function (d) { - var updated = $$.updateAngle(d), interpolate; - if (! updated) { - return function () { return "M 0 0"; }; - } -/* - if (this._current === d) { - this._current = { - startAngle: Math.PI*2, - endAngle: Math.PI*2, - }; - } -*/ - if (isNaN(this._current.endAngle)) { - this._current.endAngle = this._current.startAngle; - } - interpolate = d3.interpolate(this._current, updated); - this._current = interpolate(0); - return function (t) { return $$.getArc(interpolate(t), true); }; - }) - .attr("transform", withTransform ? "scale(1)" : "") - .style("fill", function (d) { - return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); - }) // Where gauge reading color would receive customization. - .style("opacity", 1) - .call($$.endall, function () { - $$.transiting = false; - }); - mainArc.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - main.selectAll('.' + CLASS.chartArc).select('text') - .style("opacity", 0) - .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) - .text(function (d) { return $$.textForArcLabel(d); }) - .attr("transform", function (d) { return $$.transformForArcLabel(d); }) - .transition().duration(duration) - .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); - main.select('.' + CLASS.chartArcsTitle) - .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); + if (isFunction(redrawArc)) { redrawArc.call($$, duration, durationForExit, withTransform); } // subchart if ($$.config.subchart_show) { @@ -3934,13 +3771,7 @@ if (c.zoom_enabled) { $$.zoom.scale($$.x); } } // update for arc - this.updateArc(); - }; - c3_chart_internal_fn.updateArc = function () { - var $$ = this; - $$.svgArc = $$.getSvgArc(); - $$.svgArcExpanded = $$.getSvgArcExpanded(); - $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); + if (isFunction(updateArc)) { updateArc.call($$); } }; @@ -4476,13 +4307,38 @@ - /** - * c3.arc.js - */ - c3_chart_internal_fn.updateAngle = function (d) { + //-- c3.arc.js --// + + var initPie = c3_chart_internal_fn.initPie = function () { + var $$ = this, d3 = $$.d3, c = $$.config; + $$.pie = d3.layout.pie().value(function (d) { + return d.values.reduce(function (a, b) { return a + b.value; }, 0); + }); + if (!c.data_order || !c.pie_sort || !c.donut_sort) { + $$.pie.sort(null); + } + }; + + var updateRadius = c3_chart_internal_fn.updateRadius = function () { + var $$ = this, + w = $$.config.gauge_width || $$.config.donut_width; + $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; + $$.radius = $$.radiusExpanded * 0.95; + $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; + $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; + }; + + var updateArc = c3_chart_internal_fn.updateArc = function () { + var $$ = this; + $$.svgArc = getSvgArc.call($$); + $$.svgArcExpanded = getSvgArcExpanded.call($$); + $$.svgArcExpandedSub = getSvgArcExpanded.call($$, 0.98); + }; + + var updateAngle = c3_chart_internal_fn.updateAngle = function (d) { var $$ = this, found = false, index = 0; - $$.pie($$.filterTargetsToShow($$.data.targets)).sort(this.descByStartAngle).forEach(function (t) { + $$.pie($$.filterTargetsToShow($$.data.targets)).sort(descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { found = true; d = t; @@ -4493,7 +4349,7 @@ if (isNaN(d.endAngle)) { d.endAngle = d.startAngle; } - if (this.isGaugeType(d.data)) { + if ($$.isGaugeType(d.data)) { var gMin = $$.config.gauge_min, gMax = $$.config.gauge_max, gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; @@ -4502,33 +4358,38 @@ } return found ? d : null; }; - c3_chart_internal_fn.getSvgArc = function () { + + var getSvgArc = c3_chart_internal_fn.getSvgArc = function () { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { var updated; if (withoutUpdate) { return arc(d); } // for interpolate - updated = $$.updateAngle(d); + updated = updateAngle.call($$, d); return updated ? arc(updated) : "M 0 0"; }; // TODO: extends all function newArc.centroid = arc.centroid; return newArc; }; - c3_chart_internal_fn.getSvgArcExpanded = function (rate) { + + var getSvgArcExpanded = c3_chart_internal_fn.getSvgArcExpanded = function (rate) { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { - var updated = $$.updateAngle(d); + var updated = updateAngle.call($$, d); return updated ? arc(updated) : "M 0 0"; }; }; - c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { + + var getArc = c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; }; - c3_chart_internal_fn.transformForArcLabel = function (d) { + + + var transformForArcLabel = c3_chart_internal_fn.transformForArcLabel = function (d) { var $$ = this, - updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + updated = updateAngle.call($$, d), c, x, y, h, ratio, translate = ""; if (updated && !$$.hasGaugeType($$.data.targets)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; @@ -4540,36 +4401,40 @@ } return translate; }; - c3_chart_internal_fn.getArcRatio = function (d) { + + var getArcRatio = c3_chart_internal_fn.getArcRatio = function (d) { var $$ = this, whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; - c3_chart_internal_fn.convertToArcData = function (d) { + + var convertToArcData = c3_chart_internal_fn.convertToArcData = function (d) { return this.addName({ id: d.data.id, value: d.value, - ratio: this.getArcRatio(d), + ratio: getArcRatio.call(this, d), index: d.index }); }; - c3_chart_internal_fn.textForArcLabel = function (d) { + + var textForArcLabel = c3_chart_internal_fn.textForArcLabel = function (d) { var $$ = this, updated, value, ratio, format; - if (! $$.shouldShowArcLabel()) { return ""; } - updated = $$.updateAngle(d); + if (! shouldShowArcLabel.call($$)) { return ""; } + updated = updateAngle.call($$, d); value = updated ? updated.value : null; - ratio = $$.getArcRatio(updated); - if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } - format = $$.getArcLabelFormat(); + ratio = getArcRatio.call($$, updated); + if (! $$.hasGaugeType($$.data.targets) && ! meetsArcLabelThreshold.call($$, ratio)) { return ""; } + format = getArcLabelFormat.call($$); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; - c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { + + var expandArc = c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, CLASS = $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); - if ($$.shouldExpand(id)) { + if (shouldExpand.call($$, id)) { target.selectAll('path') .transition().duration(50) .attr("d", $$.svgArcExpanded) @@ -4585,7 +4450,8 @@ noneTargets.style("opacity", 0.3); } }; - c3_chart_internal_fn.unexpandArc = function (id) { + + var unexpandArc = c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, CLASS = $$.CLASS, target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); target.selectAll('path.' + CLASS.arc) @@ -4594,11 +4460,13 @@ $$.svg.selectAll('.' + CLASS.arc) .style("opacity", 1); }; - c3_chart_internal_fn.shouldExpand = function (id) { + + var shouldExpand = c3_chart_internal_fn.shouldExpand = function (id) { var $$ = this; return ($$.isDonutType(id) && $$.config.donut_expand) || ($$.isGaugeType(id) && $$.config.gauge_expand) || ($$.isPieType(id) && $$.config.pie_expand); }; - c3_chart_internal_fn.shouldShowArcLabel = function () { + + var shouldShowArcLabel = c3_chart_internal_fn.shouldShowArcLabel = function () { var $$ = this, shouldShow = true; if ($$.hasDonutType($$.data.targets)) { shouldShow = $$.config.donut_label_show; @@ -4608,12 +4476,14 @@ // when gauge, always true return shouldShow; }; - c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { + + var meetsArcLabelThreshold = c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { var $$ = this, c = $$.config, threshold = this.hasDonutType($$.data.targets) ? c.donut_label_threshold : c.pie_label_threshold; return ratio >= threshold; }; - c3_chart_internal_fn.getArcLabelFormat = function () { + + var getArcLabelFormat = c3_chart_internal_fn.getArcLabelFormat = function () { var $$ = this, format = $$.config.pie_label_format; if ($$.hasGaugeType($$.data.targets)) { @@ -4623,14 +4493,180 @@ } return format; }; - c3_chart_internal_fn.getArcTitle = function () { + + var getArcTitle = c3_chart_internal_fn.getArcTitle = function () { var $$ = this; return $$.hasDonutType($$.data.targets) ? $$.config.donut_title : ""; }; - c3_chart_internal_fn.descByStartAngle = function (a, b) { + + var descByStartAngle = c3_chart_internal_fn.descByStartAngle = function (a, b) { return a.startAngle - b.startAngle; }; + var updateTargetsForArc = c3_chart_internal_fn.updateTargetsForArc = function (targets) { + var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; + mainPieUpdate = main.select('.' + $$.CLASS.chartArcs).selectAll('.' + $$.CLASS.chartArc) + .data($$.pie(targets)) + .attr("class", function (d) { return $$.classChartArc(d); }); + mainPieEnter = mainPieUpdate.enter().append("g") + .attr("class", function (d) { return $$.classChartArc(d); }); + mainPieEnter.append('g') + .attr('class', function (d) { return $$.classArcs(d); }); + mainPieEnter.append("text") + .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") + .style("opacity", 0) + .style("text-anchor", "middle") + .style("pointer-events", "none"); + // MEMO: can not keep same color..., but not bad to update color in redraw + //mainPieUpdate.exit().remove(); + }; + + var initArc = c3_chart_internal_fn.initArc = function () { + var $$ = this, CLASS = $$.CLASS, arcs; + arcs = $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartArcs) + .attr("transform", $$.translate.arc); + arcs.append('text') + .attr('class', CLASS.chartArcsTitle) + .style("text-anchor", "middle") + .text(getArcTitle.call($$)); + }; + + var redrawArc = c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { + var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, main = $$.main, + mainArc; + mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) + .data(function (d) { return $$.arcData(d); }); + mainArc.enter().append('path') + .attr("class", function (d) { return $$.classArc(d); }) + .style("fill", function (d) { return $$.color(d.data); }) + .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) + .style("opacity", 0) + .each(function (d) { + if ($$.isGaugeType(d.data)) { + d.startAngle = d.endAngle = -1 * (Math.PI / 2); + } + this._current = d; + }) + .on('mouseover', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; + } + updated = updateAngle.call($$, d); + arcData = convertToArcData.call($$, updated); + // transitions + expandArc.call($$, updated.data.id); + $$.toggleFocusLegend(updated.data.id, true); + $$.config.data_onmouseover.call(c3, arcData, this); + }) + .on('mousemove', function (d) { + var updated = updateAngle.call($$, d), + arcData = convertToArcData.call($$, updated), + selectedData = [arcData]; + $$.showTooltip(selectedData, d3.mouse(this)); + }) + .on('mouseout', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; + } + updated = updateAngle.call($$, d); + arcData = convertToArcData.call($$, updated); + // transitions + unexpandArc.call($$, updated.data.id); + $$.revertLegend(); + $$.hideTooltip(); + $$.config.data_onmouseout.call(c3, arcData, this); + }) + .on('click', function (d, i) { + var updated = updateAngle.call($$, d), + arcData = convertToArcData.call($$, updated); + $$.toggleShape(this, arcData, i); // onclick called in toogleShape() + }); + mainArc + .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .style("opacity", function (d) { return d === this._current ? 0 : 1; }) + .each(function () { $$.transiting = true; }) + .transition().duration(duration) + .attrTween("d", function (d) { + var updated = updateAngle.call($$, d), interpolate; + if (! updated) { + return function () { return "M 0 0"; }; + } +// if (this._current === d) { +// this._current = { +// startAngle: Math.PI*2, +// endAngle: Math.PI*2, +// }; +// } + if (isNaN(this._current.endAngle)) { + this._current.endAngle = this._current.startAngle; + } + interpolate = d3.interpolate(this._current, updated); + this._current = interpolate(0); + return function (t) { return getArc.call($$, interpolate(t), true); }; + }) + .attr("transform", withTransform ? "scale(1)" : "") + .style("fill", function (d) { + return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); + }) // Where gauge reading color would receive customization. + .style("opacity", 1) + .call($$.endall, function () { + $$.transiting = false; + }); + mainArc.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + main.selectAll('.' + CLASS.chartArc).select('text') + .style("opacity", 0) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .text(function (d) { return textForArcLabel.call($$, d); }) + .attr("transform", function (d) { return transformForArcLabel.call($$, d); }) + .transition().duration(duration) + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); + main.select('.' + CLASS.chartArcsTitle) + .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); + + }; + + //-- gauge.js --// + + var initGauge = c3_chart_internal_fn.initGauge = function () { + var $$ = this, CLASS = $$.CLASS, c = $$.config, arcs; + if ($$.hasGaugeType($$.data.targets)) { + arcs.append('path') + .attr("class", CLASS.chartArcsBackground) + .attr("d", function () { + var d = { + data: [{value: c.gauge_max}], + startAngle: -1 * (Math.PI / 2), + endAngle: Math.PI / 2 + }; + return $$.getArc(d, true, true); + }); + arcs.append("text") + .attr("dy", ".75em") + .attr("class", CLASS.chartArcsGaugeUnit) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(c.gauge_label_show ? c.gauge_units : ''); + arcs.append("text") + .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS.chartArcsGaugeMin) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(c.gauge_label_show ? c.gauge_min : ''); + arcs.append("text") + .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS.chartArcsGaugeMax) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(c.gauge_label_show ? c.gauge_max : ''); + } + }; /** @@ -4672,6 +4708,10 @@ c3_chart_internal_fn.isValue = function (v) { return v || v === 0; }; + function isFunction(s) { + return s === 'function'; + } + c3_chart_internal_fn.isFunction = isFunction(); c3_chart_internal_fn.isUndefined = function (v) { return typeof v === 'undefined'; }; @@ -5192,7 +5232,7 @@ focus(candidatesForNoneArc.classed($$.CLASS.focused, true)); focus(candidatesForArc); if ($$.hasArcType($$.data.targets)) { - $$.expandArc(targetId, true); + expandArc.call($$, targetId, true); } $$.toggleFocusLegend(targetId, true); }; @@ -5209,7 +5249,7 @@ defocus(candidatesForNoneArc.classed($$.CLASS.focused, false)); defocus(candidatesForArc); if ($$.hasArcType($$.data.targets)) { - $$.unexpandArc(targetId); + unexpandArc.call($$, targetId); } $$.toggleFocusLegend(targetId, false); }; @@ -5225,7 +5265,7 @@ revert(candidatesForNoneArc.classed($$.CLASS.focused, false)); revert(candidatesForArc); if ($$.hasArcType($$.data.targets)) { - $$.unexpandArc(targetId); + unexpandArc.call($$, targetId); } $$.revertLegend(); }; From 841f76b128abceebe6ec3fa83d5ecf3145921440 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 27 Jul 2014 18:14:16 +0100 Subject: [PATCH 08/44] Make subchart plugable --- c3.js | 802 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 408 insertions(+), 394 deletions(-) diff --git a/c3.js b/c3.js index ac42aa4..eff38ab 100644 --- a/c3.js +++ b/c3.js @@ -288,20 +288,6 @@ - // should be define in c3.brush.js (c3.subchart.js?) - c3_chart_internal_fn.initBrush = function () { - var $$ = this, d3 = $$.d3; - // TODO: this should be pluggable - $$.brush = d3.svg.brush().on("brush", $$.redrawForBrush); - $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } - return this; - }; - $$.brush.scale = function (scale) { - return $$.config.axis_rotated ? this.y(scale) : this.x(scale); - }; - }; - // should be define in c3.zoom.js c3_chart_internal_fn.initZoom = function () { var $$ = this, d3 = $$.d3; @@ -420,8 +406,12 @@ $$.withoutFadeIn = {}; - if (isFunction(initPie)) { initPie.call($$); } - if ($$.initBrush) { $$.initBrush(); } + if (isFunctionType(initPie)) { initPie.call($$); } + if (isFunctionType(typeof initBrush)) { + initBrush.call($$); + } else { + $$.axes.subx = d3.selectAll([]); + } if ($$.initZoom) { $$.initZoom(); } $$.selectChart = d3.select(c.bindto); @@ -446,7 +436,7 @@ } // when gauge, hide legend // TODO: fix - if ($$.hasGaugeType($$.data.targets)) { + if (hasGaugeType.call($$, $$.data.targets)) { c.legend_show = false; } @@ -466,7 +456,7 @@ $$.orgXDomain = $$.x.domain(); // Set initialized scales to brush and zoom - $$.brush.scale($$.subX); + if ($$.brush) { $$.brush.scale($$.subX); } if (c.zoom_enabled) { $$.zoom.scale($$.x); } /*-- Basic Elements --*/ @@ -486,12 +476,9 @@ // Define regions $$.main = $$.svg.append("g").attr("transform", $$.translate.main); - $$.context = $$.svg.append("g").attr("transform", $$.translate.context); $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); - if (!c.subchart_show) { - $$.context.style('visibility', 'hidden'); - } + if (isFunctionType(typeof initSubchart)) { initSubchart.call($$); } if (!c.legend_show) { $$.legend.style('visibility', 'hidden'); @@ -562,8 +549,8 @@ .attr("class", CLASS.chartLines); // Define g for arc chart area - if (isFunction(initArc)) { initArc.call($$); } - if (isFunction(initGauge)) { initGauge.call($$); } + if (isFunctionType(initArc)) { initArc.call($$); } + if (isFunctionType(initGauge)) { initGauge.call($$); } $$.main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartTexts); @@ -612,36 +599,6 @@ .attr("transform", c.axis_rotated ? "" : "rotate(-90)") .style("text-anchor", function () { return $$.textAnchorForY2AxisLabel(); }); - /*-- Context Region --*/ - - // Define g for chart area - $$.context.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS.chart); - - // Define g for bar chart area - $$.context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); - - // Define g for line chart area - $$.context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); - - // Add extent rect for Brush - $$.context.append("g") - .attr("clip-path", $$.clipPath) - .attr("class", CLASS.brush) - .call($$.brush) - .selectAll("rect") - .attr(c.axis_rotated ? "width" : "height", c.axis_rotated ? $$.width2 : $$.height2); - - // ATTENTION: This must be called AFTER chart added - // Add Axis - $$.axes.subx = $$.context.append("g") - .attr("class", CLASS.axisX) - .attr("transform", $$.translate.subx) - .attr("clip-path", c.axis_rotated ? "" : $$.clipPathForXAxis); - // Set targets $$.updateTargets($$.data.targets); @@ -667,7 +624,7 @@ } $$.tooltip.html(c.tooltip_contents.call($$, $$.data.targets.map(function (d) { return $$.addName(d.values[c.tooltip_init_x]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); + }), $$.getXAxisTickFormat(), $$.getYFormat(hasArcType.call($$, $$.data.targets)), $$.color)); $$.tooltip.style("top", c.tooltip_init_position.top) .style("left", c.tooltip_init_position.left) .style("display", "block"); @@ -718,7 +675,7 @@ var $$ = this, c = $$.config; var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = $$.hasArcType($$.data.targets), + hasArc = hasArcType.call($$, $$.data.targets), xAxisHeight = c.axis_rotated || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), subchartHeight = c.subchart_show && !hasArc ? (c.subchart_size_height + xAxisHeight) : 0; @@ -778,7 +735,7 @@ // for arc $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); - if (isFunction(updateRadius)) { updateRadius.call($$); } + if (isFunctionType(updateRadius)) { updateRadius.call($$); } if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; @@ -787,94 +744,66 @@ c3_chart_internal_fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; - var contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; - var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS; + var $$ = this, main = $$.main, CLASS = $$.CLASS; /*-- Main --*/ //-- Text --// mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) .data(targets) - .attr('class', function (d) { return $$.classChartText(d); }); + .attr('class', function (d) { return classChartText.call($$, d); }); mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', function (d) { return $$.classChartText(d); }) + .attr('class', function (d) { return classChartText.call($$, d); }) .style('opacity', 0) .style("pointer-events", "none"); mainTextEnter.append('g') - .attr('class', function (d) { return $$.classTexts(d); }); + .attr('class', function (d) { return classTexts.call($$, d); }); //-- Bar --// mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr('class', function (d) { return $$.classChartBar(d); }); + .attr('class', function (d) { return classChartBar.call($$, d); }); mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', function (d) { return $$.classChartBar(d); }) + .attr('class', function (d) { return classChartBar.call($$, d); }) .style('opacity', 0) .style("pointer-events", "none"); // Bars for each data mainBarEnter.append('g') - .attr("class", function (d) { return $$.classBars(d); }) + .attr("class", function (d) { return classBars.call($$, d); }) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); //-- Line --// mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr('class', function (d) { return $$.classChartLine(d); }); + .attr('class', function (d) { return classChartLine.call($$, d); }); mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', function (d) { return $$.classChartLine(d); }) + .attr('class', function (d) { return classChartLine.call($$, d); }) .style('opacity', 0) .style("pointer-events", "none"); // Lines for each data mainLineEnter.append('g') - .attr("class", function (d) { return $$.classLines(d); }); + .attr("class", function (d) { return classLines.call($$, d); }); // Areas mainLineEnter.append('g') - .attr('class', function (d) { return $$.classAreas(d); }); + .attr('class', function (d) { return classAreas.call($$, d); }); // Circles for each data point on lines mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); + .attr("class", function (d) { return generateClass.call($$, CLASS.selectedCircles, d.id); }); mainLineEnter.append('g') - .attr("class", function (d) { return $$.classCircles(d); }) + .attr("class", function (d) { return classCircles.call($$, d); }) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + main.selectAll('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { d.value = t.values[d.index].value; }); }); // MEMO: can not keep same color... //mainLineUpdate.exit().remove(); - if (isFunction(updateTargetsForArc)) { updateTargetsForArc.call($$, targets); } - - /*-- Context --*/ - - if ($$.config.subchart_show) { + if (isFunctionType(updateTargetsForArc)) { updateTargetsForArc.call($$, targets); } - contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) - .data(targets) - .attr('class', $$.classChartBar); - contextBarEnter = contextBarUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', $$.classChartBar); - // Bars for each data - contextBarEnter.append('g') - .attr("class", $$.classBars); - - //-- Line --// - contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) - .data(targets) - .attr('class', $$.classChartLine); - contextLineEnter = contextLineUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', $$.classChartLine); - // Lines for each data - contextLineEnter.append("g") - .attr("class", $$.classLines); - // Area - contextLineEnter.append("g") - .attr("class", $$.classAreas); - } + if (isFunctionType(typeof updateTargetsForSubchart)) { updateTargetsForSubchart.call($$, targets); } /*-- Show --*/ @@ -885,14 +814,14 @@ }; c3_chart_internal_fn.redraw = function (options, transitions) { - var $$ = this, main = $$.main, context = $$.context, CLASS = $$.CLASS, d3 = $$.d3; + var $$ = this, main = $$.main, d3 = $$.d3; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; - var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, contextLine, contextArea, contextBar, eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; + var areaIndices = $$.getShapeIndices(isAreaType), barIndices = $$.getShapeIndices(isBarType), lineIndices = $$.getShapeIndices(isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$.hasArcType($$.data.targets); - var drawArea, drawAreaOnSub, drawBar, drawBarOnSub, drawLine, drawLineOnSub, xForText, yForText; + var hideAxis = hasArcType.call($$, $$.data.targets); + var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; @@ -1104,7 +1033,7 @@ mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) .data($$.config.regions); mainRegion.enter().append('g') - .attr('class', function (d) { return $$.classRegion(d); }) + .attr('class', function (d) { return classRegion.call($$, d); }) .append('rect') .style("fill-opacity", 0); mainRegion.exit().transition().duration(duration) @@ -1113,34 +1042,34 @@ // bars mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(function (d) { return $$.barData(d); }); + .data(function (d) { return barData.call($$, d); }); mainBar.enter().append('path') - .attr("class", function (d) { return $$.classBar(d); }) + .attr("class", function (d) { return classBar.call($$, d); }) .style("stroke", function (d) { return $$.color(d.id); }) .style("fill", function (d) { return $$.color(d.id); }); mainBar - .style("opacity", function (d) { return $$.initialOpacity(d); }); + .style("opacity", function (d) { return initialOpacity.call($$, d); }); mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); // lines, areas and cricles mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(function (d) { return $$.lineData(d); }); + .data(function (d) { return lineData.call($$, d); }); mainLine.enter().append('path') - .attr('class', function (d) { return $$.classLine(d); }) + .attr('class', function (d) { return classLine.call($$, d); }) .style("stroke", $$.color); mainLine - .style("opacity", function (d) { return $$.initialOpacity(d); }) + .style("opacity", function (d) { return initialOpacity.call($$, d); }) .attr('transform', null); mainLine.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(function (d) { return $$.lineData(d); }); + .data(function (d) { return lineData.call($$, d); }); mainArea.enter().append('path') - .attr("class", function (d) { return $$.classArea(d); }) + .attr("class", function (d) { return classArea.call($$, d); }) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); mainArea @@ -1151,21 +1080,21 @@ if ($$.config.point_show) { mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) - .data(function (d) { return $$.lineOrScatterData(d); }); + .data(function (d) { return lineOrScatterData.call($$, d); }); mainCircle.enter().append("circle") - .attr("class", function (d) { return $$.classCircle(d); }) + .attr("class", function (d) { return classCircle.call($$, d); }) .attr("r", function (d) { return $$.pointR(d); }) .style("fill", $$.color); mainCircle - .style("opacity", function (d) { return $$.initialOpacity(d); }); + .style("opacity", function (d) { return initialOpacity.call($$, d); }); mainCircle.exit().remove(); } if ($$.hasDataLabel()) { mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) - .data($$.barOrLineData); + .data(function (d) { return barOrLineData.call($$, d); }); mainText.enter().append('text') - .attr("class", function (d) { return $$.classText(d); }) + .attr("class", function (d) { return classText.call($$, d); }) .attr('text-anchor', function (d) { return $$.config.axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) @@ -1179,81 +1108,14 @@ } // arc - if (isFunction(redrawArc)) { redrawArc.call($$, duration, durationForExit, withTransform); } + if (isFunctionType(redrawArc)) { redrawArc.call($$, duration, durationForExit, withTransform); } // subchart - if ($$.config.subchart_show) { - // reflect main chart to extent on subchart if zoomed - if (d3.event && d3.event.type === 'zoom') { - $$.brush.extent($$.x.orgDomain()).update(); - } - // update subchart elements if needed - if (withSubchart) { - - // rotate tick text if needed - if (!$$.config.axis_rotated && $$.config.axis_x_tick_rotate) { - $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.config.axis_x_tick_rotate); - } - - // extent rect - if (!$$.brush.empty()) { - $$.brush.extent($$.x.orgDomain()).update(); - } - // setup drawer - MEMO: this must be called after axis updated - drawAreaOnSub = $$.generateDrawArea(areaIndices, true); - drawBarOnSub = $$.generateDrawBar(barIndices, true); - drawLineOnSub = $$.generateDrawLine(lineIndices, true); - // bars - contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data($$.barData); - contextBar.enter().append('path') - .attr("class", $$.classBar) - .style("stroke", 'none') - .style("fill", $$.color); - contextBar - .style("opacity", $$.initialOpacity) - .transition().duration(duration) - .attr('d', drawBarOnSub) - .style('opacity', 1); - contextBar.exit().transition().duration(duration) - .style('opacity', 0) - .remove(); - // lines - contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data($$.lineData); - contextLine.enter().append('path') - .attr('class', function (d) { return $$.classLine(d); }) - .style('stroke', $$.color); - contextLine - .style("opacity", $$.initialOpacity) - .transition().duration(duration) - .attr("d", drawLineOnSub) - .style('opacity', 1); - contextLine.exit().transition().duration(duration) - .style('opacity', 0) - .remove(); - // area - contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data($$.lineData); - contextArea.enter().append('path') - .attr("class", function (d) { return $$.classArea(d); }) - .style("fill", $$.color) - .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); - contextArea - .style("opacity", 0) - .transition().duration(duration) - .attr("d", drawAreaOnSub) - .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity); - contextArea.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - } - } + if (isFunctionType(typeof redrawSubchart)) { redrawSubchart.call($$, withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } // circles for select main.selectAll('.' + CLASS.selectedCircles) - .filter(function (d) { return $$.isBarType(d); }) + .filter(function (d) { return isBarType.call($$, d); }) .selectAll('circle') .remove(); @@ -1313,7 +1175,7 @@ $$.generateEventRectsForSingleX(eventRectUpdate.enter()); // update eventRectUpdate - .attr('class', function (d) { return $$.classEvent(d); }) + .attr('class', function (d) { return classEvent.call($$, d); }) .attr("x", $$.config.axis_rotated ? 0 : rectX) .attr("y", $$.config.axis_rotated ? rectX : 0) .attr("width", $$.config.axis_rotated ? $$.width : rectW) @@ -1505,16 +1367,6 @@ $$.updateZoom(); }; - c3_chart_internal_fn.redrawForBrush = function () { - var $$ = this, x = $$.x; - $$.redraw({ - withTransition: false, - withY: false, - withSubchart: false, - withUpdateXDomain: true - }); - $$.config.subchart_onbrush.call(c3, x.orgDomain()); - }; c3_chart_internal_fn.redrawForZoom = function () { var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; if (!$$.config.zoom_enabled) { @@ -1571,13 +1423,13 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, CLASS = $$.CLASS; eventRectEnter.append("rect") - .attr("class", function (d) { return $$.classEvent(d); }) + .attr("class", function (d) { return classEvent.call($$, d); }) .style("cursor", $$.config.data_selection_enabled && $$.config.data_selection_grouped ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; if ($$.dragging) { return; } // do nothing if dragging - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } selectedData = $$.data.targets.map(function (t) { return $$.addName($$.getValueOnIndex(t.values, index)); @@ -1607,7 +1459,7 @@ }) .on('mouseout', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } $$.hideXGridFocus(); $$.hideTooltip(); // Undo expanded shapes @@ -1623,7 +1475,7 @@ eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } // Show tooltip selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { @@ -1676,7 +1528,7 @@ }) .on('click', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } if ($$.cancelClick) { $$.cancelClick = false; return; @@ -1711,14 +1563,14 @@ var mouse, closest, sameXData, selectedData; if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType(targetsToShow)) { return; } + if (hasArcType.call($$, targetsToShow)) { return; } mouse = d3.mouse(this); closest = $$.findClosestFromTargets(targetsToShow, mouse); if (! closest) { return; } - if ($$.isScatterType(closest)) { + if (isScatterType.call($$, closest)) { sameXData = [closest]; } else { sameXData = $$.filterSameX(targetsToShow, closest.x); @@ -1756,7 +1608,7 @@ var targetsToShow = $$.filterTargetsToShow($$.data.targets); var mouse, closest; - if ($$.hasArcType(targetsToShow)) { return; } + if (hasArcType.call($$, targetsToShow)) { return; } mouse = d3.mouse(this); closest = $$.findClosestFromTargets(targetsToShow, mouse); @@ -1765,7 +1617,7 @@ // select if selection enabled if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.main.select('.' + CLASS.circles + getTargetSelectorSuffix.call($$, closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); } @@ -1786,13 +1638,12 @@ - c3_chart_internal_fn.initialOpacity = function (d) { - var $$ = this; - return d.value !== null && $$.withoutFadeIn[d.id] ? 1 : 0; + var initialOpacity = c3_chart_internal_fn.initialOpacity = function (d) { + return d.value !== null && this.withoutFadeIn[d.id] ? 1 : 0; }; c3_chart_internal_fn.opacityForCircle = function (d) { var $$ = this; - return $$.isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 0; + return $$.isValue(d.value) ? isScatterType.call($$, d) ? 0.5 : 1 : 0; }; c3_chart_internal_fn.opacityForText = function () { return this.hasDataLabel() ? 1 : 0; @@ -1842,17 +1693,6 @@ y2Axis.attr("transform", $$.translate.y2); $$.main.select('.' + CLASS.chartArcs).attr("transform", $$.translate.arc); }; - c3_chart_internal_fn.transformContext = function (withTransition, transitions) { - var $$ = this, subXAxis; - if (transitions && transitions.axisSubX) { - subXAxis = transitions.axisSubX; - } else { - subXAxis = $$.context.select('.' + $$.CLASS.axisX); - if (withTransition) { subXAxis = subXAxis.transition(); } - } - $$.context.attr("transform", $$.translate.context); - subXAxis.attr("transform", $$.translate.subx); - }; c3_chart_internal_fn.transformLegend = function (withTransition) { var $$ = this; (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); @@ -1860,7 +1700,7 @@ c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); - if ($$.config.subchart_show) { $$.transformContext(withTransition, transitions); } + if ($$.config.subchart_show) { transformContext.call($$, withTransition, transitions); } $$.transformLegend(withTransition); }; @@ -2011,7 +1851,7 @@ leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$.hasArcType($$.data.targets), + hasArc = hasArcType.call($$, $$.data.targets), svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); return svgLeft > 0 ? svgLeft : 0; }; @@ -2043,7 +1883,7 @@ return $$.config.axis_rotated ? $$.height : $$.width; } maxDataCount = $$.getMaxDataCount(); - ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + ratio = (hasBarType.call($$, $$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2055,7 +1895,7 @@ c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { var $$ = this; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$.hasArcType($$.data.targets), + var forArc = hasArcType.call($$, $$.data.targets), dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); if (dataToShow.length === 0 || !$$.config.tooltip_show) { return; @@ -2108,7 +1948,7 @@ var $$ = this, dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); if (! $$.config.tooltip_show) { return; } // Hide when scatter plot exists - if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } + if (hasScatterType.call($$, $$.data.targets) || hasArcType.call($$, $$.data.targets)) { return; } var focusEl = $$.main.selectAll('line.' + $$.CLASS.xgridFocus); focusEl .style("visibility", "visible") @@ -2239,7 +2079,7 @@ $$.legend.style('visibility', 'visible'); } $$.removeHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) + $$.legend.selectAll(selectorLegends.call($$, targetIds)) .style('visibility', 'visible') .transition() .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); @@ -2251,7 +2091,7 @@ $$.legend.style('visibility', 'hidden'); } $$.addHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) + $$.legend.selectAll(selectorLegends.call($$, targetIds)) .style('opacity', 0) .style('visibility', 'hidden'); }; @@ -2347,7 +2187,7 @@ l = $$.legend.selectAll('.' + CLASS.legendItem) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) + .attr('class', function (id) { return generateClass.call($$, CLASS.legendItem, id); }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { @@ -3019,7 +2859,7 @@ done(); return; } - $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) + $$.svg.selectAll(targetIds.map(function (id) { return selectorTarget.call($$, id); })) .transition() .style('opacity', 0) .remove() @@ -3028,7 +2868,7 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + $$.CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); + $$.legend.selectAll('.' + $$.CLASS.legendItem + getTargetSelectorSuffix.call($$, id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -3100,7 +2940,7 @@ c3_chart_internal_fn.getInterpolate = function (d) { var $$ = this; - return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; + return isSplineType.call($$, d) ? "cardinal" : isStepType.call($$, d) ? "step-after" : "linear"; }; @@ -3109,12 +2949,12 @@ }; c3_chart_internal_fn.circleY = function (d, i) { var $$ = this, - lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + lineIndices = $$.getShapeIndices(isLineType), getPoint = $$.generateGetLinePoint(lineIndices); return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; - return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix.call($$, id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this, CLASS = $$.CLASS; @@ -3131,7 +2971,7 @@ }; c3_chart_internal_fn.pointR = function (d) { var $$ = this; - return $$.config.point_show && !$$.isStepType(d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; + return $$.config.point_show && !isStepType.call($$, d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; }; c3_chart_internal_fn.pointExpandedR = function (d) { var $$ = this, c = $$.config; @@ -3186,7 +3026,7 @@ barW = $$.getBarW($$.xAxis, barTargetsNum), barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), barY = $$.getShapeY(!!isSub), - barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + barOffset = $$.getShapeOffset(isBarType, barIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3222,7 +3062,7 @@ return function (d) { var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; - if ($$.isAreaType(d)) { + if (isAreaType.call($$, d)) { path = area.interpolate($$.getInterpolate(d))(data); } else { if (data[0]) { @@ -3250,7 +3090,7 @@ return function (d) { var data = $$.config.line_connect_null ? $$.filterRemoveNull(d.values) : d.values, x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; - if ($$.isLineType(d)) { + if (isLineType.call($$, d)) { if ($$.config.data_regions[d.id]) { path = $$.lineWithRegions(data, x, y, $$.config.data_regions[d.id]); } else { @@ -3279,7 +3119,7 @@ var $$ = this, box = textElement.getBoundingClientRect(), xPos, padding; if ($$.config.axis_rotated) { - padding = $$.isBarType(d) ? 4 : 6; + padding = isBarType.call($$, d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; @@ -3292,7 +3132,7 @@ if ($$.config.axis_rotated) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { - yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); + yPos = points[2][1] + (d.value < 0 ? box.height : isBarType.call($$, d) ? -3 : -6); } return yPos < box.height ? box.height : yPos; }; @@ -3302,7 +3142,7 @@ areaTargetsNum = areaIndices.__max__ + 1, x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), y = $$.getShapeY(!!isSub), - areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + areaOffset = $$.getShapeOffset(isAreaType, areaIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3325,7 +3165,7 @@ lineTargetsNum = lineIndices.__max__ + 1, x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), y = $$.getShapeY(!!isSub), - lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), + lineOffset = $$.getShapeOffset(isLineType, lineIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3525,7 +3365,7 @@ $$.config.data_type = type; } }; - c3_chart_internal_fn.hasType = function (targets, type) { + var hasType = c3_chart_internal_fn.hasType = function (targets, type) { var $$ = this, has = false; targets.forEach(function (t) { if ($$.config.data_types[t.id] === type) { has = true; } @@ -3533,91 +3373,90 @@ }); return has; }; - /* not used function hasLineType(targets) { return hasType(targets, 'line'); } */ - c3_chart_internal_fn.hasAreaType = function (targets) { - return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); + var hasAreaType = c3_chart_internal_fn.hasAreaType = function (targets) { + return hasType.call(this, targets, 'area') || hasType.call(this, targets, 'area-spline') || hasType.call(this, targets, 'area-step'); }; - c3_chart_internal_fn.hasBarType = function (targets) { - return this.hasType(targets, 'bar'); + var hasBarType = c3_chart_internal_fn.hasBarType = function (targets) { + return hasType.call(this, targets, 'bar'); }; - c3_chart_internal_fn.hasScatterType = function (targets) { - return this.hasType(targets, 'scatter'); + var hasScatterType = c3_chart_internal_fn.hasScatterType = function (targets) { + return hasType.call(this, targets, 'scatter'); }; - c3_chart_internal_fn.hasPieType = function (targets) { - return this.config.data_type === 'pie' || this.hasType(targets, 'pie'); + var hasPieType = c3_chart_internal_fn.hasPieType = function (targets) { + return this.config.data_type === 'pie' || hasType.call(this, targets, 'pie'); }; - c3_chart_internal_fn.hasGaugeType = function (targets) { - return this.hasType(targets, 'gauge'); + var hasGaugeType = c3_chart_internal_fn.hasGaugeType = function (targets) { + return hasType.call(this, targets, 'gauge'); }; - c3_chart_internal_fn.hasDonutType = function (targets) { - return this.config.data_type === 'donut' || this.hasType(targets, 'donut'); + var hasDonutType = c3_chart_internal_fn.hasDonutType = function (targets) { + return this.config.data_type === 'donut' || hasType.call(this, targets, 'donut'); }; - c3_chart_internal_fn.hasArcType = function (targets) { - return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); + var hasArcType = c3_chart_internal_fn.hasArcType = function (targets) { + return hasPieType.call(this, targets) || hasDonutType.call(this, targets) || hasGaugeType.call(this, targets); }; - c3_chart_internal_fn.isLineType = function (d) { + var isLineType = c3_chart_internal_fn.isLineType = function (d) { var id = (typeof d === 'string') ? d : d.id; return !this.config.data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3_chart_internal_fn.isStepType = function (d) { + var isStepType = c3_chart_internal_fn.isStepType = function (d) { var id = (typeof d === 'string') ? d : d.id; return ['step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3_chart_internal_fn.isSplineType = function (d) { + var isSplineType = c3_chart_internal_fn.isSplineType = function (d) { var id = (typeof d === 'string') ? d : d.id; return ['spline', 'area-spline'].indexOf(this.config.data_types[id]) >= 0; }; - c3_chart_internal_fn.isAreaType = function (d) { + var isAreaType = c3_chart_internal_fn.isAreaType = function (d) { var id = (typeof d === 'string') ? d : d.id; return ['area', 'area-spline', 'area-step'].indexOf(this.config.data_types[id]) >= 0; }; - c3_chart_internal_fn.isBarType = function (d) { + var isBarType = c3_chart_internal_fn.isBarType = function (d) { var id = (typeof d === 'string') ? d : d.id; return this.config.data_types[id] === 'bar'; }; - c3_chart_internal_fn.isScatterType = function (d) { + var isScatterType = c3_chart_internal_fn.isScatterType = function (d) { var id = (typeof d === 'string') ? d : d.id; return this.config.data_types[id] === 'scatter'; }; - c3_chart_internal_fn.isPieType = function (d) { + var isPieType = c3_chart_internal_fn.isPieType = function (d) { var id = (typeof d === 'string') ? d : d.id; return this.config.data_types[id] === 'pie'; }; - c3_chart_internal_fn.isGaugeType = function (d) { + var isGaugeType = c3_chart_internal_fn.isGaugeType = function (d) { var id = (typeof d === 'string') ? d : d.id; return this.config.data_types[id] === 'gauge'; }; - c3_chart_internal_fn.isDonutType = function (d) { + var isDonutType = c3_chart_internal_fn.isDonutType = function (d) { var id = (typeof d === 'string') ? d : d.id; return this.config.data_types[id] === 'donut'; }; - c3_chart_internal_fn.isArcType = function (d) { - return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); + var isArcType = c3_chart_internal_fn.isArcType = function (d) { + return isPieType.call(this, d) || isDonutType.call(this, d) || isGaugeType.call(this, d); }; - c3_chart_internal_fn.lineData = function (d) { - return this.isLineType(d) ? [d] : []; + var lineData = c3_chart_internal_fn.lineData = function (d) { + return isLineType.call(this, d) ? [d] : []; }; - c3_chart_internal_fn.arcData = function (d) { - return this.isArcType(d.data) ? [d] : []; + var arcData = c3_chart_internal_fn.arcData = function (d) { + return isArcType.call(this, d.data) ? [d] : []; }; /* not used function scatterData(d) { return isScatterType(d) ? d.values : []; } */ - c3_chart_internal_fn.barData = function (d) { - return this.isBarType(d) ? d.values : []; + var barData = c3_chart_internal_fn.barData = function (d) { + return isBarType.call(this, d) ? d.values : []; }; - c3_chart_internal_fn.lineOrScatterData = function (d) { - return this.isLineType(d) || this.isScatterType(d) ? d.values : []; + var lineOrScatterData = c3_chart_internal_fn.lineOrScatterData = function (d) { + return isLineType.call(this, d) || isScatterType.call(this, d) ? d.values : []; }; - c3_chart_internal_fn.barOrLineData = function (d) { - return this.isBarType(d) || this.isLineType(d) ? d.values : []; + var barOrLineData = c3_chart_internal_fn.barOrLineData = function (d) { + return isBarType.call(this, d) || isLineType.call(this, d) ? d.values : []; }; @@ -3767,11 +3606,11 @@ $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, c.axis_y2_tick_format, c.axis_y2_ticks); // Set initialized scales to brush and zoom if (!forInit) { - $$.brush.scale($$.subX); + if ($$.brush) { $$.brush.scale($$.subX); } if (c.zoom_enabled) { $$.zoom.scale($$.x); } } // update for arc - if (isFunction(updateArc)) { updateArc.call($$); } + if (isFunctionType(updateArc)) { updateArc.call($$); } }; @@ -3850,7 +3689,7 @@ domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? c.axis_y2_center : c.axis_y_center, yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$.hasBarType(yTargets) && c.bar_zerobased) || ($$.hasAreaType(yTargets) && c.area_zerobased), + isZeroBased = (hasBarType.call($$, yTargets) && c.bar_zerobased) || (hasAreaType.call($$, yTargets) && c.area_zerobased), showHorizontalDataLabel = $$.hasDataLabel() && c.axis_rotated, showVerticalDataLabel = $$.hasDataLabel() && !c.axis_rotated; if (yTargets.length === 0) { // use current domain if target of axisId is none @@ -3917,7 +3756,7 @@ maxDataCount, padding, paddingLeft, paddingRight; if ($$.isCategorized) { padding = 0; - } else if (this.hasBarType(targets)) { + } else if (hasBarType.call(this, targets)) { maxDataCount = this.getMaxDataCount(); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { @@ -3959,10 +3798,10 @@ $$.orgXDomain = $$.x.domain(); if ($$.config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } $$.subX.domain($$.x.domain()); - $$.brush.scale($$.subX); + if ($$.brush) { $$.brush.scale($$.subX); } } if (withUpdateXDomain) { - $$.x.domain(domain ? domain : $$.brush.empty() ? $$.orgXDomain : $$.brush.extent()); + $$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent()); if ($$.config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } } return $$.x.domain(); @@ -4325,7 +4164,7 @@ $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = hasDonutType.call($$, $$.data.targets) || hasGaugeType.call($$, $$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; }; var updateArc = c3_chart_internal_fn.updateArc = function () { @@ -4349,7 +4188,7 @@ if (isNaN(d.endAngle)) { d.endAngle = d.startAngle; } - if ($$.isGaugeType(d.data)) { + if (isGaugeType.call($$, d.data)) { var gMin = $$.config.gauge_min, gMax = $$.config.gauge_max, gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; @@ -4383,14 +4222,14 @@ }; var getArc = c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { - return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; + return force || isArcType.call(this, d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; }; var transformForArcLabel = c3_chart_internal_fn.transformForArcLabel = function (d) { var $$ = this, updated = updateAngle.call($$, d), c, x, y, h, ratio, translate = ""; - if (updated && !$$.hasGaugeType($$.data.targets)) { + if (updated && !hasGaugeType.call($$, $$.data.targets)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4404,7 +4243,7 @@ var getArcRatio = c3_chart_internal_fn.getArcRatio = function (d) { var $$ = this, - whole = this.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); + whole = hasGaugeType.call(this, $$.data.targets) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; @@ -4424,14 +4263,14 @@ updated = updateAngle.call($$, d); value = updated ? updated.value : null; ratio = getArcRatio.call($$, updated); - if (! $$.hasGaugeType($$.data.targets) && ! meetsArcLabelThreshold.call($$, ratio)) { return ""; } + if (! hasGaugeType.call($$, $$.data.targets) && ! meetsArcLabelThreshold.call($$, ratio)) { return ""; } format = getArcLabelFormat.call($$); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; var expandArc = c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, CLASS = $$.CLASS, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), + target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); if (shouldExpand.call($$, id)) { @@ -4441,7 +4280,7 @@ .transition().duration(100) .attr("d", $$.svgArcExpandedSub) .each(function (d) { - if ($$.isDonutType(d.data)) { + if (isDonutType.call($$, d.data)) { // callback here } }); @@ -4453,7 +4292,7 @@ var unexpandArc = c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, CLASS = $$.CLASS, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); + target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)); target.selectAll('path.' + CLASS.arc) .transition().duration(50) .attr("d", $$.svgArc); @@ -4463,14 +4302,14 @@ var shouldExpand = c3_chart_internal_fn.shouldExpand = function (id) { var $$ = this; - return ($$.isDonutType(id) && $$.config.donut_expand) || ($$.isGaugeType(id) && $$.config.gauge_expand) || ($$.isPieType(id) && $$.config.pie_expand); + return (isDonutType.call($$, id) && $$.config.donut_expand) || (isGaugeType.call($$, id) && $$.config.gauge_expand) || (isPieType.call($$, id) && $$.config.pie_expand); }; var shouldShowArcLabel = c3_chart_internal_fn.shouldShowArcLabel = function () { var $$ = this, shouldShow = true; - if ($$.hasDonutType($$.data.targets)) { + if (hasDonutType.call($$, $$.data.targets)) { shouldShow = $$.config.donut_label_show; - } else if ($$.hasPieType($$.data.targets)) { + } else if (hasPieType.call($$, $$.data.targets)) { shouldShow = $$.config.pie_label_show; } // when gauge, always true @@ -4479,16 +4318,16 @@ var meetsArcLabelThreshold = c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { var $$ = this, c = $$.config, - threshold = this.hasDonutType($$.data.targets) ? c.donut_label_threshold : c.pie_label_threshold; + threshold = hasDonutType.call(this, $$.data.targets) ? c.donut_label_threshold : c.pie_label_threshold; return ratio >= threshold; }; var getArcLabelFormat = c3_chart_internal_fn.getArcLabelFormat = function () { var $$ = this, format = $$.config.pie_label_format; - if ($$.hasGaugeType($$.data.targets)) { + if (hasGaugeType.call($$, $$.data.targets)) { format = $$.config.gauge_label_format; - } else if ($$.hasDonutType($$.data.targets)) { + } else if (hasDonutType.call($$, $$.data.targets)) { format = $$.config.donut_label_format; } return format; @@ -4496,7 +4335,7 @@ var getArcTitle = c3_chart_internal_fn.getArcTitle = function () { var $$ = this; - return $$.hasDonutType($$.data.targets) ? $$.config.donut_title : ""; + return hasDonutType.call($$, $$.data.targets) ? $$.config.donut_title : ""; }; var descByStartAngle = c3_chart_internal_fn.descByStartAngle = function (a, b) { @@ -4507,13 +4346,13 @@ var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; mainPieUpdate = main.select('.' + $$.CLASS.chartArcs).selectAll('.' + $$.CLASS.chartArc) .data($$.pie(targets)) - .attr("class", function (d) { return $$.classChartArc(d); }); + .attr("class", function (d) { return classChartArc.call($$, d); }); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", function (d) { return $$.classChartArc(d); }); + .attr("class", function (d) { return classChartArc.call($$, d); }); mainPieEnter.append('g') - .attr('class', function (d) { return $$.classArcs(d); }); + .attr('class', function (d) { return classArcs.call($$, d); }); mainPieEnter.append("text") - .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") + .attr("dy", hasGaugeType.call($$, $$.data.targets) ? "-0.35em" : ".35em") .style("opacity", 0) .style("text-anchor", "middle") .style("pointer-events", "none"); @@ -4536,14 +4375,14 @@ var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, main = $$.main, mainArc; mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(function (d) { return $$.arcData(d); }); + .data(function (d) { return arcData.call($$, d); }); mainArc.enter().append('path') - .attr("class", function (d) { return $$.classArc(d); }) + .attr("class", function (d) { return classArc.call($$, d); }) .style("fill", function (d) { return $$.color(d.data); }) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) .style("opacity", 0) .each(function (d) { - if ($$.isGaugeType(d.data)) { + if (isGaugeType.call($$, d.data)) { d.startAngle = d.endAngle = -1 * (Math.PI / 2); } this._current = d; @@ -4585,7 +4424,7 @@ $$.toggleShape(this, arcData, i); // onclick called in toogleShape() }); mainArc - .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .attr("transform", function (d) { return !isGaugeType.call($$, d.data) && withTransform ? "scale(0)" : ""; }) .style("opacity", function (d) { return d === this._current ? 0 : 1; }) .each(function () { $$.transiting = true; }) .transition().duration(duration) @@ -4620,13 +4459,13 @@ .remove(); main.selectAll('.' + CLASS.chartArc).select('text') .style("opacity", 0) - .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .attr('class', function (d) { return isGaugeType.call($$, d.data) ? CLASS.gaugeValue : ''; }) .text(function (d) { return textForArcLabel.call($$, d); }) .attr("transform", function (d) { return transformForArcLabel.call($$, d); }) .transition().duration(duration) - .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && isArcType.call($$, d.data) ? 1 : 0; }); main.select('.' + CLASS.chartArcsTitle) - .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); + .style("opacity", hasDonutType.call($$, $$.data.targets) || hasGaugeType.call($$, $$.data.targets) ? 1 : 0); }; @@ -4634,7 +4473,7 @@ var initGauge = c3_chart_internal_fn.initGauge = function () { var $$ = this, CLASS = $$.CLASS, c = $$.config, arcs; - if ($$.hasGaugeType($$.data.targets)) { + if (hasGaugeType.call($$, $$.data.targets)) { arcs.append('path') .attr("class", CLASS.chartArcsBackground) .attr("d", function () { @@ -4689,6 +4528,182 @@ return targets; }; + //-- subchart.js --// + + var initBrush = c3_chart_internal_fn.initBrush = function () { + var $$ = this, d3 = $$.d3; + $$.brush = d3.svg.brush().on("brush", function () { redrawForBrush.call($$); }); + $$.brush.update = function () { + if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } + return this; + }; + $$.brush.scale = function (scale) { + return $$.config.axis_rotated ? this.y(scale) : this.x(scale); + }; + }; + var initSubchart = c3_chart_internal_fn.initSubchart = function () { + var $$ = this, c = $$.config, + context = $$.context = $$.svg.append("g").attr("transform", $$.translate.context); + + if (!c.subchart_show) { + context.style('visibility', 'hidden'); + } + + // Define g for chart area + context.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS.chart); + + // Define g for bar chart area + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); + + // Define g for line chart area + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); + + // Add extent rect for Brush + context.append("g") + .attr("clip-path", $$.clipPath) + .attr("class", CLASS.brush) + .call($$.brush) + .selectAll("rect") + .attr(c.axis_rotated ? "width" : "height", c.axis_rotated ? $$.width2 : $$.height2); + + // ATTENTION: This must be called AFTER chart added + // Add Axis + $$.axes.subx = context.append("g") + .attr("class", CLASS.axisX) + .attr("transform", $$.translate.subx) + .attr("clip-path", c.axis_rotated ? "" : $$.clipPathForXAxis); + }; + var updateTargetsForSubchart = c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { + var $$ = this, context = $$.context, c = $$.config, + contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + + if (c.subchart_show) { + + contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + .data(targets) + .attr('class', function (d) { return classChartBar.call($$, d); }); + contextBarEnter = contextBarUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', function (d) { return classChartBar.call($$, d); }); + // Bars for each data + contextBarEnter.append('g') + .attr("class", function (d) { return classBars.call($$, d); }); + + //-- Line --// + contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + .data(targets) + .attr('class', function (d) { return classChartLine.call($$, d); }); + contextLineEnter = contextLineUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', function (d) { return classChartLine.call($$, d); }); + // Lines for each data + contextLineEnter.append("g") + .attr("class", function (d) { return classLines.call($$, d); }); + // Area + contextLineEnter.append("g") + .attr("class", function (d) { return classAreas.call($$, d); }); + } + }; + var redrawSubchart = c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { + var $$ = this, d3 = $$.d3, context = $$.context, c = $$.config, + contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; + + // subchart + if (c.subchart_show) { + // reflect main chart to extent on subchart if zoomed + if (d3.event && d3.event.type === 'zoom') { + $$.brush.extent($$.x.orgDomain()).update(); + } + // update subchart elements if needed + if (withSubchart) { + + // rotate tick text if needed + if (!c.axis_rotated && c.axis_x_tick_rotate) { + $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.config.axis_x_tick_rotate); + } + + // extent rect + if (!$$.brush.empty()) { + $$.brush.extent($$.x.orgDomain()).update(); + } + // setup drawer - MEMO: this must be called after axis updated + drawAreaOnSub = $$.generateDrawArea(areaIndices, true); + drawBarOnSub = $$.generateDrawBar(barIndices, true); + drawLineOnSub = $$.generateDrawLine(lineIndices, true); + // bars + contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(function (d) { return barData.call($$, d); }); + contextBar.enter().append('path') + .attr("class", function (d) { return classBar.call($$, d); }) + .style("stroke", 'none') + .style("fill", $$.color); + contextBar + .style("opacity", function (d) { return initialOpacity.call($$, d); }) + .transition().duration(duration) + .attr('d', drawBarOnSub) + .style('opacity', 1); + contextBar.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // lines + contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(function (d) { return lineData.call($$, d); }); + contextLine.enter().append('path') + .attr('class', function (d) { return classLine.call($$, d); }) + .style('stroke', $$.color); + contextLine + .style("opacity", function (d) { return initialOpacity.call($$, d); }) + .transition().duration(duration) + .attr("d", drawLineOnSub) + .style('opacity', 1); + contextLine.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // area + contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(function (d) { return lineData.call($$, d); }); + contextArea.enter().append('path') + .attr("class", function (d) { return classArea.call($$, d); }) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + contextArea + .style("opacity", 0) + .transition().duration(duration) + .attr("d", drawAreaOnSub) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity); + contextArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + } + } + }; + var redrawForBrush = c3_chart_internal_fn.redrawForBrush = function () { + var $$ = this, x = $$.x; + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false, + withUpdateXDomain: true + }); + $$.config.subchart_onbrush.call($$, x.orgDomain()); + }; + var transformContext = c3_chart_internal_fn.transformContext = function (withTransition, transitions) { + var $$ = this, subXAxis; + if (transitions && transitions.axisSubX) { + subXAxis = transitions.axisSubX; + } else { + subXAxis = $$.context.select('.' + $$.CLASS.axisX); + if (withTransition) { subXAxis = subXAxis.transition(); } + } + $$.context.attr("transform", $$.translate.context); + subXAxis.attr("transform", $$.translate.subx); + }; + /** * c3.zoom.js @@ -4708,10 +4723,10 @@ c3_chart_internal_fn.isValue = function (v) { return v || v === 0; }; - function isFunction(s) { - return s === 'function'; + function isFunctionType(type) { + return type === 'function'; } - c3_chart_internal_fn.isFunction = isFunction(); + c3_chart_internal_fn.isFunctionType = isFunctionType(); c3_chart_internal_fn.isUndefined = function (v) { return typeof v === 'undefined'; }; @@ -4774,10 +4789,10 @@ var $$ = this; $$.config.data_onselected.call(c3, d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + this.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + this.CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return $$.generateClass(this.CLASS.selectedCircle, i); }) + .attr("class", function () { return generateClass.call($$, this.CLASS.selectedCircle, i); }) .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY) .attr("stroke", function () { return $$.color(d); }) @@ -4789,7 +4804,7 @@ var $$ = this; $$.config.data_onunselected.call(c3, d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + $$.CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + $$.CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; @@ -4838,7 +4853,7 @@ if ($$.config.data_selection_grouped || isWithin) { if ($$.config.data_selection_enabled && $$.config.data_selection_isselectable(d)) { 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.call($$, d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this); if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } }); @@ -4905,7 +4920,7 @@ */ c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$.hasArcType($$.data.targets), + withTransitionForAxis = !hasArcType.call($$, $$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; $$.transiting = false; @@ -4917,7 +4932,7 @@ /** * c3.class.js */ - c3_chart_internal_fn.CLASS = { + var CLASS = c3_chart_internal_fn.CLASS = { target: 'c3-target', chart : 'c3-chart', chartLine: 'c3-chart-line', @@ -4990,93 +5005,92 @@ SELECTED: '_selected_', INCLUDED: '_included_' }; - c3_chart_internal_fn.generateClass = function (prefix, targetId) { - return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); + var generateClass = c3_chart_internal_fn.generateClass = function (prefix, targetId) { + return " " + prefix + " " + prefix + getTargetSelectorSuffix.call(this, targetId); }; - c3_chart_internal_fn.classText = function (d) { - return this.generateClass(this.CLASS.text, d.index); + var classText = c3_chart_internal_fn.classText = function (d) { + return generateClass.call(this, CLASS.text, d.index); }; - c3_chart_internal_fn.classTexts = function (d) { - return this.generateClass(this.CLASS.texts, d.id); + var classTexts = c3_chart_internal_fn.classTexts = function (d) { + return generateClass.call(this, CLASS.texts, d.id); }; - c3_chart_internal_fn.classShape = function (d) { - return this.generateClass(this.CLASS.shape, d.index); + var classShape = c3_chart_internal_fn.classShape = function (d) { + return generateClass.call(this, CLASS.shape, d.index); }; - c3_chart_internal_fn.classShapes = function (d) { - return this.generateClass(this.CLASS.shapes, d.id); + var classShapes = c3_chart_internal_fn.classShapes = function (d) { + return generateClass.call(this, CLASS.shapes, d.id); }; - c3_chart_internal_fn.classLine = function (d) { - return this.classShape(d) + this.generateClass(this.CLASS.line, d.id); + var classLine = c3_chart_internal_fn.classLine = function (d) { + return classShape.call(this, d) + generateClass.call(this, CLASS.line, d.id); }; - c3_chart_internal_fn.classLines = function (d) { - return this.classShapes(d) + this.generateClass(this.CLASS.lines, d.id); + var classLines = c3_chart_internal_fn.classLines = function (d) { + return classShapes.call(this, d) + generateClass.call(this, CLASS.lines, d.id); }; - c3_chart_internal_fn.classCircle = function (d) { - return this.classShape(d) + this.generateClass(this.CLASS.circle, d.index); + var classCircle = c3_chart_internal_fn.classCircle = function (d) { + return classShape.call(this, d) + generateClass.call(this, CLASS.circle, d.index); }; - c3_chart_internal_fn.classCircles = function (d) { - return this.classShapes(d) + this.generateClass(this.CLASS.circles, d.id); + var classCircles = c3_chart_internal_fn.classCircles = function (d) { + return classShapes.call(this, d) + generateClass.call(this, CLASS.circles, d.id); }; - c3_chart_internal_fn.classBar = function (d) { - return this.classShape(d) + this.generateClass(this.CLASS.bar, d.index); + var classBar = c3_chart_internal_fn.classBar = function (d) { + return classShape.call(this, d) + generateClass.call(this, CLASS.bar, d.index); }; - c3_chart_internal_fn.classBars = function (d) { - return this.classShapes(d) + this.generateClass(this.CLASS.bars, d.id); + var classBars = c3_chart_internal_fn.classBars = function (d) { + return classShapes.call(this, d) + generateClass.call(this, CLASS.bars, d.id); }; - c3_chart_internal_fn.classArc = function (d) { - return this.classShape(d.data) + this.generateClass(this.CLASS.arc, d.data.id); + var classArc = c3_chart_internal_fn.classArc = function (d) { + return classShape.call(this, d.data) + generateClass.call(this, CLASS.arc, d.data.id); }; - c3_chart_internal_fn.classArcs = function (d) { - return this.classShapes(d.data) + this.generateClass(this.CLASS.arcs, d.data.id); + var classArcs = c3_chart_internal_fn.classArcs = function (d) { + return classShapes.call(this, d.data) + generateClass.call(this, CLASS.arcs, d.data.id); }; - c3_chart_internal_fn.classArea = function (d) { - return this.classShape(d) + this.generateClass(this.CLASS.area, d.id); + var classArea = c3_chart_internal_fn.classArea = function (d) { + return classShape.call(this, d) + generateClass.call(this, CLASS.area, d.id); }; - c3_chart_internal_fn.classAreas = function (d) { - return this.classShapes(d) + this.generateClass(this.CLASS.areas, d.id); + var classAreas = c3_chart_internal_fn.classAreas = function (d) { + return classShapes.call(this, d) + generateClass.call(this, CLASS.areas, d.id); }; - c3_chart_internal_fn.classRegion = function (d, i) { - return this.generateClass(this.CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); + var classRegion = c3_chart_internal_fn.classRegion = function (d, i) { + return generateClass.call(this, CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); }; - c3_chart_internal_fn.classEvent = function (d) { - return this.generateClass(this.CLASS.eventRect, d.index); + var classEvent = c3_chart_internal_fn.classEvent = function (d) { + return generateClass.call(this, CLASS.eventRect, d.index); }; - c3_chart_internal_fn.classTarget = function (id) { + var classTarget = c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config.data_classes[id], additionalClass = ''; if (additionalClassSuffix) { additionalClass = ' ' + $$.CLASS.target + '-' + additionalClassSuffix; } - return $$.generateClass($$.CLASS.target, id) + additionalClass; + return generateClass.call($$, CLASS.target, id) + additionalClass; }; - c3_chart_internal_fn.classChartText = function (d) { - return this.CLASS.chartText + this.classTarget(d.id); + var classChartText = c3_chart_internal_fn.classChartText = function (d) { + return CLASS.chartText + classTarget.call(this, d.id); }; - c3_chart_internal_fn.classChartLine = function (d) { - return this.CLASS.chartLine + this.classTarget(d.id); + var classChartLine = c3_chart_internal_fn.classChartLine = function (d) { + return CLASS.chartLine + classTarget.call(this, d.id); }; - c3_chart_internal_fn.classChartBar = function (d) { - return this.CLASS.chartBar + this.classTarget(d.id); + var classChartBar = c3_chart_internal_fn.classChartBar = function (d) { + return CLASS.chartBar + classTarget.call(this, d.id); }; - c3_chart_internal_fn.classChartArc = function (d) { - return this.CLASS.chartArc + this.classTarget(d.data.id); + var classChartArc = c3_chart_internal_fn.classChartArc = function (d) { + return CLASS.chartArc + classTarget.call(this, d.data.id); }; - c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { + var getTargetSelectorSuffix = c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; - c3_chart_internal_fn.selectorTarget = function (id) { - return '.' + this.CLASS.target + this.getTargetSelectorSuffix(id); + var selectorTarget = c3_chart_internal_fn.selectorTarget = function (id) { + return '.' + CLASS.target + getTargetSelectorSuffix.call(this, id); }; - c3_chart_internal_fn.selectorTargets = function (ids) { - var $$ = this; - return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; + var selectorTargets = c3_chart_internal_fn.selectorTargets = function (ids) { + return ids.length ? ids.map(function (id) { return selectorTarget.call(this, id); }) : null; }; - c3_chart_internal_fn.selectorLegend = function (id) { - return '.' + this.CLASS.legendItem + this.getTargetSelectorSuffix(id); + var selectorLegend = c3_chart_internal_fn.selectorLegend = function (id) { + return '.' + CLASS.legendItem + getTargetSelectorSuffix.call(this, id); }; - c3_chart_internal_fn.selectorLegends = function (ids) { + var selectorLegends = c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; + return ids.length ? ids.map(function (id) { return selectorLegend.call($$, id); }) : null; }; @@ -5086,8 +5100,8 @@ */ c3_chart_internal_fn.getYFormat = function (forArc) { var $$ = this, - formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !hasGaugeType.call($$, $$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !hasGaugeType.call($$, $$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); @@ -5132,7 +5146,7 @@ var $$ = this, main = $$.main, CLASS = $$.CLASS, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } 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.data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection @@ -5188,7 +5202,7 @@ c3_chart_internal_fn.dragstart = function (mouse) { var $$ = this; - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable $$.dragStart = mouse; $$.main.select('.' + $$.CLASS.chart).append('rect') @@ -5200,7 +5214,7 @@ c3_chart_internal_fn.dragend = function () { var $$ = this; - if ($$.hasArcType($$.data.targets)) { return; } + if (hasArcType.call($$, $$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable $$.main.select('.' + $$.CLASS.dragarea) .transition().duration(100) @@ -5221,7 +5235,7 @@ */ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); function focus(targets) { @@ -5231,7 +5245,7 @@ this.defocus(); focus(candidatesForNoneArc.classed($$.CLASS.focused, true)); focus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if (hasArcType.call($$, $$.data.targets)) { expandArc.call($$, targetId, true); } $$.toggleFocusLegend(targetId, true); @@ -5239,7 +5253,7 @@ c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); function defocus(targets) { @@ -5248,7 +5262,7 @@ this.revert(); defocus(candidatesForNoneArc.classed($$.CLASS.focused, false)); defocus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if (hasArcType.call($$, $$.data.targets)) { unexpandArc.call($$, targetId); } $$.toggleFocusLegend(targetId, false); @@ -5256,7 +5270,7 @@ c3_chart_fn.revert = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); function revert(targets) { @@ -5264,7 +5278,7 @@ } revert(candidatesForNoneArc.classed($$.CLASS.focused, false)); revert(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if (hasArcType.call($$, $$.data.targets)) { unexpandArc.call($$, targetId); } $$.revertLegend(); @@ -5277,7 +5291,7 @@ options = options || {}; $$.removeHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) + $$.svg.selectAll(selectorTargets.call($$, targetIds)) .transition() .style('opacity', 1); @@ -5295,7 +5309,7 @@ options = options || {}; $$.addHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) + $$.svg.selectAll(selectorTargets.call($$, targetIds)) .transition() .style('opacity', 0); @@ -5509,7 +5523,7 @@ c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3, CLASS = $$.CLASS; return d3.merge( - $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) + $$.main.selectAll('.' + CLASS.shapes + getTargetSelectorSuffix.call($$, targetId)).selectAll('.' + CLASS.shape) .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); From c649a1cf0f3e94062088f8c9579342638c33a017 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 27 Jul 2014 20:31:21 +0100 Subject: [PATCH 09/44] Use closure variables for minify --- c3.js | 891 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 442 insertions(+), 449 deletions(-) diff --git a/c3.js b/c3.js index eff38ab..33f204d 100644 --- a/c3.js +++ b/c3.js @@ -8,9 +8,9 @@ var c3_chart_fn, c3_chart_internal_fn; function Chart(config) { - this.internal = new ChartInternal(config, this); - this.internal.loadConfig(config); - this.internal.init(); + var $$ = this.internal = new ChartInternal(config, this); + loadConfig.call($$, config); + init.call($$); } function ChartInternal(config, api) { @@ -239,14 +239,14 @@ if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - text += ""; + text += ""; text += ""; text += ""; text += ""; @@ -258,7 +258,7 @@ tooltip_init_position: {top: '0px', left: '50px'} }; - c3_chart_internal_fn.loadConfig = function (config) { + var loadConfig = c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -304,7 +304,7 @@ return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { - var ratio = $$.diffDomain($$.x.orgDomain()) / $$.diffDomain($$.orgXDomain), + var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), extent = $$.orgScaleExtent(); $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); return this; @@ -312,28 +312,28 @@ }; - c3_chart_internal_fn.init = function () { + var init = c3_chart_internal_fn.init = function () { var $$ = this, c = $$.config; if (c.data_url) { - $$.convertUrlToData(c.data_url, c.data_mimeType, c.data_keys, $$.initWithData); + convertUrlToData.call($$, c.data_url, c.data_mimeType, c.data_keys, initWithData); } else if (c.data_json) { - $$.initWithData($$.convertJsonToData(c.data_json, c.data_keys)); + initWithData.call($$, convertJsonToData.call($$, c.data_json, c.data_keys)); } else if (c.data_rows) { - $$.initWithData($$.convertRowsToData(c.data_rows)); + initWithData.call($$, convertRowsToData.call($$, c.data_rows)); } else if (c.data_columns) { - $$.initWithData($$.convertColumnsToData(c.data_columns)); + initWithData.call($$, convertColumnsToData.call($$, c.data_columns)); } else { throw Error('url or json or rows or columns is required.'); } }; - c3_chart_internal_fn.initWithData = function (data) { - var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, c = $$.config; - var eventRect, i, binding = true; + var initWithData = c3_chart_internal_fn.initWithData = function (data) { + var $$ = this, d3 = $$.d3, c = $$.config; + var main, legend, eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId = "c3-" + (+new Date()) + '-clip', @@ -345,7 +345,7 @@ $$.isTimeSeries = (c.axis_x_type === 'timeseries'); $$.isCategorized = (c.axis_x_type.indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && (c.data_x || $$.notEmpty(c.data_xs)); }; + $$.isCustomX = function () { return !$$.isTimeSeries && (c.data_x || notEmpty(c.data_xs)); }; $$.dragStart = null; $$.dragging = false; @@ -354,8 +354,8 @@ $$.transiting = false; $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor(c.data_colors, $$.notEmpty(c.color_pattern) ? c.color_pattern : $$.defaultColorPattern, c.data_color); - $$.levelColor = $$.notEmpty(c.color_threshold) ? $$.generateLevelColor(c.color_pattern, c.color_threshold) : null; + $$.color = $$.generateColor(c.data_colors, notEmpty(c.color_pattern) ? c.color_pattern : $$.defaultColorPattern, c.data_color); + $$.levelColor = notEmpty(c.color_threshold) ? $$.generateLevelColor(c.color_pattern, c.color_threshold) : null; $$.dataTimeFormat = c.data_x_localtime ? d3.time.format : d3.time.format.utc; $$.axisTimeFormat = c.axis_x_localtime ? d3.time.format : d3.time.format.utc; @@ -379,8 +379,8 @@ $$.subXOrient = c.axis_rotated ? "left" : "bottom"; $$.translate = { - main : function () { return "translate(" + $$.asHalfPixel($$.margin.left) + "," + $$.asHalfPixel($$.margin.top) + ")"; }, - context : function () { return "translate(" + $$.asHalfPixel($$.margin2.left) + "," + $$.asHalfPixel($$.margin2.top) + ")"; }, + main : function () { return "translate(" + asHalfPixel($$.margin.left) + "," + asHalfPixel($$.margin.top) + ")"; }, + context : function () { return "translate(" + asHalfPixel($$.margin2.left) + "," + asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, x : function () { return "translate(0," + (c.axis_rotated ? 0 : $$.height) + ")"; }, y : function () { return "translate(0," + (c.axis_rotated ? $$.height : 0) + ")"; }, @@ -424,7 +424,7 @@ // Init data as targets $$.data.xs = {}; - $$.data.targets = $$.convertDataToTargets(data); + $$.data.targets = convertDataToTargets.call($$, data); if (c.data_filter) { $$.data.targets = $$.data.targets.filter(c.data_filter); @@ -441,8 +441,8 @@ } // Init sizes and scales - $$.updateSizes(); - $$.updateScales(); + updateSizes.call($$); + updateScales.call($$); // Set domains for each scale $$.x.domain(d3.extent($$.getXDomain($$.data.targets))); @@ -475,8 +475,8 @@ $$.updateSvgSize(); // Define regions - $$.main = $$.svg.append("g").attr("transform", $$.translate.main); - $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); + main = $$.main = $$.svg.append("g").attr("transform", $$.translate.main); + legend = $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); if (isFunctionType(typeof initSubchart)) { initSubchart.call($$); } @@ -501,18 +501,18 @@ /*-- Main Region --*/ // text when empty - $$.main.append("text") + 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 - $$.main.append('g') + main.append('g') .attr("clip-path", $$.clipPath) .attr("class", CLASS.regions); // Grids - $$.grid = $$.main.append('g') + $$.grid = main.append('g') .attr("clip-path", $$.clipPath) .attr('class', CLASS.grid); if (c.grid_x_show) { @@ -531,32 +531,32 @@ } // Define g for chart area - $$.main.append('g') + main.append('g') .attr("clip-path", $$.clipPath) .attr('class', CLASS.chart); // Cover whole with rects for events - eventRect = $$.main.select('.' + CLASS.chart).append("g") + eventRect = main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.eventRects) .style('fill-opacity', 0); // Define g for bar chart area - $$.main.select('.' + CLASS.chart).append("g") + main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartBars); // Define g for line chart area - $$.main.select('.' + CLASS.chart).append("g") + main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartLines); // Define g for arc chart area if (isFunctionType(initArc)) { initArc.call($$); } if (isFunctionType(initGauge)) { initGauge.call($$); } - $$.main.select('.' + CLASS.chart).append("g") + main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartTexts); // if zoom privileged, insert rect to forefront - $$.main.insert('rect', c.zoom_privileged ? null : 'g.' + CLASS.regions) + main.insert('rect', c.zoom_privileged ? null : 'g.' + CLASS.regions) .attr('class', CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height) @@ -569,7 +569,7 @@ } // Add Axis - $$.axes.x = $$.main.append("g") + $$.axes.x = main.append("g") .attr("class", CLASS.axis + ' ' + CLASS.axisX) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) @@ -577,9 +577,9 @@ $$.axes.x.append("text") .attr("class", CLASS.axisXLabel) .attr("transform", c.axis_rotated ? "rotate(-90)" : "") - .style("text-anchor", function () { return $$.textAnchorForXAxisLabel(); }); + .style("text-anchor", generateCall(textAnchorForXAxisLabel, $$)); - $$.axes.y = $$.main.append("g") + $$.axes.y = main.append("g") .attr("class", CLASS.axis + ' ' + CLASS.axisY) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) @@ -587,9 +587,9 @@ $$.axes.y.append("text") .attr("class", CLASS.axisYLabel) .attr("transform", c.axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", function () { return $$.textAnchorForYAxisLabel(); }); + .style("text-anchor", generateCall(textAnchorForYAxisLabel, $$)); - $$.axes.y2 = $$.main.append("g") + $$.axes.y2 = main.append("g") .attr("class", CLASS.axis + ' ' + CLASS.axisY2) // clip-path? .attr("transform", $$.translate.y2) @@ -597,10 +597,10 @@ $$.axes.y2.append("text") .attr("class", CLASS.axisY2Label) .attr("transform", c.axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", function () { return $$.textAnchorForY2AxisLabel(); }); + .style("text-anchor", generateCall(textAnchorForY2AxisLabel, $$)); // Set targets - $$.updateTargets($$.data.targets); + updateTargets.call($$, $$.data.targets); // Draw with targets if (binding) { @@ -624,7 +624,7 @@ } $$.tooltip.html(c.tooltip_contents.call($$, $$.data.targets.map(function (d) { return $$.addName(d.values[c.tooltip_init_x]); - }), $$.getXAxisTickFormat(), $$.getYFormat(hasArcType.call($$, $$.data.targets)), $$.color)); + }), getXAxisTickFormat.call($$), $$.getYFormat(hasArcType.call($$, $$.data.targets)), $$.color)); $$.tooltip.style("top", c.tooltip_init_position.top) .style("left", c.tooltip_init_position.left) .style("display", "block"); @@ -671,7 +671,7 @@ }; - c3_chart_internal_fn.updateSizes = function () { + var updateSizes = c3_chart_internal_fn.updateSizes = function () { var $$ = this, c = $$.config; var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, @@ -742,55 +742,55 @@ } }; - c3_chart_internal_fn.updateTargets = function (targets) { + var updateTargets = c3_chart_internal_fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; - var $$ = this, main = $$.main, CLASS = $$.CLASS; + var $$ = this, main = $$.main; /*-- Main --*/ //-- Text --// mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) .data(targets) - .attr('class', function (d) { return classChartText.call($$, d); }); + .attr('class', generateCall(classChartText, $$)); mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', function (d) { return classChartText.call($$, d); }) + .attr('class', generateCall(classChartText, $$)) .style('opacity', 0) .style("pointer-events", "none"); mainTextEnter.append('g') - .attr('class', function (d) { return classTexts.call($$, d); }); + .attr('class', generateCall(classTexts, $$)); //-- Bar --// mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr('class', function (d) { return classChartBar.call($$, d); }); + .attr('class', generateCall(classChartBar, $$)); mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', function (d) { return classChartBar.call($$, d); }) + .attr('class', generateCall(classChartBar, $$)) .style('opacity', 0) .style("pointer-events", "none"); // Bars for each data mainBarEnter.append('g') - .attr("class", function (d) { return classBars.call($$, d); }) + .attr("class", generateCall(classBars, $$)) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); //-- Line --// mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr('class', function (d) { return classChartLine.call($$, d); }); + .attr('class', generateCall(classChartLine, $$)); mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', function (d) { return classChartLine.call($$, d); }) + .attr('class', generateCall(classChartLine, $$)) .style('opacity', 0) .style("pointer-events", "none"); // Lines for each data mainLineEnter.append('g') - .attr("class", function (d) { return classLines.call($$, d); }); + .attr("class", generateCall(classLines, $$)); // Areas mainLineEnter.append('g') - .attr('class', function (d) { return classAreas.call($$, d); }); + .attr('class', generateCall(classAreas, $$)); // Circles for each data point on lines mainLineEnter.append('g') .attr("class", function (d) { return generateClass.call($$, CLASS.selectedCircles, d.id); }); mainLineEnter.append('g') - .attr("class", function (d) { return classCircles.call($$, d); }) + .attr("class", generateCall(classCircles, $$)) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { @@ -825,18 +825,18 @@ var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - xgrid = xgridLines = mainCircle = mainText = $$.getEmptySelection(); + xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); 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); - withLegend = $$.getOption(options, "withLegend", false); - withTransitionForExit = $$.getOption(options, "withTransitionForExit", withTransition); - withTransitionForAxis = $$.getOption(options, "withTransitionForAxis", withTransition); + 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); + withLegend = getOption(options, "withLegend", false); + withTransitionForExit = getOption(options, "withTransitionForExit", withTransition); + withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition); duration = withTransition ? $$.config.transition_duration : 0; durationForExit = withTransitionForExit ? duration : 0; @@ -1009,18 +1009,18 @@ .attr('dy', -5) .style("opacity", 0); // update - var yv = function (d) { return $$.yv.call($$, d); }; + var yv_ = generateCall(yv, $$); ygridLines.select('line') .transition().duration(duration) - .attr("x1", $$.config.axis_rotated ? yv : 0) - .attr("x2", $$.config.axis_rotated ? yv : $$.width) - .attr("y1", $$.config.axis_rotated ? 0 : yv) - .attr("y2", $$.config.axis_rotated ? $$.height : yv) + .attr("x1", $$.config.axis_rotated ? yv_ : 0) + .attr("x2", $$.config.axis_rotated ? yv_ : $$.width) + .attr("y1", $$.config.axis_rotated ? 0 : yv_) + .attr("y2", $$.config.axis_rotated ? $$.height : yv_) .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) .attr("x", $$.config.axis_rotated ? 0 : $$.width) - .attr("y", yv) + .attr("y", yv_) .text(function (d) { return d.text; }) .style("opacity", 1); // exit @@ -1033,7 +1033,7 @@ mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) .data($$.config.regions); mainRegion.enter().append('g') - .attr('class', function (d) { return classRegion.call($$, d); }) + .attr('class', generateCall(classRegion, $$)) .append('rect') .style("fill-opacity", 0); mainRegion.exit().transition().duration(duration) @@ -1042,34 +1042,34 @@ // bars mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(function (d) { return barData.call($$, d); }); + .data(generateCall(barData, $$)); mainBar.enter().append('path') - .attr("class", function (d) { return classBar.call($$, d); }) + .attr("class", generateCall(classBar, $$)) .style("stroke", function (d) { return $$.color(d.id); }) .style("fill", function (d) { return $$.color(d.id); }); mainBar - .style("opacity", function (d) { return initialOpacity.call($$, d); }); + .style("opacity", generateCall(initialOpacity, $$)); mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); // lines, areas and cricles mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(function (d) { return lineData.call($$, d); }); + .data(generateCall(lineData, $$)); mainLine.enter().append('path') - .attr('class', function (d) { return classLine.call($$, d); }) + .attr('class', generateCall(classLine, $$)) .style("stroke", $$.color); mainLine - .style("opacity", function (d) { return initialOpacity.call($$, d); }) + .style("opacity", generateCall(initialOpacity, $$)) .attr('transform', null); mainLine.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(function (d) { return lineData.call($$, d); }); + .data(generateCall(lineData, $$)); mainArea.enter().append('path') - .attr("class", function (d) { return classArea.call($$, d); }) + .attr("class", generateCall(classArea, $$)) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); mainArea @@ -1080,21 +1080,21 @@ if ($$.config.point_show) { mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) - .data(function (d) { return lineOrScatterData.call($$, d); }); + .data(generateCall(lineOrScatterData, $$)); mainCircle.enter().append("circle") - .attr("class", function (d) { return classCircle.call($$, d); }) - .attr("r", function (d) { return $$.pointR(d); }) + .attr("class", generateCall(classCircle, $$)) + .attr("r", generateCall(pointR, $$)) .style("fill", $$.color); mainCircle - .style("opacity", function (d) { return initialOpacity.call($$, d); }); + .style("opacity", generateCall(initialOpacity, $$)); mainCircle.exit().remove(); } if ($$.hasDataLabel()) { mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) - .data(function (d) { return barOrLineData.call($$, d); }); + .data(generateCall(barOrLineData, $$)); mainText.enter().append('text') - .attr("class", function (d) { return classText.call($$, d); }) + .attr("class", generateCall(classText, $$)) .attr('text-anchor', function (d) { return $$.config.axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) @@ -1115,7 +1115,7 @@ // circles for select main.selectAll('.' + CLASS.selectedCircles) - .filter(function (d) { return isBarType.call($$, d); }) + .filter(generateCall(isBarType, $$)) .selectAll('circle') .remove(); @@ -1123,7 +1123,7 @@ // rect for mouseover eventRect = main.select('.' + CLASS.eventRects) .style('cursor', $$.config.zoom_enabled ? $$.config.axis_rotated ? 'ns-resize' : 'ew-resize' : null); - if ($$.notEmpty($$.config.data_xs) && !$$.isSingleX($$.config.data_xs)) { + if (notEmpty($$.config.data_xs) && !$$.isSingleX($$.config.data_xs)) { if (!eventRect.classed(CLASS.eventRectsMultiple)) { eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) @@ -1175,7 +1175,7 @@ $$.generateEventRectsForSingleX(eventRectUpdate.enter()); // update eventRectUpdate - .attr('class', function (d) { return classEvent.call($$, d); }) + .attr('class', generateCall(classEvent, $$)) .attr("x", $$.config.axis_rotated ? 0 : rectX) .attr("y", $$.config.axis_rotated ? rectX : 0) .attr("width", $$.config.axis_rotated ? $$.width : rectW) @@ -1188,8 +1188,8 @@ // transition should be derived from one transition d3.transition().duration(duration).each(function () { var transitions = [], - cx = $$.config.axis_rotated ? $$.circleY : $$.circleX, - cy = $$.config.axis_rotated ? $$.circleX : $$.circleY; + cx = generateCall($$.config.axis_rotated ? $$.circleY : $$.circleX, $$), + cy = generateCall($$.config.axis_rotated ? $$.circleX : $$.circleY, $$); transitions.push(mainBar.transition() .attr('d', drawBar) @@ -1204,13 +1204,13 @@ .style("fill", $$.color) .style("opacity", $$.orgAreaOpacity)); transitions.push(mainCircle.transition() - .style('opacity', function (d) { return $$.opacityForCircle(d); }) + .style('opacity', generateCall(opacityForCircle, $$)) .style("fill", $$.color) - .attr("cx", function (d, i) { return cx.call($$, d, i); }) - .attr("cy", function (d, i) { return cy.call($$, d, i); })); + .attr("cx", cx) + .attr("cy", cy)); transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() - .attr("cx", function (d, i) { return cx.call($$, d, i); }) - .attr("cy", function (d, i) { return cy.call($$, d, i); })); + .attr("cx", cx) + .attr("cy", cy)); transitions.push(mainText.transition() .attr('x', xForText) .attr('y', yForText) @@ -1221,7 +1221,7 @@ .attr("y", $$.regionY) .attr("width", $$.regionWidth) .attr("height", $$.regionHeight) - .style("fill-opacity", function (d) { return $$.isValue(d.opacity) ? d.opacity : 0.1; })); + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() .attr("x1", $$.config.axis_rotated ? 0 : $$.xv) .attr("x2", $$.config.axis_rotated ? $$.width : $$.xv) @@ -1272,7 +1272,7 @@ flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); } else { - translateX = $$.diffDomain(domain) / 2; + translateX = diffDomain(domain) / 2; } } } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { @@ -1284,7 +1284,7 @@ translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); } } - scaleX = ($$.diffDomain(orgDomain) / $$.diffDomain(domain)); + scaleX = (diffDomain(orgDomain) / diffDomain(domain)); transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; d3.transition().ease('linear').duration(durationForFlow).each(function () { @@ -1397,21 +1397,21 @@ var $$ = this, transitions; options = options || {}; // same with redraw - options.withTransition = $$.getOption(options, "withTransition", true); - options.withTransform = $$.getOption(options, "withTransform", false); - options.withLegend = $$.getOption(options, "withLegend", false); + 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); + 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(); + updateSizes.call($$); // MEMO: called in updateLegend in redraw if withLegend if (!(options.withLegend && $$.config.legend_show)) { transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.config.transition_duration : 0); // Update scales - $$.updateScales(); + updateScales.call($$); $$.updateSvgSize(); // Update g positions $$.transformAll(options.withTransitionForTransform, transitions); @@ -1421,9 +1421,9 @@ }; c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { - var $$ = this, d3 = $$.d3, CLASS = $$.CLASS; + var $$ = this, d3 = $$.d3; eventRectEnter.append("rect") - .attr("class", function (d) { return classEvent.call($$, d); }) + .attr("class", generateCall(classEvent, $$)) .style("cursor", $$.config.data_selection_enabled && $$.config.data_selection_grouped ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; @@ -1453,7 +1453,7 @@ $$.expandBars(index); // Call event handler - $$.main.selectAll('.' + $$.CLASS.shape + '-' + index).each(function (d) { + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.config.data_onmouseover.call(c3, d); }); }) @@ -1545,7 +1545,7 @@ }; c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { - var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; + var $$ = this, d3 = $$.d3; eventRectEnter.append('rect') .attr('x', 0) .attr('y', 0) @@ -1641,21 +1641,21 @@ var initialOpacity = c3_chart_internal_fn.initialOpacity = function (d) { return d.value !== null && this.withoutFadeIn[d.id] ? 1 : 0; }; - c3_chart_internal_fn.opacityForCircle = function (d) { + var opacityForCircle = c3_chart_internal_fn.opacityForCircle = function (d) { var $$ = this; - return $$.isValue(d.value) ? isScatterType.call($$, d) ? 0.5 : 1 : 0; + return isValue(d.value) ? isScatterType.call($$, d) ? 0.5 : 1 : 0; }; c3_chart_internal_fn.opacityForText = function () { return this.hasDataLabel() ? 1 : 0; }; - c3_chart_internal_fn.xx = function (d) { + var xx = c3_chart_internal_fn.xx = function (d) { return d ? this.x(d.x) : null; }; c3_chart_internal_fn.xv = function (d) { var $$ = this; return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); }; - c3_chart_internal_fn.yv = function (d) { + var yv = c3_chart_internal_fn.yv = function (d) { var $$ = this, yScale = d.axis && d.axis === 'y2' ? $$.y2 : $$.y; return Math.ceil(yScale(d.value)); @@ -1667,7 +1667,7 @@ c3_chart_internal_fn.transformMain = function (withTransition, transitions) { - var $$ = this, CLASS = $$.CLASS, + var $$ = this, xAxis, yAxis, y2Axis; if (transitions && transitions.axisX) { xAxis = transitions.axisX; @@ -1721,7 +1721,7 @@ .attr('y', function () { return $$.getYAxisClipY(); }) .attr('width', function () { return $$.getYAxisClipWidth(); }) .attr('height', function () { return $$.getYAxisClipHeight(); }); - $$.svg.select('.' + $$.CLASS.zoomRect) + $$.svg.select('.' + CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height); // MEMO: parent div's height will be bigger than svg when @@ -1738,8 +1738,8 @@ $$.axes.y.call($$.yAxis); $$.axes.y2.call($$.y2Axis); } - $$.updateSizes(); - $$.updateScales(); + updateSizes.call($$); + updateScales.call($$); $$.updateSvgSize(); $$.transformAll(false); }; @@ -1798,30 +1798,30 @@ }; c3_chart_internal_fn.getCurrentPaddingTop = function () { var $$ = this; - return $$.isValue($$.config.padding_top) ? $$.config.padding_top : 0; + return isValue($$.config.padding_top) ? $$.config.padding_top : 0; }; c3_chart_internal_fn.getCurrentPaddingBottom = function () { var $$ = this; - return $$.isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; + return isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; }; c3_chart_internal_fn.getCurrentPaddingLeft = function () { var $$ = this; - if ($$.isValue($$.config.padding_left)) { + if (isValue($$.config.padding_left)) { return $$.config.padding_left; } else if ($$.config.axis_rotated) { - return !$$.config.axis_x_show ? 1 : Math.max($$.ceil10($$.getAxisWidthByAxisId('x')), 40); + return !$$.config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); } else { - return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : $$.ceil10($$.getAxisWidthByAxisId('y')); + return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : ceil10($$.getAxisWidthByAxisId('y')); } }; c3_chart_internal_fn.getCurrentPaddingRight = function () { var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; - if ($$.isValue($$.config.padding_right)) { + if (isValue($$.config.padding_right)) { return $$.config.padding_right + 1; // 1 is needed not to hide tick line } else if ($$.config.axis_rotated) { return defaultPadding + legendWidthOnRight; } else { - return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : $$.ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; @@ -1847,7 +1847,7 @@ c3_chart_internal_fn.getSvgLeft = function () { var $$ = this, - leftAxisClass = $$.config.axis_rotated ? $$.CLASS.axisX : $$.CLASS.axisY, + leftAxisClass = $$.config.axis_rotated ? CLASS.axisX : CLASS.axisY, leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), @@ -1858,7 +1858,7 @@ c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { - var $$ = this, position = $$.getAxisLabelPositionById(id); + var $$ = this, position = getAxisLabelPositionById.call($$, id); return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); }; c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { @@ -1867,7 +1867,7 @@ if (axisId === 'x' && $$.config.axis_x_height) { return $$.config.axis_x_height; } if (axisId === 'y' && !$$.config.axis_y_show) { return $$.config.legend_show && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } if (axisId === 'y2' && !$$.config.axis_y2_show) { return $$.rotated_padding_top; } - return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + return (getAxisLabelPositionById.call($$, axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; c3_chart_internal_fn.getEventRectWidth = function () { @@ -1896,11 +1896,11 @@ var $$ = this; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; var forArc = hasArcType.call($$, $$.data.targets), - dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !$$.config.tooltip_show) { return; } - $$.tooltip.html($$.config.tooltip_contents.call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + $$.tooltip.html($$.config.tooltip_contents.call($$, selectedData, getXAxisTickFormat.call($$), $$.getYFormat(forArc), $$.color)).style("display", "block"); // Get tooltip dimensions tWidth = $$.tooltip.property('offsetWidth'); @@ -1945,25 +1945,24 @@ * c3.grid.js */ c3_chart_internal_fn.showXGridFocus = function (selectedData) { - var $$ = this, dataToShow = selectedData.filter(function (d) { return d && $$.isValue(d.value); }); + var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! $$.config.tooltip_show) { return; } // Hide when scatter plot exists if (hasScatterType.call($$, $$.data.targets) || hasArcType.call($$, $$.data.targets)) { return; } - var focusEl = $$.main.selectAll('line.' + $$.CLASS.xgridFocus); + var focusEl = $$.main.selectAll('line.' + CLASS.xgridFocus); focusEl .style("visibility", "visible") .data([dataToShow[0]]) - .attr($$.config.axis_rotated ? 'y1' : 'x1', function (d) { return $$.xx(d); }) - .attr($$.config.axis_rotated ? 'y2' : 'x2', function (d) { return $$.xx(d); }); + .attr($$.config.axis_rotated ? 'y1' : 'x1', generateCall(xx, $$)) + .attr($$.config.axis_rotated ? 'y2' : 'x2', generateCall(xx, $$)); $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { - var $$ = this; - $$.main.select('line.' + $$.CLASS.xgridFocus).style("visibility", "hidden"); + this.main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); }; c3_chart_internal_fn.updateXgridFocus = function () { var $$ = this, config = $$.config; - $$.main.select('line.' + $$.CLASS.xgridFocus) + $$.main.select('line.' + CLASS.xgridFocus) .attr("x1", config.axis_rotated ? 0 : -10) .attr("x2", config.axis_rotated ? $$.width : -10) .attr("y1", config.axis_rotated ? -10 : 0) @@ -1972,7 +1971,7 @@ c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + $$.CLASS.axisX).selectAll('.tick').size(); + tickNum = $$.main.select("." + CLASS.axisX).selectAll('.tick').size(); if (type === 'year') { xDomain = $$.getXDomain(); firstYear = xDomain[0].getFullYear(); @@ -2000,7 +1999,7 @@ } : function () { return true; }; }; c3_chart_internal_fn.removeGridLines = function (params, forX) { - var $$ = this, CLASS = $$.CLASS, + var $$ = this, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, @@ -2047,15 +2046,15 @@ }; c3_chart_internal_fn.opacityForLegend = function (legendItem) { var $$ = this; - return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; + return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; }; c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; - return legendItem.classed($$.CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; + return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; }; c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { var $$ = this; - $$.legend.selectAll('.' + $$.CLASS.legendItem) + $$.legend.selectAll('.' + CLASS.legendItem) .transition().duration(100) .style('opacity', function (_id) { var This = $$.d3.select(this); @@ -2068,7 +2067,7 @@ }; c3_chart_internal_fn.revertLegend = function () { var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + $$.CLASS.legendItem) + $$.legend.selectAll('.' + CLASS.legendItem) .transition().duration(100) .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; @@ -2086,7 +2085,7 @@ }; c3_chart_internal_fn.hideLegend = function (targetIds) { var $$ = this; - if ($$.config.legend_show && $$.isEmpty(targetIds)) { + if ($$.config.legend_show && isEmpty(targetIds)) { $$.config.legend_show = false; $$.legend.style('visibility', 'hidden'); } @@ -2096,7 +2095,7 @@ .style('visibility', 'hidden'); }; c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this, c = $$.config; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; @@ -2105,11 +2104,11 @@ var texts, rects, tiles; options = options || {}; - withTransition = $$.getOption(options, "withTransition", true); - withTransitionForTransform = $$.getOption(options, "withTransitionForTransform", true); + withTransition = getOption(options, "withTransition", true); + withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), + var box = getTextRect.call($$, textElement.textContent, CLASS.legendItem), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, @@ -2139,7 +2138,7 @@ maxHeight = 0; } - if ($$.config.legend_show && !$$.isLegendToShow(id)) { + if (c.legend_show && !$$.isLegendToShow(id)) { widths[id] = heights[id] = steps[id] = offsets[id] = 0; return; } @@ -2151,7 +2150,7 @@ if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; - if ($$.config.legend_equally) { + if (c.legend_equally) { Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); margin = (areaLength - maxLength * targetIds.length) / 2; @@ -2191,15 +2190,15 @@ .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - typeof $$.config.legend_item_onclick === 'function' ? $$.config.legend_item_onclick.call(c3, id) : $$.api.toggle(id); + typeof clegend_item_onclick === 'function' ? clegend_item_onclick.call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed(CLASS.legendItemFocused, true); if (!$$.transiting) { $$.api.focus(id); } - if (typeof $$.config.legend_item_onmouseover === 'function') { - $$.config.legend_item_onmouseover.call(c3, id); + if (typeof c.legend_item_onmouseover === 'function') { + c.legend_item_onmouseover.call(c3, id); } }) .on('mouseout', function (id) { @@ -2207,12 +2206,12 @@ if (!$$.transiting) { $$.api.revert(); } - if (typeof $$.config.legend_item_onmouseout === 'function') { - $$.config.legend_item_onmouseout.call(c3, id); + if (typeof c.legend_item_onmouseout === 'function') { + c.legend_item_onmouseout.call(c3, id); } }); l.append('text') - .text(function (id) { return $$.isDefined($$.config.data_names[id]) ? $$.config.data_names[id] : id; }) + .text(function (id) { return isDefined(c.data_names[id]) ? c.data_names[id] : id; }) .each(function (id, i) { updatePositions(this, id, i === 0); }) .style("pointer-events", "none") .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2241,7 +2240,7 @@ texts = $$.legend.selectAll('text') .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(c.data_names[id]) ? c.data_names[id] : id; }) // MEMO: needed for update .each(function (id, i) { updatePositions(this, id, i === 0); }); (withTransition ? texts.transition() : texts) .attr('x', xForLegendText) @@ -2280,8 +2279,8 @@ $$.updateLegendItemHeight(maxHeight); $$.updateLegendStep(step); // Update size and scale - $$.updateSizes(); - $$.updateScales(); + updateSizes.call($$); + updateScales.call($$); $$.updateSvgSize(); // Update g positions $$.transformAll(withTransitionForTransform, transitions); @@ -2349,18 +2348,18 @@ */ c3_chart_internal_fn.isX = function (key) { var $$ = this, c = $$.config; - return (c.data_x && key === c.data_x) || ($$.notEmpty(c.data_xs) && $$.hasValue(c.data_xs, key)); + return (c.data_x && key === c.data_x) || (notEmpty(c.data_xs) && hasValue(c.data_xs, key)); }; c3_chart_internal_fn.isNotX = function (key) { return !this.isX(key); }; c3_chart_internal_fn.getXKey = function (id) { var $$ = this, c = $$.config; - return c.data_x ? c.data_x : this.notEmpty(c.data_xs) ? c.data_xs[id] : null; + return c.data_x ? c.data_x : notEmpty(c.data_xs) ? c.data_xs[id] : null; }; c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { var $$ = this, - xValues, ids = targets && $$.notEmpty(targets) ? $$.mapToIds(targets) : []; + xValues, ids = targets && notEmpty(targets) ? $$.mapToIds(targets) : []; ids.forEach(function (id) { if ($$.getXKey(id) === key) { xValues = $$.data.xs[id]; @@ -2370,7 +2369,7 @@ }; c3_chart_internal_fn.getXValue = function (id, i) { var $$ = this; - return id in $$.data.xs && $$.data.xs[id] && $$.isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; + return id in $$.data.xs && $$.data.xs[id] && isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; }; c3_chart_internal_fn.getOtherTargetXs = function () { var $$ = this, @@ -2425,21 +2424,21 @@ x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); } else if ($$.isCustomX() && !$$.isCategorized) { - x = $$.isValue(rawX) ? +rawX : $$.getXValue(id, index); + x = isValue(rawX) ? +rawX : $$.getXValue(id, index); } else { x = index; } return x; }; - c3_chart_internal_fn.convertUrlToData = function convertUrlToData(url, mimeType, keys, done) { + var convertUrlToData = c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { var $$ = this, type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; if (type === 'json') { - d = $$.convertJsonToData(JSON.parse(data.response), keys); + d = convertJsonToData.call($$, JSON.parse(data.response), keys); } else { - d = $$.convertCsvToData(data.response); + d = convertCsvToData.call($$, data.response); } done(d); }); @@ -2584,14 +2583,13 @@ return this.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); }; c3_chart_internal_fn.filterRemoveNull = function (data) { - var $$ = this; - return data.filter(function (d) { return $$.isValue(d.value); }); + return data.filter(function (d) { return isValue(d.value); }); }; c3_chart_internal_fn.hasDataLabel = function () { - var $$ = this, c = $$.config; + var c = this.config; if (typeof c.data_labels === 'boolean' && c.data_labels) { return true; - } else if (typeof c.data_labels === 'object' && $$.notEmpty(c.data_labels)) { + } else if (typeof c.data_labels === 'object' && notEmpty(c.data_labels)) { return true; } return false; @@ -2609,10 +2607,10 @@ .remove(); return lengths; }; - c3_chart_internal_fn.isNoneArc = function (d) { + var isNoneArc = c3_chart_internal_fn.isNoneArc = function (d) { return this.hasTarget(this.data.targets, d.id); - }; - c3_chart_internal_fn.isArc = function (d) { + }, + isArc = c3_chart_internal_fn.isArc = function (d) { return 'data' in d && this.hasTarget(this.data.targets, d.data.id); }; @@ -2620,7 +2618,7 @@ /** * c3.data.convert.js */ - c3_chart_internal_fn.convertCsvToData = function (csv) { + var convertCsvToData = c3_chart_internal_fn.convertCsvToData = function (csv) { var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; @@ -2632,7 +2630,7 @@ } return d; }; - c3_chart_internal_fn.convertJsonToData = function (json, keys) { + var convertJsonToData = c3_chart_internal_fn.convertJsonToData = function (json, keys) { var $$ = this, new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects @@ -2651,16 +2649,16 @@ }); new_rows.push(new_row); }); - data = $$.convertRowsToData(new_rows); + data = convertRowsToData.call($$, new_rows); } else { Object.keys(json).forEach(function (key) { new_rows.push([key].concat(json[key])); }); - data = $$.convertColumnsToData(new_rows); + data = convertColumnsToData.call($$, new_rows); } return data; }; - c3_chart_internal_fn.convertRowsToData = function (rows) { + var convertRowsToData = c3_chart_internal_fn.convertRowsToData = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; @@ -2674,7 +2672,7 @@ } return new_rows; }; - c3_chart_internal_fn.convertColumnsToData = function (columns) { + var convertColumnsToData = c3_chart_internal_fn.convertColumnsToData = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; @@ -2690,7 +2688,7 @@ } return new_rows; }; - c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { + var convertDataToTargets = c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { var $$ = this, c = $$.config, ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), @@ -2705,7 +2703,7 @@ if (xs.indexOf(xKey) >= 0) { $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( data.map(function (d) { return d[xKey]; }) - .filter($$.isValue) + .filter(isValue) .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }) ); } @@ -2714,7 +2712,7 @@ $$.data.xs[id] = $$.getOtherTargetXs(); } // if not included in input data, find from preloaded data - else if ($$.notEmpty(c.data_xs)) { + else if (notEmpty(c.data_xs)) { $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used @@ -2815,7 +2813,7 @@ } // Set targets - $$.updateTargets($$.data.targets); + updateTargets.call($$, $$.data.targets); // Redraw with new targets $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); @@ -2827,21 +2825,21 @@ c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; if (args.data) { - $$.load($$.convertDataToTargets(args.data), args); + $$.load(convertDataToTargets.call($$, args.data), args); } else if (args.url) { $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { - $$.load($$.convertDataToTargets(data), args); + $$.load(convertDataToTargets.call($$, data), args); }); } else if (args.json) { - $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); + $$.load(convertDataToTargets.call($$, convertJsonToData.call($$, args.json, args.keys)), args); } else if (args.rows) { - $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); + $$.load(convertDataToTargets.call($$, convertRowsToData.call($$, args.rows)), args); } else if (args.columns) { - $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); + $$.load(convertDataToTargets.call($$, convertColumnsToData.call($$, args.columns)), args); } else { $$.load(null, args); @@ -2868,7 +2866,7 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + $$.CLASS.legendItem + getTargetSelectorSuffix.call($$, id)).remove(); + $$.legend.selectAll('.' + CLASS.legendItem + getTargetSelectorSuffix.call($$, id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -2902,7 +2900,7 @@ } } } - if ($$.isUndefined(indices[d.id])) { indices[d.id] = i++; } + if (isUndefined(indices[d.id])) { indices[d.id] = i++; } }); indices.__max__ = i - 1; return indices; @@ -2953,33 +2951,33 @@ return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; c3_chart_internal_fn.getCircles = function (i, id) { - var $$ = this, CLASS = $$.CLASS; - return (id ? $$.main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix.call($$, id)) : $$.main).selectAll('.' + CLASS.circle + ($$.isValue(i) ? '-' + i : '')); + var $$ = this; + return (id ? $$.main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix.call($$, id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this; $$.getCircles(i, id) .classed(CLASS.EXPANDED, true) - .attr('r', function (d) { return $$.pointExpandedR(d); }); + .attr('r', generateCall(pointExpandedR, $$)); }; c3_chart_internal_fn.unexpandCircles = function (i) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this; $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) .classed(CLASS.EXPANDED, false) - .attr('r', function (d) { return $$.pointR(d); }); + .attr('r', generateCall(pointR, $$)); }; - c3_chart_internal_fn.pointR = function (d) { + var pointR = c3_chart_internal_fn.pointR = function (d) { var $$ = this; return $$.config.point_show && !isStepType.call($$, d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; }; - c3_chart_internal_fn.pointExpandedR = function (d) { + var pointExpandedR = c3_chart_internal_fn.pointExpandedR = function (d) { var $$ = this, c = $$.config; - return c.point_focus_expand_enabled ? (c.point_focus_expand_r ? c.point_focus_expand_r : $$.pointR(d) * 1.75) : $$.pointR(d); + return c.point_focus_expand_enabled ? (c.point_focus_expand_r ? c.point_focus_expand_r : pointR.call($$, d) * 1.75) : pointR.call($$, d); }; c3_chart_internal_fn.pointSelectR = function (d) { var $$ = this, c = $$.config; - return c.point_select_r ? c.point_select_r : $$.pointR(d) * 4; + return c.point_select_r ? c.point_select_r : pointR.call($$, d) * 4; }; @@ -2991,15 +2989,15 @@ }; c3_chart_internal_fn.getBars = function (i) { var $$ = this; - return $$.main.selectAll('.' + $$.CLASS.bar + ($$.isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandBars = function (i) { var $$ = this; - $$.getBars(i).classed($$.CLASS.EXPANDED, true); + $$.getBars(i).classed(CLASS.EXPANDED, true); }; c3_chart_internal_fn.unexpandBars = function (i) { var $$ = this; - $$.getBars(i).classed($$.CLASS.EXPANDED, false); + $$.getBars(i).classed(CLASS.EXPANDED, false); }; c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { var $$ = this, getPoints = $$.generateGetBarPoints(barIndices, isSub); @@ -3192,15 +3190,15 @@ regions = []; // Check start/end of regions - if ($$.isDefined(_regions)) { + if (isDefined(_regions)) { for (i = 0; i < _regions.length; i++) { regions[i] = {}; - if ($$.isUndefined(_regions[i].start)) { + if (isUndefined(_regions[i].start)) { regions[i].start = d[0].x; } else { regions[i].start = $$.isTimeSeries ? $$.parseDate(_regions[i].start) : _regions[i].start; } - if ($$.isUndefined(_regions[i].end)) { + if (isUndefined(_regions[i].end)) { regions[i].end = d[d.length - 1].x; } else { regions[i].end = $$.isTimeSeries ? $$.parseDate(_regions[i].end) : _regions[i].end; @@ -3230,7 +3228,7 @@ for (i = 0; i < d.length; i++) { // 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]); } // Draw with region // TODO: Fix for horizotal charts @@ -3578,7 +3576,7 @@ c3_chart_internal_fn.getSubYScale = function (id) { return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; }; - c3_chart_internal_fn.updateScales = function () { + var updateScales = c3_chart_internal_fn.updateScales = function () { var $$ = this, c = $$.config, forInit = !$$.x; // update edges @@ -3598,7 +3596,7 @@ $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes - $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickFormat = getXAxisTickFormat.call($$); $$.xAxisTickValues = c.axis_x_tick_values ? c.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); @@ -3684,8 +3682,8 @@ yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), yMin = axisId === 'y2' ? c.axis_y2_min : c.axis_y_min, yMax = axisId === 'y2' ? c.axis_y2_max : c.axis_y_max, - yDomainMin = $$.isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), - yDomainMax = $$.isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), + yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), + yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? c.axis_y2_center : c.axis_y_center, yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, @@ -3718,7 +3716,7 @@ // add padding for data label if (showHorizontalDataLabel) { lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); - diff = $$.diffDomain($$.y.range()); + diff = diffDomain($$.y.range()); ratio = [lengths[0] / diff, lengths[1] / diff]; padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); @@ -3762,9 +3760,9 @@ } else { padding = diff * 0.01; } - if (typeof c.axis_x_padding === 'object' && this.notEmpty(c.axis_x_padding)) { - paddingLeft = this.isValue(c.axis_x_padding.left) ? c.axis_x_padding.left : padding; - paddingRight = this.isValue(c.axis_x_padding.right) ? c.axis_x_padding.right : padding; + if (typeof c.axis_x_padding === 'object' && notEmpty(c.axis_x_padding)) { + paddingLeft = isValue(c.axis_x_padding.left) ? c.axis_x_padding.left : padding; + paddingRight = isValue(c.axis_x_padding.right) ? c.axis_x_padding.right : padding; } else if (typeof c.axis_x_padding === 'number') { paddingLeft = paddingRight = c.axis_x_padding; } else { @@ -3818,7 +3816,7 @@ axis.tickFormat(tickFormat).tickValues(tickValues); if ($$.isCategorized) { axis.tickCentered($$.config.axis_x_tick_centered); - if ($$.isEmpty($$.config.axis_x_tick_culling)) { + if (isEmpty($$.config.axis_x_tick_culling)) { $$.config.axis_x_tick_culling = false; } } else { @@ -3839,7 +3837,7 @@ var c = this.config; return id in c.data_axes ? c.data_axes[id] : 'y'; }; - c3_chart_internal_fn.getXAxisTickFormat = function () { + var getXAxisTickFormat = c3_chart_internal_fn.getXAxisTickFormat = function () { var $$ = this, c = $$.config, format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; if (c.axis_x_tick_format) { @@ -3853,7 +3851,7 @@ } return function (v) { return format.call($$, v); }; }; - c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { + var getAxisLabelOptionByAxisId = c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { var $$ = this, c = $$.config, option; if (axisId === 'y') { option = c.axis_y_label; @@ -3864,13 +3862,13 @@ } return option; }; - c3_chart_internal_fn.getAxisLabelText = function (axisId) { - var option = this.getAxisLabelOptionByAxisId(axisId); + var getAxisLabelText = c3_chart_internal_fn.getAxisLabelText = function (axisId) { + var option = getAxisLabelOptionByAxisId.call(this, axisId); return typeof option === 'string' ? option : option ? option.text : null; }; - c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { + var setAxisLabelText = c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { var $$ = this, c = $$.config, - option = $$.getAxisLabelOptionByAxisId(axisId); + option = getAxisLabelOptionByAxisId.call($$, axisId); if (typeof option === 'string') { if (axisId === 'y') { c.axis_y_label = text; @@ -3883,8 +3881,8 @@ option.text = text; } }; - c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { - var option = this.getAxisLabelOptionByAxisId(axisId), + var getAxisLabelPosition = c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { + var option = getAxisLabelOptionByAxisId.call(this, axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { isInner: position.indexOf('inner') >= 0, @@ -3897,28 +3895,28 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - c3_chart_internal_fn.getXAxisLabelPosition = function () { - return this.getAxisLabelPosition('x', this.config.axis_rotated ? 'inner-top' : 'inner-right'); + var getXAxisLabelPosition = c3_chart_internal_fn.getXAxisLabelPosition = function () { + return getAxisLabelPosition.call(this, 'x', this.config.axis_rotated ? 'inner-top' : 'inner-right'); }; - c3_chart_internal_fn.getYAxisLabelPosition = function () { - return this.getAxisLabelPosition('y', this.config.axis_rotated ? 'inner-right' : 'inner-top'); + var getYAxisLabelPosition = c3_chart_internal_fn.getYAxisLabelPosition = function () { + return getAxisLabelPosition.call(this, 'y', this.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3_chart_internal_fn.getY2AxisLabelPosition = function () { - return this.getAxisLabelPosition('y2', this.config.axis_rotated ? 'inner-right' : 'inner-top'); + var getY2AxisLabelPosition = c3_chart_internal_fn.getY2AxisLabelPosition = function () { + return getAxisLabelPosition.call(this, 'y2', this.config.axis_rotated ? 'inner-right' : 'inner-top'); }; - c3_chart_internal_fn.getAxisLabelPositionById = function (id) { - return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); + var getAxisLabelPositionById = c3_chart_internal_fn.getAxisLabelPositionById = function (id) { + return id === 'y2' ? getY2AxisLabelPosition.call(this) : id === 'y' ? getYAxisLabelPosition.call(this) : getXAxisLabelPosition.call(this); }; - c3_chart_internal_fn.textForXAxisLabel = function () { - return this.getAxisLabelText('x'); + var textForXAxisLabel = c3_chart_internal_fn.textForXAxisLabel = function () { + return getAxisLabelText.call(this, 'x'); }; - c3_chart_internal_fn.textForYAxisLabel = function () { - return this.getAxisLabelText('y'); + var textForYAxisLabel = c3_chart_internal_fn.textForYAxisLabel = function () { + return getAxisLabelText.call(this, 'y'); }; - c3_chart_internal_fn.textForY2AxisLabel = function () { - return this.getAxisLabelText('y2'); + var textForY2AxisLabel = c3_chart_internal_fn.textForY2AxisLabel = function () { + return getAxisLabelText.call(this, 'y2'); }; - c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { + var xForAxisLabel = c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -3926,76 +3924,76 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - c3_chart_internal_fn.dxForAxisLabel = function (forHorizontal, position) { + var dxForAxisLabel = c3_chart_internal_fn.dxForAxisLabel = function (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"; } }; - c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { + var textAnchorForAxisLabel = c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - c3_chart_internal_fn.xForXAxisLabel = function () { - return this.xForAxisLabel(!this.config.axis_rotated, this.getXAxisLabelPosition()); + var xForXAxisLabel = c3_chart_internal_fn.xForXAxisLabel = function () { + return xForAxisLabel.call(this, !this.config.axis_rotated, getXAxisLabelPosition.call(this)); }; - c3_chart_internal_fn.xForYAxisLabel = function () { - return this.xForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); + var xForYAxisLabel = c3_chart_internal_fn.xForYAxisLabel = function () { + return xForAxisLabel.call(this, this.config.axis_rotated, getYAxisLabelPosition.call(this)); }; - c3_chart_internal_fn.xForY2AxisLabel = function () { - return this.xForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); + var xForY2AxisLabel = c3_chart_internal_fn.xForY2AxisLabel = function () { + return xForAxisLabel.call(this, this.config.axis_rotated, getY2AxisLabelPosition.call(this)); }; - c3_chart_internal_fn.dxForXAxisLabel = function () { - return this.dxForAxisLabel(!this.__axis_rotated, this.getXAxisLabelPosition()); + var dxForXAxisLabel = c3_chart_internal_fn.dxForXAxisLabel = function () { + return dxForAxisLabel.call(this, !this.config.axis_rotated, getXAxisLabelPosition.call(this)); }; - c3_chart_internal_fn.dxForYAxisLabel = function () { - return this.dxForAxisLabel(this.__axis_rotated, this.getYAxisLabelPosition()); + var dxForYAxisLabel = c3_chart_internal_fn.dxForYAxisLabel = function () { + return dxForAxisLabel.call(this, this.config.axis_rotated, getYAxisLabelPosition.call(this)); }; - c3_chart_internal_fn.dxForY2AxisLabel = function () { - return this.dxForAxisLabel(this.__axis_rotated, this.getY2AxisLabelPosition()); + var dxForY2AxisLabel = c3_chart_internal_fn.dxForY2AxisLabel = function () { + return dxForAxisLabel.call(this, this.config.axis_rotated, getY2AxisLabelPosition.call(this)); }; - c3_chart_internal_fn.dyForXAxisLabel = function () { + var dyForXAxisLabel = c3_chart_internal_fn.dyForXAxisLabel = function () { var $$ = this, c = $$.config, - position = $$.getXAxisLabelPosition(); + position = getXAxisLabelPosition.call($$); if (c.axis_rotated) { return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); } else { return position.isInner ? "-0.5em" : c.axis_x_height ? c.axis_x_height - 10 : "3em"; } }; - c3_chart_internal_fn.dyForYAxisLabel = function () { + var dyForYAxisLabel = c3_chart_internal_fn.dyForYAxisLabel = function () { var $$ = this, - position = $$.getYAxisLabelPosition(); + position = getYAxisLabelPosition.call($$); if ($$.config.axis_rotated) { return position.isInner ? "-0.5em" : "3em"; } else { return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); } }; - c3_chart_internal_fn.dyForY2AxisLabel = function () { + var dyForY2AxisLabel = c3_chart_internal_fn.dyForY2AxisLabel = function () { var $$ = this, - position = $$.getY2AxisLabelPosition(); + position = getY2AxisLabelPosition.call($$); if ($$.config.axis_rotated) { return position.isInner ? "1.2em" : "-2.2em"; } else { return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); } }; - c3_chart_internal_fn.textAnchorForXAxisLabel = function () { + var textAnchorForXAxisLabel = c3_chart_internal_fn.textAnchorForXAxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel(!$$.config.axis_rotated, $$.getXAxisLabelPosition()); + return textAnchorForAxisLabel.call($$, !$$.config.axis_rotated, getXAxisLabelPosition.call($$)); }; - c3_chart_internal_fn.textAnchorForYAxisLabel = function () { + var textAnchorForYAxisLabel = c3_chart_internal_fn.textAnchorForYAxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getYAxisLabelPosition()); + return textAnchorForAxisLabel.call($$, $$.config.axis_rotated, getYAxisLabelPosition.call($$)); }; - c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { + var textAnchorForY2AxisLabel = c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.config.axis_rotated, $$.getY2AxisLabelPosition()); + return textAnchorForAxisLabel.call($$, $$.config.axis_rotated, getY2AxisLabelPosition.call($$)); }; c3_chart_internal_fn.xForRotatedTickText = function (r) { @@ -4026,7 +4024,7 @@ axis = $$.getYAxis(scale, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); } else { scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); - axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); + axis = $$.getXAxis(scale, $$.xOrient, getXAxisTickFormat.call($$), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4040,31 +4038,30 @@ }; c3_chart_internal_fn.updateAxisLabels = function (withTransition) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this; 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", function () { return $$.xForXAxisLabel(); }) - .attr("dx", function () { return $$.dxForXAxisLabel(); }) - .attr("dy", function () { return $$.dyForXAxisLabel(); }) - .text(function () { return $$.textForXAxisLabel(); }); + .attr("x", generateCall(xForXAxisLabel, $$)) + .attr("dx", generateCall(dxForXAxisLabel, $$)) + .attr("dy", generateCall(dyForXAxisLabel, $$)) + .text(generateCall(textForXAxisLabel, $$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", function () { return $$.xForYAxisLabel(); }) - .attr("dx", function () { return $$.dxForYAxisLabel(); }) - .attr("dy", function () { return $$.dyForYAxisLabel(); }) - .attr("dy", function () { return $$.dyForYAxisLabel(); }) - .text(function () { return $$.textForYAxisLabel(); }); + .attr("x", generateCall(xForYAxisLabel, $$)) + .attr("dx", generateCall(dxForYAxisLabel, $$)) + .attr("dy", generateCall(dyForYAxisLabel, $$)) + .text(generateCall(textForYAxisLabel, $$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", function () { return $$.xForY2AxisLabel(); }) - .attr("dx", function () { return $$.dxForY2AxisLabel(); }) - .attr("dy", function () { return $$.dyForY2AxisLabel(); }) - .text(function () { return $$.textForY2AxisLabel(); }); + .attr("x", generateCall(xForY2AxisLabel, $$)) + .attr("dx", generateCall(dxForY2AxisLabel, $$)) + .attr("dy", generateCall(dyForY2AxisLabel, $$)) + .text(generateCall(textForY2AxisLabel, $$)); }; c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { var ratio = padding.unit === 'ratio' ? all : 1; - return this.isValue(padding[key]) ? padding[key] * ratio : defaultValue; + return isValue(padding[key]) ? padding[key] * ratio : defaultValue; }; c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { @@ -4269,7 +4266,7 @@ }; var expandArc = c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { - var $$ = this, CLASS = $$.CLASS, + var $$ = this, target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); @@ -4291,7 +4288,7 @@ }; var unexpandArc = c3_chart_internal_fn.unexpandArc = function (id) { - var $$ = this, CLASS = $$.CLASS, + var $$ = this, target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)); target.selectAll('path.' + CLASS.arc) .transition().duration(50) @@ -4344,13 +4341,13 @@ var updateTargetsForArc = c3_chart_internal_fn.updateTargetsForArc = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; - mainPieUpdate = main.select('.' + $$.CLASS.chartArcs).selectAll('.' + $$.CLASS.chartArc) + mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) .data($$.pie(targets)) - .attr("class", function (d) { return classChartArc.call($$, d); }); + .attr("class", generateCall(classChartArc, $$)); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", function (d) { return classChartArc.call($$, d); }); + .attr("class", generateCall(classChartArc, $$)); mainPieEnter.append('g') - .attr('class', function (d) { return classArcs.call($$, d); }); + .attr('class', generateCall(classArcs, $$)); mainPieEnter.append("text") .attr("dy", hasGaugeType.call($$, $$.data.targets) ? "-0.35em" : ".35em") .style("opacity", 0) @@ -4361,7 +4358,7 @@ }; var initArc = c3_chart_internal_fn.initArc = function () { - var $$ = this, CLASS = $$.CLASS, arcs; + var $$ = this, arcs; arcs = $$.main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartArcs) .attr("transform", $$.translate.arc); @@ -4372,12 +4369,12 @@ }; var redrawArc = c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { - var $$ = this, d3 = $$.d3, CLASS = $$.CLASS, main = $$.main, + var $$ = this, d3 = $$.d3, main = $$.main, mainArc; mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(function (d) { return arcData.call($$, d); }); + .data(generateCall(arcData, $$)); mainArc.enter().append('path') - .attr("class", function (d) { return classArc.call($$, d); }) + .attr("class", generateCall(classArc, $$)) .style("fill", function (d) { return $$.color(d.data); }) .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) .style("opacity", 0) @@ -4460,8 +4457,8 @@ main.selectAll('.' + CLASS.chartArc).select('text') .style("opacity", 0) .attr('class', function (d) { return isGaugeType.call($$, d.data) ? CLASS.gaugeValue : ''; }) - .text(function (d) { return textForArcLabel.call($$, d); }) - .attr("transform", function (d) { return transformForArcLabel.call($$, d); }) + .text(generateCall(textForArcLabel, $$)) + .attr("transform", generateCall(transformForArcLabel, $$)) .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && isArcType.call($$, d.data) ? 1 : 0; }); main.select('.' + CLASS.chartArcsTitle) @@ -4472,7 +4469,7 @@ //-- gauge.js --// var initGauge = c3_chart_internal_fn.initGauge = function () { - var $$ = this, CLASS = $$.CLASS, c = $$.config, arcs; + var $$ = this, c = $$.config, arcs; if (hasGaugeType.call($$, $$.data.targets)) { arcs.append('path') .attr("class", CLASS.chartArcsBackground) @@ -4534,7 +4531,7 @@ var $$ = this, d3 = $$.d3; $$.brush = d3.svg.brush().on("brush", function () { redrawForBrush.call($$); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } + if ($$.context) { $$.context.select('.' + CLASS.brush).call(this); } return this; }; $$.brush.scale = function (scale) { @@ -4585,27 +4582,27 @@ contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr('class', function (d) { return classChartBar.call($$, d); }); + .attr('class', generateCall(classChartBar, $$)); contextBarEnter = contextBarUpdate.enter().append('g') .style('opacity', 0) - .attr('class', function (d) { return classChartBar.call($$, d); }); + .attr('class', generateCall(classChartBar, $$)); // Bars for each data contextBarEnter.append('g') - .attr("class", function (d) { return classBars.call($$, d); }); + .attr("class", generateCall(classBars, $$)); //-- Line --// contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr('class', function (d) { return classChartLine.call($$, d); }); + .attr('class', generateCall(classChartLine, $$)); contextLineEnter = contextLineUpdate.enter().append('g') .style('opacity', 0) - .attr('class', function (d) { return classChartLine.call($$, d); }); + .attr('class', generateCall(classChartLine, $$)); // Lines for each data contextLineEnter.append("g") - .attr("class", function (d) { return classLines.call($$, d); }); + .attr("class", generateCall(classLines, $$)); // Area contextLineEnter.append("g") - .attr("class", function (d) { return classAreas.call($$, d); }); + .attr("class", generateCall(classAreas, $$)); } }; var redrawSubchart = c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { @@ -4636,13 +4633,13 @@ drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(function (d) { return barData.call($$, d); }); + .data(generateCall(barData, $$)); contextBar.enter().append('path') - .attr("class", function (d) { return classBar.call($$, d); }) + .attr("class", generateCall(classBar, $$)) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style("opacity", function (d) { return initialOpacity.call($$, d); }) + .style("opacity", generateCall(initialOpacity, $$)) .transition().duration(duration) .attr('d', drawBarOnSub) .style('opacity', 1); @@ -4651,12 +4648,12 @@ .remove(); // lines contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(function (d) { return lineData.call($$, d); }); + .data(generateCall(lineData, $$)); contextLine.enter().append('path') - .attr('class', function (d) { return classLine.call($$, d); }) + .attr('class', generateCall(classLine, $$)) .style('stroke', $$.color); contextLine - .style("opacity", function (d) { return initialOpacity.call($$, d); }) + .style("opacity", generateCall(initialOpacity, $$)) .transition().duration(duration) .attr("d", drawLineOnSub) .style('opacity', 1); @@ -4665,9 +4662,9 @@ .remove(); // area contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(function (d) { return lineData.call($$, d); }); + .data(generateCall(lineData, $$)); contextArea.enter().append('path') - .attr("class", function (d) { return classArea.call($$, d); }) + .attr("class", generateCall(classArea, $$)) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea @@ -4697,7 +4694,7 @@ if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + $$.CLASS.axisX); + subXAxis = $$.context.select('.' + CLASS.axisX); if (withTransition) { subXAxis = subXAxis.transition(); } } $$.context.attr("transform", $$.translate.context); @@ -4710,8 +4707,8 @@ */ c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config.zoom_enabled ? $$.zoom : function () {}; - $$.main.select('.' + $$.CLASS.zoomRect).call(z); - $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); + $$.main.select('.' + CLASS.zoomRect).call(z); + $$.main.selectAll('.' + CLASS.eventRect).call(z); }; @@ -4720,53 +4717,52 @@ /** * c3.util.js */ - c3_chart_internal_fn.isValue = function (v) { + var isValue = c3_chart_internal_fn.isValue = function (v) { return v || v === 0; - }; - function isFunctionType(type) { + }, + isFunctionType = c3_chart_internal_fn.isFunctionType = function (type) { return type === 'function'; - } - c3_chart_internal_fn.isFunctionType = isFunctionType(); - c3_chart_internal_fn.isUndefined = function (v) { + }, + isUndefined = c3_chart_internal_fn.isUndefined = function (v) { return typeof v === 'undefined'; - }; - c3_chart_internal_fn.isDefined = function (v) { + }, + isDefined = c3_chart_internal_fn.isDefined = function (v) { return typeof v !== 'undefined'; - }; - c3_chart_internal_fn.ceil10 = function (v) { + }, + ceil10 = c3_chart_internal_fn.ceil10 = function (v) { return Math.ceil(v / 10) * 10; - }; - c3_chart_internal_fn.asHalfPixel = function (n) { + }, + asHalfPixel = c3_chart_internal_fn.asHalfPixel = function (n) { return Math.ceil(n) + 0.5; - }; - c3_chart_internal_fn.diffDomain = function (d) { + }, + diffDomain = c3_chart_internal_fn.diffDomain = function (d) { return d[1] - d[0]; - }; - c3_chart_internal_fn.isEmpty = function (o) { + }, + isEmpty = c3_chart_internal_fn.isEmpty = function (o) { return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); - }; - c3_chart_internal_fn.notEmpty = function (o) { + }, + notEmpty = c3_chart_internal_fn.notEmpty = function (o) { return Object.keys(o).length > 0; - }; - c3_chart_internal_fn.getOption = function (options, key, defaultValue) { + }, + getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { return typeof options[key] !== 'undefined' ? options[key] : defaultValue; - }; - c3_chart_internal_fn.hasValue = function (dict, value) { + }, + hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { var found = false; Object.keys(dict).forEach(function (key) { if (dict[key] === value) { found = true; } }); return found; - }; - c3_chart_internal_fn.getPathBox = function (path) { + }, + getPathBox = c3_chart_internal_fn.getPathBox = function (path) { var box = path.getBoundingClientRect(), items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; - }; - c3_chart_internal_fn.getTextRect = function (text, cls) { - var $$ = this, rect; - $$.d3.select('body').selectAll('.dummy') + }, + getTextRect = c3_chart_internal_fn.getTextRect = function (text, cls) { + var rect; + this.d3.select('body').selectAll('.dummy') .data([text]) .enter().append('text') .classed(cls ? cls : "", true) @@ -4774,11 +4770,9 @@ .each(function () { rect = this.getBoundingClientRect(); }) .remove(); return rect; - }; - - c3_chart_internal_fn.getEmptySelection = function () { - var $$ = this; - return $$.d3.selectAll([]); + }, + generateCall = c3_chart_internal_fn.generateCall = function (f, context) { + return function (d, i) { return f.call(context, d, i); }; }; @@ -4789,10 +4783,10 @@ var $$ = this; $$.config.data_onselected.call(c3, d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + this.CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return generateClass.call($$, this.CLASS.selectedCircle, i); }) + .attr("class", function () { return generateClass.call($$, CLASS.selectedCircle, i); }) .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY) .attr("stroke", function () { return $$.color(d); }) @@ -4804,7 +4798,7 @@ var $$ = this; $$.config.data_onunselected.call(c3, d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + $$.CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + this.CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; @@ -4832,10 +4826,10 @@ c3_chart_internal_fn.getToggle = function (that) { var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed($$.CLASS.bar) ? $$.toggleBar : $$.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS.bar) ? $$.toggleBar : $$.toggleArc); }; c3_chart_internal_fn.toggleShape = function (that, d, i) { - var $$ = this, CLASS = $$.CLASS, d3 = $$.d3, + var $$ = this, d3 = $$.d3, shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; if (that.nodeName === 'circle') { isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); @@ -5004,91 +4998,91 @@ EXPANDED: '_expanded_', SELECTED: '_selected_', INCLUDED: '_included_' - }; - var generateClass = c3_chart_internal_fn.generateClass = function (prefix, targetId) { + }, + generateClass = c3_chart_internal_fn.generateClass = function (prefix, targetId) { return " " + prefix + " " + prefix + getTargetSelectorSuffix.call(this, targetId); - }; - var classText = c3_chart_internal_fn.classText = function (d) { + }, + classText = c3_chart_internal_fn.classText = function (d) { return generateClass.call(this, CLASS.text, d.index); - }; - var classTexts = c3_chart_internal_fn.classTexts = function (d) { + }, + classTexts = c3_chart_internal_fn.classTexts = function (d) { return generateClass.call(this, CLASS.texts, d.id); - }; - var classShape = c3_chart_internal_fn.classShape = function (d) { + }, + classShape = c3_chart_internal_fn.classShape = function (d) { return generateClass.call(this, CLASS.shape, d.index); - }; - var classShapes = c3_chart_internal_fn.classShapes = function (d) { + }, + classShapes = c3_chart_internal_fn.classShapes = function (d) { return generateClass.call(this, CLASS.shapes, d.id); - }; - var classLine = c3_chart_internal_fn.classLine = function (d) { + }, + classLine = c3_chart_internal_fn.classLine = function (d) { return classShape.call(this, d) + generateClass.call(this, CLASS.line, d.id); - }; - var classLines = c3_chart_internal_fn.classLines = function (d) { + }, + classLines = c3_chart_internal_fn.classLines = function (d) { return classShapes.call(this, d) + generateClass.call(this, CLASS.lines, d.id); - }; - var classCircle = c3_chart_internal_fn.classCircle = function (d) { + }, + classCircle = c3_chart_internal_fn.classCircle = function (d) { return classShape.call(this, d) + generateClass.call(this, CLASS.circle, d.index); - }; - var classCircles = c3_chart_internal_fn.classCircles = function (d) { + }, + classCircles = c3_chart_internal_fn.classCircles = function (d) { return classShapes.call(this, d) + generateClass.call(this, CLASS.circles, d.id); - }; - var classBar = c3_chart_internal_fn.classBar = function (d) { + }, + classBar = c3_chart_internal_fn.classBar = function (d) { return classShape.call(this, d) + generateClass.call(this, CLASS.bar, d.index); - }; - var classBars = c3_chart_internal_fn.classBars = function (d) { + }, + classBars = c3_chart_internal_fn.classBars = function (d) { return classShapes.call(this, d) + generateClass.call(this, CLASS.bars, d.id); - }; - var classArc = c3_chart_internal_fn.classArc = function (d) { + }, + classArc = c3_chart_internal_fn.classArc = function (d) { return classShape.call(this, d.data) + generateClass.call(this, CLASS.arc, d.data.id); - }; - var classArcs = c3_chart_internal_fn.classArcs = function (d) { + }, + classArcs = c3_chart_internal_fn.classArcs = function (d) { return classShapes.call(this, d.data) + generateClass.call(this, CLASS.arcs, d.data.id); - }; - var classArea = c3_chart_internal_fn.classArea = function (d) { + }, + classArea = c3_chart_internal_fn.classArea = function (d) { return classShape.call(this, d) + generateClass.call(this, CLASS.area, d.id); - }; - var classAreas = c3_chart_internal_fn.classAreas = function (d) { + }, + classAreas = c3_chart_internal_fn.classAreas = function (d) { return classShapes.call(this, d) + generateClass.call(this, CLASS.areas, d.id); - }; - var classRegion = c3_chart_internal_fn.classRegion = function (d, i) { + }, + classRegion = c3_chart_internal_fn.classRegion = function (d, i) { return generateClass.call(this, CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); - }; - var classEvent = c3_chart_internal_fn.classEvent = function (d) { + }, + classEvent = c3_chart_internal_fn.classEvent = function (d) { return generateClass.call(this, CLASS.eventRect, d.index); - }; - var classTarget = c3_chart_internal_fn.classTarget = function (id) { + }, + classTarget = c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config.data_classes[id], additionalClass = ''; if (additionalClassSuffix) { - additionalClass = ' ' + $$.CLASS.target + '-' + additionalClassSuffix; + additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; } return generateClass.call($$, CLASS.target, id) + additionalClass; - }; - var classChartText = c3_chart_internal_fn.classChartText = function (d) { + }, + classChartText = c3_chart_internal_fn.classChartText = function (d) { return CLASS.chartText + classTarget.call(this, d.id); - }; - var classChartLine = c3_chart_internal_fn.classChartLine = function (d) { + }, + classChartLine = c3_chart_internal_fn.classChartLine = function (d) { return CLASS.chartLine + classTarget.call(this, d.id); - }; - var classChartBar = c3_chart_internal_fn.classChartBar = function (d) { + }, + classChartBar = c3_chart_internal_fn.classChartBar = function (d) { return CLASS.chartBar + classTarget.call(this, d.id); - }; - var classChartArc = c3_chart_internal_fn.classChartArc = function (d) { + }, + classChartArc = c3_chart_internal_fn.classChartArc = function (d) { return CLASS.chartArc + classTarget.call(this, d.data.id); - }; - var getTargetSelectorSuffix = c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { + }, + getTargetSelectorSuffix = c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; - }; - var selectorTarget = c3_chart_internal_fn.selectorTarget = function (id) { + }, + selectorTarget = c3_chart_internal_fn.selectorTarget = function (id) { return '.' + CLASS.target + getTargetSelectorSuffix.call(this, id); - }; - var selectorTargets = c3_chart_internal_fn.selectorTargets = function (ids) { + }, + selectorTargets = c3_chart_internal_fn.selectorTargets = function (ids) { return ids.length ? ids.map(function (id) { return selectorTarget.call(this, id); }) : null; - }; - var selectorLegend = c3_chart_internal_fn.selectorLegend = function (id) { + }, + selectorLegend = c3_chart_internal_fn.selectorLegend = function (id) { return '.' + CLASS.legendItem + getTargetSelectorSuffix.call(this, id); - }; - var selectorLegends = c3_chart_internal_fn.selectorLegends = function (ids) { + }, + selectorLegends = c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return selectorLegend.call($$, id); }) : null; }; @@ -5118,14 +5112,14 @@ return format.call($$, v); }; c3_chart_internal_fn.defaultValueFormat = function (v) { - return this.isValue(v) ? +v : ""; + return isValue(v) ? +v : ""; }; c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { return (ratio * 100).toFixed(1) + '%'; }; c3_chart_internal_fn.formatByAxisId = function (axisId) { var $$ = this.internal, data_labels = $$.config.data_labels, - format = function (v) { return this.isValue(v) ? +v : ""; }; + format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id if (typeof data_labels.format === 'function') { format = data_labels.format; @@ -5143,7 +5137,7 @@ * c3.drag.js */ c3_chart_internal_fn.drag = function (mouse) { - var $$ = this, main = $$.main, CLASS = $$.CLASS, d3 = $$.d3; + var $$ = this, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; if (hasArcType.call($$, $$.data.targets)) { return; } @@ -5180,7 +5174,7 @@ isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; } else if (shape.classed(CLASS.bar)) { - box = $$.getPathBox(this); + box = getPathBox(this); _x = box.x; _y = box.y; _w = box.width; @@ -5205,8 +5199,8 @@ if (hasArcType.call($$, $$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable $$.dragStart = mouse; - $$.main.select('.' + $$.CLASS.chart).append('rect') - .attr('class', $$.CLASS.dragarea) + $$.main.select('.' + CLASS.chart).append('rect') + .attr('class', CLASS.dragarea) .style('opacity', 0.1); $$.dragging = true; $$.config.data_ondragstart.call(c3); @@ -5216,12 +5210,12 @@ var $$ = this; if (hasArcType.call($$, $$.data.targets)) { return; } if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable - $$.main.select('.' + $$.CLASS.dragarea) + $$.main.select('.' + CLASS.dragarea) .transition().duration(100) .style('opacity', 0) .remove(); - $$.main.selectAll('.' + $$.CLASS.shape) - .classed($$.CLASS.INCLUDED, false); + $$.main.selectAll('.' + CLASS.shape) + .classed(CLASS.INCLUDED, false); $$.dragging = false; $$.config.data_ondragend.call(c3); }; @@ -5236,14 +5230,14 @@ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), - candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall(isArc, $$)); function focus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } this.revert(); this.defocus(); - focus(candidatesForNoneArc.classed($$.CLASS.focused, true)); + focus(candidatesForNoneArc.classed(CLASS.focused, true)); focus(candidatesForArc); if (hasArcType.call($$, $$.data.targets)) { expandArc.call($$, targetId, true); @@ -5254,13 +5248,13 @@ c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), - candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall(isArc, $$)); function defocus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } this.revert(); - defocus(candidatesForNoneArc.classed($$.CLASS.focused, false)); + defocus(candidatesForNoneArc.classed(CLASS.focused, false)); defocus(candidatesForArc); if (hasArcType.call($$, $$.data.targets)) { unexpandArc.call($$, targetId); @@ -5271,12 +5265,12 @@ c3_chart_fn.revert = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(function (d) { return $$.isNoneArc(d); }), - candidatesForArc = candidates.filter(function (d) { return $$.isArc(d); }); + candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall(isArc, $$)); function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } - revert(candidatesForNoneArc.classed($$.CLASS.focused, false)); + revert(candidatesForNoneArc.classed(CLASS.focused, false)); revert(candidatesForArc); if (hasArcType.call($$, $$.data.targets)) { unexpandArc.call($$, targetId); @@ -5385,18 +5379,18 @@ dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; if (args.json) { - data = $$.convertJsonToData(args.json, args.keys); + data = convertJsonToData.call($$, args.json, args.keys); } else if (args.rows) { - data = $$.convertRowsToData(args.rows); + data = convertRowsToData.call($$, args.rows); } else if (args.columns) { - data = $$.convertColumnsToData(args.columns); + data = convertColumnsToData.call($$, args.columns); } else { return; } - targets = $$.convertDataToTargets(data, true); + targets = convertDataToTargets.call($$, data, true); // Update/Add data $$.data.targets.forEach(function (t) { @@ -5472,13 +5466,13 @@ baseValue = baseTarget.values[0]; // Update length to flow if needed - if ($$.isDefined(args.to)) { + if (isDefined(args.to)) { length = 0; to = $$.isTimeSeries ? $$.parseDate(args.to) : args.to; baseTarget.values.forEach(function (v) { if (v.x < to) { length++; } }); - } else if ($$.isDefined(args.length)) { + } else if (isDefined(args.length)) { length = args.length; } @@ -5504,14 +5498,14 @@ } // Set targets - $$.updateTargets($$.data.targets); + updateTargets.call($$, $$.data.targets); // Redraw with new targets $$.redraw({ flow: { index: baseValue.index, length: length, - duration: $$.isValue(args.duration) ? args.duration : $$.config.transition_duration, + duration: isValue(args.duration) ? args.duration : $$.config.transition_duration, done: args.done, orgDataCount: orgDataCount, }, @@ -5521,7 +5515,7 @@ }; c3_chart_fn.selected = function (targetId) { - var $$ = this.internal, d3 = $$.d3, CLASS = $$.CLASS; + var $$ = this.internal, d3 = $$.d3; return d3.merge( $$.main.selectAll('.' + CLASS.shapes + getTargetSelectorSuffix.call($$, targetId)).selectAll('.' + CLASS.shape) .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) @@ -5529,7 +5523,7 @@ ); }; c3_chart_fn.select = function (ids, indices, resetOther) { - var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; + var $$ = this.internal, d3 = $$.d3; if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), @@ -5544,7 +5538,7 @@ if ($$.config.data_selection_isselectable(d) && !isSelected) { toggle(true, shape.classed(CLASS.SELECTED, true), d, i); } - } else if ($$.isDefined(resetOther) && resetOther) { + } else if (isDefined(resetOther) && resetOther) { if (isSelected) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } @@ -5552,7 +5546,7 @@ }); }; c3_chart_fn.unselect = function (ids, indices) { - var $$ = this.internal, CLASS = $$.CLASS, d3 = $$.d3; + var $$ = this.internal, d3 = $$.d3; if (! $$.config.data_selection_enabled) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), @@ -5581,7 +5575,7 @@ c3_chart_fn.groups = function (groups) { var $$ = this.internal; - if ($$.isUndefined(groups)) { return $$.config.data_groups; } + if (isUndefined(groups)) { return $$.config.data_groups; } $$.config.data_groups = groups; $$.redraw(); return $$.config.data_groups; @@ -5634,7 +5628,7 @@ return $$.config.regions; }; c3_chart_fn.regions.remove = function (options) { - var $$ = this.internal, CLASS = $$.CLASS, + var $$ = this.internal, duration, classes, regions; options = options || {}; @@ -5663,9 +5657,8 @@ c3_chart_fn.data = function () { }; c3_chart_fn.data.get = function (targetId) { - var $$ = this.internal, - target = this.data.getAsTarget(targetId); - return $$.isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; + var target = this.data.getAsTarget(targetId); + return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; }; c3_chart_fn.data.getAsTarget = function (targetId) { var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); @@ -5735,7 +5728,7 @@ var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { - $$.setAxisLabelText(axisId, labels[axisId]); + setAxisLabelText.call($$, axisId, labels[axisId]); }); $$.updateAxisLabels(); } @@ -5745,9 +5738,9 @@ var $$ = this.internal; if (arguments.length) { if (typeof max === 'object') { - if ($$.isValue(max.x)) { $$.config.axis_x_max = max.x; } - if ($$.isValue(max.y)) { $$.config.axis_y_max = max.y; } - if ($$.isValue(max.y2)) { $$.config.axis_y2_max = max.y2; } + if (isValue(max.x)) { $$.config.axis_x_max = max.x; } + if (isValue(max.y)) { $$.config.axis_y_max = max.y; } + if (isValue(max.y2)) { $$.config.axis_y2_max = max.y2; } } else { $$.config.axis_y_max = $$.config.axis_y2_max = max; } @@ -5758,9 +5751,9 @@ var $$ = this.internal; if (arguments.length) { if (typeof min === 'object') { - if ($$.isValue(min.x)) { $$.config.axis_x_min = min.x; } - if ($$.isValue(min.y)) { $$.config.axis_y_min = min.y; } - if ($$.isValue(min.y2)) { $$.config.axis_y2_min = min.y2; } + if (isValue(min.x)) { $$.config.axis_x_min = min.x; } + if (isValue(min.y)) { $$.config.axis_y_min = min.y; } + if (isValue(min.y2)) { $$.config.axis_y2_min = min.y2; } } else { $$.config.axis_y_min = $$.config.axis_y2_min = min; } From f720eb3e53eeee63550d3b7a170966e4c0a18c20 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Tue, 29 Jul 2014 21:46:12 +0100 Subject: [PATCH 10/44] Refactor config --- .jshintrc | 2 +- c3.js | 2691 ++++++++++++++++++++++++++++------------------------- 2 files changed, 1440 insertions(+), 1253 deletions(-) diff --git a/.jshintrc b/.jshintrc index ce3c17b..5bbc9db 100644 --- a/.jshintrc +++ b/.jshintrc @@ -6,7 +6,7 @@ "trailing": true, "white": true, "maxlen": 210, - "undef": false, + "undef": true, "unused": true, "indent": 4, diff --git a/c3.js b/c3.js index 33f204d..515697f 100644 --- a/c3.js +++ b/c3.js @@ -9,13 +9,13 @@ function Chart(config) { var $$ = this.internal = new ChartInternal(config, this); - loadConfig.call($$, config); - init.call($$); + $$.loadConfig(config); + $$.init(); } function ChartInternal(config, api) { var $$ = this; - $$.d3 = window.d3 ? window.d3 : 'undefined' !== typeof require ? require("d3") : undefined; + $$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined; $$.api = api; $$.data = {}; $$.cache = {}; @@ -39,226 +39,381 @@ /** * c3.config.js */ - c3_chart_internal_fn.config = { - bindto: '#chart', - size_width: undefined, - size_height: undefined, - - padding_left: undefined, - padding_right: undefined, - padding_top: undefined, - padding_bottom: undefined, - - zoom_enabled: false, - zoom_extent: undefined, - zoom_privileged: false, - zoom_onzoom: function () {}, - - interaction_enabled: true, - - onmouseover: function () {}, - onmouseout: function () {}, - onresize: function () {}, - onresized: function () {}, - - transition_duration: 350, - - data_x: undefined, - data_xs: {}, - data_x_format: '%Y-%m-%d', - data_x_localtime: true, - data_id_converter: function (id) { return id; }, - data_names: {}, - data_classes: {}, - data_groups: [], - data_axes: {}, - data_type: undefined, - data_types: {}, - data_labels: {}, - data_order: 'desc', - data_regions: {}, - data_color: undefined, - data_colors: {}, - data_hide: false, - data_filter: undefined, - data_selection_enabled: false, - data_selection_grouped: false, - data_selection_isselectable: function () { return true; }, - data_selection_multiple: true, - data_onclick: function () {}, - data_onmouseover: function () {}, - data_onmouseout: function () {}, - data_onselected: function () {}, - data_onunselected: function () {}, - data_ondragstart: function () {}, - data_ondragend: function () {}, - data_url: undefined, - data_json: undefined, - data_rows: undefined, - data_columns: undefined, - data_mimeType: undefined, - data_keys: undefined, - - // configuration for no plot-able data supplied. - data_empty_label_text: "", - - // subchart - subchart_show: false, - subchart_size_height: 60, - subchart_onbrush: function () {}, - - // color - color_pattern: [], - color_threshold : {}, - - // legend - legend_show: true, - legend_position: 'bottom', - legend_inset_anchor: 'top-left', - legend_inset_x: 10, - legend_inset_y: 0, - legend_inset_step: undefined, - legend_item_onclick: undefined, - legend_item_onmouseover: undefined, - legend_item_onmouseout: undefined, - legend_equally: false, - - // axis - axis_rotated: false, - axis_x_show: true, - axis_x_type: 'indexed', - axis_x_localtime: true, - axis_x_categories: [], - axis_x_tick_centered: false, - axis_x_tick_format: undefined, - axis_x_tick_culling: {}, - axis_x_tick_culling_max: 10, - axis_x_tick_count: undefined, - axis_x_tick_fit: true, - axis_x_tick_values: null, - axis_x_tick_rotate: undefined, - axis_x_tick_outer: true, - axis_x_max: null, - axis_x_min: null, - axis_x_padding: {}, - axis_x_height: undefined, - axis_x_default: undefined, - axis_x_label: {}, - axis_y_show: true, - axis_y_max: undefined, - axis_y_min: undefined, - axis_y_center: undefined, - axis_y_label: {}, - axis_y_inner: false, - axis_y_tick_format: undefined, - axis_y_tick_outer: true, - axis_y_padding: undefined, - axis_y_ticks: 10, - axis_y2_show: false, - axis_y2_max: undefined, - axis_y2_min: undefined, - axis_y2_center: undefined, - axis_y2_label: {}, - axis_y2_inner: false, - axis_y2_tick_format: undefined, - axis_y2_tick_outer: true, - axis_y2_padding: undefined, - axis_y2_ticks: 10, + var __bindto = 'bindto', + __size_width = 'size_width', + __size_height = 'size_height', + __padding_left = 'padding_left', + __padding_right = 'padding_right', + __padding_top = 'padding_top', + __padding_bottom = 'padding_bottom', + __zoom_enabled = 'zoom_enabled', + __zoom_extent = 'zoom_extent', + __zoom_privileged = 'zoom_privileged', + __zoom_onzoom = 'zoom_onzoom', + __interaction_enabled = 'interaction_enabled', + __onmouseover = 'onmouseover', + __onmouseout = 'onmouseout', + __onresize = 'onresize', + __onresized = 'onresized', + __transition_duration = 'transition_duration', + __data_x = 'data_x', + __data_xs = 'data_xs', + __data_x_format = 'data_x_format', + __data_x_localtime = 'data_x_localtime', + __data_id_converter = 'data_id_converter', + __data_names = 'data_names', + __data_classes = 'data_classes', + __data_groups = 'data_groups', + __data_axes = 'data_axes', + __data_type = 'data_type', + __data_types = 'data_types', + __data_labels = 'data_labels', + __data_order = 'data_order', + __data_regions = 'data_regions', + __data_color = 'data_color', + __data_colors = 'data_colors', + __data_hide = 'data_hide', + __data_filter = 'data_filter', + __data_selection_enabled = 'data_selection_enabled', + __data_selection_grouped = 'data_selection_grouped', + __data_selection_isselectable = 'data_selection_isselectable', + __data_selection_multiple = 'data_selection_multiple', + __data_onclick = 'data_onclick', + __data_onmouseover = 'data_onmouseover', + __data_onmouseout = 'data_onmouseout', + __data_onselected = 'data_onselected', + __data_onunselected = 'data_onunselected', + __data_ondragstart = 'data_ondragstart', + __data_ondragend = 'data_ondragend', + __data_url = 'data_url', + __data_json = 'data_json', + __data_rows = 'data_rows', + __data_columns = 'data_columns', + __data_mimeType = 'data_mimeType', + __data_keys = 'data_keys', + __data_empty_label_text = 'data_empty_label_text', + __subchart_show = 'subchart_show', + __subchart_size_height = 'subchart_size_height', + __subchart_onbrush = 'subchart_onbrush', + __color_pattern = 'color_pattern', + __color_threshold = 'color_threshold', + __legend_show = 'legend_show', + __legend_position = 'legend_position', + __legend_inset_anchor = 'legend_inset_anchor', + __legend_inset_x = 'legend_inset_x', + __legend_inset_y = 'legend_inset_y', + __legend_inset_step = 'legend_inset_step', + __legend_item_onclick = 'legend_item_onclick', + __legend_item_onmouseover = 'legend_item_onmouseover', + __legend_item_onmouseout = 'legend_item_onmouseout', + __legend_equally = 'legend_equally', + __axis_rotated = 'axis_rotated', + __axis_x_show = 'axis_x_show', + __axis_x_type = 'axis_x_type', + __axis_x_localtime = 'axis_x_localtime', + __axis_x_categories = 'axis_x_categories', + __axis_x_tick_centered = 'axis_x_tick_centered', + __axis_x_tick_format = 'axis_x_tick_format', + __axis_x_tick_culling = 'axis_x_tick_culling', + __axis_x_tick_culling_max = 'axis_x_tick_culling_max', + __axis_x_tick_count = 'axis_x_tick_count', + __axis_x_tick_fit = 'axis_x_tick_fit', + __axis_x_tick_values = 'axis_x_tick_values', + __axis_x_tick_rotate = 'axis_x_tick_rotate', + __axis_x_tick_outer = 'axis_x_tick_outer', + __axis_x_max = 'axis_x_max', + __axis_x_min = 'axis_x_min', + __axis_x_padding = 'axis_x_padding', + __axis_x_height = 'axis_x_height', + __axis_x_default = 'axis_x_default', + __axis_x_label = 'axis_x_label', + __axis_y_show = 'axis_y_show', + __axis_y_max = 'axis_y_max', + __axis_y_min = 'axis_y_min', + __axis_y_center = 'axis_y_center', + __axis_y_label = 'axis_y_label', + __axis_y_inner = 'axis_y_inner', + __axis_y_tick_format = 'axis_y_tick_format', + __axis_y_tick_outer = 'axis_y_tick_outer', + __axis_y_padding = 'axis_y_padding', + __axis_y_ticks = 'axis_y_ticks', + __axis_y2_show = 'axis_y2_show', + __axis_y2_max = 'axis_y2_max', + __axis_y2_min = 'axis_y2_min', + __axis_y2_center = 'axis_y2_center', + __axis_y2_label = 'axis_y2_label', + __axis_y2_inner = 'axis_y2_inner', + __axis_y2_tick_format = 'axis_y2_tick_format', + __axis_y2_tick_outer = 'axis_y2_tick_outer', + __axis_y2_padding = 'axis_y2_padding', + __axis_y2_ticks = 'axis_y2_ticks', + __grid_x_show = 'grid_x_show', + __grid_x_type = 'grid_x_type', + __grid_x_lines = 'grid_x_lines', + __grid_y_show = 'grid_y_show', + __grid_y_lines = 'grid_y_lines', + __grid_y_ticks = 'grid_y_ticks', + __grid_focus_show = 'grid_focus_show', + __point_show = 'point_show', + __point_r = 'point_r', + __point_focus_expand_enabled = 'point_focus_expand_enabled', + __point_focus_expand_r = 'point_focus_expand_r', + __point_select_r = 'point_select_r', + __line_connect_null = 'line_connect_null', + __bar_width = 'bar_width', + __bar_width_ratio = 'bar_width_ratio', + __bar_width_max = 'bar_width_max', + __bar_zerobased = 'bar_zerobased', + __area_zerobased = 'area_zerobased', + __pie_label_show = 'pie_label_show', + __pie_label_format = 'pie_label_format', + __pie_label_threshold = 'pie_label_threshold', + __pie_sort = 'pie_sort', + __pie_expand = 'pie_expand', + __gauge_label_show = 'gauge_label_show', + __gauge_label_format = 'gauge_label_format', + __gauge_expand = 'gauge_expand', + __gauge_min = 'gauge_min', + __gauge_max = 'gauge_max', + __gauge_units = 'gauge_units', + __gauge_width = 'gauge_width', + __donut_label_show = 'donut_label_show', + __donut_label_format = 'donut_label_format', + __donut_label_threshold = 'donut_label_threshold', + __donut_width = 'donut_width', + __donut_sort = 'donut_sort', + __donut_expand = 'donut_expand', + __donut_title = 'donut_title', + __regions = 'regions', + __tooltip_show = 'tooltip_show', + __tooltip_grouped = 'tooltip_grouped', + __tooltip_format_title = 'tooltip_format_title', + __tooltip_format_name = 'tooltip_format_name', + __tooltip_format_value = 'tooltip_format_value', + __tooltip_contents = 'tooltip_contents', + __tooltip_init_show = 'tooltip_init_show', + __tooltip_init_x = 'tooltip_init_x', + __tooltip_init_position = 'tooltip_init_position'; + + var config = c3_chart_internal_fn.config = {}; + config[__bindto] = '#chart'; + config[__size_width] = undefined; + config[__size_height] = undefined; + + config[__padding_left] = undefined; + config[__padding_right] = undefined; + config[__padding_top] = undefined; + config[__padding_bottom] = undefined; + + config[__zoom_enabled] = false; + config[__zoom_extent] = undefined; + config[__zoom_privileged] = false; + config[__zoom_onzoom] = function () {}; + + config[__interaction_enabled] = true; + + config[__onmouseover] = function () {}; + config[__onmouseout] = function () {}; + config[__onresize] = function () {}; + config[__onresized] = function () {}; + + config[__transition_duration] = 350; + + config[__data_x] = undefined; + config[__data_xs] = {}; + config[__data_x_format] = '%Y-%m-%d'; + config[__data_x_localtime] = true; + config[__data_id_converter] = function (id) { return id; }; + config[__data_names] = {}; + config[__data_classes] = {}; + config[__data_groups] = []; + config[__data_axes] = {}; + config[__data_type] = undefined; + config[__data_types] = {}; + config[__data_labels] = {}; + config[__data_order] = 'desc'; + config[__data_regions] = {}; + config[__data_color] = undefined; + config[__data_colors] = {}; + config[__data_hide] = false; + config[__data_filter] = undefined; + config[__data_selection_enabled] = false; + config[__data_selection_grouped] = false; + config[__data_selection_isselectable] = function () { return true; }; + config[__data_selection_multiple] = true; + config[__data_onclick] = function () {}; + config[__data_onmouseover] = function () {}; + config[__data_onmouseout] = function () {}; + config[__data_onselected] = function () {}; + config[__data_onunselected] = function () {}; + config[__data_ondragstart] = function () {}; + config[__data_ondragend] = function () {}; + config[__data_url] = undefined; + config[__data_json] = undefined; + config[__data_rows] = undefined; + config[__data_columns] = undefined; + config[__data_mimeType] = undefined; + config[__data_keys] = undefined; + + // configuration for no plot-able data supplied. + config[__data_empty_label_text] = ""; + + // subchart + config[__subchart_show] = false; + config[__subchart_size_height] = 60; + config[__subchart_onbrush] = function () {}; + + // color + config[__color_pattern] = []; + config[__color_threshold] = {}; + + // legend + config[__legend_show] = true; + config[__legend_position] = 'bottom'; + config[__legend_inset_anchor] = 'top-left'; + config[__legend_inset_x] = 10; + config[__legend_inset_y] = 0; + config[__legend_inset_step] = undefined; + config[__legend_item_onclick] = undefined; + config[__legend_item_onmouseover] = undefined; + config[__legend_item_onmouseout] = undefined; + config[__legend_equally] = false; + + // axis + config[__axis_rotated] = false; + config[__axis_x_show] = true; + config[__axis_x_type] = 'indexed'; + config[__axis_x_localtime] = true; + config[__axis_x_categories] = []; + config[__axis_x_tick_centered] = false; + config[__axis_x_tick_format] = undefined; + config[__axis_x_tick_culling] = {}; + config[__axis_x_tick_culling_max] = 10; + config[__axis_x_tick_count] = undefined; + config[__axis_x_tick_fit] = true; + config[__axis_x_tick_values] = null; + config[__axis_x_tick_rotate] = undefined; + config[__axis_x_tick_outer] = true; + config[__axis_x_max] = null; + config[__axis_x_min] = null; + config[__axis_x_padding] = {}; + config[__axis_x_height] = undefined; + config[__axis_x_default] = undefined; + config[__axis_x_label] = {}; + config[__axis_y_show] = true; + config[__axis_y_max] = undefined; + config[__axis_y_min] = undefined; + config[__axis_y_center] = undefined; + config[__axis_y_label] = {}; + config[__axis_y_inner] = false; + config[__axis_y_tick_format] = undefined; + config[__axis_y_tick_outer] = true; + config[__axis_y_padding] = undefined; + config[__axis_y_ticks] = 10; + config[__axis_y2_show] = false; + config[__axis_y2_max] = undefined; + config[__axis_y2_min] = undefined; + config[__axis_y2_center] = undefined; + config[__axis_y2_label] = {}; + config[__axis_y2_inner] = false; + config[__axis_y2_tick_format] = undefined; + config[__axis_y2_tick_outer] = true; + config[__axis_y2_padding] = undefined; + config[__axis_y2_ticks] = 10; + + // grid + config[__grid_x_show] = false; + config[__grid_x_type] = 'tick'; + config[__grid_x_lines] = []; + config[__grid_y_show] = false; + // not used + // grid_y_type: {}, 'tick'), + config[__grid_y_lines] = []; + config[__grid_y_ticks] = 10; + config[__grid_focus_show] = true; + + // point - point of each data + config[__point_show] = true; + config[__point_r] = 2.5; + config[__point_focus_expand_enabled] = true; + config[__point_focus_expand_r] = undefined; + config[__point_select_r] = undefined; + + config[__line_connect_null] = false; + + // bar + config[__bar_width] = undefined; + config[__bar_width_ratio] = 0.6; + config[__bar_width_max] = undefined; + config[__bar_zerobased] = true; + + // area + config[__area_zerobased] = true; + + // pie + config[__pie_label_show] = true; + config[__pie_label_format] = undefined; + config[__pie_label_threshold] = 0.05; + config[__pie_sort] = true; + config[__pie_expand] = true; + + // gauge + config[__gauge_label_show] = true; + config[__gauge_label_format] = undefined; + config[__gauge_expand] = true; + config[__gauge_min] = 0; + config[__gauge_max] = 100; + config[__gauge_units] = undefined; + config[__gauge_width] = undefined; + + // donut + config[__donut_label_show] = true; + config[__donut_label_format] = undefined; + config[__donut_label_threshold] = 0.05; + config[__donut_width] = undefined; + config[__donut_sort] = true; + config[__donut_expand] = true; + config[__donut_title] = ""; + + // region - region to change style + config[__regions] = []; + + // tooltip - show when mouseover on each data + config[__tooltip_show] = true; + config[__tooltip_grouped] = true; + config[__tooltip_format_title] = undefined; + config[__tooltip_format_name] = undefined; + config[__tooltip_format_value] = undefined; + config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { + var $$ = this, config = $$.config, + titleFormat = config[__tooltip_format_title] || defaultTitleFormat, + nameFormat = config[__tooltip_format_name] || function (name) { return name; }, + valueFormat = config[__tooltip_format_value] || defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } - // grid - grid_x_show: false, - grid_x_type: 'tick', - grid_x_lines: [], - grid_y_show: false, - // not used - // grid_y_type: {}, 'tick'), - grid_y_lines: [], - grid_y_ticks: 10, - grid_focus_show: true, - - // point - point of each data - point_show: true, - point_r: 2.5, - point_focus_expand_enabled: true, - point_focus_expand_r: undefined, - point_select_r: undefined, - - line_connect_null: false, - - // bar - bar_width: undefined, - bar_width_ratio: 0.6, - bar_width_max: undefined, - bar_zerobased: true, - - // area - area_zerobased: true, - - // pie - pie_label_show: true, - pie_label_format: undefined, - pie_label_threshold: 0.05, - pie_sort: true, - pie_expand: true, - - // gauge - gauge_label_show: true, - gauge_label_format: undefined, - gauge_expand: true, - gauge_min: 0, - gauge_max: 100, - gauge_units: undefined, - gauge_width: undefined, - - // donut - donut_label_show: true, - donut_label_format: undefined, - donut_label_threshold: 0.05, - donut_width: undefined, - donut_sort: true, - donut_expand: true, - donut_title: "", - - // region - region to change style - regions: [], - - // tooltip - show when mouseover on each data - tooltip_show: true, - tooltip_grouped: true, - tooltip_format_title: undefined, - tooltip_format_name: undefined, - tooltip_format_value: undefined, - tooltip_contents: function (d, defaultTitleFormat, defaultValueFormat, color) { - var $$ = this, - titleFormat = $$.config.tooltip_format_title || defaultTitleFormat, - nameFormat = $$.config.tooltip_format_name || function (name) { return name; }, - valueFormat = $$.config.tooltip_format_value || defaultValueFormat, - text, i, title, value, name, bgcolor; - for (i = 0; i < d.length; i++) { - if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } - - if (! text) { - title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); - } + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "
" + title + "
" + (title || title === 0 ? "" : ""); + } - name = nameFormat(d[i].name); - value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - text += ""; - text += ""; - text += ""; - text += ""; - } - return text + "
" + title + "
" + name + "" + value + "
"; - }, - tooltip_init_show: false, - tooltip_init_x: 0, - tooltip_init_position: {top: '0px', left: '50px'} + text += ""; + text += "" + name + ""; + text += "" + value + ""; + text += ""; + } + return text + ""; }; + config[__tooltip_init_show] = false; + config[__tooltip_init_x] = 0; + config[__tooltip_init_position] = {top: '0px', left: '50px'}; - var loadConfig = c3_chart_internal_fn.loadConfig = function (config) { + c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -279,7 +434,7 @@ keys = key.split('_'); read = find(); // console.log("CONFIG : ", key, read); - if (typeof read !== 'undefined') { + if (isDefined(read)) { this_config[key] = read; } }); @@ -287,20 +442,19 @@ - // should be define in c3.zoom.js c3_chart_internal_fn.initZoom = function () { - var $$ = this, d3 = $$.d3; + var $$ = this, d3 = $$.d3, config = $$.config; $$.zoom = d3.behavior.zoom() .on("zoomstart", function () { $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; }) .on("zoom", $$.redrawForZoom); $$.zoom.scale = function (scale) { - return $$.config.axis_rotated ? this.y(scale) : this.x(scale); + return config[__axis_rotated] ? this.y(scale) : this.x(scale); }; $$.zoom.orgScaleExtent = function () { - var extent = $$.config.zoom_extent ? $$.config.zoom_extent : [1, 10]; + var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { @@ -312,27 +466,27 @@ }; - var init = c3_chart_internal_fn.init = function () { - var $$ = this, c = $$.config; - if (c.data_url) { - convertUrlToData.call($$, c.data_url, c.data_mimeType, c.data_keys, initWithData); + c3_chart_internal_fn.init = function () { + var $$ = this, config = $$.config; + if (config[__data_url]) { + $$.convertUrlToData(config[__data_url], config[__data_mimeType], config[__data_keys], $$.initWithData); } - else if (c.data_json) { - initWithData.call($$, convertJsonToData.call($$, c.data_json, c.data_keys)); + else if (config[__data_json]) { + $$.initWithData($$.convertJsonToData(config[__data_json], config[__data_keys])); } - else if (c.data_rows) { - initWithData.call($$, convertRowsToData.call($$, c.data_rows)); + else if (config[__data_rows]) { + $$.initWithData($$.convertRowsToData(config[__data_rows])); } - else if (c.data_columns) { - initWithData.call($$, convertColumnsToData.call($$, c.data_columns)); + else if (config[__data_columns]) { + $$.initWithData($$.convertColumnsToData(config[__data_columns])); } else { throw Error('url or json or rows or columns is required.'); } }; - var initWithData = c3_chart_internal_fn.initWithData = function (data) { - var $$ = this, d3 = $$.d3, c = $$.config; + c3_chart_internal_fn.initWithData = function (data) { + var $$ = this, d3 = $$.d3, config = $$.config; var main, legend, eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist @@ -343,9 +497,9 @@ $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - $$.isTimeSeries = (c.axis_x_type === 'timeseries'); - $$.isCategorized = (c.axis_x_type.indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && (c.data_x || notEmpty(c.data_xs)); }; + $$.isTimeSeries = (config[__axis_x_type] === 'timeseries'); + $$.isCategorized = (config[__axis_x_type].indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && (config[__data_x] || notEmpty(config[__data_xs])); }; $$.dragStart = null; $$.dragging = false; @@ -354,11 +508,11 @@ $$.transiting = false; $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor(c.data_colors, notEmpty(c.color_pattern) ? c.color_pattern : $$.defaultColorPattern, c.data_color); - $$.levelColor = notEmpty(c.color_threshold) ? $$.generateLevelColor(c.color_pattern, c.color_threshold) : null; + $$.color = $$.generateColor(config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$.defaultColorPattern, config[__data_color]); + $$.levelColor = notEmpty(config[__color_threshold]) ? $$.generateLevelColor(config[__color_pattern], config[__color_threshold]) : null; - $$.dataTimeFormat = c.data_x_localtime ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = c.axis_x_localtime ? d3.time.format : d3.time.format.utc; + $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.time.format.utc; $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ [".%L", function (d) { return d.getMilliseconds(); }], [":%S", function (d) { return d.getSeconds(); }], @@ -373,26 +527,26 @@ $$.hiddenTargetIds = []; $$.hiddenLegendIds = []; - $$.xOrient = c.axis_rotated ? "left" : "bottom"; - $$.yOrient = c.axis_rotated ? (c.axis_y_inner ? "top" : "bottom") : (c.axis_y_inner ? "right" : "left"); - $$.y2Orient = c.axis_rotated ? (c.axis_y2_inner ? "bottom" : "top") : (c.axis_y2_inner ? "left" : "right"); - $$.subXOrient = c.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"); + $$.y2Orient = config[__axis_rotated] ? (config[__axis_y2_inner] ? "bottom" : "top") : (config[__axis_y2_inner] ? "left" : "right"); + $$.subXOrient = config[__axis_rotated] ? "left" : "bottom"; $$.translate = { main : function () { return "translate(" + asHalfPixel($$.margin.left) + "," + asHalfPixel($$.margin.top) + ")"; }, context : function () { return "translate(" + asHalfPixel($$.margin2.left) + "," + asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, - x : function () { return "translate(0," + (c.axis_rotated ? 0 : $$.height) + ")"; }, - y : function () { return "translate(0," + (c.axis_rotated ? $$.height : 0) + ")"; }, - y2 : function () { return "translate(" + (c.axis_rotated ? 0 : $$.width) + "," + (c.axis_rotated ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + (c.axis_rotated ? 0 : $$.height2) + ")"; }, + x : function () { return "translate(0," + (config[__axis_rotated] ? 0 : $$.height) + ")"; }, + y : function () { return "translate(0," + (config[__axis_rotated] ? $$.height : 0) + ")"; }, + y2 : function () { return "translate(" + (config[__axis_rotated] ? 0 : $$.width) + "," + (config[__axis_rotated] ? 1 : 0) + ")"; }, + subx : function () { return "translate(0," + (config[__axis_rotated] ? 0 : $$.height2) + ")"; }, arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } }; - $$.isLegendRight = c.legend_position === 'right'; - $$.isLegendInset = c.legend_position === 'inset'; - $$.isLegendTop = c.legend_inset_anchor === 'top-left' || c.legend_inset_anchor === 'top-right'; - $$.isLegendLeft = c.legend_inset_anchor === 'top-left' || c.legend_inset_anchor === 'bottom-left'; + $$.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; @@ -401,20 +555,22 @@ $$.currentMaxTickWidth = 0; $$.rotated_padding_left = 30; - $$.rotated_padding_right = c.axis_rotated && !c.axis_x_show ? 0 : 30; + $$.rotated_padding_right = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; $$.rotated_padding_top = 5; $$.withoutFadeIn = {}; - if (isFunctionType(initPie)) { initPie.call($$); } - if (isFunctionType(typeof initBrush)) { - initBrush.call($$); + if (isFunction($$.initPie)) { + $$.initPie(); + } + if (isFunction($$.initBrush)) { + $$.initBrush(); } else { $$.axes.subx = d3.selectAll([]); } if ($$.initZoom) { $$.initZoom(); } - $$.selectChart = d3.select(c.bindto); + $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); $$.observeInserted($$.selectChart); @@ -424,25 +580,25 @@ // Init data as targets $$.data.xs = {}; - $$.data.targets = convertDataToTargets.call($$, data); + $$.data.targets = $$.convertDataToTargets(data); - if (c.data_filter) { - $$.data.targets = $$.data.targets.filter(c.data_filter); + if (config[__data_filter]) { + $$.data.targets = $$.data.targets.filter(config[__data_filter]); } // Set targets to hide if needed - if (c.data_hide) { - $$.addHiddenTargetIds(c.data_hide === true ? $$.mapToIds($$.data.targets) : c.data_hide); + if (config[__data_hide]) { + $$.addHiddenTargetIds(config[__data_hide] === true ? $$.mapToIds($$.data.targets) : config[__data_hide]); } // when gauge, hide legend // TODO: fix - if (hasGaugeType.call($$, $$.data.targets)) { - c.legend_show = false; + if ($$.hasGaugeType($$.data.targets)) { + config[__legend_show] = false; } // Init sizes and scales - updateSizes.call($$); - updateScales.call($$); + $$.updateSizes(); + $$.updateScales(); // Set domains for each scale $$.x.domain(d3.extent($$.getXDomain($$.data.targets))); @@ -457,15 +613,15 @@ // Set initialized scales to brush and zoom if ($$.brush) { $$.brush.scale($$.subX); } - if (c.zoom_enabled) { $$.zoom.scale($$.x); } + if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } /*-- Basic Elements --*/ // Define svgs $$.svg = $$.selectChart.append("svg") .style("overflow", "hidden") - .on('mouseenter', function () { return c.onmouseover.call(c3); }) - .on('mouseleave', function () { return c.onmouseout.call(c3); }); + .on('mouseenter', function () { return config[__onmouseover].call($$); }) + .on('mouseleave', function () { return config[__onmouseout].call($$); }); // Define defs $$.defs = $$.svg.append("defs"); @@ -478,9 +634,11 @@ main = $$.main = $$.svg.append("g").attr("transform", $$.translate.main); legend = $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); - if (isFunctionType(typeof initSubchart)) { initSubchart.call($$); } + if (isFunction($$.initSubchart)) { + $$.initSubchart(); + } - if (!c.legend_show) { + if (!config[__legend_show]) { $$.legend.style('visibility', 'hidden'); $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } @@ -515,15 +673,15 @@ $$.grid = main.append('g') .attr("clip-path", $$.clipPath) .attr('class', CLASS.grid); - if (c.grid_x_show) { + if (config[__grid_x_show]) { $$.grid.append("g").attr("class", CLASS.xgrids); } - if (c.grid_y_show) { + if (config[__grid_y_show]) { $$.grid.append('g').attr('class', CLASS.ygrids); } $$.grid.append('g').attr("class", CLASS.xgridLines); $$.grid.append('g').attr('class', CLASS.ygridLines); - if (c.grid_focus_show) { + if (config[__grid_focus_show]) { $$.grid.append('g') .attr("class", CLASS.xgridFocus) .append('line') @@ -549,14 +707,18 @@ .attr("class", CLASS.chartLines); // Define g for arc chart area - if (isFunctionType(initArc)) { initArc.call($$); } - if (isFunctionType(initGauge)) { initGauge.call($$); } + if (isFunction($$.initArc)) { + $$.initArc(); + } + if (isFunction($$.initGauge)) { + $$.initGauge(); + } main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartTexts); // if zoom privileged, insert rect to forefront - main.insert('rect', c.zoom_privileged ? null : 'g.' + CLASS.regions) + main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS.regions) .attr('class', CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height) @@ -564,8 +726,8 @@ .on("dblclick.zoom", null); // Set default extent if defined - if (c.axis_x_default) { - $$.brush.extent(typeof c.axis_x_default !== 'function' ? c.axis_x_default : c.axis_x_default($$.getXDomain())); + if (config[__axis_x_default]) { + $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); } // Add Axis @@ -573,34 +735,34 @@ .attr("class", CLASS.axis + ' ' + CLASS.axisX) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) - .style("visibility", c.axis_x_show ? 'visible' : 'hidden'); + .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); $$.axes.x.append("text") .attr("class", CLASS.axisXLabel) - .attr("transform", c.axis_rotated ? "rotate(-90)" : "") - .style("text-anchor", generateCall(textAnchorForXAxisLabel, $$)); + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); $$.axes.y = main.append("g") .attr("class", CLASS.axis + ' ' + CLASS.axisY) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) - .style("visibility", c.axis_y_show ? 'visible' : 'hidden'); + .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); $$.axes.y.append("text") .attr("class", CLASS.axisYLabel) - .attr("transform", c.axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", generateCall(textAnchorForYAxisLabel, $$)); + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); $$.axes.y2 = main.append("g") .attr("class", CLASS.axis + ' ' + CLASS.axisY2) // clip-path? .attr("transform", $$.translate.y2) - .style("visibility", c.axis_y2_show ? 'visible' : 'hidden'); + .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); $$.axes.y2.append("text") .attr("class", CLASS.axisY2Label) - .attr("transform", c.axis_rotated ? "" : "rotate(-90)") - .style("text-anchor", generateCall(textAnchorForY2AxisLabel, $$)); + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); // Set targets - updateTargets.call($$, $$.data.targets); + $$.updateTargets($$.data.targets); // Draw with targets if (binding) { @@ -614,19 +776,19 @@ } // Show tooltip if needed - if (c.tooltip_init_show) { - if ($$.isTimeSeries && typeof c.tooltip_init_x === 'string') { - c.tooltip_init_x = $$.parseDate(c.tooltip_init_x); + if (config[__tooltip_init_show]) { + if ($$.isTimeSeries && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - c.tooltip_init_x) === 0) { break; } + if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } } - c.tooltip_init_x = i; + config[__tooltip_init_x] = i; } - $$.tooltip.html(c.tooltip_contents.call($$, $$.data.targets.map(function (d) { - return $$.addName(d.values[c.tooltip_init_x]); - }), getXAxisTickFormat.call($$), $$.getYFormat(hasArcType.call($$, $$.data.targets)), $$.color)); - $$.tooltip.style("top", c.tooltip_init_position.top) - .style("left", c.tooltip_init_position.left) + $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); + $$.tooltip.style("top", config[__tooltip_init_position].top) + .style("left", config[__tooltip_init_position].left) .style("display", "block"); } @@ -636,13 +798,13 @@ } if (window.onresize.add) { window.onresize.add(function () { - c.onresize.call(c3); + config[__onresize].call($$); }); window.onresize.add(function () { $$.api.flush(); }); window.onresize.add(function () { - c.onresized.call(c3); + config[__onresized].call($$); }); } @@ -671,19 +833,19 @@ }; - var updateSizes = c3_chart_internal_fn.updateSizes = function () { - var $$ = this, c = $$.config; + c3_chart_internal_fn.updateSizes = function () { + var $$ = this, config = $$.config; var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = hasArcType.call($$, $$.data.targets), - xAxisHeight = c.axis_rotated || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), - subchartHeight = c.subchart_show && !hasArc ? (c.subchart_size_height + xAxisHeight) : 0; + hasArc = $$.hasArcType($$.data.targets), + 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, context - if (c.axis_rotated) { + if (config[__axis_rotated]) { $$.margin = { top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), right: hasArc ? 0 : $$.getCurrentPaddingRight(), @@ -712,8 +874,8 @@ } // for legend var insetLegendPosition = { - top: $$.isLegendTop ? $$.getCurrentPaddingTop() + c.legend_inset_y + 5.5 : $$.currentHeight - legendHeight - $$.getCurrentPaddingBottom() - c.legend_inset_y, - left: $$.isLegendLeft ? $$.getCurrentPaddingLeft() + c.legend_inset_x + 0.5 : $$.currentWidth - legendWidth - $$.getCurrentPaddingRight() - c.legend_inset_x + 0.5 + 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 }; $$.margin3 = { top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, @@ -727,100 +889,105 @@ if ($$.width < 0) { $$.width = 0; } if ($$.height < 0) { $$.height = 0; } - $$.width2 = c.axis_rotated ? $$.margin.left - $$.rotated_padding_left - $$.rotated_padding_right : $$.width; - $$.height2 = c.axis_rotated ? $$.height : $$.currentHeight - $$.margin2.top - $$.margin2.bottom; + $$.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 (isFunctionType(updateRadius)) { updateRadius.call($$); } + if (isFunction($$.updateRadius)) { + $$.updateRadius(); + } if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } }; - var updateTargets = c3_chart_internal_fn.updateTargets = function (targets) { + c3_chart_internal_fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; - var $$ = this, main = $$.main; + var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ //-- Text --// mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) .data(targets) - .attr('class', generateCall(classChartText, $$)); + .attr('class', generateCall($$.classChartText, $$)); mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', generateCall(classChartText, $$)) + .attr('class', generateCall($$.classChartText, $$)) .style('opacity', 0) .style("pointer-events", "none"); mainTextEnter.append('g') - .attr('class', generateCall(classTexts, $$)); + .attr('class', generateCall($$.classTexts, $$)); //-- Bar --// mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr('class', generateCall(classChartBar, $$)); + .attr('class', generateCall($$.classChartBar, $$)); mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', generateCall(classChartBar, $$)) + .attr('class', generateCall($$.classChartBar, $$)) .style('opacity', 0) .style("pointer-events", "none"); // Bars for each data mainBarEnter.append('g') - .attr("class", generateCall(classBars, $$)) - .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); + .attr("class", generateCall($$.classBars, $$)) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); //-- Line --// mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr('class', generateCall(classChartLine, $$)); + .attr('class', generateCall($$.classChartLine, $$)); mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', generateCall(classChartLine, $$)) + .attr('class', generateCall($$.classChartLine, $$)) .style('opacity', 0) .style("pointer-events", "none"); // Lines for each data mainLineEnter.append('g') - .attr("class", generateCall(classLines, $$)); + .attr("class", generateCall($$.classLines, $$)); // Areas mainLineEnter.append('g') - .attr('class', generateCall(classAreas, $$)); + .attr('class', generateCall($$.classAreas, $$)); // Circles for each data point on lines mainLineEnter.append('g') - .attr("class", function (d) { return generateClass.call($$, CLASS.selectedCircles, d.id); }); + .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); mainLineEnter.append('g') - .attr("class", generateCall(classCircles, $$)) - .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }); + .attr("class", generateCall($$.classCircles, $$)) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { d.value = t.values[d.index].value; }); }); // MEMO: can not keep same color... //mainLineUpdate.exit().remove(); - if (isFunctionType(updateTargetsForArc)) { updateTargetsForArc.call($$, targets); } - - if (isFunctionType(typeof updateTargetsForSubchart)) { updateTargetsForSubchart.call($$, targets); } + if (isFunction($$.updateTargetsForArc)) { + $$.updateTargetsForArc(targets); + } + if (isFunction($$.updateTargetsForSubchart)) { + $$.updateTargetsForSubchart(targets); + } /*-- Show --*/ // Fade-in each chart $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) - .transition().duration($$.config.transition_duration) + .transition().duration(config[__transition_duration]) .style("opacity", 1); }; c3_chart_internal_fn.redraw = function (options, transitions) { - var $$ = this, main = $$.main, d3 = $$.d3; + var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices(isAreaType), barIndices = $$.getShapeIndices(isBarType), lineIndices = $$.getShapeIndices(isLineType), maxDataCountTarget, tickOffset; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = hasArcType.call($$, $$.data.targets); + var hideAxis = $$.hasArcType($$.data.targets); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; @@ -838,14 +1005,14 @@ withTransitionForExit = getOption(options, "withTransitionForExit", withTransition); withTransitionForAxis = getOption(options, "withTransitionForAxis", withTransition); - duration = withTransition ? $$.config.transition_duration : 0; + duration = withTransition ? config[__transition_duration] : 0; durationForExit = withTransitionForExit ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0; transitions = transitions || $$.generateAxisTransitions(durationForAxis); // update legend and transform each g - if (withLegend && $$.config.legend_show) { + if (withLegend && config[__legend_show]) { $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); } @@ -857,8 +1024,8 @@ if (targetsToShow.length) { $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); // update axis tick values according to options - if (!$$.config.axis_x_tick_values && ($$.config.axis_x_tick_fit || $$.config.axis_x_tick_count)) { - tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), $$.config.axis_x_tick_count); + if (!config[__axis_x_tick_values] && (config[__axis_x_tick_fit] || config[__axis_x_tick_count])) { + tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config[__axis_x_tick_count]); $$.xAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues); } @@ -885,9 +1052,9 @@ // show/hide if manual culling needed if (withUpdateXDomain && targetsToShow.length) { - if ($$.config.axis_x_tick_culling && tickValues) { + if (config[__axis_x_tick_culling] && tickValues) { for (i = 1; i < tickValues.length; i++) { - if (tickValues.length / i < $$.config.axis_x_tick_culling_max) { + if (tickValues.length / i < config[__axis_x_tick_culling_max]) { intervalForCulling = i; break; } @@ -904,8 +1071,8 @@ } // rotate tick text if needed - if (!$$.config.axis_rotated && $$.config.axis_x_tick_rotate) { - $$.rotateTickText($$.axes.x, transitions.axisX, $$.config.axis_x_tick_rotate); + if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { + $$.rotateTickText($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); } // setup drawer - MEMO: these must be called after axis updated @@ -929,14 +1096,14 @@ main.select("text." + CLASS.text + '.' + CLASS.empty) .attr("x", $$.width / 2) .attr("y", $$.height / 2) - .text($$.config.data_empty_label_text) + .text(config[__data_empty_label_text]) .transition() .style('opacity', targetsToShow.length ? 0 : 1); // grid main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); - if ($$.config.grid_x_show) { - xgridAttr = $$.config.axis_rotated ? { + if (config[__grid_x_show]) { + xgridAttr = config[__axis_rotated] ? { 'x1': 0, 'x2': $$.width, 'y1': function (d) { return $$.x(d) - tickOffset; }, @@ -949,21 +1116,21 @@ }; // this is used to flow flushXGrid = function (withoutUpdate) { - xgridData = $$.generateGridData($$.config.grid_x_type, $$.x); + xgridData = $$.generateGridData(config[__grid_x_type], $$.x); tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) .data(xgridData); xgrid.enter().append('line').attr("class", CLASS.xgrid); if (!withoutUpdate) { xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr($$.config.axis_rotated ? 'y1' : 'x1') === ($$.config.axis_rotated ? $$.height : 0) ? 0 : 1; }); + .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); } xgrid.exit().remove(); }; flushXGrid(); } xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) - .data($$.config.grid_x_lines); + .data(config[__grid_x_lines]); // enter xgridLine = xgridLines.enter().append('g') .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); @@ -971,8 +1138,8 @@ .style("opacity", 0); xgridLine.append('text') .attr("text-anchor", "end") - .attr("transform", $$.config.axis_rotated ? "" : "rotate(-90)") - .attr('dx', $$.config.axis_rotated ? 0 : -$$.margin.top) + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) .style("opacity", 0); // udpate @@ -982,21 +1149,21 @@ .style("opacity", 0) .remove(); // Y-Grid - if (withY && $$.config.grid_y_show) { + if (withY && config[__grid_y_show]) { ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) - .data($$.y.ticks($$.config.grid_y_ticks)); + .data($$.y.ticks(config[__grid_y_ticks])); ygrid.enter().append('line') .attr('class', CLASS.ygrid); - ygrid.attr("x1", $$.config.axis_rotated ? $$.y : 0) - .attr("x2", $$.config.axis_rotated ? $$.y : $$.width) - .attr("y1", $$.config.axis_rotated ? 0 : $$.y) - .attr("y2", $$.config.axis_rotated ? $$.height : $$.y); + ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) + .attr("x2", config[__axis_rotated] ? $$.y : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : $$.y) + .attr("y2", config[__axis_rotated] ? $$.height : $$.y); ygrid.exit().remove(); $$.smoothLines(ygrid, 'grid'); } if (withY) { ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) - .data($$.config.grid_y_lines); + .data(config[__grid_y_lines]); // enter ygridLine = ygridLines.enter().append('g') .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); @@ -1004,22 +1171,22 @@ .style("opacity", 0); ygridLine.append('text') .attr("text-anchor", "end") - .attr("transform", $$.config.axis_rotated ? "rotate(-90)" : "") - .attr('dx', $$.config.axis_rotated ? 0 : -$$.margin.top) + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) .style("opacity", 0); // update - var yv_ = generateCall(yv, $$); + var yv_ = generateCall($$.yv, $$); ygridLines.select('line') .transition().duration(duration) - .attr("x1", $$.config.axis_rotated ? yv_ : 0) - .attr("x2", $$.config.axis_rotated ? yv_ : $$.width) - .attr("y1", $$.config.axis_rotated ? 0 : yv_) - .attr("y2", $$.config.axis_rotated ? $$.height : yv_) + .attr("x1", config[__axis_rotated] ? yv_ : 0) + .attr("x2", config[__axis_rotated] ? yv_ : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv_) + .attr("y2", config[__axis_rotated] ? $$.height : yv_) .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) - .attr("x", $$.config.axis_rotated ? 0 : $$.width) + .attr("x", config[__axis_rotated] ? 0 : $$.width) .attr("y", yv_) .text(function (d) { return d.text; }) .style("opacity", 1); @@ -1031,9 +1198,9 @@ // rect for regions mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) - .data($$.config.regions); + .data(config[__regions]); mainRegion.enter().append('g') - .attr('class', generateCall(classRegion, $$)) + .attr('class', generateCall($$.classRegion, $$)) .append('rect') .style("fill-opacity", 0); mainRegion.exit().transition().duration(duration) @@ -1042,34 +1209,34 @@ // bars mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(generateCall(barData, $$)); + .data(generateCall($$.barData, $$)); mainBar.enter().append('path') - .attr("class", generateCall(classBar, $$)) + .attr("class", generateCall($$.classBar, $$)) .style("stroke", function (d) { return $$.color(d.id); }) .style("fill", function (d) { return $$.color(d.id); }); mainBar - .style("opacity", generateCall(initialOpacity, $$)); + .style("opacity", generateCall($$.initialOpacity, $$)); mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); // lines, areas and cricles mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(generateCall(lineData, $$)); + .data(generateCall($$.lineData, $$)); mainLine.enter().append('path') - .attr('class', generateCall(classLine, $$)) + .attr('class', generateCall($$.classLine, $$)) .style("stroke", $$.color); mainLine - .style("opacity", generateCall(initialOpacity, $$)) + .style("opacity", generateCall($$.initialOpacity, $$)) .attr('transform', null); mainLine.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(generateCall(lineData, $$)); + .data(generateCall($$.lineData, $$)); mainArea.enter().append('path') - .attr("class", generateCall(classArea, $$)) + .attr("class", generateCall($$.classArea, $$)) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); mainArea @@ -1078,24 +1245,24 @@ .style('opacity', 0) .remove(); - if ($$.config.point_show) { + if (config[__point_show]) { mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) - .data(generateCall(lineOrScatterData, $$)); + .data(generateCall($$.lineOrScatterData, $$)); mainCircle.enter().append("circle") - .attr("class", generateCall(classCircle, $$)) - .attr("r", generateCall(pointR, $$)) + .attr("class", generateCall($$.classCircle, $$)) + .attr("r", generateCall($$.pointR, $$)) .style("fill", $$.color); mainCircle - .style("opacity", generateCall(initialOpacity, $$)); + .style("opacity", generateCall($$.initialOpacity, $$)); mainCircle.exit().remove(); } if ($$.hasDataLabel()) { mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) - .data(generateCall(barOrLineData, $$)); + .data(generateCall($$.barOrLineData, $$)); mainText.enter().append('text') - .attr("class", generateCall(classText, $$)) - .attr('text-anchor', function (d) { return $$.config.axis_rotated ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .attr("class", generateCall($$.classText, $$)) + .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) .style("fill-opacity", 0); @@ -1108,22 +1275,26 @@ } // arc - if (isFunctionType(redrawArc)) { redrawArc.call($$, duration, durationForExit, withTransform); } + if (isFunction($$.redrawArc)) { + $$.redrawArc(duration, durationForExit, withTransform); + } // subchart - if (isFunctionType(typeof redrawSubchart)) { redrawSubchart.call($$, withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } + if (isFunction($$.redrawSubchart)) { + $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); + } // circles for select main.selectAll('.' + CLASS.selectedCircles) - .filter(generateCall(isBarType, $$)) + .filter(generateCall($$.isBarType, $$)) .selectAll('circle') .remove(); - if ($$.config.interaction_enabled) { + if (config[__interaction_enabled]) { // rect for mouseover eventRect = main.select('.' + CLASS.eventRects) - .style('cursor', $$.config.zoom_enabled ? $$.config.axis_rotated ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty($$.config.data_xs) && !$$.isSingleX($$.config.data_xs)) { + .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); + if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { if (!eventRect.classed(CLASS.eventRectsMultiple)) { eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) @@ -1175,21 +1346,23 @@ $$.generateEventRectsForSingleX(eventRectUpdate.enter()); // update eventRectUpdate - .attr('class', generateCall(classEvent, $$)) - .attr("x", $$.config.axis_rotated ? 0 : rectX) - .attr("y", $$.config.axis_rotated ? rectX : 0) - .attr("width", $$.config.axis_rotated ? $$.width : rectW) - .attr("height", $$.config.axis_rotated ? rectW : $$.height); + .attr('class', generateCall($$.classEvent, $$)) + .attr("x", config[__axis_rotated] ? 0 : rectX) + .attr("y", config[__axis_rotated] ? rectX : 0) + .attr("width", config[__axis_rotated] ? $$.width : rectW) + .attr("height", config[__axis_rotated] ? rectW : $$.height); // exit eventRectUpdate.exit().remove(); } } + var xv_ = generateCall($$.xv, $$); + // transition should be derived from one transition d3.transition().duration(duration).each(function () { var transitions = [], - cx = generateCall($$.config.axis_rotated ? $$.circleY : $$.circleX, $$), - cy = generateCall($$.config.axis_rotated ? $$.circleX : $$.circleY, $$); + cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), + cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); transitions.push(mainBar.transition() .attr('d', drawBar) @@ -1204,7 +1377,7 @@ .style("fill", $$.color) .style("opacity", $$.orgAreaOpacity)); transitions.push(mainCircle.transition() - .style('opacity', generateCall(opacityForCircle, $$)) + .style('opacity', generateCall($$.opacityForCircle, $$)) .style("fill", $$.color) .attr("cx", cx) .attr("cy", cy)); @@ -1215,7 +1388,7 @@ .attr('x', xForText) .attr('y', yForText) .style("fill", $$.color) - .style("fill-opacity", options.flow ? 0 : $$.opacityForText)); + .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); transitions.push(mainRegion.selectAll('rect').transition() .attr("x", $$.regionX) .attr("y", $$.regionY) @@ -1223,14 +1396,14 @@ .attr("height", $$.regionHeight) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() - .attr("x1", $$.config.axis_rotated ? 0 : $$.xv) - .attr("x2", $$.config.axis_rotated ? $$.width : $$.xv) - .attr("y1", $$.config.axis_rotated ? $$.xv : $$.margin.top) - .attr("y2", $$.config.axis_rotated ? $$.xv : $$.height) + .attr("x1", config[__axis_rotated] ? 0 : xv_) + .attr("x2", config[__axis_rotated] ? $$.width : xv_) + .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv_ : $$.height) .style("opacity", 1)); transitions.push(xgridLines.select('text').transition() - .attr("x", $$.config.axis_rotated ? $$.width : 0) - .attr("y", $$.xv) + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv_) .text(function (d) { return d.text; }) .style("opacity", 1)); // Wait for end of transitions if called from flow API @@ -1321,11 +1494,11 @@ xgridLines .attr('transform', null); xgridLines.select('line') - .attr("x1", $$.config.axis_rotated ? 0 : $$.xv) - .attr("x2", $$.config.axis_rotated ? $$.width : $$.xv); + .attr("x1", config[__axis_rotated] ? 0 : xv_) + .attr("x2", config[__axis_rotated] ? $$.width : xv_); xgridLines.select('text') - .attr("x", $$.config.axis_rotated ? $$.width : 0) - .attr("y", $$.xv); + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv_); mainBar .attr('transform', null) .attr("d", drawBar); @@ -1337,23 +1510,23 @@ .attr("d", drawArea); mainCircle .attr('transform', null) - .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) - .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY); + .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) + .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY); mainText .attr('transform', null) .attr('x', xForText) .attr('y', yForText) - .style('fill-opacity', $$.opacityForText); + .style('fill-opacity', generateCall($$.opacityForText, $$)); mainRegion .attr('transform', null); mainRegion.select('rect').filter($$.isRegionOnX) .attr("x", $$.regionX) .attr("width", $$.regionWidth); eventRectUpdate - .attr("x", $$.config.axis_rotated ? 0 : rectX) - .attr("y", $$.config.axis_rotated ? rectX : 0) - .attr("width", $$.config.axis_rotated ? $$.width : rectW) - .attr("height", $$.config.axis_rotated ? rectW : $$.height); + .attr("x", config[__axis_rotated] ? 0 : rectX) + .attr("y", config[__axis_rotated] ? rectX : 0) + .attr("width", config[__axis_rotated] ? $$.width : rectW) + .attr("height", config[__axis_rotated] ? rectW : $$.height); // callback for end of flow done(); @@ -1368,8 +1541,8 @@ $$.updateZoom(); }; c3_chart_internal_fn.redrawForZoom = function () { - var $$ = this, d3 = $$.d3, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; - if (!$$.config.zoom_enabled) { + var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; + if (!config[__zoom_enabled]) { return; } if ($$.filterTargetsToShow($$.data.targets).length === 0) { @@ -1391,10 +1564,10 @@ if (d3.event.sourceEvent.type === 'mousemove') { $$.cancelClick = true; } - $$.config.zoom_onzoom.call(c3, x.orgDomain()); + config[__zoom_onzoom].call(c3, x.orgDomain()); }; c3_chart_internal_fn.updateAndRedraw = function (options) { - var $$ = this, transitions; + var $$ = this, config = $$.config, transitions; options = options || {}; // same with redraw options.withTransition = getOption(options, "withTransition", true); @@ -1406,12 +1579,12 @@ 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.call($$); + $$.updateSizes(); // MEMO: called in updateLegend in redraw if withLegend - if (!(options.withLegend && $$.config.legend_show)) { - transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? $$.config.transition_duration : 0); + if (!(options.withLegend && config[__legend_show])) { + transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? config[__transition_duration] : 0); // Update scales - updateScales.call($$); + $$.updateScales(); $$.updateSvgSize(); // Update g positions $$.transformAll(options.withTransitionForTransform, transitions); @@ -1421,15 +1594,15 @@ }; c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { - var $$ = this, d3 = $$.d3; + var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append("rect") - .attr("class", generateCall(classEvent, $$)) - .style("cursor", $$.config.data_selection_enabled && $$.config.data_selection_grouped ? "pointer" : null) + .attr("class", generateCall($$.classEvent, $$)) + .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; if ($$.dragging) { return; } // do nothing if dragging - if (hasArcType.call($$, $$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } selectedData = $$.data.targets.map(function (t) { return $$.addName($$.getValueOnIndex(t.values, index)); @@ -1437,7 +1610,7 @@ // Sort selectedData as names order newData = []; - Object.keys($$.config.data_names).forEach(function (id) { + Object.keys(config[__data_names]).forEach(function (id) { for (var j = 0; j < selectedData.length; j++) { if (selectedData[j] && selectedData[j].id === id) { newData.push(selectedData[j]); @@ -1449,17 +1622,17 @@ selectedData = newData.concat(selectedData); // Add remained // Expand shapes for selection - if ($$.config.point_focus_expand_enabled) { $$.expandCircles(index); } + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } $$.expandBars(index); // Call event handler $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - $$.config.data_onmouseover.call(c3, d); + config[__data_onmouseover].call(c3, d); }); }) .on('mouseout', function (d) { var index = d.index; - if (hasArcType.call($$, $$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } $$.hideXGridFocus(); $$.hideTooltip(); // Undo expanded shapes @@ -1467,7 +1640,7 @@ $$.unexpandBars(); // Call event handler $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - $$.config.data_onmouseout.call(c3, d); + config[__data_onmouseout].call($$, d); }); }) .on('mousemove', function (d) { @@ -1475,32 +1648,32 @@ eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); if ($$.dragging) { return; } // do nothing when dragging - if (hasArcType.call($$, $$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } // Show tooltip selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { return $$.addName($$.getValueOnIndex(t.values, index)); }); - if ($$.config.tooltip_grouped) { + if (config[__tooltip_grouped]) { $$.showTooltip(selectedData, d3.mouse(this)); $$.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; } $$.main.selectAll('.' + CLASS.shape + '-' + index) .each(function () { d3.select(this).classed(CLASS.EXPANDED, true); - if ($$.config.data_selection_enabled) { - eventRect.style('cursor', $$.config.data_selection_grouped ? 'pointer' : null); + if (config[__data_selection_enabled]) { + eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); } - if (!$$.config.tooltip_grouped) { + if (!config[__tooltip_grouped]) { $$.hideXGridFocus(); $$.hideTooltip(); - if (!$$.config.data_selection_grouped) { + if (!config[__data_selection_grouped]) { $$.unexpandCircles(index); $$.unexpandBars(); } @@ -1515,20 +1688,20 @@ } }) .each(function (d) { - if ($$.config.data_selection_enabled && ($$.config.data_selection_grouped || $$.config.data_selection_isselectable(d))) { + if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { eventRect.style('cursor', 'pointer'); } - if (!$$.config.tooltip_grouped) { + if (!config[__tooltip_grouped]) { $$.showTooltip([d], d3.mouse(this)); $$.showXGridFocus([d]); - if ($$.config.point_focus_expand_enabled) { $$.expandCircles(index, d.id); } + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } $$.expandBars(index, d.id); } }); }) .on('click', function (d) { var index = d.index; - if (hasArcType.call($$, $$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } if ($$.cancelClick) { $$.cancelClick = false; return; @@ -1545,7 +1718,7 @@ }; c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { - var $$ = this, d3 = $$.d3; + var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append('rect') .attr('x', 0) .attr('y', 0) @@ -1563,14 +1736,14 @@ var mouse, closest, sameXData, selectedData; if ($$.dragging) { return; } // do nothing when dragging - if (hasArcType.call($$, targetsToShow)) { return; } + if ($$.hasArcType(targetsToShow)) { return; } mouse = d3.mouse(this); closest = $$.findClosestFromTargets(targetsToShow, mouse); if (! closest) { return; } - if (isScatterType.call($$, closest)) { + if ($$.isScatterType(closest)) { sameXData = [closest]; } else { sameXData = $$.filterSameX(targetsToShow, closest.x); @@ -1583,7 +1756,7 @@ $$.showTooltip(selectedData, mouse); // expand points - if ($$.config.point_focus_expand_enabled) { + if (config[__point_focus_expand_enabled]) { $$.unexpandCircles(); $$.expandCircles(closest.index, closest.id); } @@ -1595,12 +1768,12 @@ if ($$.dist(closest, mouse) < 100) { $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); if (!$$.mouseover) { - $$.config.data_onmouseover.call(c3, closest); + config[__data_onmouseover].call($$, closest); $$.mouseover = true; } } else if ($$.mouseover) { $$.svg.select('.' + CLASS.eventRect).style('cursor', null); - $$.config.data_onmouseout.call(c3, closest); + config[__data_onmouseout].call($$, closest); $$.mouseover = false; } }) @@ -1608,7 +1781,7 @@ var targetsToShow = $$.filterTargetsToShow($$.data.targets); var mouse, closest; - if (hasArcType.call($$, targetsToShow)) { return; } + if ($$.hasArcType(targetsToShow)) { return; } mouse = d3.mouse(this); closest = $$.findClosestFromTargets(targetsToShow, mouse); @@ -1617,7 +1790,7 @@ // select if selection enabled if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS.circles + getTargetSelectorSuffix.call($$, closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); } @@ -1638,24 +1811,24 @@ - var initialOpacity = c3_chart_internal_fn.initialOpacity = function (d) { + c3_chart_internal_fn.initialOpacity = function (d) { return d.value !== null && this.withoutFadeIn[d.id] ? 1 : 0; }; - var opacityForCircle = c3_chart_internal_fn.opacityForCircle = function (d) { + c3_chart_internal_fn.opacityForCircle = function (d) { var $$ = this; - return isValue(d.value) ? isScatterType.call($$, d) ? 0.5 : 1 : 0; + return isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 0; }; c3_chart_internal_fn.opacityForText = function () { return this.hasDataLabel() ? 1 : 0; }; - var xx = c3_chart_internal_fn.xx = function (d) { + c3_chart_internal_fn.xx = function (d) { return d ? this.x(d.x) : null; }; c3_chart_internal_fn.xv = function (d) { var $$ = this; return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); }; - var yv = c3_chart_internal_fn.yv = function (d) { + c3_chart_internal_fn.yv = function (d) { var $$ = this, yScale = d.axis && d.axis === 'y2' ? $$.y2 : $$.y; return Math.ceil(yScale(d.value)); @@ -1700,7 +1873,7 @@ c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); - if ($$.config.subchart_show) { transformContext.call($$, withTransition, transitions); } + if (config[__subchart_show]) { $$.transformContext(withTransition, transitions); } $$.transformLegend(withTransition); }; @@ -1731,15 +1904,15 @@ c3_chart_internal_fn.updateDimension = function () { var $$ = this; - if ($$.config.axis_rotated) { + if ($$.config[__axis_rotated]) { $$.axes.x.call($$.xAxis); $$.axes.subx.call($$.subXAxis); } else { $$.axes.y.call($$.yAxis); $$.axes.y2.call($$.y2Axis); } - updateSizes.call($$); - updateScales.call($$); + $$.updateSizes(); + $$.updateScales(); $$.updateSvgSize(); $$.transformAll(false); }; @@ -1789,44 +1962,46 @@ c3_chart_internal_fn.getCurrentWidth = function () { - var $$ = this; - return $$.config.size_width ? $$.config.size_width : $$.getParentWidth(); + var $$ = this, config = $$.config; + return config[__size_width] ? config[__size_width] : $$.getParentWidth(); }; c3_chart_internal_fn.getCurrentHeight = function () { - var $$ = this, h = $$.config.size_height ? $$.config.size_height : $$.getParentHeight(); + var $$ = this, config = $$.config, + h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); return h > 0 ? h : 320; }; c3_chart_internal_fn.getCurrentPaddingTop = function () { - var $$ = this; - return isValue($$.config.padding_top) ? $$.config.padding_top : 0; + var config = this.config; + return isValue(config[__padding_top]) ? config[__padding_top] : 0; }; c3_chart_internal_fn.getCurrentPaddingBottom = function () { - var $$ = this; - return isValue($$.config.padding_bottom) ? $$.config.padding_bottom : 0; + var config = this.config; + return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; }; c3_chart_internal_fn.getCurrentPaddingLeft = function () { - var $$ = this; - if (isValue($$.config.padding_left)) { - return $$.config.padding_left; - } else if ($$.config.axis_rotated) { - return !$$.config.axis_x_show ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); + var $$ = this, config = $$.config; + if (isValue(config[__padding_left])) { + return config[__padding_left]; + } else if (config[__axis_rotated]) { + return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); } else { - return !$$.config.axis_y_show || $$.config.axis_y_inner ? 1 : ceil10($$.getAxisWidthByAxisId('y')); + return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); } }; c3_chart_internal_fn.getCurrentPaddingRight = function () { - var $$ = this, defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; - if (isValue($$.config.padding_right)) { - return $$.config.padding_right + 1; // 1 is needed not to hide tick line - } else if ($$.config.axis_rotated) { + var $$ = this, config = $$.config, + defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; + if (isValue(config[__padding_right])) { + return config[__padding_right] + 1; // 1 is needed not to hide tick line + } else if (config[__axis_rotated]) { return defaultPadding + legendWidthOnRight; } else { - return (!$$.config.axis_y2_show || $$.config.axis_y2_inner ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; c3_chart_internal_fn.getParentRectValue = function (key) { - var $$ = this, parent = $$.selectChart.node(), v; + var parent = this.selectChart.node(), v; while (parent && parent.tagName !== 'BODY') { v = parent.getBoundingClientRect()[key]; if (v) { @@ -1846,28 +2021,28 @@ c3_chart_internal_fn.getSvgLeft = function () { - var $$ = this, - leftAxisClass = $$.config.axis_rotated ? CLASS.axisX : CLASS.axisY, + var $$ = this, config = $$.config, + leftAxisClass = config[__axis_rotated] ? CLASS.axisX : CLASS.axisY, leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = hasArcType.call($$, $$.data.targets), + hasArc = $$.hasArcType($$.data.targets), svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); return svgLeft > 0 ? svgLeft : 0; }; c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { - var $$ = this, position = getAxisLabelPositionById.call($$, id); + var $$ = this, position = $$.getAxisLabelPositionById(id); return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); }; c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { - var $$ = this; - if (axisId === 'x' && !$$.config.axis_x_show) { return 0; } - if (axisId === 'x' && $$.config.axis_x_height) { return $$.config.axis_x_height; } - if (axisId === 'y' && !$$.config.axis_y_show) { return $$.config.legend_show && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } - if (axisId === 'y2' && !$$.config.axis_y2_show) { return $$.rotated_padding_top; } - return (getAxisLabelPositionById.call($$, axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + var $$ = this, config = $$.config; + if (axisId === 'x' && !config[__axis_x_show]) { return 0; } + if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } + if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } + return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; c3_chart_internal_fn.getEventRectWidth = function () { @@ -1880,10 +2055,10 @@ firstData = target.values[0], lastData = target.values[target.values.length - 1]; base = $$.x(lastData.x) - $$.x(firstData.x); if (base === 0) { - return $$.config.axis_rotated ? $$.height : $$.width; + return $$.config[__axis_rotated] ? $$.height : $$.width; } maxDataCount = $$.getMaxDataCount(); - ratio = (hasBarType.call($$, $$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -1893,14 +2068,14 @@ * c3.tooltip.js */ c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { - var $$ = this; + var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = hasArcType.call($$, $$.data.targets), + var forArc = $$.hasArcType($$.data.targets), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (dataToShow.length === 0 || !$$.config.tooltip_show) { + if (dataToShow.length === 0 || !config[__tooltip_show]) { return; } - $$.tooltip.html($$.config.tooltip_contents.call($$, selectedData, getXAxisTickFormat.call($$), $$.getYFormat(forArc), $$.color)).style("display", "block"); + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); // Get tooltip dimensions tWidth = $$.tooltip.property('offsetWidth'); @@ -1910,7 +2085,7 @@ tooltipLeft = ($$.width / 2) + mouse[0]; tooltipTop = ($$.height / 2) + mouse[1] + 20; } else { - if ($$.config.axis_rotated) { + if (config[__axis_rotated]) { svgLeft = $$.getSvgLeft(); tooltipLeft = svgLeft + mouse[0] + 100; tooltipRight = tooltipLeft + tWidth; @@ -1946,15 +2121,15 @@ */ c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (! $$.config.tooltip_show) { return; } + if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if (hasScatterType.call($$, $$.data.targets) || hasArcType.call($$, $$.data.targets)) { return; } + if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } var focusEl = $$.main.selectAll('line.' + CLASS.xgridFocus); focusEl .style("visibility", "visible") .data([dataToShow[0]]) - .attr($$.config.axis_rotated ? 'y1' : 'x1', generateCall(xx, $$)) - .attr($$.config.axis_rotated ? 'y2' : 'x2', generateCall(xx, $$)); + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { @@ -1963,10 +2138,10 @@ c3_chart_internal_fn.updateXgridFocus = function () { var $$ = this, config = $$.config; $$.main.select('line.' + CLASS.xgridFocus) - .attr("x1", config.axis_rotated ? 0 : -10) - .attr("x2", config.axis_rotated ? $$.width : -10) - .attr("y1", config.axis_rotated ? -10 : 0) - .attr("y2", config.axis_rotated ? -10 : $$.height); + .attr("x1", config[__axis_rotated] ? 0 : -10) + .attr("x2", config[__axis_rotated] ? $$.width : -10) + .attr("y1", config[__axis_rotated] ? -10 : 0) + .attr("y2", config[__axis_rotated] ? -10 : $$.height); }; c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, @@ -1999,18 +2174,18 @@ } : function () { return true; }; }; c3_chart_internal_fn.removeGridLines = function (params, forX) { - var $$ = this, + var $$ = this, config = $$.config, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) - .transition().duration($$.config.transition_duration) + .transition().duration(config[__transition_duration]) .style('opacity', 0).remove(); if (forX) { - $$.config.grid_x_lines = $$.config.grid_x_lines.filter(toShow); + config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); } else { - $$.config.grid_y_lines = $$.config.grid_y_lines.filter(toShow); + config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); } }; @@ -2029,15 +2204,15 @@ }; c3_chart_internal_fn.getLegendWidth = function () { var $$ = this; - return $$.config.legend_show ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; + return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; }; c3_chart_internal_fn.getLegendHeight = function () { - var $$ = this, h = 0; - if ($$.config.legend_show) { + var $$ = this, config = $$.config, h = 0; + if (config[__legend_show]) { if ($$.isLegendRight) { h = $$.currentHeight; } else if ($$.isLegendInset) { - h = $$.config.legend_inset_step ? Math.max(20, $$.legendItemHeight) * ($$.config.legend_inset_step + 1) : $$.height; + h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; } else { h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); } @@ -2072,30 +2247,30 @@ .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; c3_chart_internal_fn.showLegend = function (targetIds) { - var $$ = this; - if (!$$.config.legend_show) { - $$.config.legend_show = true; + var $$ = this, config = $$.config; + if (!config[__legend_show]) { + config[__legend_show] = true; $$.legend.style('visibility', 'visible'); } $$.removeHiddenLegendIds(targetIds); - $$.legend.selectAll(selectorLegends.call($$, targetIds)) + $$.legend.selectAll($$.selectorLegends(targetIds)) .style('visibility', 'visible') .transition() .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); }; c3_chart_internal_fn.hideLegend = function (targetIds) { - var $$ = this; - if ($$.config.legend_show && isEmpty(targetIds)) { - $$.config.legend_show = false; + var $$ = this, config = $$.config; + if (config[__legend_show] && isEmpty(targetIds)) { + config[__legend_show] = false; $$.legend.style('visibility', 'hidden'); } $$.addHiddenLegendIds(targetIds); - $$.legend.selectAll(selectorLegends.call($$, targetIds)) + $$.legend.selectAll($$.selectorLegends(targetIds)) .style('opacity', 0) .style('visibility', 'hidden'); }; c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { - var $$ = this, c = $$.config; + var $$ = this, config = $$.config; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; @@ -2108,7 +2283,7 @@ withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = getTextRect.call($$, textElement.textContent, CLASS.legendItem), + var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, @@ -2138,7 +2313,7 @@ maxHeight = 0; } - if (c.legend_show && !$$.isLegendToShow(id)) { + if (config[__legend_show] && !$$.isLegendToShow(id)) { widths[id] = heights[id] = steps[id] = offsets[id] = 0; return; } @@ -2150,7 +2325,7 @@ if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; - if (c.legend_equally) { + if (config[__legend_equally]) { Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); margin = (areaLength - maxLength * targetIds.length) / 2; @@ -2186,19 +2361,19 @@ l = $$.legend.selectAll('.' + CLASS.legendItem) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return generateClass.call($$, CLASS.legendItem, id); }) + .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - typeof clegend_item_onclick === 'function' ? clegend_item_onclick.call(c3, id) : $$.api.toggle(id); + isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed(CLASS.legendItemFocused, true); if (!$$.transiting) { $$.api.focus(id); } - if (typeof c.legend_item_onmouseover === 'function') { - c.legend_item_onmouseover.call(c3, id); + if (isFunction(config[__legend_item_onmouseover])) { + config[__legend_item_onmouseover].call($$, id); } }) .on('mouseout', function (id) { @@ -2206,12 +2381,12 @@ if (!$$.transiting) { $$.api.revert(); } - if (typeof c.legend_item_onmouseout === 'function') { - c.legend_item_onmouseout.call(c3, id); + if (isFunction(config[__legend_item_onmouseout])) { + config[__legend_item_onmouseout].call($$, id); } }); l.append('text') - .text(function (id) { return isDefined(c.data_names[id]) ? c.data_names[id] : id; }) + .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) .each(function (id, i) { updatePositions(this, id, i === 0); }) .style("pointer-events", "none") .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2240,7 +2415,7 @@ texts = $$.legend.selectAll('text') .data(targetIds) - .text(function (id) { return isDefined(c.data_names[id]) ? c.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 .each(function (id, i) { updatePositions(this, id, i === 0); }); (withTransition ? texts.transition() : texts) .attr('x', xForLegendText) @@ -2279,8 +2454,8 @@ $$.updateLegendItemHeight(maxHeight); $$.updateLegendStep(step); // Update size and scale - updateSizes.call($$); - updateScales.call($$); + $$.updateSizes(); + $$.updateScales(); $$.updateSvgSize(); // Update g positions $$.transformAll(withTransitionForTransform, transitions); @@ -2302,19 +2477,19 @@ }; c3_chart_internal_fn.getXAxisClipX = function () { var $$ = this; - return $$.getAxisClipX(!$$.config.axis_rotated); + return $$.getAxisClipX(!$$.config[__axis_rotated]); }; c3_chart_internal_fn.getXAxisClipY = function () { var $$ = this; - return $$.getAxisClipY(!$$.config.axis_rotated); + return $$.getAxisClipY(!$$.config[__axis_rotated]); }; c3_chart_internal_fn.getYAxisClipX = function () { var $$ = this; - return $$.getAxisClipX($$.config.axis_rotated); + return $$.getAxisClipX($$.config[__axis_rotated]); }; c3_chart_internal_fn.getYAxisClipY = function () { var $$ = this; - return $$.getAxisClipY($$.config.axis_rotated); + return $$.getAxisClipY($$.config[__axis_rotated]); }; c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { var $$ = this; @@ -2322,24 +2497,24 @@ return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { - var $$ = this; - return forHorizontal ? ($$.config.axis_x_height ? $$.config.axis_x_height : 0) + 80 : $$.height + 8; + var $$ = this, config = $$.config; + return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; }; c3_chart_internal_fn.getXAxisClipWidth = function () { var $$ = this; - return $$.getAxisClipWidth(!$$.config.axis_rotated); + return $$.getAxisClipWidth(!$$.config[__axis_rotated]); }; c3_chart_internal_fn.getXAxisClipHeight = function () { var $$ = this; - return $$.getAxisClipHeight(!$$.config.axis_rotated); + return $$.getAxisClipHeight(!$$.config[__axis_rotated]); }; c3_chart_internal_fn.getYAxisClipWidth = function () { var $$ = this; - return $$.getAxisClipWidth($$.config.axis_rotated); + return $$.getAxisClipWidth($$.config[__axis_rotated]); }; c3_chart_internal_fn.getYAxisClipHeight = function () { var $$ = this; - return $$.getAxisClipHeight($$.config.axis_rotated); + return $$.getAxisClipHeight($$.config[__axis_rotated]); }; @@ -2347,15 +2522,15 @@ * $$.data.js */ c3_chart_internal_fn.isX = function (key) { - var $$ = this, c = $$.config; - return (c.data_x && key === c.data_x) || (notEmpty(c.data_xs) && hasValue(c.data_xs, key)); + var $$ = this, config = $$.config; + return (config[__data_x] && key === config[__data_x]) || (notEmpty(config[__data_xs]) && hasValue(config[__data_xs], key)); }; c3_chart_internal_fn.isNotX = function (key) { return !this.isX(key); }; c3_chart_internal_fn.getXKey = function (id) { - var $$ = this, c = $$.config; - return c.data_x ? c.data_x : notEmpty(c.data_xs) ? c.data_xs[id] : null; + var $$ = this, config = $$.config; + return config[__data_x] ? config[__data_x] : notEmpty(config[__data_xs]) ? config[__data_xs][id] : null; }; c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { var $$ = this, @@ -2383,7 +2558,7 @@ c3_chart_internal_fn.addXs = function (xs) { var $$ = this; Object.keys(xs).forEach(function (id) { - $$.config.data_xs[id] = xs[id]; + $$.config[__data_xs][id] = xs[id]; }); }; c3_chart_internal_fn.isSingleX = function (xs) { @@ -2392,7 +2567,7 @@ c3_chart_internal_fn.addName = function (data) { var $$ = this, name; if (data) { - name = $$.config.data_names[data.id]; + name = $$.config[__data_names][data.id]; data.name = name ? name : data.id; } return data; @@ -2431,14 +2606,14 @@ } return x; }; - var convertUrlToData = c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { + c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { var $$ = this, type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; if (type === 'json') { - d = convertJsonToData.call($$, JSON.parse(data.response), keys); + d = $$.convertJsonToData(JSON.parse(data.response), keys); } else { - d = convertCsvToData.call($$, data.response); + d = $$.convertCsvToData(data.response); } done(d); }); @@ -2491,7 +2666,7 @@ }; c3_chart_internal_fn.mapToTargetIds = function (ids) { var $$ = this; - return ids ? (typeof ids === 'string' ? [ids] : ids) : $$.mapToIds($$.data.targets); + return ids ? (isString(ids) ? [ids] : ids) : $$.mapToIds($$.data.targets); }; c3_chart_internal_fn.hasTarget = function (targets, id) { var ids = this.mapToIds(targets), i; @@ -2558,15 +2733,15 @@ return this.checkValueInTargets(targets, function (v) { return v > 0; }); }; c3_chart_internal_fn.isOrderDesc = function () { - var c = this.config; - return c.data_order && c.data_order.toLowerCase() === 'desc'; + var config = this.config; + return config[__data_order] && config[__data_order].toLowerCase() === 'desc'; }; c3_chart_internal_fn.isOrderAsc = function () { - var c = this.config; - return c.data_order && c.data_order.toLowerCase() === 'asc'; + var config = this.config; + return config[__data_order] && config[__data_order].toLowerCase() === 'asc'; }; c3_chart_internal_fn.orderTargets = function (targets) { - var $$ = this, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); + var $$ = this, config = $$.config, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); if (orderAsc || orderDesc) { targets.sort(function (t1, t2) { var reducer = function (p, c) { return p + Math.abs(c.value); }; @@ -2574,8 +2749,8 @@ t2Sum = t2.values.reduce(reducer, 0); return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; }); - } else if (typeof $$.config.data_order === 'function') { - targets.sort($$.config.data_order); + } else if (isFunction(config[__data_order])) { + targets.sort(config[__data_order]); } // TODO: accept name array for order return targets; }; @@ -2586,10 +2761,10 @@ return data.filter(function (d) { return isValue(d.value); }); }; c3_chart_internal_fn.hasDataLabel = function () { - var c = this.config; - if (typeof c.data_labels === 'boolean' && c.data_labels) { + var config = this.config; + if (typeof config[__data_labels] === 'boolean' && config[__data_labels]) { return true; - } else if (typeof c.data_labels === 'object' && notEmpty(c.data_labels)) { + } else if (typeof config[__data_labels] === 'object' && notEmpty(config[__data_labels])) { return true; } return false; @@ -2607,10 +2782,10 @@ .remove(); return lengths; }; - var isNoneArc = c3_chart_internal_fn.isNoneArc = function (d) { + c3_chart_internal_fn.isNoneArc = function (d) { return this.hasTarget(this.data.targets, d.id); }, - isArc = c3_chart_internal_fn.isArc = function (d) { + c3_chart_internal_fn.isArc = function (d) { return 'data' in d && this.hasTarget(this.data.targets, d.data.id); }; @@ -2618,7 +2793,7 @@ /** * c3.data.convert.js */ - var convertCsvToData = c3_chart_internal_fn.convertCsvToData = function (csv) { + c3_chart_internal_fn.convertCsvToData = function (csv) { var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; @@ -2630,40 +2805,40 @@ } return d; }; - var convertJsonToData = c3_chart_internal_fn.convertJsonToData = function (json, keys) { + c3_chart_internal_fn.convertJsonToData = function (json, keys) { var $$ = this, new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects targetKeys = keys.value; if (keys.x) { targetKeys.push(keys.x); - $$.config.data_x = keys.x; + $$.config[__data_x] = keys.x; } new_rows.push(targetKeys); json.forEach(function (o) { var new_row = []; targetKeys.forEach(function (key) { // convert undefined to null because undefined data will be removed in convertDataToTargets() - var v = typeof o[key] === 'undefined' ? null : o[key]; + var v = isUndefined(o[key]) ? null : o[key]; new_row.push(v); }); new_rows.push(new_row); }); - data = convertRowsToData.call($$, new_rows); + data = $$.convertRowsToData(new_rows); } else { Object.keys(json).forEach(function (key) { new_rows.push([key].concat(json[key])); }); - data = convertColumnsToData.call($$, new_rows); + data = $$.convertColumnsToData(new_rows); } return data; }; - var convertRowsToData = c3_chart_internal_fn.convertRowsToData = function (rows) { + c3_chart_internal_fn.convertRowsToData = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; for (j = 0; j < rows[i].length; j++) { - if (typeof rows[i][j] === 'undefined') { + if (isUndefined(rows[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_row[keys[j]] = rows[i][j]; @@ -2672,15 +2847,15 @@ } return new_rows; }; - var convertColumnsToData = c3_chart_internal_fn.convertColumnsToData = function (columns) { + c3_chart_internal_fn.convertColumnsToData = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; for (j = 1; j < columns[i].length; j++) { - if (typeof new_rows[j - 1] === 'undefined') { + if (isUndefined(new_rows[j - 1])) { new_rows[j - 1] = {}; } - if (typeof columns[i][j] === 'undefined') { + if (isUndefined(columns[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_rows[j - 1][key] = columns[i][j]; @@ -2688,8 +2863,8 @@ } return new_rows; }; - var convertDataToTargets = c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { - var $$ = this, c = $$.config, + c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { + var $$ = this, config = $$.config, ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), targets; @@ -2708,11 +2883,11 @@ ); } // if not included in input data, find from preloaded data of other id's x - else if (c.data_x) { + else if (config[__data_x]) { $$.data.xs[id] = $$.getOtherTargetXs(); } // if not included in input data, find from preloaded data - else if (notEmpty(c.data_xs)) { + else if (notEmpty(config[__data_xs])) { $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used @@ -2730,7 +2905,7 @@ // convert to target targets = ids.map(function (id, index) { - var convertedId = c.data_id_converter(id); + var convertedId = config[__data_id_converter](id); return { id: convertedId, id_org: id, @@ -2738,15 +2913,15 @@ var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); // use x as categories if custom x and categorized if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { - if (i === 0) { c.axis_x_categories = []; } - c.axis_x_categories.push(rawX); + if (i === 0) { config[__axis_x_categories] = []; } + config[__axis_x_categories].push(rawX); } // mark as x = undefined if value is undefined and filter to remove after mapped - if (typeof d[id] === 'undefined' || $$.data.xs[id].length <= i) { + if (isUndefined(d[id]) || $$.data.xs[id].length <= i) { x = undefined; } return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; - }).filter(function (v) { return typeof v.x !== 'undefined'; }) + }).filter(function (v) { return isDefined(v.x); }) }; }); @@ -2771,8 +2946,8 @@ }); // set target types - if (c.data_type) { - $$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in c.data_types); }), c.data_type); + if (config[__data_type]) { + $$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config[__data_types]); }), config[__data_type]); } // cache as original id keyed @@ -2813,33 +2988,33 @@ } // Set targets - updateTargets.call($$, $$.data.targets); + $$.updateTargets($$.data.targets); // Redraw with new targets $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (typeof args.done === 'function') { + if (isFunction(args.done)) { args.done(); } }; c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; if (args.data) { - $$.load(convertDataToTargets.call($$, args.data), args); + $$.load($$.convertDataToTargets(args.data), args); } else if (args.url) { $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { - $$.load(convertDataToTargets.call($$, data), args); + $$.load($$.convertDataToTargets(data), args); }); } else if (args.json) { - $$.load(convertDataToTargets.call($$, convertJsonToData.call($$, args.json, args.keys)), args); + $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); } else if (args.rows) { - $$.load(convertDataToTargets.call($$, convertRowsToData.call($$, args.rows)), args); + $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); } else if (args.columns) { - $$.load(convertDataToTargets.call($$, convertColumnsToData.call($$, args.columns)), args); + $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); } else { $$.load(null, args); @@ -2847,7 +3022,7 @@ }; c3_chart_internal_fn.unload = function (targetIds, done) { var $$ = this; - if (typeof done !== 'function') { + if (!isFunction(done)) { done = function () {}; } // filter existing target @@ -2857,7 +3032,7 @@ done(); return; } - $$.svg.selectAll(targetIds.map(function (id) { return selectorTarget.call($$, id); })) + $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) .transition() .style('opacity', 0) .remove() @@ -2866,7 +3041,7 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS.legendItem + getTargetSelectorSuffix.call($$, id)).remove(); + $$.legend.selectAll('.' + CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -2879,8 +3054,8 @@ * c3.data.category.js */ c3_chart_internal_fn.categoryName = function (i) { - var c = this.config; - return i < c.axis_x_categories.length ? c.axis_x_categories[i] : i; + var config = this.config; + return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; }; @@ -2888,14 +3063,14 @@ * c3.shape.js */ c3_chart_internal_fn.getShapeIndices = function (typeFilter) { - var $$ = this, c = $$.config, + var $$ = this, config = $$.config, indices = {}, i = 0, j, k; $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { - for (j = 0; j < c.data_groups.length; j++) { - if (c.data_groups[j].indexOf(d.id) < 0) { continue; } - for (k = 0; k < c.data_groups[j].length; k++) { - if (c.data_groups[j][k] in indices) { - indices[d.id] = indices[c.data_groups[j][k]]; + for (j = 0; j < config[__data_groups].length; j++) { + if (config[__data_groups][j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < config[__data_groups][j].length; k++) { + if (config[__data_groups][j][k] in indices) { + indices[d.id] = indices[config[__data_groups][j][k]]; break; } } @@ -2938,7 +3113,7 @@ c3_chart_internal_fn.getInterpolate = function (d) { var $$ = this; - return isSplineType.call($$, d) ? "cardinal" : isStepType.call($$, d) ? "step-after" : "linear"; + return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; @@ -2947,45 +3122,45 @@ }; c3_chart_internal_fn.circleY = function (d, i) { var $$ = this, - lineIndices = $$.getShapeIndices(isLineType), getPoint = $$.generateGetLinePoint(lineIndices); - return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS.circles + getTargetSelectorSuffix.call($$, id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this; $$.getCircles(i, id) .classed(CLASS.EXPANDED, true) - .attr('r', generateCall(pointExpandedR, $$)); + .attr('r', generateCall($$.pointExpandedR, $$)); }; c3_chart_internal_fn.unexpandCircles = function (i) { var $$ = this; $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) .classed(CLASS.EXPANDED, false) - .attr('r', generateCall(pointR, $$)); + .attr('r', generateCall($$.pointR, $$)); }; - var pointR = c3_chart_internal_fn.pointR = function (d) { - var $$ = this; - return $$.config.point_show && !isStepType.call($$, d) ? (typeof $$.config.point_r === 'function' ? $$.config.point_r(d) : $$.config.point_r) : 0; + c3_chart_internal_fn.pointR = function (d) { + var $$ = this, config = $$.config; + return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; }; - var pointExpandedR = c3_chart_internal_fn.pointExpandedR = function (d) { - var $$ = this, c = $$.config; - return c.point_focus_expand_enabled ? (c.point_focus_expand_r ? c.point_focus_expand_r : pointR.call($$, d) * 1.75) : pointR.call($$, d); + c3_chart_internal_fn.pointExpandedR = function (d) { + var $$ = this, config = $$.config; + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); }; c3_chart_internal_fn.pointSelectR = function (d) { - var $$ = this, c = $$.config; - return c.point_select_r ? c.point_select_r : pointR.call($$, d) * 4; + var $$ = this, config = $$.config; + return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; }; c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { - var $$ = this, c = $$.config, - w = typeof c.bar_width === 'number' ? c.bar_width : barTargetsNum ? (axis.tickOffset() * 2 * c.bar_width_ratio) / barTargetsNum : 0; - return c.bar_width_ratio && w > c.bar_width_max ? c.bar_width_max : w; + var $$ = this, config = $$.config, + w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; + return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; }; c3_chart_internal_fn.getBars = function (i) { var $$ = this; @@ -3000,14 +3175,15 @@ $$.getBars(i).classed(CLASS.EXPANDED, false); }; c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { - var $$ = this, getPoints = $$.generateGetBarPoints(barIndices, isSub); + var $$ = this, config = $$.config, + getPoints = $$.generateGetBarPoints(barIndices, isSub); return function (d, i) { // 4 points that make a bar var points = getPoints(d, i); // switch points if axis is rotated, not applicable for sub chart - var indexX = $$.config.axis_rotated ? 1 : 0; - var indexY = $$.config.axis_rotated ? 0 : 1; + var indexX = config[__axis_rotated] ? 1 : 0; + var indexY = config[__axis_rotated] ? 0 : 1; var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + @@ -3024,14 +3200,14 @@ barW = $$.getBarW($$.xAxis, barTargetsNum), barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), barY = $$.getShapeY(!!isSub), - barOffset = $$.getShapeOffset(isBarType, barIndices, !!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), offset = barOffset(d, i) || y0, // offset is for stacked bar chart posX = barX(d), posY = barY(d); // fix posY not to overflow opposite quadrant - if ($$.config.axis_rotated) { + if ($$.config[__axis_rotated]) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 4 points that make a bar @@ -3045,52 +3221,52 @@ }; c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { - var $$ = this, area = $$.d3.svg.area(), + var $$ = this, config = $$.config, area = $$.d3.svg.area(), getPoint = $$.generateGetAreaPoint(areaIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, value0 = function (d, i) { - return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); }, value1 = function (d, i) { - return $$.config.data_groups.length > 0 ? getPoint(d, i)[1][1] : yScaleGetter.call($$, d.id)(d.value); + return config[__data_groups].length > 0 ? getPoint(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); return function (d) { var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; - if (isAreaType.call($$, d)) { + if ($$.isAreaType(d)) { path = area.interpolate($$.getInterpolate(d))(data); } else { if (data[0]) { x0 = $$.x(data[0].x); y0 = $$.getYScale(d.id)(data[0].value); } - path = $$.config.axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } return path ? path : "M 0 0"; }; }; c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { - var $$ = this, + var $$ = this, config = $$.config, line = $$.d3.svg.line(), getPoint = $$.generateGetLinePoint(lineIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, yValue = function (d, i) { - return $$.config.data_groups.length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); }; - line = $$.config.axis_rotated ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); - if (!$$.config.line_connect_null) { line = line.defined(function (d) { return d.value != null; }); } + line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } return function (d) { - var data = $$.config.line_connect_null ? $$.filterRemoveNull(d.values) : d.values, + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; - if (isLineType.call($$, d)) { - if ($$.config.data_regions[d.id]) { - path = $$.lineWithRegions(data, x, y, $$.config.data_regions[d.id]); + if ($$.isLineType(d)) { + if (config[__data_regions][d.id]) { + path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); } else { path = line.interpolate($$.getInterpolate(d))(data); } @@ -3099,7 +3275,7 @@ x0 = x(data[0].x); y0 = y(data[0].value); } - path = $$.config.axis_rotated ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } return path ? path : "M 0 0"; }; @@ -3116,8 +3292,8 @@ c3_chart_internal_fn.getXForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), xPos, padding; - if ($$.config.axis_rotated) { - padding = isBarType.call($$, d) ? 4 : 6; + if (config[__axis_rotated]) { + padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; @@ -3127,27 +3303,27 @@ c3_chart_internal_fn.getYForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), yPos; - if ($$.config.axis_rotated) { + if (config[__axis_rotated]) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { - yPos = points[2][1] + (d.value < 0 ? box.height : isBarType.call($$, d) ? -3 : -6); + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); } return yPos < box.height ? box.height : yPos; }; c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints - var $$ = this, + var $$ = this, config = $$.config, areaTargetsNum = areaIndices.__max__ + 1, x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), y = $$.getShapeY(!!isSub), - areaOffset = $$.getShapeOffset(isAreaType, areaIndices, !!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), offset = areaOffset(d, i) || y0, // offset is for stacked area chart posX = x(d), posY = y(d); // fix posY not to overflow opposite quadrant - if ($$.config.axis_rotated) { + if (config[__axis_rotated]) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 1 point that marks the area position @@ -3159,18 +3335,18 @@ }; c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints - var $$ = this, + var $$ = this, config = $$.config, lineTargetsNum = lineIndices.__max__ + 1, x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), y = $$.getShapeY(!!isSub), - lineOffset = $$.getShapeOffset(isLineType, lineIndices, !!isSub), + lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), offset = lineOffset(d, i) || y0, // offset is for stacked area chart posX = x(d), posY = y(d); // fix posY not to overflow opposite quadrant - if ($$.config.axis_rotated) { + if (config[__axis_rotated]) { if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } } // 1 point that marks the line position @@ -3182,7 +3358,7 @@ c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { - var $$ = this, + var $$ = this, config = $$.config, prev = -1, i, j, s = "M", sWithRegion, xp, yp, dx, dy, dd, diff, diffx2, @@ -3207,8 +3383,8 @@ } // Set scales - 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); }; + 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); }; // Define svg generator function for region if ($$.isTimeSeries) { @@ -3298,7 +3474,7 @@ max = _max ? _max : values.length - 1, med = Math.floor((max - min) / 2) + min, value = values[med], - diff = $$.x(value.x) - pos[$$.config.axis_rotated ? 1 : 0], + diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], candidates; // Update range for search @@ -3345,29 +3521,29 @@ return closest; }; c3_chart_internal_fn.dist = function (data, pos) { - var $$ = this, + var $$ = this, config = $$.config, yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, - xIndex = $$.config.axis_rotated ? 1 : 0, - yIndex = $$.config.axis_rotated ? 0 : 1; + xIndex = config[__axis_rotated] ? 1 : 0, + yIndex = config[__axis_rotated] ? 0 : 1; return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); }; c3_chart_internal_fn.setTargetType = function (targetIds, type) { - var $$ = this; + var $$ = this, config = $$.config; $$.mapToTargetIds(targetIds).forEach(function (id) { - $$.withoutFadeIn[id] = (type === $$.config.data_types[id]); - $$.config.data_types[id] = type; + $$.withoutFadeIn[id] = (type === config[__data_types][id]); + config[__data_types][id] = type; }); if (!targetIds) { - $$.config.data_type = type; + config[__data_type] = type; } }; - var hasType = c3_chart_internal_fn.hasType = function (targets, type) { - var $$ = this, has = false; + c3_chart_internal_fn.hasType = function (targets, type) { + var $$ = this, config = $$.config, has = false; targets.forEach(function (t) { - if ($$.config.data_types[t.id] === type) { has = true; } - if (!(t.id in $$.config.data_types) && type === 'line') { has = true; } + if (config[__data_types][t.id] === type) { has = true; } + if (!(t.id in config[__data_types]) && type === 'line') { has = true; } }); return has; }; @@ -3376,85 +3552,85 @@ return hasType(targets, 'line'); } */ - var hasAreaType = c3_chart_internal_fn.hasAreaType = function (targets) { - return hasType.call(this, targets, 'area') || hasType.call(this, targets, 'area-spline') || hasType.call(this, targets, 'area-step'); + c3_chart_internal_fn.hasAreaType = function (targets) { + return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); }; - var hasBarType = c3_chart_internal_fn.hasBarType = function (targets) { - return hasType.call(this, targets, 'bar'); + c3_chart_internal_fn.hasBarType = function (targets) { + return this.hasType(targets, 'bar'); }; - var hasScatterType = c3_chart_internal_fn.hasScatterType = function (targets) { - return hasType.call(this, targets, 'scatter'); + c3_chart_internal_fn.hasScatterType = function (targets) { + return this.hasType(targets, 'scatter'); }; - var hasPieType = c3_chart_internal_fn.hasPieType = function (targets) { - return this.config.data_type === 'pie' || hasType.call(this, targets, 'pie'); + c3_chart_internal_fn.hasPieType = function (targets) { + return this.config[__data_type] === 'pie' || this.hasType(targets, 'pie'); }; - var hasGaugeType = c3_chart_internal_fn.hasGaugeType = function (targets) { - return hasType.call(this, targets, 'gauge'); + c3_chart_internal_fn.hasGaugeType = function (targets) { + return this.hasType(targets, 'gauge'); }; - var hasDonutType = c3_chart_internal_fn.hasDonutType = function (targets) { - return this.config.data_type === 'donut' || hasType.call(this, targets, 'donut'); + c3_chart_internal_fn.hasDonutType = function (targets) { + return this.config[__data_type] === 'donut' || this.hasType(targets, 'donut'); }; - var hasArcType = c3_chart_internal_fn.hasArcType = function (targets) { - return hasPieType.call(this, targets) || hasDonutType.call(this, targets) || hasGaugeType.call(this, targets); + c3_chart_internal_fn.hasArcType = function (targets) { + return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); }; - var isLineType = c3_chart_internal_fn.isLineType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return !this.config.data_types[id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; + c3_chart_internal_fn.isLineType = function (d) { + var config = this.config, id = isString(d) ? d : d.id; + return !config[__data_types][id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(config[__data_types][id]) >= 0; }; - var isStepType = c3_chart_internal_fn.isStepType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return ['step', 'area-step'].indexOf(this.config.data_types[id]) >= 0; + c3_chart_internal_fn.isStepType = function (d) { + var id = isString(d) ? d : d.id; + return ['step', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - var isSplineType = c3_chart_internal_fn.isSplineType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return ['spline', 'area-spline'].indexOf(this.config.data_types[id]) >= 0; + c3_chart_internal_fn.isSplineType = function (d) { + var id = isString(d) ? d : d.id; + return ['spline', 'area-spline'].indexOf(this.config[__data_types][id]) >= 0; }; - var isAreaType = c3_chart_internal_fn.isAreaType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return ['area', 'area-spline', 'area-step'].indexOf(this.config.data_types[id]) >= 0; + c3_chart_internal_fn.isAreaType = function (d) { + var id = isString(d) ? d : d.id; + return ['area', 'area-spline', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - var isBarType = c3_chart_internal_fn.isBarType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return this.config.data_types[id] === 'bar'; + c3_chart_internal_fn.isBarType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'bar'; }; - var isScatterType = c3_chart_internal_fn.isScatterType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return this.config.data_types[id] === 'scatter'; + c3_chart_internal_fn.isScatterType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'scatter'; }; - var isPieType = c3_chart_internal_fn.isPieType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return this.config.data_types[id] === 'pie'; + c3_chart_internal_fn.isPieType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'pie'; }; - var isGaugeType = c3_chart_internal_fn.isGaugeType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return this.config.data_types[id] === 'gauge'; + c3_chart_internal_fn.isGaugeType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'gauge'; }; - var isDonutType = c3_chart_internal_fn.isDonutType = function (d) { - var id = (typeof d === 'string') ? d : d.id; - return this.config.data_types[id] === 'donut'; + c3_chart_internal_fn.isDonutType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'donut'; }; - var isArcType = c3_chart_internal_fn.isArcType = function (d) { - return isPieType.call(this, d) || isDonutType.call(this, d) || isGaugeType.call(this, d); + c3_chart_internal_fn.isArcType = function (d) { + return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); }; - var lineData = c3_chart_internal_fn.lineData = function (d) { - return isLineType.call(this, d) ? [d] : []; + c3_chart_internal_fn.lineData = function (d) { + return this.isLineType(d) ? [d] : []; }; - var arcData = c3_chart_internal_fn.arcData = function (d) { - return isArcType.call(this, d.data) ? [d] : []; + c3_chart_internal_fn.arcData = function (d) { + return this.isArcType(d.data) ? [d] : []; }; /* not used function scatterData(d) { return isScatterType(d) ? d.values : []; } */ - var barData = c3_chart_internal_fn.barData = function (d) { - return isBarType.call(this, d) ? d.values : []; + c3_chart_internal_fn.barData = function (d) { + return this.isBarType(d) ? d.values : []; }; - var lineOrScatterData = c3_chart_internal_fn.lineOrScatterData = function (d) { - return isLineType.call(this, d) || isScatterType.call(this, d) ? d.values : []; + c3_chart_internal_fn.lineOrScatterData = function (d) { + return this.isLineType(d) || this.isScatterType(d) ? d.values : []; }; - var barOrLineData = c3_chart_internal_fn.barOrLineData = function (d) { - return isBarType.call(this, d) || isLineType.call(this, d) ? d.values : []; + c3_chart_internal_fn.barOrLineData = function (d) { + return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; @@ -3469,7 +3645,7 @@ } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = $$.dataTimeFormat($$.config.data_x_format).parse(date); + parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -3576,18 +3752,18 @@ c3_chart_internal_fn.getSubYScale = function (id) { return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; }; - var updateScales = c3_chart_internal_fn.updateScales = function () { - var $$ = this, c = $$.config, + c3_chart_internal_fn.updateScales = function () { + var $$ = this, config = $$.config, forInit = !$$.x; // update edges - $$.xMin = c.axis_rotated ? 1 : 0; - $$.xMax = c.axis_rotated ? $$.height : $$.width; - $$.yMin = c.axis_rotated ? 0 : $$.height; - $$.yMax = c.axis_rotated ? $$.width : 1; + $$.xMin = config[__axis_rotated] ? 1 : 0; + $$.xMax = config[__axis_rotated] ? $$.height : $$.width; + $$.yMin = config[__axis_rotated] ? 0 : $$.height; + $$.yMax = config[__axis_rotated] ? $$.width : 1; $$.subXMin = $$.xMin; $$.subXMax = $$.xMax; - $$.subYMin = c.axis_rotated ? 0 : $$.height2; - $$.subYMax = c.axis_rotated ? $$.width2 : 1; + $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; + $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; // update scales $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); @@ -3596,19 +3772,21 @@ $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes - $$.xAxisTickFormat = getXAxisTickFormat.call($$); - $$.xAxisTickValues = c.axis_x_tick_values ? c.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$.getYAxis($$.y, $$.yOrient, c.axis_y_tick_format, c.axis_y_ticks); - $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, c.axis_y2_tick_format, c.axis_y2_ticks); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); // Set initialized scales to brush and zoom if (!forInit) { if ($$.brush) { $$.brush.scale($$.subX); } - if (c.zoom_enabled) { $$.zoom.scale($$.x); } + if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } } // update for arc - if (isFunctionType(updateArc)) { updateArc.call($$); } + if (isFunction($$.updateArc)) { + $$.updateArc(); + } }; @@ -3616,14 +3794,14 @@ * c3.domain.js */ c3_chart_internal_fn.getYDomainMin = function (targets) { - var $$ = this, + var $$ = this, config = $$.config, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; - if ($$.config.data_groups.length > 0) { + if (config[__data_groups].length > 0) { hasNegativeValue = $$.hasNegativeValueInTargets(targets); - for (j = 0; j < $$.config.data_groups.length; j++) { + for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId - idsInGroup = $$.config.data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); if (idsInGroup.length === 0) { continue; } baseId = idsInGroup[0]; // Consider negative values @@ -3647,14 +3825,14 @@ return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); }; c3_chart_internal_fn.getYDomainMax = function (targets) { - var $$ = this, + var $$ = this, config = $$.config, ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; - if ($$.config.data_groups.length > 0) { + if (config[__data_groups].length > 0) { hasPositiveValue = $$.hasPositiveValueInTargets(targets); - for (j = 0; j < $$.config.data_groups.length; j++) { + for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId - idsInGroup = $$.config.data_groups[j].filter(function (id) { return ids.indexOf(id) >= 0; }); + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); if (idsInGroup.length === 0) { continue; } baseId = idsInGroup[0]; // Consider positive values @@ -3678,18 +3856,18 @@ return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; c3_chart_internal_fn.getYDomain = function (targets, axisId) { - var $$ = this, c = $$.config, + var $$ = this, config = $$.config, yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), - yMin = axisId === 'y2' ? c.axis_y2_min : c.axis_y_min, - yMax = axisId === 'y2' ? c.axis_y2_max : c.axis_y_max, + yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], + yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), domainLength, padding, padding_top, padding_bottom, - center = axisId === 'y2' ? c.axis_y2_center : c.axis_y_center, + center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = (hasBarType.call($$, yTargets) && c.bar_zerobased) || (hasAreaType.call($$, yTargets) && c.area_zerobased), - showHorizontalDataLabel = $$.hasDataLabel() && c.axis_rotated, - showVerticalDataLabel = $$.hasDataLabel() && !c.axis_rotated; + isZeroBased = ($$.hasBarType(yTargets) && config[__bar_zerobased]) || ($$.hasAreaType(yTargets) && config[__area_zerobased]), + showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], + showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } @@ -3725,13 +3903,13 @@ padding_top += lengths[1]; padding_bottom += lengths[0]; } - if (axisId === 'y' && c.axis_y_padding) { - padding_top = $$.getAxisPadding(c.axis_y_padding, 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(c.axis_y_padding, 'bottom', padding, domainLength); + if (axisId === 'y' && config[__axis_y_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); } - if (axisId === 'y2' && c.axis_y2_padding) { - padding_top = $$.getAxisPadding(c.axis_y2_padding, 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(c.axis_y2_padding, 'bottom', padding, domainLength); + if (axisId === 'y2' && config[__axis_y2_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); } // Bar/Area chart should be 0-based if all positive|negative if (isZeroBased) { @@ -3741,30 +3919,34 @@ return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; c3_chart_internal_fn.getXDomainMin = function (targets) { - var $$ = this, c = $$.config; - return c.axis_x_min ? ($$.isTimeSeries ? this.parseDate(c.axis_x_min) : c.axis_x_min) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); + var $$ = this, config = $$.config; + return config[__axis_x_min] ? + ($$.isTimeSeries ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : + $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; c3_chart_internal_fn.getXDomainMax = function (targets) { - var $$ = this, c = $$.config; - return c.axis_x_max ? ($$.isTimeSeries ? this.parseDate(c.axis_x_max) : c.axis_x_max) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); + var $$ = this, config = $$.config; + return config[__axis_x_max] ? + ($$.isTimeSeries ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : + $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; c3_chart_internal_fn.getXDomainPadding = function (targets) { - var $$ = this, c = $$.config, + var $$ = this, config = $$.config, edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; if ($$.isCategorized) { padding = 0; - } else if (hasBarType.call(this, targets)) { - maxDataCount = this.getMaxDataCount(); + } else if ($$.hasBarType(targets)) { + maxDataCount = $$.getMaxDataCount(); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { padding = diff * 0.01; } - if (typeof c.axis_x_padding === 'object' && notEmpty(c.axis_x_padding)) { - paddingLeft = isValue(c.axis_x_padding.left) ? c.axis_x_padding.left : padding; - paddingRight = isValue(c.axis_x_padding.right) ? c.axis_x_padding.right : padding; - } else if (typeof c.axis_x_padding === 'number') { - paddingLeft = paddingRight = c.axis_x_padding; + if (typeof config[__axis_x_padding] === 'object' && notEmpty(config[__axis_x_padding])) { + paddingLeft = isValue(config[__axis_x_padding].left) ? config[__axis_x_padding].left : padding; + paddingRight = isValue(config[__axis_x_padding].right) ? config[__axis_x_padding].right : padding; + } else if (typeof config[__axis_x_padding] === 'number') { + paddingLeft = paddingRight = config[__axis_x_padding]; } else { paddingLeft = paddingRight = padding; } @@ -3790,17 +3972,17 @@ return [min, max]; }; c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { - var $$ = this; + var $$ = this, config = $$.config; if (withUpdateOrgXDomain) { $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); $$.orgXDomain = $$.x.domain(); - if ($$.config.zoom_enabled) { $$.zoom.scale($$.x).updateScaleExtent(); } + if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } $$.subX.domain($$.x.domain()); if ($$.brush) { $$.brush.scale($$.subX); } } if (withUpdateXDomain) { $$.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(); } } return $$.x.domain(); }; @@ -3809,21 +3991,21 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { - var $$ = this, + var $$ = this, config = $$.config, axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); // 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; + axis.tickCentered(config[__axis_x_tick_centered]); + if (isEmpty(config[__axis_x_tick_culling])) { + config[__axis_x_tick_culling] = false; } } else { // TODO: move this to c3_axis axis.tickOffset = function () { var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), - base = diff ? diff : ($$.config.axis_rotated ? $$.height : $$.width); + base = diff ? diff : (config[__axis_rotated] ? $$.height : $$.width); return (base / $$.getMaxDataCount()) / 2; }; } @@ -3834,55 +4016,55 @@ return c3_axis(this.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); }; c3_chart_internal_fn.getAxisId = function (id) { - var c = this.config; - return id in c.data_axes ? c.data_axes[id] : 'y'; + var config = this.config; + return id in config[__data_axes] ? config[__data_axes][id] : 'y'; }; - var getXAxisTickFormat = c3_chart_internal_fn.getXAxisTickFormat = function () { - var $$ = this, c = $$.config, + c3_chart_internal_fn.getXAxisTickFormat = function () { + var $$ = this, config = $$.config, format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; - if (c.axis_x_tick_format) { - if (typeof c.axis_x_tick_format === 'function') { - format = c.axis_x_tick_format; + if (config[__axis_x_tick_format]) { + if (isFunction(config[__axis_x_tick_format])) { + format = config[__axis_x_tick_format]; } else if ($$.isTimeSeries) { format = function (date) { - return date ? $$.axisTimeFormat(c.axis_x_tick_format)(date) : ""; + return date ? $$.axisTimeFormat(config[__axis_x_tick_format])(date) : ""; }; } } return function (v) { return format.call($$, v); }; }; - var getAxisLabelOptionByAxisId = c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { - var $$ = this, c = $$.config, option; + c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { + var $$ = this, config = $$.config, option; if (axisId === 'y') { - option = c.axis_y_label; + option = config[__axis_y_label]; } else if (axisId === 'y2') { - option = c.axis_y2_label; + option = config[__axis_y2_label]; } else if (axisId === 'x') { - option = c.axis_x_label; + option = config[__axis_x_label]; } return option; }; - var getAxisLabelText = c3_chart_internal_fn.getAxisLabelText = function (axisId) { - var option = getAxisLabelOptionByAxisId.call(this, axisId); - return typeof option === 'string' ? option : option ? option.text : null; + c3_chart_internal_fn.getAxisLabelText = function (axisId) { + var option = this.getAxisLabelOptionByAxisId(axisId); + return isString(option) ? option : option ? option.text : null; }; - var setAxisLabelText = c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { - var $$ = this, c = $$.config, - option = getAxisLabelOptionByAxisId.call($$, axisId); - if (typeof option === 'string') { + c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { + var $$ = this, config = $$.config, + option = $$.getAxisLabelOptionByAxisId(axisId); + if (isString(option)) { if (axisId === 'y') { - c.axis_y_label = text; + config[__axis_y_label] = text; } else if (axisId === 'y2') { - c.axis_y2_label = text; + config[__axis_y2_label] = text; } else if (axisId === 'x') { - c.axis_x_label = text; + config[__axis_x_label] = text; } } else if (option) { option.text = text; } }; - var getAxisLabelPosition = c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { - var option = getAxisLabelOptionByAxisId.call(this, axisId), + c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { + var option = this.getAxisLabelOptionByAxisId(axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { isInner: position.indexOf('inner') >= 0, @@ -3895,28 +4077,28 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - var getXAxisLabelPosition = c3_chart_internal_fn.getXAxisLabelPosition = function () { - return getAxisLabelPosition.call(this, 'x', this.config.axis_rotated ? 'inner-top' : 'inner-right'); + c3_chart_internal_fn.getXAxisLabelPosition = function () { + return this.getAxisLabelPosition('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); }; - var getYAxisLabelPosition = c3_chart_internal_fn.getYAxisLabelPosition = function () { - return getAxisLabelPosition.call(this, 'y', this.config.axis_rotated ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getYAxisLabelPosition = function () { + return this.getAxisLabelPosition('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - var getY2AxisLabelPosition = c3_chart_internal_fn.getY2AxisLabelPosition = function () { - return getAxisLabelPosition.call(this, 'y2', this.config.axis_rotated ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getY2AxisLabelPosition = function () { + return this.getAxisLabelPosition('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - var getAxisLabelPositionById = c3_chart_internal_fn.getAxisLabelPositionById = function (id) { - return id === 'y2' ? getY2AxisLabelPosition.call(this) : id === 'y' ? getYAxisLabelPosition.call(this) : getXAxisLabelPosition.call(this); + c3_chart_internal_fn.getAxisLabelPositionById = function (id) { + return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); }; - var textForXAxisLabel = c3_chart_internal_fn.textForXAxisLabel = function () { - return getAxisLabelText.call(this, 'x'); + c3_chart_internal_fn.textForXAxisLabel = function () { + return this.getAxisLabelText('x'); }; - var textForYAxisLabel = c3_chart_internal_fn.textForYAxisLabel = function () { - return getAxisLabelText.call(this, 'y'); + c3_chart_internal_fn.textForYAxisLabel = function () { + return this.getAxisLabelText('y'); }; - var textForY2AxisLabel = c3_chart_internal_fn.textForY2AxisLabel = function () { - return getAxisLabelText.call(this, 'y2'); + c3_chart_internal_fn.textForY2AxisLabel = function () { + return this.getAxisLabelText('y2'); }; - var xForAxisLabel = c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -3924,76 +4106,76 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - var dxForAxisLabel = c3_chart_internal_fn.dxForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.dxForAxisLabel = function (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"; } }; - var textAnchorForAxisLabel = c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { + c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - var xForXAxisLabel = c3_chart_internal_fn.xForXAxisLabel = function () { - return xForAxisLabel.call(this, !this.config.axis_rotated, getXAxisLabelPosition.call(this)); + c3_chart_internal_fn.xForXAxisLabel = function () { + return this.xForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); }; - var xForYAxisLabel = c3_chart_internal_fn.xForYAxisLabel = function () { - return xForAxisLabel.call(this, this.config.axis_rotated, getYAxisLabelPosition.call(this)); + c3_chart_internal_fn.xForYAxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); }; - var xForY2AxisLabel = c3_chart_internal_fn.xForY2AxisLabel = function () { - return xForAxisLabel.call(this, this.config.axis_rotated, getY2AxisLabelPosition.call(this)); + c3_chart_internal_fn.xForY2AxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); }; - var dxForXAxisLabel = c3_chart_internal_fn.dxForXAxisLabel = function () { - return dxForAxisLabel.call(this, !this.config.axis_rotated, getXAxisLabelPosition.call(this)); + c3_chart_internal_fn.dxForXAxisLabel = function () { + return this.dxForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); }; - var dxForYAxisLabel = c3_chart_internal_fn.dxForYAxisLabel = function () { - return dxForAxisLabel.call(this, this.config.axis_rotated, getYAxisLabelPosition.call(this)); + c3_chart_internal_fn.dxForYAxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); }; - var dxForY2AxisLabel = c3_chart_internal_fn.dxForY2AxisLabel = function () { - return dxForAxisLabel.call(this, this.config.axis_rotated, getY2AxisLabelPosition.call(this)); + c3_chart_internal_fn.dxForY2AxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); }; - var dyForXAxisLabel = c3_chart_internal_fn.dyForXAxisLabel = function () { - var $$ = this, c = $$.config, - position = getXAxisLabelPosition.call($$); - if (c.axis_rotated) { + c3_chart_internal_fn.dyForXAxisLabel = function () { + var $$ = this, config = $$.config, + position = $$.getXAxisLabelPosition(); + if (config[__axis_rotated]) { return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); } else { - return position.isInner ? "-0.5em" : c.axis_x_height ? c.axis_x_height - 10 : "3em"; + return position.isInner ? "-0.5em" : config[__axis_x_height] ? config[__axis_x_height] - 10 : "3em"; } }; - var dyForYAxisLabel = c3_chart_internal_fn.dyForYAxisLabel = function () { + c3_chart_internal_fn.dyForYAxisLabel = function () { var $$ = this, - position = getYAxisLabelPosition.call($$); - if ($$.config.axis_rotated) { + position = $$.getYAxisLabelPosition(); + if ($$.config[__axis_rotated]) { return position.isInner ? "-0.5em" : "3em"; } else { return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); } }; - var dyForY2AxisLabel = c3_chart_internal_fn.dyForY2AxisLabel = function () { + c3_chart_internal_fn.dyForY2AxisLabel = function () { var $$ = this, - position = getY2AxisLabelPosition.call($$); - if ($$.config.axis_rotated) { + position = $$.getY2AxisLabelPosition(); + if ($$.config[__axis_rotated]) { return position.isInner ? "1.2em" : "-2.2em"; } else { return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); } }; - var textAnchorForXAxisLabel = c3_chart_internal_fn.textAnchorForXAxisLabel = function () { + c3_chart_internal_fn.textAnchorForXAxisLabel = function () { var $$ = this; - return textAnchorForAxisLabel.call($$, !$$.config.axis_rotated, getXAxisLabelPosition.call($$)); + return $$.textAnchorForAxisLabel(!$$.config[__axis_rotated], $$.getXAxisLabelPosition()); }; - var textAnchorForYAxisLabel = c3_chart_internal_fn.textAnchorForYAxisLabel = function () { + c3_chart_internal_fn.textAnchorForYAxisLabel = function () { var $$ = this; - return textAnchorForAxisLabel.call($$, $$.config.axis_rotated, getYAxisLabelPosition.call($$)); + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getYAxisLabelPosition()); }; - var textAnchorForY2AxisLabel = c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { + c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { var $$ = this; - return textAnchorForAxisLabel.call($$, $$.config.axis_rotated, getY2AxisLabelPosition.call($$)); + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getY2AxisLabelPosition()); }; c3_chart_internal_fn.xForRotatedTickText = function (r) { @@ -4012,19 +4194,19 @@ }; c3_chart_internal_fn.getMaxTickWidth = function (id) { - var $$ = this; - var maxWidth = 0, targetsToShow, scale, axis; + var $$ = this, config = $$.config, + maxWidth = 0, targetsToShow, scale, axis; if ($$.svg) { targetsToShow = $$.filterTargetsToShow($$.data.targets); if (id === 'y') { scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); - axis = $$.getYAxis(scale, $$.yOrient, $$.config.axis_y_tick_format, $$.config.axis_y_ticks); + axis = $$.getYAxis(scale, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); } else if (id === 'y2') { scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); - axis = $$.getYAxis(scale, $$.y2Orient, $$.config.axis_y2_tick_format, $$.config.axis_y2_ticks); + axis = $$.getYAxis(scale, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); } else { scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); - axis = $$.getXAxis(scale, $$.xOrient, getXAxisTickFormat.call($$), $$.config.axis_x_tick_values ? $$.config.axis_x_tick_values : $$.xAxis.tickValues()); + axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4043,20 +4225,20 @@ axisYLabel = $$.main.select('.' + CLASS.axisY + ' .' + CLASS.axisYLabel), axisY2Label = $$.main.select('.' + CLASS.axisY2 + ' .' + CLASS.axisY2Label); (withTransition ? axisXLabel.transition() : axisXLabel) - .attr("x", generateCall(xForXAxisLabel, $$)) - .attr("dx", generateCall(dxForXAxisLabel, $$)) - .attr("dy", generateCall(dyForXAxisLabel, $$)) - .text(generateCall(textForXAxisLabel, $$)); + .attr("x", generateCall($$.xForXAxisLabel, $$)) + .attr("dx", generateCall($$.dxForXAxisLabel, $$)) + .attr("dy", generateCall($$.dyForXAxisLabel, $$)) + .text(generateCall($$.textForXAxisLabel, $$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", generateCall(xForYAxisLabel, $$)) - .attr("dx", generateCall(dxForYAxisLabel, $$)) - .attr("dy", generateCall(dyForYAxisLabel, $$)) - .text(generateCall(textForYAxisLabel, $$)); + .attr("x", generateCall($$.xForYAxisLabel, $$)) + .attr("dx", generateCall($$.dxForYAxisLabel, $$)) + .attr("dy", generateCall($$.dyForYAxisLabel, $$)) + .text(generateCall($$.textForYAxisLabel, $$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", generateCall(xForY2AxisLabel, $$)) - .attr("dx", generateCall(dxForY2AxisLabel, $$)) - .attr("dy", generateCall(dyForY2AxisLabel, $$)) - .text(generateCall(textForY2AxisLabel, $$)); + .attr("x", generateCall($$.xForY2AxisLabel, $$)) + .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) + .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) + .text(generateCall($$.textForY2AxisLabel, $$)); }; c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { @@ -4068,7 +4250,7 @@ var $$ = this; var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { - targetCount = typeof tickCount === 'function' ? tickCount() : tickCount; + targetCount = isFunction(tickCount) ? tickCount() : tickCount; // compute ticks according to $$.config.axis_x_tick_count if (targetCount === 1) { tickValues = [xs[0]]; @@ -4097,42 +4279,42 @@ * c3.region.js */ c3_chart_internal_fn.regionX = function (d) { - var $$ = this, + var $$ = this, config = $$.config, xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { - xPos = $$.config.axis_rotated ? ('start' in d ? yScale(d.start) : 0) : 0; + xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = $$.config.axis_rotated ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); } return xPos; }; c3_chart_internal_fn.regionY = function (d) { - var $$ = this, + var $$ = this, config = $$.config, yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { - yPos = $$.config.axis_rotated ? 0 : ('end' in d ? yScale(d.end) : 0); + yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = $$.config.axis_rotated ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; + yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; } return yPos; }; c3_chart_internal_fn.regionWidth = function (d) { - var $$ = this, + var $$ = this, config = $$.config, start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { - end = $$.config.axis_rotated ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; + end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = $$.config.axis_rotated ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; c3_chart_internal_fn.regionHeight = function (d) { - var $$ = this, + var $$ = this, config = $$.config, start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { - end = $$.config.axis_rotated ? $$.height : ('start' in d ? yScale(d.start) : $$.height); + end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = $$.config.axis_rotated ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; + end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; @@ -4145,36 +4327,36 @@ //-- c3.arc.js --// - var initPie = c3_chart_internal_fn.initPie = function () { - var $$ = this, d3 = $$.d3, c = $$.config; + c3_chart_internal_fn.initPie = function () { + var $$ = this, d3 = $$.d3, config = $$.config; $$.pie = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); }); - if (!c.data_order || !c.pie_sort || !c.donut_sort) { + if (!config[__data_order] || !config[__pie_sort] || !config[__donut_sort]) { $$.pie.sort(null); } }; - var updateRadius = c3_chart_internal_fn.updateRadius = function () { - var $$ = this, - w = $$.config.gauge_width || $$.config.donut_width; + c3_chart_internal_fn.updateRadius = function () { + var $$ = this, config = $$.config, + w = config[__gauge_width] || config[__donut_width]; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = hasDonutType.call($$, $$.data.targets) || hasGaugeType.call($$, $$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; }; - var updateArc = c3_chart_internal_fn.updateArc = function () { + c3_chart_internal_fn.updateArc = function () { var $$ = this; - $$.svgArc = getSvgArc.call($$); - $$.svgArcExpanded = getSvgArcExpanded.call($$); - $$.svgArcExpandedSub = getSvgArcExpanded.call($$, 0.98); + $$.svgArc = $$.getSvgArc(); + $$.svgArcExpanded = $$.getSvgArcExpanded(); + $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); }; - var updateAngle = c3_chart_internal_fn.updateAngle = function (d) { - var $$ = this, + c3_chart_internal_fn.updateAngle = function (d) { + var $$ = this, config = $$.config, found = false, index = 0; - $$.pie($$.filterTargetsToShow($$.data.targets)).sort(descByStartAngle).forEach(function (t) { + $$.pie($$.filterTargetsToShow($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { found = true; d = t; @@ -4185,8 +4367,8 @@ if (isNaN(d.endAngle)) { d.endAngle = d.startAngle; } - if (isGaugeType.call($$, d.data)) { - var gMin = $$.config.gauge_min, gMax = $$.config.gauge_max, + if ($$.isGaugeType(d.data)) { + var gMin = config[__gauge_min], gMax = config[__gauge_max], gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); @@ -4195,13 +4377,13 @@ return found ? d : null; }; - var getSvgArc = c3_chart_internal_fn.getSvgArc = function () { + c3_chart_internal_fn.getSvgArc = function () { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { var updated; if (withoutUpdate) { return arc(d); } // for interpolate - updated = updateAngle.call($$, d); + updated = $$.updateAngle(d); return updated ? arc(updated) : "M 0 0"; }; // TODO: extends all function @@ -4209,24 +4391,24 @@ return newArc; }; - var getSvgArcExpanded = c3_chart_internal_fn.getSvgArcExpanded = function (rate) { + c3_chart_internal_fn.getSvgArcExpanded = function (rate) { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { - var updated = updateAngle.call($$, d); + var updated = $$.updateAngle(d); return updated ? arc(updated) : "M 0 0"; }; }; - var getArc = c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { - return force || isArcType.call(this, d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; + c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { + return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; }; - var transformForArcLabel = c3_chart_internal_fn.transformForArcLabel = function (d) { + c3_chart_internal_fn.transformForArcLabel = function (d) { var $$ = this, - updated = updateAngle.call($$, d), c, x, y, h, ratio, translate = ""; - if (updated && !hasGaugeType.call($$, $$.data.targets)) { + updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !$$.hasGaugeType($$.data.targets)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4238,46 +4420,46 @@ return translate; }; - var getArcRatio = c3_chart_internal_fn.getArcRatio = function (d) { + c3_chart_internal_fn.getArcRatio = function (d) { var $$ = this, - whole = hasGaugeType.call(this, $$.data.targets) ? Math.PI : (Math.PI * 2); + whole = $$.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; - var convertToArcData = c3_chart_internal_fn.convertToArcData = function (d) { + c3_chart_internal_fn.convertToArcData = function (d) { return this.addName({ id: d.data.id, value: d.value, - ratio: getArcRatio.call(this, d), + ratio: this.getArcRatio(d), index: d.index }); }; - var textForArcLabel = c3_chart_internal_fn.textForArcLabel = function (d) { + c3_chart_internal_fn.textForArcLabel = function (d) { var $$ = this, updated, value, ratio, format; - if (! shouldShowArcLabel.call($$)) { return ""; } - updated = updateAngle.call($$, d); + if (! $$.shouldShowArcLabel()) { return ""; } + updated = $$.updateAngle(d); value = updated ? updated.value : null; - ratio = getArcRatio.call($$, updated); - if (! hasGaugeType.call($$, $$.data.targets) && ! meetsArcLabelThreshold.call($$, ratio)) { return ""; } - format = getArcLabelFormat.call($$); + ratio = $$.getArcRatio(updated); + if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } + format = $$.getArcLabelFormat(); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; - var expandArc = c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { + c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)), + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); - if (shouldExpand.call($$, id)) { + if ($$.shouldExpand(id)) { target.selectAll('path') .transition().duration(50) .attr("d", $$.svgArcExpanded) .transition().duration(100) .attr("d", $$.svgArcExpandedSub) .each(function (d) { - if (isDonutType.call($$, d.data)) { + if ($$.isDonutType(d.data)) { // callback here } }); @@ -4287,9 +4469,9 @@ } }; - var unexpandArc = c3_chart_internal_fn.unexpandArc = function (id) { + c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + selectorTarget.call($$, id)); + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); target.selectAll('path.' + CLASS.arc) .transition().duration(50) .attr("d", $$.svgArc); @@ -4297,59 +4479,59 @@ .style("opacity", 1); }; - var shouldExpand = c3_chart_internal_fn.shouldExpand = function (id) { - var $$ = this; - return (isDonutType.call($$, id) && $$.config.donut_expand) || (isGaugeType.call($$, id) && $$.config.gauge_expand) || (isPieType.call($$, id) && $$.config.pie_expand); + c3_chart_internal_fn.shouldExpand = function (id) { + var $$ = this, config = $$.config; + return ($$.isDonutType(id) && config[__donut_expand]) || ($$.isGaugeType(id) && config[__gauge_expand]) || ($$.isPieType(id) && config[__pie_expand]); }; - var shouldShowArcLabel = c3_chart_internal_fn.shouldShowArcLabel = function () { - var $$ = this, shouldShow = true; - if (hasDonutType.call($$, $$.data.targets)) { - shouldShow = $$.config.donut_label_show; - } else if (hasPieType.call($$, $$.data.targets)) { - shouldShow = $$.config.pie_label_show; + c3_chart_internal_fn.shouldShowArcLabel = function () { + var $$ = this, config = $$.config, shouldShow = true; + if ($$.hasDonutType($$.data.targets)) { + shouldShow = config[__donut_label_show]; + } else if ($$.hasPieType($$.data.targets)) { + shouldShow = config[__pie_label_show]; } // when gauge, always true return shouldShow; }; - var meetsArcLabelThreshold = c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { - var $$ = this, c = $$.config, - threshold = hasDonutType.call(this, $$.data.targets) ? c.donut_label_threshold : c.pie_label_threshold; + c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { + var $$ = this, config = $$.config, + threshold = $$.hasDonutType($$.data.targets) ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; - var getArcLabelFormat = c3_chart_internal_fn.getArcLabelFormat = function () { - var $$ = this, - format = $$.config.pie_label_format; - if (hasGaugeType.call($$, $$.data.targets)) { - format = $$.config.gauge_label_format; - } else if (hasDonutType.call($$, $$.data.targets)) { - format = $$.config.donut_label_format; + c3_chart_internal_fn.getArcLabelFormat = function () { + var $$ = this, config = $$.config, + format = config[__pie_label_format]; + if ($$.hasGaugeType($$.data.targets)) { + format = config[__gauge_label_format]; + } else if ($$.hasDonutType($$.data.targets)) { + format = config[__donut_label_format]; } return format; }; - var getArcTitle = c3_chart_internal_fn.getArcTitle = function () { + c3_chart_internal_fn.getArcTitle = function () { var $$ = this; - return hasDonutType.call($$, $$.data.targets) ? $$.config.donut_title : ""; + return $$.hasDonutType($$.data.targets) ? $$.config[__donut_title] : ""; }; - var descByStartAngle = c3_chart_internal_fn.descByStartAngle = function (a, b) { + c3_chart_internal_fn.descByStartAngle = function (a, b) { return a.startAngle - b.startAngle; }; - var updateTargetsForArc = c3_chart_internal_fn.updateTargetsForArc = function (targets) { + c3_chart_internal_fn.updateTargetsForArc = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) .data($$.pie(targets)) - .attr("class", generateCall(classChartArc, $$)); + .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", generateCall(classChartArc, $$)); + .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter.append('g') - .attr('class', generateCall(classArcs, $$)); + .attr('class', generateCall($$.classArcs, $$)); mainPieEnter.append("text") - .attr("dy", hasGaugeType.call($$, $$.data.targets) ? "-0.35em" : ".35em") + .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") .style("opacity", 0) .style("text-anchor", "middle") .style("pointer-events", "none"); @@ -4357,7 +4539,7 @@ //mainPieUpdate.exit().remove(); }; - var initArc = c3_chart_internal_fn.initArc = function () { + c3_chart_internal_fn.initArc = function () { var $$ = this, arcs; arcs = $$.main.select('.' + CLASS.chart).append("g") .attr("class", CLASS.chartArcs) @@ -4365,21 +4547,21 @@ arcs.append('text') .attr('class', CLASS.chartArcsTitle) .style("text-anchor", "middle") - .text(getArcTitle.call($$)); + .text($$.getArcTitle()); }; - var redrawArc = c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { - var $$ = this, d3 = $$.d3, main = $$.main, + c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { + var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(generateCall(arcData, $$)); + .data(generateCall($$.arcData, $$)); mainArc.enter().append('path') - .attr("class", generateCall(classArc, $$)) + .attr("class", generateCall($$.classArc, $$)) .style("fill", function (d) { return $$.color(d.data); }) - .style("cursor", function (d) { return $$.config.data_selection_isselectable(d) ? "pointer" : null; }) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) .style("opacity", 0) .each(function (d) { - if (isGaugeType.call($$, d.data)) { + if ($$.isGaugeType(d.data)) { d.startAngle = d.endAngle = -1 * (Math.PI / 2); } this._current = d; @@ -4389,16 +4571,16 @@ if ($$.transiting) { // skip while transiting return; } - updated = updateAngle.call($$, d); - arcData = convertToArcData.call($$, updated); + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); // transitions - expandArc.call($$, updated.data.id); + $$.expandArc(updated.data.id); $$.toggleFocusLegend(updated.data.id, true); - $$.config.data_onmouseover.call(c3, arcData, this); + $$.config[__data_onmouseover](arcData, this); }) .on('mousemove', function (d) { - var updated = updateAngle.call($$, d), - arcData = convertToArcData.call($$, updated), + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated), selectedData = [arcData]; $$.showTooltip(selectedData, d3.mouse(this)); }) @@ -4407,26 +4589,26 @@ if ($$.transiting) { // skip while transiting return; } - updated = updateAngle.call($$, d); - arcData = convertToArcData.call($$, updated); + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); // transitions - unexpandArc.call($$, updated.data.id); + $$.unexpandArc(updated.data.id); $$.revertLegend(); $$.hideTooltip(); - $$.config.data_onmouseout.call(c3, arcData, this); + $$.config[__data_onmouseout](arcData, this); }) .on('click', function (d, i) { - var updated = updateAngle.call($$, d), - arcData = convertToArcData.call($$, updated); + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated); $$.toggleShape(this, arcData, i); // onclick called in toogleShape() }); mainArc - .attr("transform", function (d) { return !isGaugeType.call($$, d.data) && withTransform ? "scale(0)" : ""; }) + .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) .style("opacity", function (d) { return d === this._current ? 0 : 1; }) .each(function () { $$.transiting = true; }) .transition().duration(duration) .attrTween("d", function (d) { - var updated = updateAngle.call($$, d), interpolate; + var updated = $$.updateAngle(d), interpolate; if (! updated) { return function () { return "M 0 0"; }; } @@ -4441,7 +4623,7 @@ } interpolate = d3.interpolate(this._current, updated); this._current = interpolate(0); - return function (t) { return getArc.call($$, interpolate(t), true); }; + return function (t) { return $$.getArc(interpolate(t), true); }; }) .attr("transform", withTransform ? "scale(1)" : "") .style("fill", function (d) { @@ -4456,26 +4638,26 @@ .remove(); main.selectAll('.' + CLASS.chartArc).select('text') .style("opacity", 0) - .attr('class', function (d) { return isGaugeType.call($$, d.data) ? CLASS.gaugeValue : ''; }) - .text(generateCall(textForArcLabel, $$)) - .attr("transform", generateCall(transformForArcLabel, $$)) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .text(generateCall($$.textForArcLabel, $$)) + .attr("transform", generateCall($$.transformForArcLabel, $$)) .transition().duration(duration) - .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && isArcType.call($$, d.data) ? 1 : 0; }); + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS.chartArcsTitle) - .style("opacity", hasDonutType.call($$, $$.data.targets) || hasGaugeType.call($$, $$.data.targets) ? 1 : 0); + .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); }; //-- gauge.js --// - var initGauge = c3_chart_internal_fn.initGauge = function () { - var $$ = this, c = $$.config, arcs; - if (hasGaugeType.call($$, $$.data.targets)) { + c3_chart_internal_fn.initGauge = function () { + var $$ = this, config = $$.config, arcs; + if ($$.hasGaugeType($$.data.targets)) { arcs.append('path') .attr("class", CLASS.chartArcsBackground) .attr("d", function () { var d = { - data: [{value: c.gauge_max}], + data: [{value: config[__gauge_max]}], startAngle: -1 * (Math.PI / 2), endAngle: Math.PI / 2 }; @@ -4486,21 +4668,21 @@ .attr("class", CLASS.chartArcsGaugeUnit) .style("text-anchor", "middle") .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_units : ''); + .text(config[__gauge_label_show] ? config[__gauge_units] : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") .attr("class", CLASS.chartArcsGaugeMin) .style("text-anchor", "middle") .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_min : ''); + .text(config[__gauge_label_show] ? config[__gauge_min] : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") .attr("class", CLASS.chartArcsGaugeMax) .style("text-anchor", "middle") .style("pointer-events", "none") - .text(c.gauge_label_show ? c.gauge_max : ''); + .text(config[__gauge_label_show] ? config[__gauge_max] : ''); } }; @@ -4527,22 +4709,22 @@ //-- subchart.js --// - var initBrush = c3_chart_internal_fn.initBrush = function () { + c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; - $$.brush = d3.svg.brush().on("brush", function () { redrawForBrush.call($$); }); + $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + CLASS.brush).call(this); } + if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } return this; }; $$.brush.scale = function (scale) { - return $$.config.axis_rotated ? this.y(scale) : this.x(scale); + return $$.config[__axis_rotated] ? this.y(scale) : this.x(scale); }; }; - var initSubchart = c3_chart_internal_fn.initSubchart = function () { - var $$ = this, c = $$.config, + c3_chart_internal_fn.initSubchart = function () { + var $$ = this, config = $$.config, context = $$.context = $$.svg.append("g").attr("transform", $$.translate.context); - if (!c.subchart_show) { + if (!config[__subchart_show]) { context.style('visibility', 'hidden'); } @@ -4565,52 +4747,52 @@ .attr("class", CLASS.brush) .call($$.brush) .selectAll("rect") - .attr(c.axis_rotated ? "width" : "height", c.axis_rotated ? $$.width2 : $$.height2); + .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = context.append("g") .attr("class", CLASS.axisX) .attr("transform", $$.translate.subx) - .attr("clip-path", c.axis_rotated ? "" : $$.clipPathForXAxis); + .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); }; - var updateTargetsForSubchart = c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { - var $$ = this, context = $$.context, c = $$.config, + c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { + var $$ = this, context = $$.context, config = $$.config, contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; - if (c.subchart_show) { + if (config[__subchart_show]) { contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr('class', generateCall(classChartBar, $$)); + .attr('class', generateCall($$.classChartBar, $$)); contextBarEnter = contextBarUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall(classChartBar, $$)); + .attr('class', generateCall($$.classChartBar, $$)); // Bars for each data contextBarEnter.append('g') - .attr("class", generateCall(classBars, $$)); + .attr("class", generateCall($$.classBars, $$)); //-- Line --// contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr('class', generateCall(classChartLine, $$)); + .attr('class', generateCall($$.classChartLine, $$)); contextLineEnter = contextLineUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall(classChartLine, $$)); + .attr('class', generateCall($$.classChartLine, $$)); // Lines for each data contextLineEnter.append("g") - .attr("class", generateCall(classLines, $$)); + .attr("class", generateCall($$.classLines, $$)); // Area contextLineEnter.append("g") - .attr("class", generateCall(classAreas, $$)); + .attr("class", generateCall($$.classAreas, $$)); } }; - var redrawSubchart = c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { - var $$ = this, d3 = $$.d3, context = $$.context, c = $$.config, + c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { + var $$ = this, d3 = $$.d3, context = $$.context, config = $$.config, contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; // subchart - if (c.subchart_show) { + if (config[__subchart_show]) { // reflect main chart to extent on subchart if zoomed if (d3.event && d3.event.type === 'zoom') { $$.brush.extent($$.x.orgDomain()).update(); @@ -4619,8 +4801,8 @@ if (withSubchart) { // rotate tick text if needed - if (!c.axis_rotated && c.axis_x_tick_rotate) { - $$.rotateTickText($$.axes.subx, transitions.axisSubX, $$.config.axis_x_tick_rotate); + if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { + $$.rotateTickText($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); } // extent rect @@ -4633,13 +4815,13 @@ drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(generateCall(barData, $$)); + .data(generateCall($$.barData, $$)); contextBar.enter().append('path') - .attr("class", generateCall(classBar, $$)) + .attr("class", generateCall($$.classBar, $$)) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style("opacity", generateCall(initialOpacity, $$)) + .style("opacity", generateCall($$.initialOpacity, $$)) .transition().duration(duration) .attr('d', drawBarOnSub) .style('opacity', 1); @@ -4648,12 +4830,12 @@ .remove(); // lines contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(generateCall(lineData, $$)); + .data(generateCall($$.lineData, $$)); contextLine.enter().append('path') - .attr('class', generateCall(classLine, $$)) + .attr('class', generateCall($$.classLine, $$)) .style('stroke', $$.color); contextLine - .style("opacity", generateCall(initialOpacity, $$)) + .style("opacity", generateCall($$.initialOpacity, $$)) .transition().duration(duration) .attr("d", drawLineOnSub) .style('opacity', 1); @@ -4662,9 +4844,9 @@ .remove(); // area contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(generateCall(lineData, $$)); + .data(generateCall($$.lineData, $$)); contextArea.enter().append('path') - .attr("class", generateCall(classArea, $$)) + .attr("class", generateCall($$.classArea, $$)) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea @@ -4679,7 +4861,7 @@ } } }; - var redrawForBrush = c3_chart_internal_fn.redrawForBrush = function () { + c3_chart_internal_fn.redrawForBrush = function () { var $$ = this, x = $$.x; $$.redraw({ withTransition: false, @@ -4687,9 +4869,9 @@ withSubchart: false, withUpdateXDomain: true }); - $$.config.subchart_onbrush.call($$, x.orgDomain()); + $$.config[__subchart_onbrush].call($$, x.orgDomain()); }; - var transformContext = c3_chart_internal_fn.transformContext = function (withTransition, transitions) { + c3_chart_internal_fn.transformContext = function (withTransition, transitions) { var $$ = this, subXAxis; if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; @@ -4706,9 +4888,9 @@ * c3.zoom.js */ c3_chart_internal_fn.updateZoom = function () { - var $$ = this, z = $$.config.zoom_enabled ? $$.zoom : function () {}; - $$.main.select('.' + CLASS.zoomRect).call(z); - $$.main.selectAll('.' + CLASS.eventRect).call(z); + var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; + $$.main.select('.' + $$.CLASS.zoomRect).call(z); + $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); }; @@ -4720,8 +4902,11 @@ var isValue = c3_chart_internal_fn.isValue = function (v) { return v || v === 0; }, - isFunctionType = c3_chart_internal_fn.isFunctionType = function (type) { - return type === 'function'; + isFunction = c3_chart_internal_fn.isFunction = function (o) { + return typeof o === 'function'; + }, + isString = c3_chart_internal_fn.isString = function (o) { + return typeof o === 'string'; }, isUndefined = c3_chart_internal_fn.isUndefined = function (v) { return typeof v === 'undefined'; @@ -4739,13 +4924,13 @@ return d[1] - d[0]; }, isEmpty = c3_chart_internal_fn.isEmpty = function (o) { - return !o || (typeof o === 'string' && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); + return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); }, notEmpty = c3_chart_internal_fn.notEmpty = function (o) { return Object.keys(o).length > 0; }, getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { - return typeof options[key] !== 'undefined' ? options[key] : defaultValue; + return isDefined(options[key]) ? options[key] : defaultValue; }, hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { var found = false; @@ -4760,7 +4945,11 @@ minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; }, - getTextRect = c3_chart_internal_fn.getTextRect = function (text, cls) { + generateCall = c3_chart_internal_fn.generateCall = function (f, context) { + return function (d, i) { return f.call(context, d, i); }; + }; + + c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; this.d3.select('body').selectAll('.dummy') .data([text]) @@ -4771,24 +4960,21 @@ .remove(); return rect; }, - generateCall = c3_chart_internal_fn.generateCall = function (f, context) { - return function (d, i) { return f.call(context, d, i); }; - }; /** * c3.selection.js */ c3_chart_internal_fn.selectPoint = function (target, d, i) { - var $$ = this; - $$.config.data_onselected.call(c3, d, target.node()); + var $$ = this, config = $$.config; + config[__data_onselected](d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return generateClass.call($$, CLASS.selectedCircle, i); }) - .attr("cx", $$.config.axis_rotated ? $$.circleY : $$.circleX) - .attr("cy", $$.config.axis_rotated ? $$.circleX : $$.circleY) + .attr("class", function () { return $$.generateClass(CLASS.selectedCircle, i); }) + .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) + .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) .attr("stroke", function () { return $$.color(d); }) .attr("r", $$.pointSelectR(d) * 1.4) .transition().duration(100) @@ -4796,9 +4982,9 @@ }; c3_chart_internal_fn.unselectPoint = function (target, d, i) { var $$ = this; - $$.config.data_onunselected.call(c3, d, target.node()); + $$.config[__data_onunselected](d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + CLASS.selectedCircles + getTargetSelectorSuffix.call($$, d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; @@ -4807,13 +4993,13 @@ }; c3_chart_internal_fn.selectBar = function (target, d) { var $$ = this; - $$.config.data_onselected.call(c3, d, target.node()); + $$.config[__data_onselected].call($$, d, target.node()); target.transition().duration(100) .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); }; c3_chart_internal_fn.unselectBar = function (target, d) { var $$ = this; - $$.config.data_onunselected.call(c3, d, target.node()); + $$.config[__data_onunselected].call($$, d, target.node()); target.transition().duration(100) .style("fill", function () { return $$.color(d); }); }; @@ -4829,7 +5015,7 @@ return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS.bar) ? $$.toggleBar : $$.toggleArc); }; c3_chart_internal_fn.toggleShape = function (that, d, i) { - var $$ = this, d3 = $$.d3, + var $$ = this, d3 = $$.d3, config = $$.config, shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; if (that.nodeName === 'circle') { isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); @@ -4844,10 +5030,10 @@ toggle = $$.toggleArc; } } - if ($$.config.data_selection_grouped || isWithin) { - if ($$.config.data_selection_enabled && $$.config.data_selection_isselectable(d)) { - if (!$$.config.data_selection_multiple) { - $$.main.selectAll('.' + CLASS.shapes + ($$.config.data_selection_grouped ? getTargetSelectorSuffix.call($$, d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { + if (config[__data_selection_grouped] || isWithin) { + if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { + if (!config[__data_selection_multiple]) { + $$.main.selectAll('.' + CLASS.shapes + (config[__data_selection_grouped] ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this); if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } }); @@ -4855,7 +5041,7 @@ shape.classed(CLASS.SELECTED, !isSelected); toggle(!isSelected, shape, d, i); } - $$.config.data_onclick.call(c3, d, that); + $$.config[__data_onclick](d, that); } }; @@ -4914,7 +5100,7 @@ */ c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !hasArcType.call($$, $$.data.targets), + withTransitionForAxis = !$$.hasArcType($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; $$.transiting = false; @@ -4998,93 +5184,94 @@ EXPANDED: '_expanded_', SELECTED: '_selected_', INCLUDED: '_included_' - }, - generateClass = c3_chart_internal_fn.generateClass = function (prefix, targetId) { - return " " + prefix + " " + prefix + getTargetSelectorSuffix.call(this, targetId); - }, - classText = c3_chart_internal_fn.classText = function (d) { - return generateClass.call(this, CLASS.text, d.index); - }, - classTexts = c3_chart_internal_fn.classTexts = function (d) { - return generateClass.call(this, CLASS.texts, d.id); - }, - classShape = c3_chart_internal_fn.classShape = function (d) { - return generateClass.call(this, CLASS.shape, d.index); - }, - classShapes = c3_chart_internal_fn.classShapes = function (d) { - return generateClass.call(this, CLASS.shapes, d.id); - }, - classLine = c3_chart_internal_fn.classLine = function (d) { - return classShape.call(this, d) + generateClass.call(this, CLASS.line, d.id); - }, - classLines = c3_chart_internal_fn.classLines = function (d) { - return classShapes.call(this, d) + generateClass.call(this, CLASS.lines, d.id); - }, - classCircle = c3_chart_internal_fn.classCircle = function (d) { - return classShape.call(this, d) + generateClass.call(this, CLASS.circle, d.index); - }, - classCircles = c3_chart_internal_fn.classCircles = function (d) { - return classShapes.call(this, d) + generateClass.call(this, CLASS.circles, d.id); - }, - classBar = c3_chart_internal_fn.classBar = function (d) { - return classShape.call(this, d) + generateClass.call(this, CLASS.bar, d.index); - }, - classBars = c3_chart_internal_fn.classBars = function (d) { - return classShapes.call(this, d) + generateClass.call(this, CLASS.bars, d.id); - }, - classArc = c3_chart_internal_fn.classArc = function (d) { - return classShape.call(this, d.data) + generateClass.call(this, CLASS.arc, d.data.id); - }, - classArcs = c3_chart_internal_fn.classArcs = function (d) { - return classShapes.call(this, d.data) + generateClass.call(this, CLASS.arcs, d.data.id); - }, - classArea = c3_chart_internal_fn.classArea = function (d) { - return classShape.call(this, d) + generateClass.call(this, CLASS.area, d.id); - }, - classAreas = c3_chart_internal_fn.classAreas = function (d) { - return classShapes.call(this, d) + generateClass.call(this, CLASS.areas, d.id); - }, - classRegion = c3_chart_internal_fn.classRegion = function (d, i) { - return generateClass.call(this, CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); - }, - classEvent = c3_chart_internal_fn.classEvent = function (d) { - return generateClass.call(this, CLASS.eventRect, d.index); - }, - classTarget = c3_chart_internal_fn.classTarget = function (id) { + }; + c3_chart_internal_fn.generateClass = function (prefix, targetId) { + return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); + }; + c3_chart_internal_fn.classText = function (d) { + return this.generateClass(CLASS.text, d.index); + }; + c3_chart_internal_fn.classTexts = function (d) { + return this.generateClass(CLASS.texts, d.id); + }; + c3_chart_internal_fn.classShape = function (d) { + return this.generateClass(CLASS.shape, d.index); + }; + c3_chart_internal_fn.classShapes = function (d) { + return this.generateClass(CLASS.shapes, d.id); + }; + c3_chart_internal_fn.classLine = function (d) { + return this.classShape(d) + this.generateClass(CLASS.line, d.id); + }; + c3_chart_internal_fn.classLines = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.lines, d.id); + }; + c3_chart_internal_fn.classCircle = function (d) { + return this.classShape(d) + this.generateClass(CLASS.circle, d.index); + }; + c3_chart_internal_fn.classCircles = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.circles, d.id); + }; + c3_chart_internal_fn.classBar = function (d) { + return this.classShape(d) + this.generateClass(CLASS.bar, d.index); + }; + c3_chart_internal_fn.classBars = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.bars, d.id); + }; + c3_chart_internal_fn.classArc = function (d) { + return this.classShape(d.data) + this.generateClass(CLASS.arc, d.data.id); + }; + c3_chart_internal_fn.classArcs = function (d) { + return this.classShapes(d.data) + this.generateClass(CLASS.arcs, d.data.id); + }; + c3_chart_internal_fn.classArea = function (d) { + return this.classShape(d) + this.generateClass(CLASS.area, d.id); + }; + c3_chart_internal_fn.classAreas = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.areas, d.id); + }; + c3_chart_internal_fn.classRegion = function (d, i) { + return this.generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); + }; + c3_chart_internal_fn.classEvent = function (d) { + return this.generateClass(CLASS.eventRect, d.index); + }; + c3_chart_internal_fn.classTarget = function (id) { var $$ = this; - var additionalClassSuffix = $$.config.data_classes[id], additionalClass = ''; + var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; if (additionalClassSuffix) { additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; } - return generateClass.call($$, CLASS.target, id) + additionalClass; - }, - classChartText = c3_chart_internal_fn.classChartText = function (d) { - return CLASS.chartText + classTarget.call(this, d.id); - }, - classChartLine = c3_chart_internal_fn.classChartLine = function (d) { - return CLASS.chartLine + classTarget.call(this, d.id); - }, - classChartBar = c3_chart_internal_fn.classChartBar = function (d) { - return CLASS.chartBar + classTarget.call(this, d.id); - }, - classChartArc = c3_chart_internal_fn.classChartArc = function (d) { - return CLASS.chartArc + classTarget.call(this, d.data.id); - }, - getTargetSelectorSuffix = c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { + return $$.generateClass(CLASS.target, id) + additionalClass; + }; + c3_chart_internal_fn.classChartText = function (d) { + return CLASS.chartText + this.classTarget(d.id); + }; + c3_chart_internal_fn.classChartLine = function (d) { + return CLASS.chartLine + this.classTarget(d.id); + }; + c3_chart_internal_fn.classChartBar = function (d) { + return CLASS.chartBar + this.classTarget(d.id); + }; + c3_chart_internal_fn.classChartArc = function (d) { + return CLASS.chartArc + this.classTarget(d.data.id); + }; + c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; - }, - selectorTarget = c3_chart_internal_fn.selectorTarget = function (id) { - return '.' + CLASS.target + getTargetSelectorSuffix.call(this, id); - }, - selectorTargets = c3_chart_internal_fn.selectorTargets = function (ids) { - return ids.length ? ids.map(function (id) { return selectorTarget.call(this, id); }) : null; - }, - selectorLegend = c3_chart_internal_fn.selectorLegend = function (id) { - return '.' + CLASS.legendItem + getTargetSelectorSuffix.call(this, id); - }, - selectorLegends = c3_chart_internal_fn.selectorLegends = function (ids) { + }; + c3_chart_internal_fn.selectorTarget = function (id) { + return '.' + CLASS.target + this.getTargetSelectorSuffix(id); + }; + c3_chart_internal_fn.selectorTargets = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return selectorLegend.call($$, id); }) : null; + return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; + }; + c3_chart_internal_fn.selectorLegend = function (id) { + return '.' + CLASS.legendItem + this.getTargetSelectorSuffix(id); + }; + c3_chart_internal_fn.selectorLegends = function (ids) { + var $$ = this; + return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; }; @@ -5094,22 +5281,22 @@ */ c3_chart_internal_fn.getYFormat = function (forArc) { var $$ = this, - formatForY = forArc && !hasGaugeType.call($$, $$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !hasGaugeType.call($$, $$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); }; }; c3_chart_internal_fn.yFormat = function (v) { - var $$ = this, - format = $$.config.axis_y_tick_format ? $$.config.axis_y_tick_format : $$.defaultValueFormat; - return format.call($$, v); + var $$ = this, config = $$.config, + format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; + return format(v); }; c3_chart_internal_fn.y2Format = function (v) { - var $$ = this, - format = $$.config.axis_y2_tick_format ? $$.config.axis_y2_tick_format : $$.defaultValueFormat; - return format.call($$, v); + var $$ = this, config = $$.config, + format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; + return format(v); }; c3_chart_internal_fn.defaultValueFormat = function (v) { return isValue(v) ? +v : ""; @@ -5118,13 +5305,13 @@ return (ratio * 100).toFixed(1) + '%'; }; c3_chart_internal_fn.formatByAxisId = function (axisId) { - var $$ = this.internal, data_labels = $$.config.data_labels, + var $$ = this.internal, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id - if (typeof data_labels.format === 'function') { + if (isFunction(data_labels.format)) { format = data_labels.format; } else if (typeof data_labels.format === 'object') { - if (typeof data_labels.format[axisId] === 'function') { + if (isFunction(data_labels.format[axisId])) { format = data_labels.format[axisId]; } } @@ -5137,13 +5324,13 @@ * c3.drag.js */ c3_chart_internal_fn.drag = function (mouse) { - var $$ = this, main = $$.main, d3 = $$.d3; + var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if (hasArcType.call($$, $$.data.targets)) { return; } - 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.data_selection_multiple) { return; } // skip when single selection because drag is used for multiple selection + if ($$.hasArcType($$.data.targets)) { return; } + 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection sx = $$.dragStart[0]; sy = $$.dragStart[1]; @@ -5151,8 +5338,8 @@ my = mouse[1]; minX = Math.min(sx, mx); maxX = Math.max(sx, mx); - minY = ($$.config.data_selection_grouped) ? $$.margin.top : Math.min(sy, my); - maxY = ($$.config.data_selection_grouped) ? $$.height : Math.max(sy, my); + minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); + maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); main.select('.' + CLASS.dragarea) .attr('x', minX) @@ -5161,7 +5348,7 @@ .attr('height', maxY - minY); // TODO: binary search when multiple xs main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) - .filter(function (d) { return $$.config.data_selection_isselectable(d); }) + .filter(function (d) { return config[__data_selection_isselectable](d); }) .each(function (d, i) { var shape = d3.select(this), isSelected = shape.classed(CLASS.SELECTED), @@ -5189,27 +5376,27 @@ shape.classed(CLASS.INCLUDED, !isIncluded); // TODO: included/unincluded callback here shape.classed(CLASS.SELECTED, !isSelected); - toggle.call($$, !isSelected, shape, d, i); + $$.toggle(!isSelected, shape, d, i); } }); }; c3_chart_internal_fn.dragstart = function (mouse) { - var $$ = this; - if (hasArcType.call($$, $$.data.targets)) { return; } - if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable + var $$ = this, config = $$.config; + if ($$.hasArcType($$.data.targets)) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.dragStart = mouse; $$.main.select('.' + CLASS.chart).append('rect') .attr('class', CLASS.dragarea) .style('opacity', 0.1); $$.dragging = true; - $$.config.data_ondragstart.call(c3); + $$.config[__data_ondragstart](); }; c3_chart_internal_fn.dragend = function () { - var $$ = this; - if (hasArcType.call($$, $$.data.targets)) { return; } - if (! $$.config.data_selection_enabled) { return; } // do nothing if not selectable + var $$ = this, config = $$.config; + if ($$.hasArcType($$.data.targets)) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.main.select('.' + CLASS.dragarea) .transition().duration(100) .style('opacity', 0) @@ -5217,7 +5404,7 @@ $$.main.selectAll('.' + CLASS.shape) .classed(CLASS.INCLUDED, false); $$.dragging = false; - $$.config.data_ondragend.call(c3); + $$.config[__data_ondragend](); }; @@ -5229,9 +5416,9 @@ */ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall(isArc, $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function focus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } @@ -5239,41 +5426,41 @@ this.defocus(); focus(candidatesForNoneArc.classed(CLASS.focused, true)); focus(candidatesForArc); - if (hasArcType.call($$, $$.data.targets)) { - expandArc.call($$, targetId, true); + if ($$.hasArcType($$.data.targets)) { + $$.expandArc(targetId, true); } $$.toggleFocusLegend(targetId, true); }; c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall(isArc, $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function defocus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } this.revert(); defocus(candidatesForNoneArc.classed(CLASS.focused, false)); defocus(candidatesForArc); - if (hasArcType.call($$, $$.data.targets)) { - unexpandArc.call($$, targetId); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); } $$.toggleFocusLegend(targetId, false); }; c3_chart_fn.revert = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll(selectorTarget.call($$, targetId)), - candidatesForNoneArc = candidates.filter(generateCall(isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall(isArc, $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } revert(candidatesForNoneArc.classed(CLASS.focused, false)); revert(candidatesForArc); - if (hasArcType.call($$, $$.data.targets)) { - unexpandArc.call($$, targetId); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); } $$.revertLegend(); }; @@ -5285,7 +5472,7 @@ options = options || {}; $$.removeHiddenTargetIds(targetIds); - $$.svg.selectAll(selectorTargets.call($$, targetIds)) + $$.svg.selectAll($$.selectorTargets(targetIds)) .transition() .style('opacity', 1); @@ -5303,7 +5490,7 @@ options = options || {}; $$.addHiddenTargetIds(targetIds); - $$.svg.selectAll(selectorTargets.call($$, targetIds)) + $$.svg.selectAll($$.selectorTargets(targetIds)) .transition() .style('opacity', 0); @@ -5323,7 +5510,7 @@ }; c3_chart_fn.zoom.enable = function (enabled) { var $$ = this.internal; - $$.config.zoom_enabled = enabled; + $$.config[__zoom_enabled] = enabled; $$.updateAndRedraw(); }; c3_chart_fn.unzoom = function () { @@ -5333,7 +5520,7 @@ }; c3_chart_fn.load = function (args) { - var $$ = this.internal; + var $$ = this.internal, config = $$.config; // update xs if specified if (args.xs) { $$.addXs(args.xs); @@ -5341,12 +5528,12 @@ // update classes if exists if ('classes' in args) { Object.keys(args.classes).forEach(function (id) { - $$.config.data_classes[id] = args.classes[id]; + config[__data_classes][id] = args.classes[id]; }); } // update categories if exists if ('categories' in args && $$.isCategorized) { - $$.config.axis_x_categories = args.categories; + config[__axis_x_categories] = args.categories; } // use cache if exists if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { @@ -5369,7 +5556,7 @@ args = args || {}; $$.unload($$.mapToTargetIds(args.ids), function () { $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (typeof args.done === 'function') { args.done(); } + if (isFunction(args.done)) { args.done(); } }); }; @@ -5379,18 +5566,18 @@ dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; if (args.json) { - data = convertJsonToData.call($$, args.json, args.keys); + data = $$.convertJsonToData(args.json, args.keys); } else if (args.rows) { - data = convertRowsToData.call($$, args.rows); + data = $$.convertRowsToData(args.rows); } else if (args.columns) { - data = convertColumnsToData.call($$, args.columns); + data = $$.convertColumnsToData(args.columns); } else { return; } - targets = convertDataToTargets.call($$, data, true); + targets = $$.convertDataToTargets(data, true); // Update/Add data $$.data.targets.forEach(function (t) { @@ -5498,14 +5685,14 @@ } // Set targets - updateTargets.call($$, $$.data.targets); + $$.updateTargets($$.data.targets); // Redraw with new targets $$.redraw({ flow: { index: baseValue.index, length: length, - duration: isValue(args.duration) ? args.duration : $$.config.transition_duration, + duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], done: args.done, orgDataCount: orgDataCount, }, @@ -5517,17 +5704,17 @@ c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( - $$.main.selectAll('.' + CLASS.shapes + getTargetSelectorSuffix.call($$, targetId)).selectAll('.' + CLASS.shape) + $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; c3_chart_fn.select = function (ids, indices, resetOther) { - var $$ = this.internal, d3 = $$.d3; - if (! $$.config.data_selection_enabled) { return; } + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = $$.config.data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet @@ -5535,7 +5722,7 @@ return; } if (isTargetId && isTargetIndex) { - if ($$.config.data_selection_isselectable(d) && !isSelected) { + if (config[__data_selection_isselectable](d) && !isSelected) { toggle(true, shape.classed(CLASS.SELECTED, true), d, i); } } else if (isDefined(resetOther) && resetOther) { @@ -5546,11 +5733,11 @@ }); }; c3_chart_fn.unselect = function (ids, indices) { - var $$ = this.internal, d3 = $$.d3; - if (! $$.config.data_selection_enabled) { return; } + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = $$.config.data_selection_grouped || !ids || ids.indexOf(id) >= 0, + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet @@ -5558,7 +5745,7 @@ return; } if (isTargetId && isTargetIndex) { - if ($$.config.data_selection_isselectable(d)) { + if (config[__data_selection_isselectable](d)) { if (isSelected) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } @@ -5574,23 +5761,23 @@ }; c3_chart_fn.groups = function (groups) { - var $$ = this.internal; - if (isUndefined(groups)) { return $$.config.data_groups; } - $$.config.data_groups = groups; + var $$ = this.internal, config = $$.config; + if (isUndefined(groups)) { return config[__data_groups]; } + config[__data_groups] = groups; $$.redraw(); - return $$.config.data_groups; + return config[__data_groups]; }; c3_chart_fn.xgrids = function (grids) { - var $$ = this.internal; - if (! grids) { return $$.config.grid_x_lines; } - $$.config.grid_x_lines = grids; + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_x_lines]; } + config[__grid_x_lines] = grids; $$.redraw(); - return $$.config.grid_x_lines; + return config[__grid_x_lines]; }; c3_chart_fn.xgrids.add = function (grids) { var $$ = this.internal; - return this.xgrids($$.config.grid_x_lines.concat(grids ? grids : [])); + return this.xgrids($$.config[__grid_x_lines].concat(grids ? grids : [])); }; c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple var $$ = this.internal; @@ -5598,15 +5785,15 @@ }; c3_chart_fn.ygrids = function (grids) { - var $$ = this.internal; - if (! grids) { return $$.config.grid_y_lines; } - $$.config.grid_y_lines = grids; + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_y_lines]; } + config[__grid_y_lines] = grids; $$.redraw(); - return $$.config.grid_y_lines; + return config[__grid_y_lines]; }; c3_chart_fn.ygrids.add = function (grids) { var $$ = this.internal; - return c3.ygrids($$.config.grid_y_lines.concat(grids ? grids : [])); + return c3.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); }; c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple var $$ = this.internal; @@ -5614,25 +5801,25 @@ }; c3_chart_fn.regions = function (regions) { - var $$ = this.internal; - if (!regions) { return $$.config.regions; } - $$.config.regions = regions; + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = regions; $$.redraw(); - return $$.config.regions; + return config[__regions]; }; c3_chart_fn.regions.add = function (regions) { - var $$ = this.internal; - if (!regions) { return $$.config.regions; } - $$.config.regions = $$.config.regions.concat(regions); + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = config[__regions].concat(regions); $$.redraw(); - return $$.config.regions; + return config[__regions]; }; c3_chart_fn.regions.remove = function (options) { - var $$ = this.internal, + var $$ = this.internal, config = $$.config, duration, classes, regions; options = options || {}; - duration = $$.getOption(options, "duration", $$.config.transition_duration); + duration = $$.getOption(options, "duration", config[__transition_duration]); classes = $$.getOption(options, "classes", [CLASS.region]); regions = $$.main.select('.' + CLASS.regions).selectAll(classes.map(function (c) { return '.' + c; })); @@ -5640,7 +5827,7 @@ .style('opacity', 0) .remove(); - $$.config.regions = $$.config.regions.filter(function (region) { + config[__regions] = config[__regions].filter(function (region) { var found = false; if (!region.class) { return true; @@ -5651,7 +5838,7 @@ return !found; }); - return $$.config.regions; + return config[__regions]; }; c3_chart_fn.data = function () { @@ -5665,37 +5852,37 @@ return targets.length > 0 ? targets[0] : undefined; }; c3_chart_fn.data.names = function (names) { - var $$ = this.internal; - if (!arguments.length) { return $$.config.data_names; } + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_names]; } Object.keys(names).forEach(function (id) { - $$.config.data_names[id] = names[id]; + config[__data_names][id] = names[id]; }); $$.redraw({withLegend: true}); - return $$.config.data_names; + return config[__data_names]; }; c3_chart_fn.data.colors = function (colors) { - var $$ = this.internal; - if (!arguments.length) { return $$.config.data_colors; } + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_colors]; } Object.keys(colors).forEach(function (id) { - $$.config.data_colors[id] = colors[id]; + config[__data_colors][id] = colors[id]; }); $$.redraw({withLegend: true}); - return $$.config.data_colors; + return config[__data_colors]; }; c3_chart_fn.category = function (i, category) { - var $$ = this.internal; + var $$ = this.internal, config = $$.config; if (arguments.length > 1) { - $$.config.axis_x_categories[i] = category; + config[__axis_x_categories][i] = category; $$.redraw(); } - return $$.config.axis_x_categories[i]; + return config[__axis_x_categories][i]; }; c3_chart_fn.categories = function (categories) { - var $$ = this.internal; - if (!arguments.length) { return $$.config.axis_x_categories; } - $$.config.axis_x_categories = categories; + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__axis_x_categories]; } + config[__axis_x_categories] = categories; $$.redraw(); - return $$.config.axis_x_categories; + return config[__axis_x_categories]; }; // TODO: fix @@ -5728,42 +5915,42 @@ var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { - setAxisLabelText.call($$, axisId, labels[axisId]); + $$.setAxisLabelText(axisId, labels[axisId]); }); $$.updateAxisLabels(); } // TODO: return some values? }; c3_chart_fn.axis.max = function (max) { - var $$ = this.internal; + var $$ = this.internal, config = $$.config; if (arguments.length) { if (typeof max === 'object') { - if (isValue(max.x)) { $$.config.axis_x_max = max.x; } - if (isValue(max.y)) { $$.config.axis_y_max = max.y; } - if (isValue(max.y2)) { $$.config.axis_y2_max = max.y2; } + if (isValue(max.x)) { config[__axis_x_max] = max.x; } + if (isValue(max.y)) { config[__axis_y_max] = max.y; } + if (isValue(max.y2)) { config[__axis_y2_max] = max.y2; } } else { - $$.config.axis_y_max = $$.config.axis_y2_max = max; + config[__axis_y_max] = config[__axis_y2_max] = max; } $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.min = function (min) { - var $$ = this.internal; + var $$ = this.internal, config = $$.config; if (arguments.length) { if (typeof min === 'object') { - if (isValue(min.x)) { $$.config.axis_x_min = min.x; } - if (isValue(min.y)) { $$.config.axis_y_min = min.y; } - if (isValue(min.y2)) { $$.config.axis_y2_min = min.y2; } + if (isValue(min.x)) { config[__axis_x_min] = min.x; } + if (isValue(min.y)) { config[__axis_y_min] = min.y; } + if (isValue(min.y2)) { config[__axis_y2_min] = min.y2; } } else { - $$.config.axis_y_min = $$.config.axis_y2_min = min; + config[__axis_y_min] = config[__axis_y2_min] = min; } $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.range = function (range) { if (arguments.length) { - if (typeof range.max !== 'undefined') { this.axis.max(range.max); } - if (typeof range.min !== 'undefined') { this.axis.min(range.min); } + if (isDefined(range.max)) { this.axis.max(range.max); } + if (isDefined(range.min)) { this.axis.min(range.min); } } }; @@ -5782,9 +5969,9 @@ }; c3_chart_fn.resize = function (size) { - var $$ = this.internal; - $$.config.size_width = size ? size.width : null; - $$.config.size_height = size ? size.height : null; + var $$ = this.internal, config = $$.config; + config[__size_width] = size ? size.width : null; + config[__size_height] = size ? size.height : null; this.flush(); }; @@ -5991,7 +6178,7 @@ return axis; } - if (typeof define === "function" && define.amd) { + if (typeof define === 'function' && define.amd) { define("c3", ["d3"], c3); } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { module.exports = c3; From 4fee43b694ee69ac3d5a3a8c15a219968893d871 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 00:58:49 +0100 Subject: [PATCH 11/44] Refactor for minify --- c3.js | 3749 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 2085 insertions(+), 1664 deletions(-) diff --git a/c3.js b/c3.js index 515697f..cdb64ab 100644 --- a/c3.js +++ b/c3.js @@ -9,8 +9,8 @@ function Chart(config) { var $$ = this.internal = new ChartInternal(config, this); - $$.loadConfig(config); - $$.init(); + $$[loadConfig](config); + $$[init](); } function ChartInternal(config, api) { @@ -35,6 +35,22 @@ c3_chart_fn = c3.chart.fn; c3_chart_internal_fn = c3.chart.internal.fn; + var CSS_CLASS = 'class', + CSS_OPACITY = 'opacity', + CSS_TRANSFORM = 'transform', + CSS_FILL_OPACITY = 'fill-opacity', + CSS_TEXT_ANCHOR = 'text-anchor', + CSS_VISIBILITY = 'visibility', + CSS_POINTER_EVENTS = 'pointer-events'; + + var TYPE_BAR = 'bar', + //TYPE_LINE = 'line', + TYPE_AREA = 'area', + TYPE_SCATTER = 'scatter', + TYPE_PIE = 'pie', + TYPE_DONUT = 'donut', + TYPE_GAUGE = 'gauge'; + /** * c3.config.js @@ -395,14 +411,14 @@ if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, 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 += ""; + text += ""; text += ""; text += ""; text += ""; @@ -413,7 +429,8 @@ config[__tooltip_init_x] = 0; config[__tooltip_init_position] = {top: '0px', left: '50px'}; - c3_chart_internal_fn.loadConfig = function (config) { + var loadConfig = 'loadConfig'; + c3_chart_internal_fn[loadConfig] = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -442,78 +459,117 @@ - // should be define in c3.zoom.js - c3_chart_internal_fn.initZoom = function () { + + var initZoom = 'initZoom';// should be define in c3.zoom.js + c3_chart_internal_fn[initZoom] = function () { var $$ = this, d3 = $$.d3, config = $$.config; $$.zoom = d3.behavior.zoom() .on("zoomstart", function () { $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; }) - .on("zoom", $$.redrawForZoom); + .on("zoom", $$[redrawForZoom]); $$.zoom.scale = function (scale) { - return config[__axis_rotated] ? this.y(scale) : this.x(scale); + return config[__axis_rotated] ? this[y](scale) : this[x](scale); }; $$.zoom.orgScaleExtent = function () { var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; - return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; + return [extent[0], Math.max($$[getMaxDataCount]() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), - extent = $$.orgScaleExtent(); - $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + extent = this.orgScaleExtent(); + this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); return this; }; }; - c3_chart_internal_fn.init = function () { + var init = 'init'; + c3_chart_internal_fn[init] = function () { var $$ = this, config = $$.config; 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]); } else if (config[__data_json]) { - $$.initWithData($$.convertJsonToData(config[__data_json], config[__data_keys])); + $$[initWithData]($$[convertJsonToData](config[__data_json], config[__data_keys])); } else if (config[__data_rows]) { - $$.initWithData($$.convertRowsToData(config[__data_rows])); + $$[initWithData]($$[convertRowsToData](config[__data_rows])); } else if (config[__data_columns]) { - $$.initWithData($$.convertColumnsToData(config[__data_columns])); + $$[initWithData]($$[convertColumnsToData](config[__data_columns])); } else { throw Error('url or json or rows or columns is required.'); } }; - c3_chart_internal_fn.initWithData = function (data) { + var initWithData = 'initWithData', + color = 'color', + isCustomX = 'isCustomX', + clipId = 'clipId', + clipIdForXAxis = 'clipIdForXAxis', + clipIdForYAxis = 'clipIdForYAxis', + clipPath = 'clipPath', + clipPathForXAxis = 'clipPathForXAxis', + clipPathForYAxis = 'clipPathForYAxis', + isTimeSeries = 'isTimeSeries', + isCategorized = 'isCategorized', + dragStart = 'dragStart', + dragging = 'dragging', + cancelClick = 'cancelClick', + mouseover = 'mouseover', + transiting = 'transiting', + defaultColorPattern = 'defaultColorPattern', + levelColor = 'levelColor', + dataTimeFormat = 'dataTimeFormat', + axisTimeFormat = 'axisTimeFormat', + defaultAxisTimeFormat = 'defaultAxisTimeFormat', + hiddenTargetIds = 'hiddenTargetIds', + hiddenLegendIds = 'hiddenLegendIds', + xOrient = 'xOrient', + yOrient = 'yOrient', + y2Orient = 'y2Orient', + subXOrient = 'subXOrient', + translate = 'translate', + isLegendRight = 'isLegendRight', + isLegendInset = 'isLegendInset', + isLegendTop = 'isLegendTop', + isLegendLeft = 'isLegendLeft', + legendStep = 'legendStep', + legendItemWidth = 'legendItemWidth', + legendItemHeight = 'legendItemHeight', + legendOpacityForHidden = 'legendOpacityForHidden', + currentMaxTickWidth = 'currentMaxTickWidth', + rotated_padding_left = 'rotated_padding_left', + rotated_padding_right = 'rotated_padding_right', + rotated_padding_top = 'rotated_padding_top', + withoutFadeIn = 'withoutFadeIn'; + c3_chart_internal_fn[initWithData] = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; var main, legend, eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist - $$.clipId = "c3-" + (+new Date()) + '-clip', - $$.clipIdForXAxis = $$.clipId + '-xaxis', - $$.clipIdForYAxis = $$.clipId + '-yaxis', - $$.clipPath = $$.getClipPath($$.clipId), - $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), - $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - - $$.isTimeSeries = (config[__axis_x_type] === 'timeseries'); - $$.isCategorized = (config[__axis_x_type].indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && (config[__data_x] || notEmpty(config[__data_xs])); }; - - $$.dragStart = null; - $$.dragging = false; - $$.cancelClick = false; - $$.mouseover = false; - $$.transiting = false; - - $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor(config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$.defaultColorPattern, config[__data_color]); - $$.levelColor = notEmpty(config[__color_threshold]) ? $$.generateLevelColor(config[__color_pattern], config[__color_threshold]) : null; - - $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.time.format.utc; - $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ + $$[clipId] = "c3-" + (+new Date()) + '-clip', + $$[clipIdForXAxis] = $$[clipId] + '-xaxis', + $$[clipIdForYAxis] = $$[clipId] + '-yaxis', + $$[clipPath] = $$[getClipPath]($$.clipId), + $$[clipPathForXAxis] = $$[getClipPath]($$[clipIdForXAxis]), + $$[clipPathForYAxis] = $$[getClipPath]($$[clipIdForYAxis]); + + $$[isTimeSeries] = (config[__axis_x_type] === 'timeseries'); + $$[isCategorized] = (config[__axis_x_type].indexOf('categor') >= 0); + $$[isCustomX] = function () { return !$$[isTimeSeries] && (config[__data_x] || notEmpty(config[__data_xs])); }; + + $$[dragStart] = $$[dragging] = $$[cancelClick] = $$[mouseover] = $$[transiting] = false; + + $$[defaultColorPattern] = d3.scale.category10().range(); + $$[color] = $$[generateColor](config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$[defaultColorPattern], config[__data_color]); + $$[levelColor] = notEmpty(config[__color_threshold]) ? $$[generateLevelColor](config[__color_pattern], config[__color_threshold]) : null; + + $$[dataTimeFormat] = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; + $$[axisTimeFormat] = config[__axis_x_localtime] ? d3.time.format : d3.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(); }], @@ -524,15 +580,15 @@ ["%Y/%-m/%-d", function () { return true; }] ]); - $$.hiddenTargetIds = []; - $$.hiddenLegendIds = []; + $$[hiddenTargetIds] = []; + $$[hiddenLegendIds] = []; - $$.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"; + $$[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"; - $$.translate = { + $$[translate] = { main : function () { return "translate(" + asHalfPixel($$.margin.left) + "," + asHalfPixel($$.margin.top) + ")"; }, context : function () { return "translate(" + asHalfPixel($$.margin2.left) + "," + asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, @@ -543,44 +599,44 @@ arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } }; - $$.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; - $$.legendOpacityForHidden = 0.15; + $$[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; + $$[legendOpacityForHidden] = 0.15; - $$.currentMaxTickWidth = 0; + $$[currentMaxTickWidth] = 0; - $$.rotated_padding_left = 30; - $$.rotated_padding_right = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; - $$.rotated_padding_top = 5; + $$[rotated_padding_left] = 30; + $$[rotated_padding_right] = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; + $$[rotated_padding_top] = 5; - $$.withoutFadeIn = {}; + $$[withoutFadeIn] = {}; if (isFunction($$.initPie)) { - $$.initPie(); + $$[initPie](); } if (isFunction($$.initBrush)) { - $$.initBrush(); + $$[initBrush](); } else { $$.axes.subx = d3.selectAll([]); } - if ($$.initZoom) { $$.initZoom(); } + if ($$[initZoom]) { $$[initZoom](); } $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { - $$.selectChart = d3.select(document.createElement('div')).style('opacity', 0); - $$.observeInserted($$.selectChart); + $$.selectChart = d3.select(document.createElement('div')).style(CSS_OPACITY, 0); + $$[observeInserted]($$.selectChart); binding = false; } $$.selectChart.html("").classed("c3", true); // Init data as targets $$.data.xs = {}; - $$.data.targets = $$.convertDataToTargets(data); + $$.data.targets = $$[convertDataToTargets](data); if (config[__data_filter]) { $$.data.targets = $$.data.targets.filter(config[__data_filter]); @@ -588,22 +644,22 @@ // Set targets to hide if needed 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]); } // when gauge, hide legend // TODO: fix - if ($$.hasGaugeType($$.data.targets)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { config[__legend_show] = false; } // Init sizes and scales - $$.updateSizes(); - $$.updateScales(); + $$[updateSizes](); + $$[updateScales](); // Set domains for each scale - $$.x.domain(d3.extent($$.getXDomain($$.data.targets))); - $$.y.domain($$.getYDomain($$.data.targets, 'y')); - $$.y2.domain($$.getYDomain($$.data.targets, 'y2')); + $$.x.domain(d3.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()); @@ -620,27 +676,27 @@ // Define svgs $$.svg = $$.selectChart.append("svg") .style("overflow", "hidden") - .on('mouseenter', function () { return config[__onmouseover].call($$); }) - .on('mouseleave', function () { return config[__onmouseout].call($$); }); + .on('mouseover', generateCall(config[__onmouseover], $$)) + .on('mouseout', generateCall(config[__onmouseout], $$)); // Define defs $$.defs = $$.svg.append("defs"); - $$.defs.append("clipPath").attr("id", $$.clipId).append("rect"); - $$.defs.append("clipPath").attr("id", $$.clipIdForXAxis).append("rect"); - $$.defs.append("clipPath").attr("id", $$.clipIdForYAxis).append("rect"); - $$.updateSvgSize(); + $$.defs.append("clipPath").attr("id", $$[clipId]).append("rect"); + $$.defs.append("clipPath").attr("id", $$[clipIdForXAxis]).append("rect"); + $$.defs.append("clipPath").attr("id", $$[clipIdForYAxis]).append("rect"); + $$[updateSvgSize](); // Define regions - main = $$.main = $$.svg.append("g").attr("transform", $$.translate.main); - legend = $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); + main = $$.main = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].main); + legend = $$.legend = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].legend); if (isFunction($$.initSubchart)) { - $$.initSubchart(); + $$[initSubchart](); } if (!config[__legend_show]) { - $$.legend.style('visibility', 'hidden'); - $$.hiddenLegendIds = $$.mapToIds($$.data.targets); + $$.legend.style(CSS_VISIBILITY, 'hidden'); + $$[hiddenLegendIds] = $$[mapToIds]($$.data.targets); } // Define tooltip @@ -648,126 +704,126 @@ .style("position", "relative") .append("div") .style("position", "absolute") - .style("pointer-events", "none") + .style(CSS_POINTER_EVENTS, "none") .style("z-index", "10") .style("display", "none"); // MEMO: call here to update legend box and tranlate for all // MEMO: translate will be upated by this, so transform not needed in updateLegend() - $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + $$[updateLegend]($$[mapToIds]($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); /*-- 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(CSS_CLASS, CLASS[text] + ' ' + CLASS[empty]) + .attr(CSS_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 main.append('g') - .attr("clip-path", $$.clipPath) - .attr("class", CLASS.regions); + .attr("clip-path", $$[clipPath]) + .attr(CSS_CLASS, CLASS[regions]); // Grids $$.grid = main.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS.grid); + .attr("clip-path", $$[clipPath]) + .attr('class', CLASS[grid]); if (config[__grid_x_show]) { - $$.grid.append("g").attr("class", CLASS.xgrids); + $$.grid.append("g").attr(CSS_CLASS, CLASS[xgrids]); } if (config[__grid_y_show]) { - $$.grid.append('g').attr('class', CLASS.ygrids); + $$.grid.append('g').attr(CSS_CLASS, CLASS[ygrids]); } - $$.grid.append('g').attr("class", CLASS.xgridLines); - $$.grid.append('g').attr('class', CLASS.ygridLines); + $$.grid.append('g').attr(CSS_CLASS, CLASS[xgridLines]); + $$.grid.append('g').attr(CSS_CLASS, CLASS[ygridLines]); if (config[__grid_focus_show]) { $$.grid.append('g') - .attr("class", CLASS.xgridFocus) + .attr(CSS_CLASS, CLASS[xgridFocus]) .append('line') - .attr('class', CLASS.xgridFocus); + .attr(CSS_CLASS, CLASS[xgridFocus]); } // Define g for chart area main.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS.chart); + .attr("clip-path", $$[clipPath]) + .attr(CSS_CLASS, CLASS[chart]); // Cover whole with rects for events - eventRect = main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.eventRects) - .style('fill-opacity', 0); + eventRect = main.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[eventRects]) + .style(CSS_FILL_OPACITY, 0); // Define g for bar chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); + main.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartBars]); // Define g for line chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); + main.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartLines]); // Define g for arc chart area if (isFunction($$.initArc)) { - $$.initArc(); + $$[initArc](); } if (isFunction($$.initGauge)) { - $$.initGauge(); + $$[initGauge](); } - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartTexts); + main.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartTexts]); // if zoom privileged, insert rect to forefront - main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS.regions) - .attr('class', CLASS.zoomRect) + main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS[regions]) + .attr(CSS_CLASS, CLASS[zoomRect]) .attr('width', $$.width) .attr('height', $$.height) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .on("dblclick.zoom", null); // Set default extent if defined if (config[__axis_x_default]) { - $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); + $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$[getXDomain]())); } // Add Axis $$.axes.x = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisX) - .attr("clip-path", $$.clipPathForXAxis) - .attr("transform", $$.translate.x) - .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); + .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisX]) + .attr("clip-path", $$[clipPathForXAxis]) + .attr(CSS_TRANSFORM, $$[translate].x) + .style(CSS_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", generateCall($$.textAnchorForXAxisLabel, $$)); + .attr(CSS_CLASS, CLASS[axisXLabel]) + .attr(CSS_TRANSFORM, config[__axis_rotated] ? "rotate(-90)" : "") + .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForXAxisLabel], $$)); $$.axes.y = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY) - .attr("clip-path", $$.clipPathForYAxis) - .attr("transform", $$.translate.y) - .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); + .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisY]) + .attr("clip-path", $$[clipPathForYAxis]) + .attr(CSS_TRANSFORM, $$[translate].y) + .style(CSS_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", generateCall($$.textAnchorForYAxisLabel, $$)); + .attr(CSS_CLASS, CLASS[axisYLabel]) + .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") + .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForYAxisLabel], $$)); $$.axes.y2 = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY2) + .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisY2]) // clip-path? - .attr("transform", $$.translate.y2) - .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); + .attr(CSS_TRANSFORM, $$[translate].y2) + .style(CSS_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", generateCall($$.textAnchorForY2AxisLabel, $$)); + .attr(CSS_CLASS, CLASS[axisY2Label]) + .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") + .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForY2AxisLabel], $$)); // Set targets - $$.updateTargets($$.data.targets); + $$[updateTargets]($$.data.targets); // Draw with targets if (binding) { - $$.updateDimension(); - $$.redraw({ + $$[updateDimension](); + $$[redraw]({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -777,16 +833,16 @@ // Show tooltip if needed if (config[__tooltip_init_show]) { - if ($$.isTimeSeries && isString(config[__tooltip_init_x])) { - config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); + if ($$[isTimeSeries] && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$[parseDate](config[__tooltip_init_x]); for (i = 0; i < $$.data.targets[0].values.length; i++) { if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } } config[__tooltip_init_x] = i; } $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { - return $$.addName(d.values[config[__tooltip_init_x]]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); + return $$[addName](d.values[config[__tooltip_init_x]]); + }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]($$.data.targets)), $$.color)); $$.tooltip.style("top", config[__tooltip_init_position].top) .style("left", config[__tooltip_init_position].left) .style("display", "block"); @@ -794,7 +850,7 @@ // Bind resize event if (window.onresize == null) { - window.onresize = $$.generateResize(); + window.onresize = $$[generateResize](); } if (window.onresize.add) { window.onresize.add(function () { @@ -813,7 +869,8 @@ }; - c3_chart_internal_fn.smoothLines = function (el, type) { + var smoothLines = 'smoothLines'; + c3_chart_internal_fn[smoothLines] = function (el, type) { var $$ = this; if (type === 'grid') { el.each(function () { @@ -833,37 +890,38 @@ }; - c3_chart_internal_fn.updateSizes = function () { + var updateSizes = 'updateSizes'; + c3_chart_internal_fn[updateSizes] = function () { var $$ = this, config = $$.config; - var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), - legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = $$.hasArcType($$.data.targets), - xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), + var legendHeight = $$[getLegendHeight](), legendWidth = $$[getLegendWidth](), + legendHeightForBottom = $$[isLegendRight] || $$[isLegendInset] ? 0 : legendHeight, + hasArc = $$[hasArcType]($$.data.targets), + xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$[getHorizontalAxisHeight]('x'), subchartHeight = config[__subchart_show] && !hasArc ? (config[__subchart_size_height] + xAxisHeight) : 0; - $$.currentWidth = $$.getCurrentWidth(); - $$.currentHeight = $$.getCurrentHeight(); + $$.currentWidth = $$[getCurrentWidth](); + $$.currentHeight = $$[getCurrentHeight](); // for main, context if (config[__axis_rotated]) { $$.margin = { - top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) + top: $$[getHorizontalAxisHeight]('y2') + $$[getCurrentPaddingTop](), + right: hasArc ? 0 : $$[getCurrentPaddingRight](), + bottom: $$[getHorizontalAxisHeight]('y') + legendHeightForBottom + $$[getCurrentPaddingBottom](), + left: subchartHeight + (hasArc ? 0 : $$[getCurrentPaddingLeft]()) }; $$.margin2 = { top: $$.margin.top, right: NaN, bottom: 20 + legendHeightForBottom, - left: $$.rotated_padding_left + left: $$[rotated_padding_left] }; } else { $$.margin = { - top: 4 + $$.getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: hasArc ? 0 : $$.getCurrentPaddingLeft() + top: 4 + $$[getCurrentPaddingTop](), // for top tick text + right: hasArc ? 0 : $$[getCurrentPaddingRight](), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$[getCurrentPaddingBottom](), + left: hasArc ? 0 : $$[getCurrentPaddingLeft]() }; $$.margin2 = { top: $$.currentHeight - subchartHeight - legendHeightForBottom, @@ -874,14 +932,14 @@ } // for legend var insetLegendPosition = { - 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 + 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 }; $$.margin3 = { - top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + top: $$[isLegendRight] ? 0 : $$[isLegendInset] ? insetLegendPosition.top : $$.currentHeight - legendHeight, right: NaN, bottom: 0, - left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + left: $$[isLegendRight] ? $$.currentWidth - legendWidth : $$[isLegendInset] ? insetLegendPosition.left : 0 }; $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; @@ -889,76 +947,77 @@ if ($$.width < 0) { $$.width = 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; if ($$.width2 < 0) { $$.width2 = 0; } if ($$.height2 < 0) { $$.height2 = 0; } // for arc - $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); - $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); + $$.arcWidth = $$.width - ($$[isLegendRight] ? legendWidth + 10 : 0); + $$.arcHeight = $$.height - ($$[isLegendRight] ? 0 : 10); if (isFunction($$.updateRadius)) { - $$.updateRadius(); + $$[updateRadius](); } - if ($$.isLegendRight && hasArc) { + if ($$[isLegendRight] && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } }; - c3_chart_internal_fn.updateTargets = function (targets) { + var updateTargets = 'updateTargets'; + c3_chart_internal_fn[updateTargets] = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) + mainTextUpdate = main.select('.' + CLASS[chartTexts]).selectAll('.' + CLASS[chartText]) .data(targets) - .attr('class', generateCall($$.classChartText, $$)); + .attr(CSS_CLASS, generateCall($$[classChartText], $$)); mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', generateCall($$.classChartText, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); + .attr(CSS_CLASS, generateCall($$[classChartText], $$)) + .style(CSS_OPACITY, 0) + .style(CSS_POINTER_EVENTS, "none"); mainTextEnter.append('g') - .attr('class', generateCall($$.classTexts, $$)); + .attr(CSS_CLASS, generateCall($$[classTexts], $$)); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + mainBarUpdate = main.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); + .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', generateCall($$.classChartBar, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); + .attr(CSS_CLASS, generateCall($$[classChartBar], $$)) + .style(CSS_OPACITY, 0) + .style(CSS_POINTER_EVENTS, "none"); // Bars for each data mainBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)) + .attr(CSS_CLASS, generateCall($$[classBars], $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); //-- Line --// - mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + mainLineUpdate = main.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); + .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', generateCall($$.classChartLine, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); + .attr(CSS_CLASS, generateCall($$[classChartLine], $$)) + .style(CSS_OPACITY, 0) + .style(CSS_POINTER_EVENTS, "none"); // Lines for each data mainLineEnter.append('g') - .attr("class", generateCall($$.classLines, $$)); + .attr(CSS_CLASS, generateCall($$[classLines], $$)); // Areas mainLineEnter.append('g') - .attr('class', generateCall($$.classAreas, $$)); + .attr(CSS_CLASS, generateCall($$[classAreas], $$)); // Circles for each data point on lines mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); + .attr(CSS_CLASS, function (d) { return $$[generateClass](CLASS[selectedCircles], d.id); }); mainLineEnter.append('g') - .attr("class", generateCall($$.classCircles, $$)) + .attr(CSS_CLASS, generateCall($$[classCircles], $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + main.selectAll('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](t.id)).selectAll('.' + CLASS[selectedCircle]).each(function (d) { d.value = t.values[d.index].value; }); }); @@ -966,31 +1025,32 @@ //mainLineUpdate.exit().remove(); if (isFunction($$.updateTargetsForArc)) { - $$.updateTargetsForArc(targets); + $$[updateTargetsForArc](targets); } if (isFunction($$.updateTargetsForSubchart)) { - $$.updateTargetsForSubchart(targets); + $$[updateTargetsForSubchart](targets); } /*-- Show --*/ // Fade-in each chart - $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) + $$.svg.selectAll('.' + CLASS[target]).filter(function (d) { return $$[isTargetToShow](d.id); }) .transition().duration(config[__transition_duration]) - .style("opacity", 1); + .style(CSS_OPACITY, 1); }; - c3_chart_internal_fn.redraw = function (options, transitions) { + var redraw = 'redraw'; + c3_chart_internal_fn[redraw] = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var areaIndices = $$[getShapeIndices]($$.isAreaType), barIndices = $$[getShapeIndices]($$.isBarType), lineIndices = $$[getShapeIndices]($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$.hasArcType($$.data.targets); + var hideAxis = $$[hasArcType]($$.data.targets); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; - var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; + var targetsToShow = $$[filterTargetsToShow]($$.data.targets), tickValues, i, intervalForCulling; xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); @@ -1009,23 +1069,23 @@ durationForExit = withTransitionForExit ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0; - transitions = transitions || $$.generateAxisTransitions(durationForAxis); + transitions = transitions || $$[generateAxisTransitions](durationForAxis); // update legend and transform each g if (withLegend && config[__legend_show]) { - $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); + $$[updateLegend]($$[mapToIds]($$.data.targets), options, transitions); } // MEMO: needed for grids calculation - if ($$.isCategorized && targetsToShow.length === 0) { + if ($$[isCategorized] && targetsToShow.length === 0) { $$.x.domain([0, $$.axes.x.selectAll('.tick').size()]); } if (targetsToShow.length) { - $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); + $$[updateXDomain](targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); // update axis tick values according to options if (!config[__axis_x_tick_values] && (config[__axis_x_tick_fit] || config[__axis_x_tick_count])) { - tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config[__axis_x_tick_count]); + tickValues = $$[generateTickValues]($$[mapTargetsToUniqueXs](targetsToShow), config[__axis_x_tick_count]); $$.xAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues); } @@ -1034,21 +1094,21 @@ $$.subXAxis.tickValues([]); } - $$.y.domain($$.getYDomain(targetsToShow, 'y')); - $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); + $$.y.domain($$[getYDomain](targetsToShow, 'y')); + $$.y2.domain($$[getYDomain](targetsToShow, 'y2')); // axes - $$.axes.x.style("opacity", hideAxis ? 0 : 1); - $$.axes.y.style("opacity", hideAxis ? 0 : 1); - $$.axes.y2.style("opacity", hideAxis ? 0 : 1); - $$.axes.subx.style("opacity", hideAxis ? 0 : 1); + $$.axes.x.style(CSS_OPACITY, hideAxis ? 0 : 1); + $$.axes.y.style(CSS_OPACITY, hideAxis ? 0 : 1); + $$.axes.y2.style(CSS_OPACITY, hideAxis ? 0 : 1); + $$.axes.subx.style(CSS_OPACITY, hideAxis ? 0 : 1); transitions.axisX.call($$.xAxis); transitions.axisY.call($$.yAxis); transitions.axisY2.call($$.y2Axis); transitions.axisSubX.call($$.subXAxis); // Update axis label - $$.updateAxisLabels(withTransition); + $$[updateAxisLabels](withTransition); // show/hide if manual culling needed if (withUpdateXDomain && targetsToShow.length) { @@ -1059,28 +1119,28 @@ break; } } - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { + $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').each(function (e) { var index = tickValues.indexOf(e); if (index >= 0) { d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); } }); } else { - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); + $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').style('display', 'block'); } } // rotate tick text if needed if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { - $$.rotateTickText($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); + $$[rotateTickText]($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); } // setup drawer - MEMO: these must be called after axis updated - drawArea = $$.generateDrawArea(areaIndices, false); - drawBar = $$.generateDrawBar(barIndices); - drawLine = $$.generateDrawLine(lineIndices, false); - xForText = $$.generateXYForText(barIndices, true); - yForText = $$.generateXYForText(barIndices, false); + drawArea = $$[generateDrawArea](areaIndices, false); + drawBar = $$[generateDrawBar](barIndices); + drawLine = $$[generateDrawLine](lineIndices, false); + xForText = $$[generateXYForText](barIndices, true); + yForText = $$[generateXYForText](barIndices, false); // Update sub domain $$.subY.domain($$.y.domain()); @@ -1090,221 +1150,221 @@ $$.tooltip.style("display", "none"); // xgrid focus - $$.updateXgridFocus(); + $$[updateXgridFocus](); // 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("y", $$.height / 2) .text(config[__data_empty_label_text]) .transition() - .style('opacity', targetsToShow.length ? 0 : 1); + .style(CSS_OPACITY, targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + main.select('line.' + CLASS[xgridFocus]).style(CSS_VISIBILITY, "hidden"); if (config[__grid_x_show]) { xgridAttr = config[__axis_rotated] ? { 'x1': 0, 'x2': $$.width, - 'y1': function (d) { return $$.x(d) - tickOffset; }, - 'y2': function (d) { return $$.x(d) - tickOffset; } + 'y1': function (d) { return $$[x](d) - tickOffset; }, + 'y2': function (d) { return $$[x](d) - tickOffset; } } : { - 'x1': function (d) { return $$.x(d) + tickOffset; }, - 'x2': function (d) { return $$.x(d) + tickOffset; }, + 'x1': function (d) { return $$[x](d) + tickOffset; }, + 'x2': function (d) { return $$[x](d) + tickOffset; }, 'y1': 0, 'y2': $$.height }; // this is used to flow flushXGrid = function (withoutUpdate) { - xgridData = $$.generateGridData(config[__grid_x_type], $$.x); - tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) + xgridData = $$[generateGridData](config[__grid_x_type], $$.x); + tickOffset = $$[isCategorized] ? $$.xAxis.tickOffset() : 0; + xgrid = main.select('.' + CLASS[xgrids]).selectAll('.' + CLASS[xgrid]) .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS.xgrid); + xgrid.enter().append('line').attr(CSS_CLASS, CLASS[xgrid]); if (!withoutUpdate) { xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); + .style(CSS_OPACITY, function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); } xgrid.exit().remove(); }; flushXGrid(); } - xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) + xgridLines = main.select('.' + CLASS[xgridLines]).selectAll('.' + CLASS[xgridLine]) .data(config[__grid_x_lines]); // enter xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); + .attr(CSS_CLASS, function (d) { return CLASS[xgridLine] + (d.class ? ' ' + d.class : ''); }); xgridLine.append('line') - .style("opacity", 0); + .style(CSS_OPACITY, 0); xgridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .attr(CSS_TEXT_ANCHOR, "end") + .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) - .style("opacity", 0); + .style(CSS_OPACITY, 0); // udpate // done in d3.transition() of the end of this function // exit xgridLines.exit().transition().duration(duration) - .style("opacity", 0) + .style(CSS_OPACITY, 0) .remove(); // Y-Grid if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) + ygrid = main.select('.' + CLASS[ygrids]).selectAll('.' + CLASS[ygrid]) .data($$.y.ticks(config[__grid_y_ticks])); ygrid.enter().append('line') - .attr('class', CLASS.ygrid); + .attr(CSS_CLASS, CLASS[ygrid]); ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) .attr("x2", config[__axis_rotated] ? $$.y : $$.width) .attr("y1", config[__axis_rotated] ? 0 : $$.y) .attr("y2", config[__axis_rotated] ? $$.height : $$.y); ygrid.exit().remove(); - $$.smoothLines(ygrid, 'grid'); + $$[smoothLines](ygrid, 'grid'); } if (withY) { - ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) + ygridLines = main.select('.' + CLASS[ygridLines]).selectAll('.' + CLASS[ygridLine]) .data(config[__grid_y_lines]); // enter ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); + .attr(CSS_CLASS, function (d) { return CLASS[ygridLine] + (d.class ? ' ' + d.class : ''); }); ygridLine.append('line') - .style("opacity", 0); + .style(CSS_OPACITY, 0); ygridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .attr(CSS_TEXT_ANCHOR, "end") + .attr(CSS_TRANSFORM, config[__axis_rotated] ? "rotate(-90)" : "") .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) - .style("opacity", 0); + .style(CSS_OPACITY, 0); // update - var yv_ = generateCall($$.yv, $$); + var yv_ = generateCall($$[yv], $$); ygridLines.select('line') .transition().duration(duration) .attr("x1", config[__axis_rotated] ? yv_ : 0) .attr("x2", config[__axis_rotated] ? yv_ : $$.width) .attr("y1", config[__axis_rotated] ? 0 : yv_) .attr("y2", config[__axis_rotated] ? $$.height : yv_) - .style("opacity", 1); + .style(CSS_OPACITY, 1); ygridLines.select('text') .transition().duration(duration) .attr("x", config[__axis_rotated] ? 0 : $$.width) .attr("y", yv_) .text(function (d) { return d.text; }) - .style("opacity", 1); + .style(CSS_OPACITY, 1); // exit ygridLines.exit().transition().duration(duration) - .style("opacity", 0) + .style(CSS_OPACITY, 0) .remove(); } // rect for regions - mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) + mainRegion = main.select('.' + CLASS[regions]).selectAll('.' + CLASS[region]) .data(config[__regions]); mainRegion.enter().append('g') - .attr('class', generateCall($$.classRegion, $$)) + .attr(CSS_CLASS, generateCall($$[classRegion], $$)) .append('rect') - .style("fill-opacity", 0); + .style(CSS_FILL_OPACITY, 0); mainRegion.exit().transition().duration(duration) - .style("opacity", 0) + .style(CSS_OPACITY, 0) .remove(); // bars - mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(generateCall($$.barData, $$)); + mainBar = main.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) + .data(generateCall($$[barData], $$)); mainBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) - .style("stroke", function (d) { return $$.color(d.id); }) - .style("fill", function (d) { return $$.color(d.id); }); + .attr(CSS_CLASS, generateCall($$[classBar], $$)) + .style("stroke", function (d) { return $$[color](d.id); }) + .style("fill", function (d) { return $$[color](d.id); }); mainBar - .style("opacity", generateCall($$.initialOpacity, $$)); + .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)); mainBar.exit().transition().duration(durationForExit) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(generateCall($$.lineData, $$)); + mainLine = main.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) + .data(generateCall($$[lineData], $$)); mainLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) + .attr(CSS_CLASS, generateCall($$[classLine], $$)) .style("stroke", $$.color); mainLine - .style("opacity", generateCall($$.initialOpacity, $$)) - .attr('transform', null); + .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) + .attr(CSS_TRANSFORM, null); mainLine.exit().transition().duration(durationForExit) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); - mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(generateCall($$.lineData, $$)); + mainArea = main.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) + .data(generateCall($$[lineData], $$)); mainArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) + .attr(CSS_CLASS, generateCall($$[classArea], $$)) .style("fill", $$.color) - .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + .style(CSS_OPACITY, function () { $$.orgAreaOpacity = +d3.select(this).style(CSS_OPACITY); return 0; }); mainArea - .style("opacity", $$.orgAreaOpacity); + .style(CSS_OPACITY, $$.orgAreaOpacity); mainArea.exit().transition().duration(durationForExit) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) - .data(generateCall($$.lineOrScatterData, $$)); + mainCircle = main.selectAll('.' + CLASS[circles]).selectAll('.' + CLASS[circle]) + .data(generateCall($$[lineOrScatterData], $$)); mainCircle.enter().append("circle") - .attr("class", generateCall($$.classCircle, $$)) - .attr("r", generateCall($$.pointR, $$)) + .attr(CSS_CLASS, generateCall($$[classCircle], $$)) + .attr("r", generateCall($$[pointR], $$)) .style("fill", $$.color); mainCircle - .style("opacity", generateCall($$.initialOpacity, $$)); + .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)); mainCircle.exit().remove(); } - if ($$.hasDataLabel()) { - mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) - .data(generateCall($$.barOrLineData, $$)); + if ($$[hasDataLabel]()) { + mainText = main.selectAll('.' + CLASS[texts]).selectAll('.' + CLASS[text]) + .data(generateCall($$[barOrLineData], $$)); mainText.enter().append('text') - .attr("class", generateCall($$.classText, $$)) - .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .attr(CSS_CLASS, generateCall($$[classText], $$)) + .attr(CSS_TEXT_ANCHOR, function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') - .style("fill", function (d) { return $$.color(d); }) - .style("fill-opacity", 0); + .style("fill", function (d) { return $$[color](d); }) + .style(CSS_FILL_OPACITY, 0); mainText - .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); + .text(function (d) { return $$[formatByAxisId]($$[getAxisId](d.id))(d.value, d.id); }); mainText.exit() .transition().duration(durationForExit) - .style('fill-opacity', 0) + .style(CSS_FILL_OPACITY, 0) .remove(); } // arc if (isFunction($$.redrawArc)) { - $$.redrawArc(duration, durationForExit, withTransform); + $$[redrawArc](duration, durationForExit, withTransform); } // subchart if (isFunction($$.redrawSubchart)) { - $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); + $$[redrawSubchart](withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } // circles for select - main.selectAll('.' + CLASS.selectedCircles) - .filter(generateCall($$.isBarType, $$)) + main.selectAll('.' + CLASS[selectedCircles]) + .filter(generateCall($$[isBarType], $$)) .selectAll('circle') .remove(); if (config[__interaction_enabled]) { // rect for mouseover - eventRect = main.select('.' + CLASS.eventRects) + eventRect = main.select('.' + CLASS[eventRects]) .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { + if (notEmpty(config[__data_xs]) && !$$[isSingleX](config[__data_xs])) { - if (!eventRect.classed(CLASS.eventRectsMultiple)) { - eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) - .selectAll('.' + CLASS.eventRect).remove(); + if (!eventRect.classed(CLASS[eventRectsMultiple])) { + eventRect.classed(CLASS[eventRectsMultiple], true).classed(CLASS[eventRectsSingle], false) + .selectAll('.' + CLASS[eventRect]).remove(); } - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) .data([0]); // enter : only one rect will be added - $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); + $$[generateEventRectsForMultipleXs](eventRectUpdate.enter()); // update eventRectUpdate .attr('x', 0) @@ -1314,39 +1374,39 @@ // exit : not needed because always only one rect exists } else { - if (!eventRect.classed(CLASS.eventRectsSingle)) { - eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) - .selectAll('.' + CLASS.eventRect).remove(); + if (!eventRect.classed(CLASS[eventRectsSingle])) { + eventRect.classed(CLASS[eventRectsMultiple], false).classed(CLASS[eventRectsSingle], true) + .selectAll('.' + CLASS[eventRect]).remove(); } - if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { + if (($$[isCustomX]() || $$[isTimeSeries]) && !$$[isCategorized]) { rectW = function (d) { - var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], - w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; + var prevX = $$[getPrevX](d.index), nextX = $$[getNextX](d.index), dx = $$.data.xs[d.id][d.index], + w = ($$[x](nextX ? nextX : dx) - $$[x](prevX ? prevX : dx)) / 2; return w < 0 ? 0 : w; }; rectX = function (d) { - var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; - return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; + var prevX = $$[getPrevX](d.index), dx = $$.data.xs[d.id][d.index]; + return ($$[x](dx) + $$[x](prevX ? prevX : dx)) / 2; }; } else { - rectW = $$.getEventRectWidth(); + rectW = $$[getEventRectWidth](); rectX = function (d) { - return $$.x(d.x) - (rectW / 2); + return $$[x](d.x) - (rectW / 2); }; } // Set data - maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); - main.select('.' + CLASS.eventRects) + maxDataCountTarget = $$[getMaxDataCountTarget]($$.data.targets); + main.select('.' + CLASS[eventRects]) .datum(maxDataCountTarget ? maxDataCountTarget.values : []); // Update rects - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) .data(function (d) { return d; }); // enter - $$.generateEventRectsForSingleX(eventRectUpdate.enter()); + $$[generateEventRectsForSingleX](eventRectUpdate.enter()); // update eventRectUpdate - .attr('class', generateCall($$.classEvent, $$)) + .attr(CSS_CLASS, generateCall($$[classEvent], $$)) .attr("x", config[__axis_rotated] ? 0 : rectX) .attr("y", config[__axis_rotated] ? rectX : 0) .attr("width", config[__axis_rotated] ? $$.width : rectW) @@ -1356,7 +1416,7 @@ } } - var xv_ = generateCall($$.xv, $$); + var xv_ = generateCall($$[xv], $$); // transition should be derived from one transition d3.transition().duration(duration).each(function () { @@ -1367,48 +1427,48 @@ transitions.push(mainBar.transition() .attr('d', drawBar) .style("fill", $$.color) - .style("opacity", 1)); + .style(CSS_OPACITY, 1)); transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) - .style("opacity", 1)); + .style(CSS_OPACITY, 1)); transitions.push(mainArea.transition() .attr("d", drawArea) .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity)); + .style(CSS_OPACITY, $$.orgAreaOpacity)); transitions.push(mainCircle.transition() - .style('opacity', generateCall($$.opacityForCircle, $$)) + .style(CSS_OPACITY, generateCall($$[opacityForCircle], $$)) .style("fill", $$.color) .attr("cx", cx) .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() + transitions.push(main.selectAll('.' + CLASS[selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); transitions.push(mainText.transition() .attr('x', xForText) .attr('y', yForText) .style("fill", $$.color) - .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); + .style(CSS_FILL_OPACITY, options.flow ? 0 : generateCall($$[opacityForText], $$))); transitions.push(mainRegion.selectAll('rect').transition() .attr("x", $$.regionX) .attr("y", $$.regionY) .attr("width", $$.regionWidth) .attr("height", $$.regionHeight) - .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + .style(CSS_FILL_OPACITY, function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() .attr("x1", config[__axis_rotated] ? 0 : xv_) .attr("x2", config[__axis_rotated] ? $$.width : xv_) .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) .attr("y2", config[__axis_rotated] ? xv_ : $$.height) - .style("opacity", 1)); + .style(CSS_OPACITY, 1)); transitions.push(xgridLines.select('text').transition() .attr("x", config[__axis_rotated] ? $$.width : 0) .attr("y", xv_) .text(function (d) { return d.text; }) - .style("opacity", 1)); + .style(CSS_OPACITY, 1)); // Wait for end of transitions if called from flow API if (options.flow) { - waitForDraw = $$.generateWait(); + waitForDraw = $$[generateWait](); transitions.forEach(function (t) { waitForDraw.add(t); }); @@ -1418,12 +1478,12 @@ var translateX, scaleX = 1, transform, flowIndex = options.flow.index, flowLength = options.flow.length, - flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), + flowStart = $$[getValueOnIndex]($$.data.targets[0].values, flowIndex), + flowEnd = $$[getValueOnIndex]($$.data.targets[0].values, flowIndex + flowLength), orgDomain = $$.x.domain(), domain, durationForFlow = options.flow.duration || duration, done = options.flow.done || function () {}, - wait = $$.generateWait(); + wait = $$[generateWait](); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -1431,30 +1491,30 @@ }); // update x domain to generate axis elements for flow - domain = $$.updateXDomain(targetsToShow, true, true); + domain = $$[updateXDomain](targetsToShow, true, true); // update elements related to x scale if (flushXGrid) { flushXGrid(true); } // generate transform to flow if (!options.flow.orgDataCount) { // if empty if ($$.data.targets[0].values.length !== 1) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + translateX = $$[x](orgDomain[0]) - $$[x](domain[0]); } else { - if ($$.isTimeSeries) { - flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); - translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); + if ($$[isTimeSeries]) { + flowStart = $$[getValueOnIndex]($$.data.targets[0].values, 0); + flowEnd = $$[getValueOnIndex]($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$[x](flowStart.x) - $$[x](flowEnd.x); } else { translateX = diffDomain(domain) / 2; } } } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + translateX = $$[x](orgDomain[0]) - $$[x](domain[0]); } else { - if ($$.isTimeSeries) { - translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); + if ($$[isTimeSeries]) { + translateX = ($$[x](orgDomain[0]) - $$[x](domain[0])); } else { - translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); + translateX = ($$[x](flowStart.x) - $$[x](flowEnd.x)); } } scaleX = (diffDomain(orgDomain) / diffDomain(domain)); @@ -1462,14 +1522,14 @@ d3.transition().ease('linear').duration(durationForFlow).each(function () { wait.add($$.axes.x.transition().call($$.xAxis)); - wait.add(mainBar.transition().attr('transform', transform)); - wait.add(mainLine.transition().attr('transform', transform)); - wait.add(mainArea.transition().attr('transform', transform)); - wait.add(mainCircle.transition().attr('transform', transform)); - wait.add(mainText.transition().attr('transform', transform)); - wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); - wait.add(xgrid.transition().attr('transform', transform)); - wait.add(xgridLines.transition().attr('transform', transform)); + wait.add(mainBar.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainLine.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainArea.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainCircle.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainText.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr(CSS_TRANSFORM, transform)); + wait.add(xgrid.transition().attr(CSS_TRANSFORM, transform)); + wait.add(xgridLines.transition().attr(CSS_TRANSFORM, transform)); }) .call(wait, function () { var i, shapes = [], texts = [], eventRects = []; @@ -1477,22 +1537,22 @@ // remove flowed elements if (flowLength) { for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); - texts.push('.' + CLASS.text + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); + shapes.push('.' + CLASS[shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[eventRect] + '-' + (flowIndex + i)); } - $$.svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS.xgrid).remove(); + $$.svg.selectAll('.' + CLASS[shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[xgrid]).remove(); } // draw again for removing flowed elements and reverting attr xgrid - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr(xgridAttr); xgridLines - .attr('transform', null); + .attr(CSS_TRANSFORM, null); xgridLines.select('line') .attr("x1", config[__axis_rotated] ? 0 : xv_) .attr("x2", config[__axis_rotated] ? $$.width : xv_); @@ -1500,25 +1560,25 @@ .attr("x", config[__axis_rotated] ? $$.width : 0) .attr("y", xv_); mainBar - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr("d", drawBar); mainLine - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr("d", drawLine); mainArea - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr("d", drawArea); mainCircle - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY); mainText - .attr('transform', null) + .attr(CSS_TRANSFORM, null) .attr('x', xForText) .attr('y', yForText) - .style('fill-opacity', generateCall($$.opacityForText, $$)); + .style(CSS_FILL_OPACITY, generateCall($$[opacityForText], $$)); mainRegion - .attr('transform', null); + .attr(CSS_TRANSFORM, null); mainRegion.select('rect').filter($$.isRegionOnX) .attr("x", $$.regionX) .attr("width", $$.regionWidth); @@ -1534,18 +1594,20 @@ }); // update fadein condition - $$.mapToIds($$.data.targets).forEach(function (id) { - $$.withoutFadeIn[id] = true; + $$[mapToIds]($$.data.targets).forEach(function (id) { + $$[withoutFadeIn][id] = true; }); - $$.updateZoom(); + $$[updateZoom](); }; - c3_chart_internal_fn.redrawForZoom = function () { + + var redrawForZoom = 'redrawForZoom'; + c3_chart_internal_fn[redrawForZoom] = function () { var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; if (!config[__zoom_enabled]) { return; } - if ($$.filterTargetsToShow($$.data.targets).length === 0) { + if ($$[filterTargetsToShow]($$.data.targets).length === 0) { return; } if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { @@ -1553,20 +1615,21 @@ zoom.scale(x).updateScaleExtent(); return; } - if ($$.isCategorized && x.orgDomain()[0] === orgXDomain[0]) { + if ($$[isCategorized] && x.orgDomain()[0] === orgXDomain[0]) { x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); } - $$.redraw({ + $$[redraw]({ withTransition: false, withY: false, withSubchart: false }); if (d3.event.sourceEvent.type === 'mousemove') { - $$.cancelClick = true; + $$[cancelClick] = true; } config[__zoom_onzoom].call(c3, x.orgDomain()); }; - c3_chart_internal_fn.updateAndRedraw = function (options) { + var updateAndRedraw = 'updateAndRedraw'; + c3_chart_internal_fn[updateAndRedraw] = function (options) { var $$ = this, config = $$.config, transitions; options = options || {}; // same with redraw @@ -1579,33 +1642,34 @@ 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(); + $$[updateSizes](); // MEMO: called in updateLegend in redraw if withLegend if (!(options.withLegend && config[__legend_show])) { - transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? config[__transition_duration] : 0); + transitions = $$[generateAxisTransitions](options.withTransitionForAxis ? config[__transition_duration] : 0); // Update scales - $$.updateScales(); - $$.updateSvgSize(); + $$[updateScales](); + $$[updateSvgSize](); // Update g positions - $$.transformAll(options.withTransitionForTransform, transitions); + $$[transformAll](options.withTransitionForTransform, transitions); } // Draw with new sizes & scales - $$.redraw(options, transitions); + $$[redraw](options, transitions); }; - c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { + var generateEventRectsForSingleX = 'generateEventRectsForSingleX'; + c3_chart_internal_fn[generateEventRectsForSingleX] = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append("rect") - .attr("class", generateCall($$.classEvent, $$)) + .attr(CSS_CLASS, generateCall($$[classEvent], $$)) .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; - if ($$.dragging) { return; } // do nothing if dragging - if ($$.hasArcType($$.data.targets)) { return; } + if ($$[dragging]) { return; } // do nothing if dragging + if ($$[hasArcType]($$.data.targets)) { return; } selectedData = $$.data.targets.map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); + return $$[addName]($$[getValueOnIndex](t.values, index)); }); // Sort selectedData as names order @@ -1622,69 +1686,69 @@ selectedData = newData.concat(selectedData); // Add remained // Expand shapes for selection - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } - $$.expandBars(index); + if (config[__point_focus_expand_enabled]) { $$[expandCircles](index); } + $$[expandBars](index); // Call event handler - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - config[__data_onmouseover].call(c3, d); - }); + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each( + generateCall(config[__data_onmouseover], $$) + ); }) .on('mouseout', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); + if ($$[hasArcType]($$.data.targets)) { return; } + $$[hideXGridFocus](); + $$[hideTooltip](); // Undo expanded shapes - $$.unexpandCircles(index); - $$.unexpandBars(); + $$[unexpandCircles](index); + $$[unexpandBars](); // Call event handler - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { - config[__data_onmouseout].call($$, d); - }); + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each( + generateCall(config[__data_onmouseout], $$) + ); }) .on('mousemove', function (d) { var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); + eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType($$.data.targets)) { return; } + if ($$[dragging]) { return; } // do nothing when dragging + if ($$[hasArcType]($$.data.targets)) { return; } // Show tooltip - selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); + selectedData = $$[filterTargetsToShow]($$.data.targets).map(function (t) { + return $$[addName]($$[getValueOnIndex](t.values, index)); }); if (config[__tooltip_grouped]) { - $$.showTooltip(selectedData, d3.mouse(this)); - $$.showXGridFocus(selectedData); + $$[showTooltip](selectedData, d3.mouse(this)); + $$[showXGridFocus](selectedData); } if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { return; } - $$.main.selectAll('.' + CLASS.shape + '-' + index) + $$.main.selectAll('.' + CLASS[shape] + '-' + index) .each(function () { - d3.select(this).classed(CLASS.EXPANDED, true); + d3.select(this).classed(CLASS[EXPANDED], true); if (config[__data_selection_enabled]) { eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); } if (!config[__tooltip_grouped]) { - $$.hideXGridFocus(); - $$.hideTooltip(); + $$[hideXGridFocus](); + $$[hideTooltip](); if (!config[__data_selection_grouped]) { - $$.unexpandCircles(index); - $$.unexpandBars(); + $$[unexpandCircles](index); + $$[unexpandBars](); } } }) .filter(function (d) { if (this.nodeName === 'circle') { - return $$.isWithinCircle(this, $$.pointSelectR(d)); + return $$[isWithinCircle](this, $$[pointSelectR](d)); } else if (this.nodeName === 'path') { - return $$.isWithinBar(this); + return $$[isWithinBar](this); } }) .each(function (d) { @@ -1692,114 +1756,115 @@ eventRect.style('cursor', 'pointer'); } if (!config[__tooltip_grouped]) { - $$.showTooltip([d], d3.mouse(this)); - $$.showXGridFocus([d]); - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } - $$.expandBars(index, d.id); + $$[showTooltip]([d], d3.mouse(this)); + $$[showXGridFocus]([d]); + if (config[__point_focus_expand_enabled]) { $$[expandCircles](index, d.id); } + $$[expandBars](index, d.id); } }); }) .on('click', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } - if ($$.cancelClick) { - $$.cancelClick = false; + if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[cancelClick]) { + $$[cancelClick] = false; return; } - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { $$[toggleShape](this, d, index); }); }) .call( d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) + .on('drag', function () { $$[drag](d3.mouse(this)); }) + .on('dragstart', function () { $$[dragstart](d3.mouse(this)); }) + .on('dragend', function () { $$[dragend](); }) ) .on("dblclick.zoom", null); }; - c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { + var generateEventRectsForMultipleXs = 'generateEventRectsForMultipleXs'; + c3_chart_internal_fn[generateEventRectsForMultipleXs] = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append('rect') .attr('x', 0) .attr('y', 0) .attr('width', $$.width) .attr('height', $$.height) - .attr('class', CLASS.eventRect) + .attr(CSS_CLASS, CLASS[eventRect]) .on('mouseout', function () { - if ($$.hasArcType($$.data.targets)) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); - $$.unexpandCircles(); + if ($$[hasArcType]($$.data.targets)) { return; } + $$[hideXGridFocus](); + $$[hideTooltip](); + $$[unexpandCircles](); }) .on('mousemove', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var targetsToShow = $$[filterTargetsToShow]($$.data.targets); var mouse, closest, sameXData, selectedData; - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType(targetsToShow)) { return; } + if ($$[dragging]) { return; } // do nothing when dragging + if ($$[hasArcType](targetsToShow)) { return; } mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); + closest = $$[findClosestFromTargets](targetsToShow, mouse); if (! closest) { return; } - if ($$.isScatterType(closest)) { + if ($$[isScatterType](closest)) { sameXData = [closest]; } else { - sameXData = $$.filterSameX(targetsToShow, closest.x); + sameXData = $$[filterSameX](targetsToShow, closest.x); } // show tooltip when cursor is close to some point selectedData = sameXData.map(function (d) { - return $$.addName(d); + return $$[addName](d); }); - $$.showTooltip(selectedData, mouse); + $$[showTooltip](selectedData, mouse); // expand points if (config[__point_focus_expand_enabled]) { - $$.unexpandCircles(); - $$.expandCircles(closest.index, closest.id); + $$[unexpandCircles](); + $$[expandCircles](closest.index, closest.id); } // Show xgrid focus line - $$.showXGridFocus(selectedData); + $$[showXGridFocus](selectedData); // Show cursor as pointer if point is close to mouse position - if ($$.dist(closest, mouse) < 100) { - $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); - if (!$$.mouseover) { + if ($$[dist](closest, mouse) < 100) { + $$.svg.select('.' + CLASS[eventRect]).style('cursor', 'pointer'); + if (!$$[mouseover]) { config[__data_onmouseover].call($$, closest); - $$.mouseover = true; + $$[mouseover] = true; } - } else if ($$.mouseover) { - $$.svg.select('.' + CLASS.eventRect).style('cursor', null); + } else if ($$[mouseover]) { + $$.svg.select('.' + CLASS[eventRect]).style('cursor', null); config[__data_onmouseout].call($$, closest); - $$.mouseover = false; + $$[mouseover] = false; } }) .on('click', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var targetsToShow = $$[filterTargetsToShow]($$.data.targets); var mouse, closest; - if ($$.hasArcType(targetsToShow)) { return; } + if ($$[hasArcType](targetsToShow)) { return; } mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); + closest = $$[findClosestFromTargets](targetsToShow, mouse); if (! closest) { return; } // select if selection enabled - if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { - $$.toggleShape(this, closest, closest.index); + if ($$[dist](closest, mouse) < 100) { + $$.main.select('.' + CLASS[circles] + $$[getTargetSelectorSuffix](closest.id)).select('.' + CLASS[circle] + '-' + closest.index).each(function () { + $$[toggleShape](this, closest, closest.index); }); } }) .call( d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) + .on('drag', function () { $$[drag](d3.mouse(this)); }) + .on('dragstart', function () { $$[dragstart](d3.mouse(this)); }) + .on('dragend', function () { $$[dragend](); }) ) .on("dblclick.zoom", null); }; @@ -1811,90 +1876,101 @@ - c3_chart_internal_fn.initialOpacity = function (d) { - return d.value !== null && this.withoutFadeIn[d.id] ? 1 : 0; + var initialOpacity = 'initialOpacity'; + c3_chart_internal_fn[initialOpacity] = function (d) { + return d.value !== null && this[withoutFadeIn][d.id] ? 1 : 0; }; - c3_chart_internal_fn.opacityForCircle = function (d) { + var opacityForCircle = 'opacityForCircle'; + c3_chart_internal_fn[opacityForCircle] = function (d) { var $$ = this; - return isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 0; + return isValue(d.value) ? $$[isScatterType](d) ? 0.5 : 1 : 0; }; - c3_chart_internal_fn.opacityForText = function () { - return this.hasDataLabel() ? 1 : 0; + var opacityForText = 'opacityForText'; + 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; + var xx = 'xx'; + c3_chart_internal_fn[xx] = function (d) { + return d ? this[x](d.x) : null; }; - c3_chart_internal_fn.xv = function (d) { + var xv = 'xv'; + c3_chart_internal_fn[xv] = function (d) { var $$ = this; - return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); + return Math.ceil($$[x]($$[isTimeSeries] ? $$[parseDate](d.value) : d.value)); }; - c3_chart_internal_fn.yv = function (d) { + var yv = 'yv'; + 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; + var subxx = 'subxx'; + c3_chart_internal_fn[subxx] = function (d) { + return d ? this[subX](d.x) : null; }; - c3_chart_internal_fn.transformMain = function (withTransition, transitions) { + var transformMain = 'transformMain'; + 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); + xAxis = $$.main.select('.' + CLASS[axisX]); if (withTransition) { xAxis = xAxis.transition(); } } if (transitions && transitions.axisY) { yAxis = transitions.axisY; } else { - yAxis = $$.main.select('.' + CLASS.axisY); + yAxis = $$.main.select('.' + CLASS[axisY]); if (withTransition) { yAxis = yAxis.transition(); } } if (transitions && transitions.axisY2) { y2Axis = transitions.axisY2; } else { - y2Axis = $$.main.select('.' + CLASS.axisY2); + y2Axis = $$.main.select('.' + CLASS[axisY2]); if (withTransition) { y2Axis = y2Axis.transition(); } } - (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); - xAxis.attr("transform", $$.translate.x); - yAxis.attr("transform", $$.translate.y); - y2Axis.attr("transform", $$.translate.y2); - $$.main.select('.' + CLASS.chartArcs).attr("transform", $$.translate.arc); + (withTransition ? $$.main.transition() : $$.main).attr(CSS_TRANSFORM, $$[translate].main); + xAxis.attr(CSS_TRANSFORM, $$[translate].x); + yAxis.attr(CSS_TRANSFORM, $$[translate].y); + y2Axis.attr(CSS_TRANSFORM, $$[translate].y2); + $$.main.select('.' + CLASS[chartArcs]).attr(CSS_TRANSFORM, $$[translate].arc); }; - c3_chart_internal_fn.transformLegend = function (withTransition) { + var transformLegend = 'transformLegend'; + c3_chart_internal_fn[transformLegend] = function (withTransition) { var $$ = this; - (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); + (withTransition ? $$.legend.transition() : $$.legend).attr(CSS_TRANSFORM, $$[translate].legend); }; - c3_chart_internal_fn.transformAll = function (withTransition, transitions) { + var transformAll = 'transformAll'; + c3_chart_internal_fn[transformAll] = function (withTransition, transitions) { var $$ = this; - $$.transformMain(withTransition, transitions); - if (config[__subchart_show]) { $$.transformContext(withTransition, transitions); } - $$.transformLegend(withTransition); + $$[transformMain](withTransition, transitions); + if (config[__subchart_show]) { $$[transformContext](withTransition, transitions); } + $$[transformLegend](withTransition); }; - c3_chart_internal_fn.updateSvgSize = function () { + var updateSvgSize = 'updateSvgSize'; + c3_chart_internal_fn[updateSvgSize] = function () { var $$ = this; $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); - $$.svg.select('#' + $$.clipId).select('rect') + $$.svg.select('#' + $$[clipId]).select('rect') .attr('width', $$.width) .attr('height', $$.height); - $$.svg.select('#' + $$.clipIdForXAxis).select('rect') - .attr('x', function () { return $$.getXAxisClipX(); }) - .attr('y', function () { return $$.getXAxisClipY(); }) - .attr('width', function () { return $$.getXAxisClipWidth(); }) - .attr('height', function () { return $$.getXAxisClipHeight(); }); - $$.svg.select('#' + $$.clipIdForYAxis).select('rect') - .attr('x', function () { return $$.getYAxisClipX(); }) - .attr('y', function () { return $$.getYAxisClipY(); }) - .attr('width', function () { return $$.getYAxisClipWidth(); }) - .attr('height', function () { return $$.getYAxisClipHeight(); }); - $$.svg.select('.' + CLASS.zoomRect) + $$.svg.select('#' + $$[clipIdForXAxis]).select('rect') + .attr('x', generateCall($$[getXAxisClipX], $$)) + .attr('y', generateCall($$[getXAxisClipY], $$)) + .attr('width', generateCall($$[getXAxisClipWidth], $$)) + .attr('height', generateCall($$[getXAxisClipHeight], $$)); + $$.svg.select('#' + $$[clipIdForYAxis]).select('rect') + .attr('x', generateCall($$[getYAxisClipX], $$)) + .attr('y', generateCall($$[getYAxisClipY], $$)) + .attr('width', generateCall($$[getYAxisClipWidth], $$)) + .attr('height', generateCall($$[getYAxisClipHeight], $$)); + $$.svg.select('.' + CLASS[zoomRect]) .attr('width', $$.width) .attr('height', $$.height); // MEMO: parent div's height will be bigger than svg when @@ -1902,7 +1978,8 @@ }; - c3_chart_internal_fn.updateDimension = function () { + var updateDimension = 'updateDimension'; + c3_chart_internal_fn[updateDimension] = function () { var $$ = this; if ($$.config[__axis_rotated]) { $$.axes.x.call($$.xAxis); @@ -1911,13 +1988,14 @@ $$.axes.y.call($$.yAxis); $$.axes.y2.call($$.y2Axis); } - $$.updateSizes(); - $$.updateScales(); - $$.updateSvgSize(); - $$.transformAll(false); + $$[updateSizes](); + $$[updateScales](); + $$[updateSvgSize](); + $$[transformAll](false); }; - c3_chart_internal_fn.observeInserted = function (selection) { + var observeInserted = 'observeInserted'; + c3_chart_internal_fn[observeInserted] = function (selection) { var $$ = this, observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' && mutation.previousSibling) { @@ -1927,8 +2005,8 @@ // parentNode will NOT be null when completed if (selection.node().parentNode) { window.clearInterval(interval); - $$.updateDimension(); - $$.redraw({ + $$[updateDimension](); + $$[redraw]({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -1936,7 +2014,7 @@ withTransitionForTransform: false, withLegend: true }); - selection.transition().style('opacity', 1); + selection.transition().style(CSS_OPACITY, 1); } }, 10); } @@ -1946,7 +2024,8 @@ }; - c3_chart_internal_fn.generateResize = function () { + var generateResize = 'generateResize'; + c3_chart_internal_fn[generateResize] = function () { var resizeFunctions = []; function callResizeFunctions() { resizeFunctions.forEach(function (f) { @@ -1961,46 +2040,53 @@ - c3_chart_internal_fn.getCurrentWidth = function () { + var getCurrentWidth = 'getCurrentWidth'; + c3_chart_internal_fn[getCurrentWidth] = function () { var $$ = this, config = $$.config; - return config[__size_width] ? config[__size_width] : $$.getParentWidth(); + return config[__size_width] ? config[__size_width] : $$[getParentWidth](); }; - c3_chart_internal_fn.getCurrentHeight = function () { + var getCurrentHeight = 'getCurrentHeight'; + c3_chart_internal_fn[getCurrentHeight] = function () { var $$ = this, config = $$.config, - h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); + h = config[__size_height] ? config[__size_height] : $$[getParentHeight](); return h > 0 ? h : 320; }; - c3_chart_internal_fn.getCurrentPaddingTop = function () { + var getCurrentPaddingTop = 'getCurrentPaddingTop'; + c3_chart_internal_fn[getCurrentPaddingTop] = function () { var config = this.config; return isValue(config[__padding_top]) ? config[__padding_top] : 0; }; - c3_chart_internal_fn.getCurrentPaddingBottom = function () { + var getCurrentPaddingBottom = 'getCurrentPaddingBottom'; + c3_chart_internal_fn[getCurrentPaddingBottom] = function () { var config = this.config; return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; }; - c3_chart_internal_fn.getCurrentPaddingLeft = function () { + var getCurrentPaddingLeft = 'getCurrentPaddingLeft'; + c3_chart_internal_fn[getCurrentPaddingLeft] = function () { var $$ = this, config = $$.config; if (isValue(config[__padding_left])) { return config[__padding_left]; } else if (config[__axis_rotated]) { - return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); + return !config[__axis_x_show] ? 1 : Math.max(ceil10($$[getAxisWidthByAxisId]('x')), 40); } else { - return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); + return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$[getAxisWidthByAxisId]('y')); } }; - c3_chart_internal_fn.getCurrentPaddingRight = function () { + var getCurrentPaddingRight = 'getCurrentPaddingRight'; + c3_chart_internal_fn[getCurrentPaddingRight] = function () { var $$ = this, config = $$.config, - defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; + defaultPadding = 10, legendWidthOnRight = $$[isLegendRight] ? $$[getLegendWidth]() + 20 : 0; if (isValue(config[__padding_right])) { return config[__padding_right] + 1; // 1 is needed not to hide tick line } else if (config[__axis_rotated]) { return defaultPadding + legendWidthOnRight; } else { - return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$[getAxisWidthByAxisId]('y2'))) + legendWidthOnRight; } }; - c3_chart_internal_fn.getParentRectValue = function (key) { + var getParentRectValue = 'getParentRectValue'; + c3_chart_internal_fn[getParentRectValue] = function (key) { var parent = this.selectChart.node(), v; while (parent && parent.tagName !== 'BODY') { v = parent.getBoundingClientRect()[key]; @@ -2011,54 +2097,60 @@ } return v; }; - c3_chart_internal_fn.getParentWidth = function () { - return this.getParentRectValue('width'); + var getParentWidth = 'getParentWidth'; + c3_chart_internal_fn[getParentWidth] = function () { + return this[getParentRectValue]('width'); }; - c3_chart_internal_fn.getParentHeight = function () { + var getParentHeight = 'getParentHeight'; + c3_chart_internal_fn[getParentHeight] = function () { var h = this.selectChart.style('height'); return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; }; - c3_chart_internal_fn.getSvgLeft = function () { + var getSvgLeft = 'getSvgLeft'; + c3_chart_internal_fn[getSvgLeft] = function () { var $$ = this, config = $$.config, - leftAxisClass = config[__axis_rotated] ? CLASS.axisX : CLASS.axisY, + leftAxisClass = config[__axis_rotated] ? CLASS[axisX] : CLASS[axisY], leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$.hasArcType($$.data.targets), - svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); + hasArc = $$[hasArcType]($$.data.targets), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$[getCurrentPaddingLeft]()); return svgLeft > 0 ? svgLeft : 0; }; - c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { - var $$ = this, position = $$.getAxisLabelPositionById(id); - return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); + var getAxisWidthByAxisId = 'getAxisWidthByAxisId'; + c3_chart_internal_fn[getAxisWidthByAxisId] = function (id) { + var $$ = this, position = $$[getAxisLabelPositionById](id); + return position.isInner ? 20 + $$[getMaxTickWidth](id) : 40 + $$[getMaxTickWidth](id); }; - c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { + var getHorizontalAxisHeight = 'getHorizontalAxisHeight'; + c3_chart_internal_fn[getHorizontalAxisHeight] = function (axisId) { var $$ = this, config = $$.config; if (axisId === 'x' && !config[__axis_x_show]) { return 0; } if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } - if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } - if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } - return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$[isLegendRight] && !$$[isLegendInset] ? 10 : 1; } + if (axisId === 'y2' && !config[__axis_y2_show]) { return $$[rotated_padding_top]; } + return ($$[getAxisLabelPositionById](axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; - c3_chart_internal_fn.getEventRectWidth = function () { + var getEventRectWidth = 'getEventRectWidth'; + c3_chart_internal_fn[getEventRectWidth] = function () { var $$ = this; - var target = $$.getMaxDataCountTarget($$.data.targets), + var target = $$[getMaxDataCountTarget]($$.data.targets), firstData, lastData, base, maxDataCount, ratio, w; if (!target) { return 0; } firstData = target.values[0], lastData = target.values[target.values.length - 1]; - base = $$.x(lastData.x) - $$.x(firstData.x); + base = $$[x](lastData.x) - $$[x](firstData.x); if (base === 0) { return $$.config[__axis_rotated] ? $$.height : $$.width; } - maxDataCount = $$.getMaxDataCount(); - ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + maxDataCount = $$[getMaxDataCount](); + ratio = ($$[hasType]($$.data.targets, TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2067,15 +2159,16 @@ /** * c3.tooltip.js */ - c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { + var showTooltip = 'showTooltip'; + c3_chart_internal_fn[showTooltip] = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$.hasArcType($$.data.targets), + var forArc = $$[hasArcType]($$.data.targets), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !config[__tooltip_show]) { return; } - $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$[getXAxisTickFormat](), $$[getYFormat](forArc), $$.color)).style("display", "block"); // Get tooltip dimensions tWidth = $$.tooltip.property('offsetWidth'); @@ -2086,23 +2179,23 @@ tooltipTop = ($$.height / 2) + mouse[1] + 20; } else { if (config[__axis_rotated]) { - svgLeft = $$.getSvgLeft(); + svgLeft = $$[getSvgLeft](); tooltipLeft = svgLeft + mouse[0] + 100; tooltipRight = tooltipLeft + tWidth; - chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); - tooltipTop = $$.x(dataToShow[0].x) + 20; + chartRight = $$[getCurrentWidth]() - $$[getCurrentPaddingRight](); + tooltipTop = $$[x](dataToShow[0].x) + 20; } else { - svgLeft = $$.getSvgLeft(); - tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; + svgLeft = $$[getSvgLeft](); + tooltipLeft = svgLeft + $$[getCurrentPaddingLeft]() + $$[x](dataToShow[0].x) + 20; tooltipRight = tooltipLeft + tWidth; - chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + chartRight = svgLeft + $$[getCurrentWidth]() - $$[getCurrentPaddingRight](); tooltipTop = mouse[1] + 15; } if (tooltipRight > chartRight) { tooltipLeft -= tooltipRight - chartRight; } - if (tooltipTop + tHeight > $$.getCurrentHeight()) { + if (tooltipTop + tHeight > $$[getCurrentHeight]()) { tooltipTop -= tHeight + 30; } } @@ -2111,7 +2204,8 @@ .style("top", tooltipTop + "px") .style("left", tooltipLeft + 'px'); }; - c3_chart_internal_fn.hideTooltip = function () { + var hideTooltip = 'hideTooltip'; + c3_chart_internal_fn[hideTooltip] = function () { this.tooltip.style("display", "none"); }; @@ -2119,36 +2213,40 @@ /** * c3.grid.js */ - c3_chart_internal_fn.showXGridFocus = function (selectedData) { + var showXGridFocus = 'showXGridFocus'; + c3_chart_internal_fn[showXGridFocus] = function (selectedData) { var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS.xgridFocus); + if ($$[hasType]($$.data.targets, TYPE_SCATTER) || $$[hasArcType]($$.data.targets)) { return; } + var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); focusEl - .style("visibility", "visible") + .style(CSS_VISIBILITY, "visible") .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); - $$.smoothLines(focusEl, 'grid'); + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$[xx], $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$[xx], $$)); + $$[smoothLines](focusEl, 'grid'); }; - c3_chart_internal_fn.hideXGridFocus = function () { - this.main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + var hideXGridFocus = 'hideXGridFocus'; + c3_chart_internal_fn[hideXGridFocus] = function () { + this.main.select('line.' + CLASS[xgridFocus]).style(CSS_VISIBILITY, "hidden"); }; - c3_chart_internal_fn.updateXgridFocus = function () { + var updateXgridFocus = 'updateXgridFocus'; + c3_chart_internal_fn[updateXgridFocus] = function () { var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS.xgridFocus) + $$.main.select('line.' + CLASS[xgridFocus]) .attr("x1", config[__axis_rotated] ? 0 : -10) .attr("x2", config[__axis_rotated] ? $$.width : -10) .attr("y1", config[__axis_rotated] ? -10 : 0) .attr("y2", config[__axis_rotated] ? -10 : $$.height); }; - c3_chart_internal_fn.generateGridData = function (type, scale) { + var generateGridData = 'generateGridData'; + c3_chart_internal_fn[generateGridData] = function (type, scale) { var $$ = this, gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS.axisX).selectAll('.tick').size(); + tickNum = $$.main.select("." + CLASS[axisX]).selectAll('.tick').size(); if (type === 'year') { - xDomain = $$.getXDomain(); + xDomain = $$[getXDomain](); firstYear = xDomain[0].getFullYear(); lastYear = xDomain[1].getFullYear(); for (i = firstYear; i <= lastYear; i++) { @@ -2162,26 +2260,28 @@ } return gridData; }; - c3_chart_internal_fn.getGridFilterToRemove = function (params) { + var getGridFilterToRemove = 'getGridFilterToRemove'; + c3_chart_internal_fn[getGridFilterToRemove] = function (params) { return params ? function (line) { var found = false; [].concat(params).forEach(function (param) { - if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + if ((('value' in param && line.value === params.value) || (CSS_CLASS in param && line.class === params.class))) { found = true; } }); return found; } : function () { return true; }; }; - c3_chart_internal_fn.removeGridLines = function (params, forX) { + var removeGridLines = 'removeGridLines'; + c3_chart_internal_fn[removeGridLines] = function (params, forX) { var $$ = this, config = $$.config, - toRemove = $$.getGridFilterToRemove(params), + toRemove = $$[getGridFilterToRemove](params), toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, - classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; + classLines = forX ? CLASS[xgridLines] : CLASS[ygridLines], + classLine = forX ? CLASS[xgridLine] : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) .transition().duration(config[__transition_duration]) - .style('opacity', 0).remove(); + .style(CSS_OPACITY, 0).remove(); if (forX) { config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); } else { @@ -2193,89 +2293,101 @@ /** * c3.legend.js */ - c3_chart_internal_fn.updateLegendStep = function (step) { - this.legendStep = step; + var updateLegendStep = 'updateLegendStep'; + c3_chart_internal_fn[updateLegendStep] = function (step) { + this[legendStep] = step; }; - c3_chart_internal_fn.updateLegendItemWidth = function (w) { - this.legendItemWidth = w; + var updateLegendItemWidth = 'updateLegendItemWidth'; + c3_chart_internal_fn[updateLegendItemWidth] = function (w) { + this[legendItemWidth] = w; }; - c3_chart_internal_fn.updateLegendItemHeight = function (h) { - this.legendItemHeight = h; + var updateLegendItemHeight = 'updateLegendItemHeight'; + c3_chart_internal_fn[updateLegendItemHeight] = function (h) { + this[legendItemHeight] = h; }; - c3_chart_internal_fn.getLegendWidth = function () { + var getLegendWidth = 'getLegendWidth'; + c3_chart_internal_fn[getLegendWidth] = function () { var $$ = this; - return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; + return $$.config[__legend_show] ? $$[isLegendRight] || $$[isLegendInset] ? $$[legendItemWidth] * ($$[legendStep] + 1) : $$.currentWidth : 0; }; - c3_chart_internal_fn.getLegendHeight = function () { + var getLegendHeight = 'getLegendHeight'; + c3_chart_internal_fn[getLegendHeight] = function () { var $$ = this, config = $$.config, h = 0; if (config[__legend_show]) { - if ($$.isLegendRight) { + if ($$[isLegendRight]) { h = $$.currentHeight; - } else if ($$.isLegendInset) { - h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; + } else if ($$[isLegendInset]) { + h = config[__legend_inset_step] ? Math.max(20, $$[legendItemHeight]) * (config[__legend_inset_step] + 1) : $$.height; } else { - h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); + h = Math.max(20, $$[legendItemHeight]) * ($$[legendStep] + 1); } } return h; }; - c3_chart_internal_fn.opacityForLegend = function (legendItem) { + var opacityForLegend = 'opacityForLegend'; + c3_chart_internal_fn[opacityForLegend] = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; + return legendItem.classed(CLASS[legendItemHidden]) ? $$[legendOpacityForHidden] : 1; }; - c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { + var opacityForUnfocusedLegend = 'opacityForUnfocusedLegend'; + c3_chart_internal_fn[opacityForUnfocusedLegend] = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; + return legendItem.classed(CLASS[legendItemHidden]) ? $$[legendOpacityForHidden] : 0.3; }; - c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { + var toggleFocusLegend = 'toggleFocusLegend'; + c3_chart_internal_fn[toggleFocusLegend] = function (id, focus) { var $$ = this; - $$.legend.selectAll('.' + CLASS.legendItem) + $$.legend.selectAll('.' + CLASS[legendItem]) .transition().duration(100) - .style('opacity', function (_id) { + .style(CSS_OPACITY, function (_id) { var This = $$.d3.select(this); if (id && _id !== id) { - return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); + return focus ? $$[opacityForUnfocusedLegend](This) : $$[opacityForLegend](This); } else { - return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + return focus ? $$[opacityForLegend](This) : $$[opacityForUnfocusedLegend](This); } }); }; - c3_chart_internal_fn.revertLegend = function () { + var revertLegend = 'revertLegend'; + c3_chart_internal_fn[revertLegend] = function () { var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + CLASS.legendItem) + $$.legend.selectAll('.' + CLASS[legendItem]) .transition().duration(100) - .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); + .style(CSS_OPACITY, function () { return $$[opacityForLegend](d3.select(this)); }); }; - c3_chart_internal_fn.showLegend = function (targetIds) { + var showLegend = 'showLegend'; + c3_chart_internal_fn[showLegend] = function (targetIds) { var $$ = this, config = $$.config; if (!config[__legend_show]) { config[__legend_show] = true; - $$.legend.style('visibility', 'visible'); + $$.legend.style(CSS_VISIBILITY, 'visible'); } - $$.removeHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) - .style('visibility', 'visible') + $$[removeHiddenLegendIds](targetIds); + $$.legend.selectAll($$[selectorLegends](targetIds)) + .style(CSS_VISIBILITY, 'visible') .transition() - .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); + .style(CSS_OPACITY, function () { return $$[opacityForLegend]($$.d3.select(this)); }); }; - c3_chart_internal_fn.hideLegend = function (targetIds) { + var hideLegend = 'hideLegend'; + c3_chart_internal_fn[hideLegend] = function (targetIds) { var $$ = this, config = $$.config; if (config[__legend_show] && isEmpty(targetIds)) { config[__legend_show] = false; - $$.legend.style('visibility', 'hidden'); + $$.legend.style(CSS_VISIBILITY, 'hidden'); } - $$.addHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) - .style('opacity', 0) - .style('visibility', 'hidden'); + $$[addHiddenLegendIds](targetIds); + $$.legend.selectAll($$[selectorLegends](targetIds)) + .style(CSS_OPACITY, 0) + .style(CSS_VISIBILITY, 'hidden'); }; - c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { + var updateLegend = 'updateLegend'; + c3_chart_internal_fn[updateLegend] = function (targetIds, options, transitions) { var $$ = this, config = $$.config; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); + var hasFocused = $$.legend.selectAll('.' + CLASS[legendItemFocused]).size(); var texts, rects, tiles; options = options || {}; @@ -2283,11 +2395,11 @@ withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), + var box = $$[getTextRect](textElement.textContent, CLASS[legendItem]), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, - itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, - areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), + itemLength = $$[isLegendRight] || $$[isLegendInset] ? itemHeight : itemWidth, + areaLength = $$[isLegendRight] || $$[isLegendInset] ? $$[getLegendHeight]() : $$[getLegendWidth](), margin, maxLength; // MEMO: care about condifion of step, totalLength @@ -2301,7 +2413,7 @@ } } steps[id] = step; - margins[step] = $$.isLegendInset ? 10 : margin; + margins[step] = $$[isLegendInset] ? 10 : margin; offsets[id] = totalLength; totalLength += itemLength; } @@ -2313,7 +2425,7 @@ maxHeight = 0; } - if (config[__legend_show] && !$$.isLegendToShow(id)) { + if (config[__legend_show] && !$$[isLegendToShow](id)) { widths[id] = heights[id] = steps[id] = offsets[id] = 0; return; } @@ -2323,7 +2435,7 @@ if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } - maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; + maxLength = $$[isLegendRight] || $$[isLegendInset] ? maxHeight : maxWidth; if (config[__legend_equally]) { Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); @@ -2342,10 +2454,10 @@ } } - if ($$.isLegendRight) { + if ($$[isLegendRight]) { xForLegend = function (id) { return maxWidth * steps[id]; }; yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else if ($$.isLegendInset) { + } else if ($$[isLegendInset]) { xForLegend = function (id) { return maxWidth * steps[id] + 10; }; yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; } else { @@ -2358,18 +2470,18 @@ yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; // Define g for legend area - l = $$.legend.selectAll('.' + CLASS.legendItem) + l = $$.legend.selectAll('.' + CLASS[legendItem]) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) - .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) + .attr(CSS_CLASS, function (id) { return $$[generateClass](CLASS[legendItem], id); }) + .style(CSS_VISIBILITY, function (id) { return $$[isLegendToShow](id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { - $$.d3.select(this).classed(CLASS.legendItemFocused, true); - if (!$$.transiting) { + $$.d3.select(this).classed(CLASS[legendItemFocused], true); + if (!$$[transiting]) { $$.api.focus(id); } if (isFunction(config[__legend_item_onmouseover])) { @@ -2377,8 +2489,8 @@ } }) .on('mouseout', function (id) { - $$.d3.select(this).classed(CLASS.legendItemFocused, false); - if (!$$.transiting) { + $$.d3.select(this).classed(CLASS[legendItemFocused], false); + if (!$$[transiting]) { $$.api.revert(); } if (isFunction(config[__legend_item_onmouseout])) { @@ -2388,28 +2500,28 @@ l.append('text') .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) .each(function (id, i) { updatePositions(this, id, i === 0); }) - .style("pointer-events", "none") - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); + .style(CSS_POINTER_EVENTS, "none") + .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendText : -200) + .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegendText); l.append('rect') - .attr("class", CLASS.legendItemEvent) - .style('fill-opacity', 0) - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); + .attr(CSS_CLASS, CLASS[legendItemEvent]) + .style(CSS_FILL_OPACITY, 0) + .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendRect : -200) + .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegendRect); l.append('rect') - .attr("class", CLASS.legendItemTile) - .style("pointer-events", "none") + .attr(CSS_CLASS, CLASS[legendItemTile]) + .style(CSS_POINTER_EVENTS, "none") .style('fill', $$.color) - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) + .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendText : -200) + .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegend) .attr('width', 10) .attr('height', 10); // Set background for inset legend - if ($$.isLegendInset && maxWidth !== 0) { - $$.legend.insert('g', '.' + CLASS.legendItem) - .attr("class", CLASS.legendBackground) + if ($$[isLegendInset] && maxWidth !== 0) { + $$.legend.insert('g', '.' + CLASS[legendItem]) + .attr(CSS_CLASS, CLASS[legendBackground]) .append('rect') - .attr('height', $$.getLegendHeight() - 10) + .attr('height', $$[getLegendHeight]() - 10) .attr('width', maxWidth * (step + 1) + 10); } @@ -2421,7 +2533,7 @@ .attr('x', xForLegendText) .attr('y', yForLegendText); - rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent) + rects = $$.legend.selectAll('rect.' + CLASS[legendItemEvent]) .data(targetIds); (withTransition ? rects.transition() : rects) .attr('width', function (id) { return widths[id]; }) @@ -2429,7 +2541,7 @@ .attr('x', xForLegendRect) .attr('y', yForLegendRect); - tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) + tiles = $$.legend.selectAll('rect.' + CLASS[legendItemTile]) .data(targetIds); (withTransition ? tiles.transition() : tiles) .style('fill', $$.color) @@ -2437,134 +2549,157 @@ .attr('y', yForLegend); // toggle legend state - $$.legend.selectAll('.' + CLASS.legendItem) - .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) + $$.legend.selectAll('.' + CLASS[legendItem]) + .classed(CLASS[legendItemHidden], function (id) { return !$$[isTargetToShow](id); }) .transition() - .style('opacity', function (id) { + .style(CSS_OPACITY, function (id) { var This = $$.d3.select(this); - if ($$.isTargetToShow(id)) { - return !hasFocused || This.classed(CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + if ($$[isTargetToShow](id)) { + return !hasFocused || This.classed(CLASS[legendItemFocused]) ? $$[opacityForLegend](This) : $$[opacityForUnfocusedLegend](This); } else { - return $$.legendOpacityForHidden; + return $$[legendOpacityForHidden]; } }); // Update all to reflect change of legend - $$.updateLegendItemWidth(maxWidth); - $$.updateLegendItemHeight(maxHeight); - $$.updateLegendStep(step); + $$[updateLegendItemWidth](maxWidth); + $$[updateLegendItemHeight](maxHeight); + $$[updateLegendStep](step); // Update size and scale - $$.updateSizes(); - $$.updateScales(); - $$.updateSvgSize(); + $$[updateSizes](); + $$[updateScales](); + $$[updateSvgSize](); // Update g positions - $$.transformAll(withTransitionForTransform, transitions); + $$[transformAll](withTransitionForTransform, transitions); }; - c3_chart_internal_fn.getClipPath = function (id) { + var getClipPath = 'getClipPath'; + c3_chart_internal_fn[getClipPath] = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; }; - c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { + var getAxisClipX = 'getAxisClipX'; + c3_chart_internal_fn[getAxisClipX] = function (forHorizontal) { // axis line width + padding for left return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); }; - c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { + var getAxisClipY = 'getAxisClipY'; + c3_chart_internal_fn[getAxisClipY] = function (forHorizontal) { return forHorizontal ? -20 : -4; }; - c3_chart_internal_fn.getXAxisClipX = function () { + var getXAxisClipX = 'getXAxisClipX'; + c3_chart_internal_fn[getXAxisClipX] = function () { var $$ = this; - return $$.getAxisClipX(!$$.config[__axis_rotated]); + return $$[getAxisClipX](!$$.config[__axis_rotated]); }; - c3_chart_internal_fn.getXAxisClipY = function () { + var getXAxisClipY = 'getXAxisClipY'; + c3_chart_internal_fn[getXAxisClipY] = function () { var $$ = this; - return $$.getAxisClipY(!$$.config[__axis_rotated]); + return $$[getAxisClipY](!$$.config[__axis_rotated]); }; - c3_chart_internal_fn.getYAxisClipX = function () { + var getYAxisClipX = 'getYAxisClipX'; + c3_chart_internal_fn[getYAxisClipX] = function () { var $$ = this; - return $$.getAxisClipX($$.config[__axis_rotated]); + return $$[getAxisClipX]($$.config[__axis_rotated]); }; - c3_chart_internal_fn.getYAxisClipY = function () { + var getYAxisClipY = 'getYAxisClipY'; + c3_chart_internal_fn[getYAxisClipY] = function () { var $$ = this; - return $$.getAxisClipY($$.config[__axis_rotated]); + return $$[getAxisClipY]($$.config[__axis_rotated]); }; - c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { + var getAxisClipWidth = 'getAxisClipWidth'; + c3_chart_internal_fn[getAxisClipWidth] = function (forHorizontal) { var $$ = this; // width + axis line width + padding for left/right return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; - c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { + var getAxisClipHeight = 'getAxisClipHeight'; + c3_chart_internal_fn[getAxisClipHeight] = function (forHorizontal) { var $$ = this, config = $$.config; return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; }; - c3_chart_internal_fn.getXAxisClipWidth = function () { + var getXAxisClipWidth = 'getXAxisClipWidth'; + c3_chart_internal_fn[getXAxisClipWidth] = function () { var $$ = this; - return $$.getAxisClipWidth(!$$.config[__axis_rotated]); + return $$[getAxisClipWidth](!$$.config[__axis_rotated]); }; - c3_chart_internal_fn.getXAxisClipHeight = function () { + var getXAxisClipHeight = 'getXAxisClipHeight'; + c3_chart_internal_fn[getXAxisClipHeight] = function () { var $$ = this; - return $$.getAxisClipHeight(!$$.config[__axis_rotated]); + return $$[getAxisClipHeight](!$$.config[__axis_rotated]); }; - c3_chart_internal_fn.getYAxisClipWidth = function () { + var getYAxisClipWidth = 'getYAxisClipWidth'; + c3_chart_internal_fn[getYAxisClipWidth] = function () { var $$ = this; - return $$.getAxisClipWidth($$.config[__axis_rotated]); + return $$[getAxisClipWidth]($$.config[__axis_rotated]); }; - c3_chart_internal_fn.getYAxisClipHeight = function () { + var getYAxisClipHeight = 'getYAxisClipHeight'; + c3_chart_internal_fn[getYAxisClipHeight] = function () { var $$ = this; - return $$.getAxisClipHeight($$.config[__axis_rotated]); + return $$[getAxisClipHeight]($$.config[__axis_rotated]); }; /** * $$.data.js */ - c3_chart_internal_fn.isX = function (key) { + var isX = 'isX'; + c3_chart_internal_fn[isX] = function (key) { var $$ = this, config = $$.config; return (config[__data_x] && key === config[__data_x]) || (notEmpty(config[__data_xs]) && hasValue(config[__data_xs], key)); }; - c3_chart_internal_fn.isNotX = function (key) { - return !this.isX(key); + var isNotX = 'isNotX'; + c3_chart_internal_fn[isNotX] = function (key) { + return !this[isX](key); }; - c3_chart_internal_fn.getXKey = function (id) { + var getXKey = 'getXKey'; + c3_chart_internal_fn[getXKey] = function (id) { var $$ = this, config = $$.config; return config[__data_x] ? config[__data_x] : notEmpty(config[__data_xs]) ? config[__data_xs][id] : null; }; - c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { + var getXValuesOfXKey = 'getXValuesOfXKey'; + c3_chart_internal_fn[getXValuesOfXKey] = function (key, targets) { var $$ = this, - xValues, ids = targets && notEmpty(targets) ? $$.mapToIds(targets) : []; + xValues, ids = targets && notEmpty(targets) ? $$[mapToIds](targets) : []; ids.forEach(function (id) { - if ($$.getXKey(id) === key) { + if ($$[getXKey](id) === key) { xValues = $$.data.xs[id]; } }); return xValues; }; - c3_chart_internal_fn.getXValue = function (id, i) { + var getXValue = 'getXValue'; + c3_chart_internal_fn[getXValue] = function (id, i) { var $$ = this; return id in $$.data.xs && $$.data.xs[id] && isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; }; - c3_chart_internal_fn.getOtherTargetXs = function () { + var getOtherTargetXs = 'getOtherTargetXs'; + c3_chart_internal_fn[getOtherTargetXs] = function () { var $$ = this, idsForX = Object.keys($$.data.xs); return idsForX.length ? $$.data.xs[idsForX[0]] : null; }; - c3_chart_internal_fn.getOtherTargetX = function (index) { - var xs = this.getOtherTargetXs(); + var getOtherTargetX = 'getOtherTargetX'; + c3_chart_internal_fn[getOtherTargetX] = function (index) { + var xs = this[getOtherTargetXs](); return xs && index < xs.length ? xs[index] : null; }; - c3_chart_internal_fn.addXs = function (xs) { + var addXs = 'addXs'; + c3_chart_internal_fn[addXs] = function (xs) { var $$ = this; Object.keys(xs).forEach(function (id) { $$.config[__data_xs][id] = xs[id]; }); }; - c3_chart_internal_fn.isSingleX = function (xs) { + var isSingleX = 'isSingleX'; + c3_chart_internal_fn[isSingleX] = function (xs) { return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; }; - c3_chart_internal_fn.addName = function (data) { + var addName = 'addName'; + c3_chart_internal_fn[addName] = function (data) { var $$ = this, name; if (data) { name = $$.config[__data_names][data.id]; @@ -2572,53 +2707,59 @@ } return data; }; - c3_chart_internal_fn.getValueOnIndex = function (values, index) { + var getValueOnIndex = 'getValueOnIndex'; + c3_chart_internal_fn[getValueOnIndex] = function (values, index) { var valueOnIndex = values.filter(function (v) { return v.index === index; }); return valueOnIndex.length ? valueOnIndex[0] : null; }; - c3_chart_internal_fn.updateTargetX = function (targets, x) { + var updateTargetX = 'updateTargetX'; + c3_chart_internal_fn[updateTargetX] = function (targets, x) { var $$ = this; targets.forEach(function (t) { t.values.forEach(function (v, i) { - v.x = $$.generateTargetX(x[i], t.id, i); + v.x = $$[generateTargetX](x[i], t.id, i); }); $$.data.xs[t.id] = x; }); }; - c3_chart_internal_fn.updateTargetXs = function (targets, xs) { + var updateTargetXs = 'updateTargetXs'; + c3_chart_internal_fn[updateTargetXs] = function (targets, xs) { var $$ = this; targets.forEach(function (t) { if (xs[t.id]) { - $$.updateTargetX([t], xs[t.id]); + $$[updateTargetX]([t], xs[t.id]); } }); }; - c3_chart_internal_fn.generateTargetX = function (rawX, id, index) { + var generateTargetX = 'generateTargetX'; + c3_chart_internal_fn[generateTargetX] = function (rawX, id, index) { var $$ = this, x; - if ($$.isTimeSeries) { - x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); + if ($$[isTimeSeries]) { + x = rawX ? $$[parseDate](rawX) : $$[parseDate]($$[getXValue](id, index)); } - else if ($$.isCustomX() && !$$.isCategorized) { - x = isValue(rawX) ? +rawX : $$.getXValue(id, index); + else if ($$[isCustomX]() && !$$[isCategorized]) { + x = isValue(rawX) ? +rawX : $$[getXValue](id, index); } else { x = index; } return x; }; - c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { + var convertUrlToData = 'convertUrlToData'; + c3_chart_internal_fn[convertUrlToData] = function (url, mimeType, keys, done) { var $$ = this, type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; if (type === 'json') { - d = $$.convertJsonToData(JSON.parse(data.response), keys); + d = $$[convertJsonToData](JSON.parse(data.response), keys); } else { - d = $$.convertCsvToData(data.response); + d = $$[convertCsvToData](data.response); } done(d); }); }; - c3_chart_internal_fn.cloneTarget = function (target) { + var cloneTarget = 'cloneTarget'; + c3_chart_internal_fn[cloneTarget] = function (target) { return { id : target.id, id_org : target.id_org, @@ -2627,19 +2768,23 @@ }) }; }; - c3_chart_internal_fn.getPrevX = function (i) { - var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); + var getPrevX = 'getPrevX'; + c3_chart_internal_fn[getPrevX] = function (i) { + var $$ = this, value = $$[getValueOnIndex]($$.data.targets[0].values, i - 1); return value ? value.x : null; }; - c3_chart_internal_fn.getNextX = function (i) { - var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); + var getNextX = 'getNextX'; + c3_chart_internal_fn[getNextX] = function (i) { + var $$ = this, value = $$[getValueOnIndex]($$.data.targets[0].values, i + 1); return value ? value.x : null; }; - c3_chart_internal_fn.getMaxDataCount = function () { + var getMaxDataCount = 'getMaxDataCount'; + c3_chart_internal_fn[getMaxDataCount] = function () { var $$ = this; return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); }; - c3_chart_internal_fn.getMaxDataCountTarget = function (targets) { + var getMaxDataCountTarget = 'getMaxDataCountTarget'; + c3_chart_internal_fn[getMaxDataCountTarget] = function (targets) { var length = targets.length, max = 0, maxTarget; if (length > 1) { targets.forEach(function (t) { @@ -2653,23 +2798,27 @@ } return maxTarget; }; - c3_chart_internal_fn.getEdgeX = function (targets) { - var target = this.getMaxDataCountTarget(targets), firstData, lastData; + var getEdgeX = 'getEdgeX'; + c3_chart_internal_fn[getEdgeX] = function (targets) { + var target = this[getMaxDataCountTarget](targets), firstData, lastData; if (!target) { return [0, 0]; } firstData = target.values[0], lastData = target.values[target.values.length - 1]; return [firstData.x, lastData.x]; }; - c3_chart_internal_fn.mapToIds = function (targets) { + var mapToIds = 'mapToIds'; + c3_chart_internal_fn[mapToIds] = function (targets) { return targets.map(function (d) { return d.id; }); }; - c3_chart_internal_fn.mapToTargetIds = function (ids) { + var mapToTargetIds = 'mapToTargetIds'; + c3_chart_internal_fn[mapToTargetIds] = function (ids) { var $$ = this; - return ids ? (isString(ids) ? [ids] : ids) : $$.mapToIds($$.data.targets); + return ids ? (isString(ids) ? [ids] : ids) : $$[mapToIds]($$.data.targets); }; - c3_chart_internal_fn.hasTarget = function (targets, id) { - var ids = this.mapToIds(targets), i; + var hasTarget = 'hasTarget'; + c3_chart_internal_fn[hasTarget] = function (targets, id) { + var ids = this[mapToIds](targets), i; for (i = 0; i < ids.length; i++) { if (ids[i] === id) { return true; @@ -2677,34 +2826,43 @@ } return false; }; - c3_chart_internal_fn.isTargetToShow = function (targetId) { - return this.hiddenTargetIds.indexOf(targetId) < 0; + var isTargetToShow = 'isTargetToShow'; + c3_chart_internal_fn[isTargetToShow] = function (targetId) { + return this[hiddenTargetIds].indexOf(targetId) < 0; }; - c3_chart_internal_fn.isLegendToShow = function (targetId) { - return this.hiddenLegendIds.indexOf(targetId) < 0; + var isLegendToShow = 'isLegendToShow'; + c3_chart_internal_fn[isLegendToShow] = function (targetId) { + return this[hiddenLegendIds].indexOf(targetId) < 0; }; - c3_chart_internal_fn.filterTargetsToShow = function (targets) { + var filterTargetsToShow = 'filterTargetsToShow'; + c3_chart_internal_fn[filterTargetsToShow] = function (targets) { var $$ = this; - return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); + return targets.filter(function (t) { return $$[isTargetToShow](t.id); }); }; - c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { + var mapTargetsToUniqueXs = 'mapTargetsToUniqueXs'; + c3_chart_internal_fn[mapTargetsToUniqueXs] = function (targets) { var $$ = this; var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); - return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); + return $$[isTimeSeries] ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); }; - c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { - this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); + var addHiddenTargetIds = 'addHiddenTargetIds'; + c3_chart_internal_fn[addHiddenTargetIds] = function (targetIds) { + this[hiddenTargetIds] = this[hiddenTargetIds].concat(targetIds); }; - c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { - this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + var removeHiddenTargetIds = 'removeHiddenTargetIds'; + c3_chart_internal_fn[removeHiddenTargetIds] = function (targetIds) { + this[hiddenTargetIds] = this[hiddenTargetIds].filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { - this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); + var addHiddenLegendIds = 'addHiddenLegendIds'; + c3_chart_internal_fn[addHiddenLegendIds] = function (targetIds) { + this[hiddenLegendIds] = this[hiddenLegendIds].concat(targetIds); }; - c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) { - this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); + var removeHiddenLegendIds = 'removeHiddenLegendIds'; + c3_chart_internal_fn[removeHiddenLegendIds] = function (targetIds) { + this[hiddenLegendIds] = this[hiddenLegendIds].filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - c3_chart_internal_fn.getValuesAsIdKeyed = function (targets) { + var getValuesAsIdKeyed = 'getValuesAsIdKeyed'; + c3_chart_internal_fn[getValuesAsIdKeyed] = function (targets) { var ys = {}; targets.forEach(function (t) { ys[t.id] = []; @@ -2714,7 +2872,8 @@ }); return ys; }; - c3_chart_internal_fn.checkValueInTargets = function (targets, checker) { + var checkValueInTargets = 'checkValueInTargets'; + c3_chart_internal_fn[checkValueInTargets] = function (targets, checker) { var ids = Object.keys(targets), i, j, values; for (i = 0; i < ids.length; i++) { values = targets[ids[i]].values; @@ -2726,22 +2885,27 @@ } return false; }; - c3_chart_internal_fn.hasNegativeValueInTargets = function (targets) { - return this.checkValueInTargets(targets, function (v) { return v < 0; }); + var hasNegativeValueInTargets = 'hasNegativeValueInTargets'; + c3_chart_internal_fn[hasNegativeValueInTargets] = function (targets) { + return this[checkValueInTargets](targets, function (v) { return v < 0; }); }; - c3_chart_internal_fn.hasPositiveValueInTargets = function (targets) { - return this.checkValueInTargets(targets, function (v) { return v > 0; }); + var hasPositiveValueInTargets = 'hasPositiveValueInTargets'; + c3_chart_internal_fn[hasPositiveValueInTargets] = function (targets) { + return this[checkValueInTargets](targets, function (v) { return v > 0; }); }; - c3_chart_internal_fn.isOrderDesc = function () { + var isOrderDesc = 'isOrderDesc'; + c3_chart_internal_fn[isOrderDesc] = function () { var config = this.config; return config[__data_order] && config[__data_order].toLowerCase() === 'desc'; }; - c3_chart_internal_fn.isOrderAsc = function () { + var isOrderAsc = 'isOrderAsc'; + c3_chart_internal_fn[isOrderAsc] = function () { var config = this.config; return config[__data_order] && config[__data_order].toLowerCase() === 'asc'; }; - c3_chart_internal_fn.orderTargets = function (targets) { - var $$ = this, config = $$.config, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); + var orderTargets = 'orderTargets'; + c3_chart_internal_fn[orderTargets] = function (targets) { + var $$ = this, config = $$.config, orderAsc = $$[isOrderAsc](), orderDesc = $$[isOrderDesc](); if (orderAsc || orderDesc) { targets.sort(function (t1, t2) { var reducer = function (p, c) { return p + Math.abs(c.value); }; @@ -2754,13 +2918,16 @@ } // TODO: accept name array for order return targets; }; - c3_chart_internal_fn.filterSameX = function (targets, x) { + var filterSameX = 'filterSameX'; + c3_chart_internal_fn[filterSameX] = function (targets, x) { return this.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); }; - c3_chart_internal_fn.filterRemoveNull = function (data) { + var filterRemoveNull = 'filterRemoveNull'; + c3_chart_internal_fn[filterRemoveNull] = function (data) { return data.filter(function (d) { return isValue(d.value); }); }; - c3_chart_internal_fn.hasDataLabel = function () { + var hasDataLabel = 'hasDataLabel'; + c3_chart_internal_fn[hasDataLabel] = function () { var config = this.config; if (typeof config[__data_labels] === 'boolean' && config[__data_labels]) { return true; @@ -2769,31 +2936,35 @@ } return false; }; - c3_chart_internal_fn.getDataLabelLength = function (min, max, axisId, key) { + var getDataLabelLength = 'getDataLabelLength'; + c3_chart_internal_fn[getDataLabelLength] = function (min, max, axisId, key) { var $$ = this, lengths = [0, 0], paddingCoef = 1.3; $$.selectChart.select('svg').selectAll('.dummy') .data([min, max]) .enter().append('text') - .text(function (d) { return $$.formatByAxisId(axisId)(d); }) + .text(function (d) { return $$[formatByAxisId](axisId)(d); }) .each(function (d, i) { lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; }) .remove(); return lengths; }; - c3_chart_internal_fn.isNoneArc = function (d) { - return this.hasTarget(this.data.targets, d.id); - }, - c3_chart_internal_fn.isArc = function (d) { - return 'data' in d && this.hasTarget(this.data.targets, d.data.id); + var isNoneArc = 'isNoneArc'; + c3_chart_internal_fn[isNoneArc] = function (d) { + return this[hasTarget](this.data.targets, d.id); + }; + var isArc = 'isArc'; + c3_chart_internal_fn[isArc] = function (d) { + return 'data' in d && this[hasTarget](this.data.targets, d.data.id); }; /** * c3.data.convert.js */ - c3_chart_internal_fn.convertCsvToData = function (csv) { + var convertCsvToData = 'convertCsvToData'; + c3_chart_internal_fn[convertCsvToData] = function (csv) { var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; @@ -2805,7 +2976,8 @@ } return d; }; - c3_chart_internal_fn.convertJsonToData = function (json, keys) { + var convertJsonToData = 'convertJsonToData'; + c3_chart_internal_fn[convertJsonToData] = function (json, keys) { var $$ = this, new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects @@ -2819,26 +2991,27 @@ var new_row = []; targetKeys.forEach(function (key) { // convert undefined to null because undefined data will be removed in convertDataToTargets() - var v = isUndefined(o[key]) ? null : o[key]; + var v = !isDefined(o[key]) ? null : o[key]; new_row.push(v); }); new_rows.push(new_row); }); - data = $$.convertRowsToData(new_rows); + data = $$[convertRowsToData](new_rows); } else { Object.keys(json).forEach(function (key) { new_rows.push([key].concat(json[key])); }); - data = $$.convertColumnsToData(new_rows); + data = $$[convertColumnsToData](new_rows); } return data; }; - c3_chart_internal_fn.convertRowsToData = function (rows) { + var convertRowsToData = 'convertRowsToData'; + c3_chart_internal_fn[convertRowsToData] = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; for (j = 0; j < rows[i].length; j++) { - if (isUndefined(rows[i][j])) { + if (!isDefined(rows[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_row[keys[j]] = rows[i][j]; @@ -2847,15 +3020,16 @@ } return new_rows; }; - c3_chart_internal_fn.convertColumnsToData = function (columns) { + var convertColumnsToData = 'convertColumnsToData'; + c3_chart_internal_fn[convertColumnsToData] = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; for (j = 1; j < columns[i].length; j++) { - if (isUndefined(new_rows[j - 1])) { + if (!isDefined(new_rows[j - 1])) { new_rows[j - 1] = {}; } - if (isUndefined(columns[i][j])) { + if (!isDefined(columns[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_rows[j - 1][key] = columns[i][j]; @@ -2863,7 +3037,8 @@ } return new_rows; }; - c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { + var convertDataToTargets = 'convertDataToTargets'; + c3_chart_internal_fn[convertDataToTargets] = function (data, appendXs) { var $$ = this, config = $$.config, ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), @@ -2871,24 +3046,24 @@ // save x for update data by load when custom x and c3.x API ids.forEach(function (id) { - var xKey = $$.getXKey(id); + var xKey = $$[getXKey](id); - if ($$.isCustomX() || $$.isTimeSeries) { + if ($$[isCustomX]() || $$[isTimeSeries]) { // if included in input data if (xs.indexOf(xKey) >= 0) { $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( data.map(function (d) { return d[xKey]; }) .filter(isValue) - .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }) + .map(function (rawX, i) { return $$[generateTargetX](rawX, id, i); }) ); } // if not included in input data, find from preloaded data of other id's x else if (config[__data_x]) { - $$.data.xs[id] = $$.getOtherTargetXs(); + $$.data.xs[id] = $$[getOtherTargetXs](); } // if not included in input data, find from preloaded data else if (notEmpty(config[__data_xs])) { - $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); + $$.data.xs[id] = $$[getXValuesOfXKey](xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used } else { @@ -2910,14 +3085,14 @@ id: convertedId, id_org: id, values: data.map(function (d, i) { - var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); + var xKey = $$[getXKey](id), rawX = d[xKey], x = $$[generateTargetX](rawX, id, i); // use x as categories if custom x and categorized - if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { + if ($$[isCustomX]() && $$[isCategorized] && index === 0 && rawX) { if (i === 0) { config[__axis_x_categories] = []; } config[__axis_x_categories].push(rawX); } // mark as x = undefined if value is undefined and filter to remove after mapped - if (isUndefined(d[id]) || $$.data.xs[id].length <= i) { + if (!isDefined(d[id]) || $$.data.xs[id].length <= i) { x = undefined; } return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; @@ -2947,12 +3122,12 @@ // set target types 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 targets.forEach(function (d) { - $$.addCache(d.id_org, d); + $$[addCache](d.id_org, d); }); return targets; @@ -2961,7 +3136,8 @@ /** * c3.data.load.js */ - c3_chart_internal_fn.load = function (targets, args) { + var load = 'load'; + c3_chart_internal_fn[load] = function (targets, args) { var $$ = this; if (targets) { // filter loading targets if needed @@ -2971,7 +3147,7 @@ // set type if args.types || args.type specified if (args.type || args.types) { targets.forEach(function (t) { - $$.setTargetType(t.id, args.types ? args.types[t.id] : args.type); + $$[setTargetType](t.id, args.types ? args.types[t.id] : args.type); }); } // Update/Add data @@ -2988,60 +3164,62 @@ } // Set targets - $$.updateTargets($$.data.targets); + $$[updateTargets]($$.data.targets); // Redraw with new targets - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); if (isFunction(args.done)) { args.done(); } }; - c3_chart_internal_fn.loadFromArgs = function (args) { + var loadFromArgs = 'loadFromArgs'; + c3_chart_internal_fn[loadFromArgs] = function (args) { var $$ = this; if (args.data) { - $$.load($$.convertDataToTargets(args.data), args); + $$[load]($$[convertDataToTargets](args.data), args); } else if (args.url) { - $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { - $$.load($$.convertDataToTargets(data), args); + $$[convertUrlToData](args.url, args.mimeType, args.keys, function (data) { + $$[load]($$[convertDataToTargets](data), args); }); } else if (args.json) { - $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); + $$[load]($$[convertDataToTargets]($$[convertJsonToData](args.json, args.keys)), args); } else if (args.rows) { - $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); + $$[load]($$[convertDataToTargets]($$[convertRowsToData](args.rows)), args); } else if (args.columns) { - $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); + $$[load]($$[convertDataToTargets]($$[convertColumnsToData](args.columns)), args); } else { - $$.load(null, args); + $$[load](null, args); } }; - c3_chart_internal_fn.unload = function (targetIds, done) { + var unload = 'unload'; + c3_chart_internal_fn[unload] = function (targetIds, done) { var $$ = this; if (!isFunction(done)) { done = function () {}; } // filter existing target - targetIds = targetIds.filter(function (id) { return $$.hasTarget($$.data.targets, id); }); + targetIds = targetIds.filter(function (id) { return $$[hasTarget]($$.data.targets, id); }); // If no target, call done and return if (!targetIds || targetIds.length === 0) { done(); return; } - $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) + $$.svg.selectAll(targetIds.map(function (id) { return $$[selectorTarget](id); })) .transition() - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove() .call($$.endall, done); targetIds.forEach(function (id) { // Reset fadein for future load - $$.withoutFadeIn[id] = false; + $$[withoutFadeIn][id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); + $$.legend.selectAll('.' + CLASS[legendItem] + $$[getTargetSelectorSuffix](id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -3053,7 +3231,8 @@ /** * c3.data.category.js */ - c3_chart_internal_fn.categoryName = function (i) { + var categoryName = 'categoryName'; + c3_chart_internal_fn[categoryName] = function (i) { var config = this.config; return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; }; @@ -3062,10 +3241,11 @@ /** * c3.shape.js */ - c3_chart_internal_fn.getShapeIndices = function (typeFilter) { + var getShapeIndices = 'getShapeIndices'; + c3_chart_internal_fn[getShapeIndices] = function (typeFilter) { var $$ = this, config = $$.config, indices = {}, i = 0, j, k; - $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { + $$[filterTargetsToShow]($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { for (j = 0; j < config[__data_groups].length; j++) { if (config[__data_groups][j].indexOf(d.id) < 0) { continue; } for (k = 0; k < config[__data_groups][j].length; k++) { @@ -3075,31 +3255,34 @@ } } } - if (isUndefined(indices[d.id])) { indices[d.id] = i++; } + if (!isDefined(indices[d.id])) { indices[d.id] = i++; } }); indices.__max__ = i - 1; return indices; }; - c3_chart_internal_fn.getShapeX = function (offset, targetsNum, indices, isSub) { + var getShapeX = 'getShapeX'; + c3_chart_internal_fn[getShapeX] = function (offset, targetsNum, indices, isSub) { var $$ = this, scale = isSub ? $$.subX : $$.x; return function (d) { var index = d.id in indices ? indices[d.id] : 0; return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; }; }; - c3_chart_internal_fn.getShapeY = function (isSub) { + var getShapeY = 'getShapeY'; + c3_chart_internal_fn[getShapeY] = function (isSub) { var $$ = this; return function (d) { - var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); + var scale = isSub ? $$[getSubYScale](d.id) : $$[getYScale](d.id); return scale(d.value); }; }; - c3_chart_internal_fn.getShapeOffset = function (typeFilter, indices, isSub) { + var getShapeOffset = 'getShapeOffset'; + c3_chart_internal_fn[getShapeOffset] = function (typeFilter, indices, isSub) { var $$ = this, - targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), + targets = $$[orderTargets]($$[filterTargetsToShow]($$.data.targets.filter(typeFilter, $$))), targetIds = targets.map(function (t) { return t.id; }); return function (d, i) { - var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id), + var scale = isSub ? $$[getSubYScale](d.id) : $$[getYScale](d.id), y0 = scale(0), offset = y0; targets.forEach(function (t) { if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } @@ -3111,72 +3294,86 @@ }; }; - c3_chart_internal_fn.getInterpolate = function (d) { + var getInterpolate = 'getInterpolate'; + c3_chart_internal_fn[getInterpolate] = function (d) { var $$ = this; - return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; + return $$[isSplineType](d) ? "cardinal" : $$[isStepType](d) ? "step-after" : "linear"; }; - c3_chart_internal_fn.circleX = function (d) { - return d.x || d.x === 0 ? this.x(d.x) : null; + var circleX = 'circleX'; + c3_chart_internal_fn[circleX] = function (d) { + return d.x || d.x === 0 ? this[x](d.x) : null; }; - c3_chart_internal_fn.circleY = function (d, i) { + var circleY = 'circleY'; + c3_chart_internal_fn[circleY] = function (d, i) { var $$ = this, - lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); - return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + lineIndices = $$[getShapeIndices]($$.isLineType), getPoint = $$[generateGetLinePoint](lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$[getYScale](d.id)(d.value); }; - c3_chart_internal_fn.getCircles = function (i, id) { + var getCircles = 'getCircles'; + c3_chart_internal_fn[getCircles] = function (i, id) { var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS[circles] + $$[getTargetSelectorSuffix](id)) : $$.main).selectAll('.' + CLASS[circle] + (isValue(i) ? '-' + i : '')); }; - c3_chart_internal_fn.expandCircles = function (i, id) { + var expandCircles = 'expandCircles'; + c3_chart_internal_fn[expandCircles] = function (i, id) { var $$ = this; - $$.getCircles(i, id) - .classed(CLASS.EXPANDED, true) - .attr('r', generateCall($$.pointExpandedR, $$)); + $$[getCircles](i, id) + .classed(CLASS[EXPANDED], true) + .attr('r', generateCall($$[pointExpandedR], $$)); }; - c3_chart_internal_fn.unexpandCircles = function (i) { + var unexpandCircles = 'unexpandCircles'; + c3_chart_internal_fn[unexpandCircles] = function (i) { var $$ = this; - $$.getCircles(i) - .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) - .classed(CLASS.EXPANDED, false) - .attr('r', generateCall($$.pointR, $$)); + $$[getCircles](i) + .filter(function () { return $$.d3.select(this).classed(CLASS[EXPANDED]); }) + .classed(CLASS[EXPANDED], false) + .attr('r', generateCall($$[pointR], $$)); }; - c3_chart_internal_fn.pointR = function (d) { + var pointR = 'pointR'; + c3_chart_internal_fn[pointR] = function (d) { var $$ = this, config = $$.config; - return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; + return config[__point_show] && !$$[isStepType](d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; }; - c3_chart_internal_fn.pointExpandedR = function (d) { + var pointExpandedR = 'pointExpandedR'; + c3_chart_internal_fn[pointExpandedR] = function (d) { var $$ = this, config = $$.config; - return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$[pointR](d) * 1.75) : $$[pointR](d); }; - c3_chart_internal_fn.pointSelectR = function (d) { + var pointSelectR = 'pointSelectR'; + c3_chart_internal_fn[pointSelectR] = function (d) { var $$ = this, config = $$.config; - return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; + return config[__point_select_r] ? config[__point_select_r] : $$[pointR](d) * 4; }; - c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { + var getBarW = 'getBarW'; + c3_chart_internal_fn[getBarW] = function (axis, barTargetsNum) { var $$ = this, config = $$.config, w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; }; - c3_chart_internal_fn.getBars = function (i) { + var getBars = 'getBars'; + c3_chart_internal_fn[getBars] = function (i) { var $$ = this; - return $$.main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + CLASS[bar] + (isValue(i) ? '-' + i : '')); }; - c3_chart_internal_fn.expandBars = function (i) { + var expandBars = 'expandBars'; + c3_chart_internal_fn[expandBars] = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS.EXPANDED, true); + $$[getBars](i).classed(CLASS[EXPANDED], true); }; - c3_chart_internal_fn.unexpandBars = function (i) { + var unexpandBars = 'unexpandBars'; + c3_chart_internal_fn[unexpandBars] = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS.EXPANDED, false); + $$[getBars](i).classed(CLASS[EXPANDED], false); }; - c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { + var generateDrawBar = 'generateDrawBar'; + c3_chart_internal_fn[generateDrawBar] = function (barIndices, isSub) { var $$ = this, config = $$.config, - getPoints = $$.generateGetBarPoints(barIndices, isSub); + getPoints = $$[generateGetBarPoints](barIndices, isSub); return function (d, i) { // 4 points that make a bar var points = getPoints(d, i); @@ -3194,13 +3391,14 @@ return path; }; }; - c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { + var generateGetBarPoints = 'generateGetBarPoints'; + c3_chart_internal_fn[generateGetBarPoints] = function (barIndices, isSub) { var $$ = this, barTargetsNum = barIndices.__max__ + 1, - barW = $$.getBarW($$.xAxis, barTargetsNum), - barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), - barY = $$.getShapeY(!!isSub), - barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + barW = $$[getBarW]($$.xAxis, barTargetsNum), + barX = $$[getShapeX](barW, barTargetsNum, barIndices, !!isSub), + barY = $$[getShapeY](!!isSub), + barOffset = $$[getShapeOffset]($$.isBarType, barIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3220,9 +3418,10 @@ }; }; - c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { + var generateDrawArea = 'generateDrawArea'; + c3_chart_internal_fn[generateDrawArea] = function (areaIndices, isSub) { var $$ = this, config = $$.config, area = $$.d3.svg.area(), - getPoint = $$.generateGetAreaPoint(areaIndices, isSub), + getPoint = $$[generateGetAreaPoint](areaIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, value0 = function (d, i) { @@ -3235,13 +3434,13 @@ area = config[__axis_rotated] ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); return function (d) { - var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; - if ($$.isAreaType(d)) { - path = area.interpolate($$.getInterpolate(d))(data); + var data = $$[filterRemoveNull](d.values), x0 = 0, y0 = 0, path; + if ($$[isAreaType](d)) { + path = area.interpolate($$[getInterpolate](d))(data); } else { if (data[0]) { - x0 = $$.x(data[0].x); - y0 = $$.getYScale(d.id)(data[0].value); + x0 = $$[x](data[0].x); + y0 = $$[getYScale](d.id)(data[0].value); } path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } @@ -3249,10 +3448,11 @@ }; }; - c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { + var generateDrawLine = 'generateDrawLine'; + c3_chart_internal_fn[generateDrawLine] = function (lineIndices, isSub) { var $$ = this, config = $$.config, line = $$.d3.svg.line(), - getPoint = $$.generateGetLinePoint(lineIndices, isSub), + getPoint = $$[generateGetLinePoint](lineIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, yValue = function (d, i) { @@ -3262,13 +3462,13 @@ line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } return function (d) { - var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, + var data = config[__line_connect_null] ? $$[filterRemoveNull](d.values) : d.values, x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; - if ($$.isLineType(d)) { + if ($$[isLineType](d)) { if (config[__data_regions][d.id]) { - path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); + path = $$[lineWithRegions](data, x, y, config[__data_regions][d.id]); } else { - path = line.interpolate($$.getInterpolate(d))(data); + path = line.interpolate($$[getInterpolate](d))(data); } } else { if (data[0]) { @@ -3281,42 +3481,46 @@ }; }; - c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { + var generateXYForText = 'generateXYForText'; + c3_chart_internal_fn[generateXYForText] = function (barIndices, forX) { var $$ = this, - getPoints = $$.generateGetBarPoints(barIndices, false), + getPoints = $$[generateGetBarPoints](barIndices, false), getter = forX ? $$.getXForText : $$.getYForText; return function (d, i) { return getter(getPoints(d, i), d, this); }; }; - c3_chart_internal_fn.getXForText = function (points, d, textElement) { + var getXForText = 'getXForText'; + c3_chart_internal_fn[getXForText] = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), xPos, padding; if (config[__axis_rotated]) { - padding = $$.isBarType(d) ? 4 : 6; + padding = $$[isBarType](d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; } return xPos > $$.width ? $$.width - box.width : xPos; }; - c3_chart_internal_fn.getYForText = function (points, d, textElement) { + var getYForText = 'getYForText'; + c3_chart_internal_fn[getYForText] = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), yPos; if (config[__axis_rotated]) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { - yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); + yPos = points[2][1] + (d.value < 0 ? box.height : $$[isBarType](d) ? -3 : -6); } return yPos < box.height ? box.height : yPos; }; - c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + var generateGetAreaPoint = 'generateGetAreaPoint'; + c3_chart_internal_fn[generateGetAreaPoint] = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, config = $$.config, areaTargetsNum = areaIndices.__max__ + 1, - x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), - y = $$.getShapeY(!!isSub), - areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + x = $$[getShapeX](0, areaTargetsNum, areaIndices, !!isSub), + y = $$[getShapeY](!!isSub), + areaOffset = $$[getShapeOffset]($$.isAreaType, areaIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3334,12 +3538,13 @@ }; }; - c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + var generateGetLinePoint = 'generateGetLinePoint'; + c3_chart_internal_fn[generateGetLinePoint] = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, config = $$.config, lineTargetsNum = lineIndices.__max__ + 1, - x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), - y = $$.getShapeY(!!isSub), - lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), + x = $$[getShapeX](0, lineTargetsNum, lineIndices, !!isSub), + y = $$[getShapeY](!!isSub), + lineOffset = $$[getShapeOffset]($$.isLineType, lineIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3357,7 +3562,8 @@ }; - c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { + var lineWithRegions = 'lineWithRegions'; + c3_chart_internal_fn[lineWithRegions] = function (d, x, y, _regions) { var $$ = this, config = $$.config, prev = -1, i, j, s = "M", sWithRegion, @@ -3369,15 +3575,15 @@ if (isDefined(_regions)) { for (i = 0; i < _regions.length; i++) { regions[i] = {}; - if (isUndefined(_regions[i].start)) { + if (!isDefined(_regions[i].start)) { regions[i].start = d[0].x; } else { - regions[i].start = $$.isTimeSeries ? $$.parseDate(_regions[i].start) : _regions[i].start; + regions[i].start = $$[isTimeSeries] ? $$[parseDate](_regions[i].start) : _regions[i].start; } - if (isUndefined(_regions[i].end)) { + if (!isDefined(_regions[i].end)) { regions[i].end = d[d.length - 1].x; } else { - regions[i].end = $$.isTimeSeries ? $$.parseDate(_regions[i].end) : _regions[i].end; + regions[i].end = $$[isTimeSeries] ? $$[parseDate](_regions[i].end) : _regions[i].end; } } } @@ -3387,7 +3593,7 @@ yValue = config[__axis_rotated] ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; // Define svg generator function for region - if ($$.isTimeSeries) { + if ($$[isTimeSeries]) { sWithRegion = function (d0, d1, j, diff) { var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, xv0 = new Date(x0 + x_diff * j), @@ -3404,13 +3610,13 @@ for (i = 0; i < d.length; i++) { // Draw as normal - if (isUndefined(regions) || ! $$.isWithinRegions(d[i].x, regions)) { + if (!isDefined(regions) || ! $$[isWithinRegions](d[i].x, regions)) { s += " " + xValue(d[i]) + " " + yValue(d[i]); } // Draw with region // TODO: Fix for horizotal charts else { - xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); - yp = $$.getScale(d[i - 1].value, d[i].value); + xp = $$[getScale](d[i - 1].x, d[i].x, $$[isTimeSeries]); + yp = $$[getScale](d[i - 1].value, d[i].value); dx = x(d[i].x) - x(d[i - 1].x); dy = y(d[i].value) - y(d[i - 1].value); @@ -3430,13 +3636,15 @@ - c3_chart_internal_fn.isWithinCircle = function (_this, _r) { + var isWithinCircle = 'isWithinCircle'; + c3_chart_internal_fn[isWithinCircle] = function (_this, _r) { var d3 = this.d3, mouse = d3.mouse(_this), d3_this = d3.select(_this), cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; - c3_chart_internal_fn.isWithinBar = function (_this) { + var isWithinBar = 'isWithinBar'; + c3_chart_internal_fn[isWithinBar] = function (_this) { var d3 = this.d3, mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), @@ -3444,7 +3652,8 @@ sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; }; - c3_chart_internal_fn.isWithinRegions = function (x, regions) { + var isWithinRegions = 'isWithinRegions'; + c3_chart_internal_fn[isWithinRegions] = function (x, regions) { var i; for (i = 0; i < regions.length; i++) { if (regions[i].start < x && x <= regions[i].end) { return true; } @@ -3455,7 +3664,8 @@ - c3_chart_internal_fn.findSameXOfValues = function (values, index) { + var findSameXOfValues = 'findSameXOfValues'; + c3_chart_internal_fn[findSameXOfValues] = function (values, index) { var i, targetX = values[index].x, sames = []; for (i = index - 1; i >= 0; i--) { if (targetX !== values[i].x) { break; } @@ -3468,13 +3678,14 @@ return sames; }; - c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + var findClosestOfValues = 'findClosestOfValues'; + c3_chart_internal_fn[findClosestOfValues] = function (values, pos, _min, _max) { // MEMO: values must be sorted by x var $$ = this, min = _min ? _min : 0, max = _max ? _max : values.length - 1, med = Math.floor((max - min) / 2) + min, value = values[med], - diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], + diff = $$[x](value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], candidates; // Update range for search @@ -3486,33 +3697,35 @@ // Get candidates that has same min and max index candidates = []; if (values[min].x || values[min].x === 0) { - candidates = candidates.concat($$.findSameXOfValues(values, min)); + candidates = candidates.concat($$[findSameXOfValues](values, min)); } if (values[max].x || values[max].x === 0) { - candidates = candidates.concat($$.findSameXOfValues(values, max)); + candidates = candidates.concat($$[findSameXOfValues](values, max)); } // Determine the closest and return - return $$.findClosest(candidates, pos); + return $$[findClosest](candidates, pos); } - return $$.findClosestOfValues(values, pos, min, max); + return $$[findClosestOfValues](values, pos, min, max); }; - c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { + var findClosestFromTargets = 'findClosestFromTargets'; + c3_chart_internal_fn[findClosestFromTargets] = function (targets, pos) { var $$ = this, candidates; // map to array of closest points of each target candidates = targets.map(function (target) { - return $$.findClosestOfValues(target.values, pos); + return $$[findClosestOfValues](target.values, pos); }); // decide closest point and return - return $$.findClosest(candidates, pos); + return $$[findClosest](candidates, pos); }; - c3_chart_internal_fn.findClosest = function (values, pos) { + var findClosest = 'findClosest'; + c3_chart_internal_fn[findClosest] = function (values, pos) { var $$ = this, minDist, closest; values.forEach(function (v) { - var d = $$.dist(v, pos); + var d = $$[dist](v, pos); if (d < minDist || ! minDist) { minDist = d; closest = v; @@ -3520,26 +3733,29 @@ }); return closest; }; - c3_chart_internal_fn.dist = function (data, pos) { + var dist = 'dist'; + c3_chart_internal_fn[dist] = function (data, pos) { var $$ = this, config = $$.config, - yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, + yScale = $$[getAxisId](data.id) === 'y' ? $$.y : $$.y2, xIndex = config[__axis_rotated] ? 1 : 0, yIndex = config[__axis_rotated] ? 0 : 1; - return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + return Math.pow($$[x](data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); }; - c3_chart_internal_fn.setTargetType = function (targetIds, type) { + var setTargetType = 'setTargetType'; + c3_chart_internal_fn[setTargetType] = function (targetIds, type) { var $$ = this, config = $$.config; - $$.mapToTargetIds(targetIds).forEach(function (id) { - $$.withoutFadeIn[id] = (type === config[__data_types][id]); + $$[mapToTargetIds](targetIds).forEach(function (id) { + $$[withoutFadeIn][id] = (type === config[__data_types][id]); config[__data_types][id] = type; }); if (!targetIds) { config[__data_type] = type; } }; - c3_chart_internal_fn.hasType = function (targets, type) { + var hasType = 'hasType'; + c3_chart_internal_fn[hasType] = function (targets, type) { var $$ = this, config = $$.config, has = false; targets.forEach(function (t) { if (config[__data_types][t.id] === type) { has = true; } @@ -3547,90 +3763,84 @@ }); return has; }; - /* not used - function hasLineType(targets) { - return hasType(targets, 'line'); - } - */ - c3_chart_internal_fn.hasAreaType = function (targets) { - return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); + var hasArcType = 'hasArcType'; + c3_chart_internal_fn[hasArcType] = function (targets) { + return this[hasType](targets, TYPE_PIE) || this[hasType](targets, TYPE_DONUT) || this[hasType](targets, TYPE_GAUGE); }; - c3_chart_internal_fn.hasBarType = function (targets) { - return this.hasType(targets, 'bar'); - }; - c3_chart_internal_fn.hasScatterType = function (targets) { - return this.hasType(targets, 'scatter'); - }; - c3_chart_internal_fn.hasPieType = function (targets) { - return this.config[__data_type] === 'pie' || this.hasType(targets, 'pie'); - }; - c3_chart_internal_fn.hasGaugeType = function (targets) { - return this.hasType(targets, 'gauge'); - }; - c3_chart_internal_fn.hasDonutType = function (targets) { - return this.config[__data_type] === 'donut' || this.hasType(targets, 'donut'); - }; - c3_chart_internal_fn.hasArcType = function (targets) { - return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); - }; - c3_chart_internal_fn.isLineType = function (d) { + + var isLineType = 'isLineType'; + c3_chart_internal_fn[isLineType] = function (d) { var config = this.config, id = isString(d) ? d : d.id; return !config[__data_types][id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(config[__data_types][id]) >= 0; }; - c3_chart_internal_fn.isStepType = function (d) { + var isStepType = 'isStepType'; + c3_chart_internal_fn[isStepType] = function (d) { var id = isString(d) ? d : d.id; return ['step', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - c3_chart_internal_fn.isSplineType = function (d) { + var isSplineType = 'isSplineType'; + c3_chart_internal_fn[isSplineType] = function (d) { var id = isString(d) ? d : d.id; return ['spline', 'area-spline'].indexOf(this.config[__data_types][id]) >= 0; }; - c3_chart_internal_fn.isAreaType = function (d) { + var isAreaType = 'isAreaType'; + c3_chart_internal_fn[isAreaType] = function (d) { var id = isString(d) ? d : d.id; return ['area', 'area-spline', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - c3_chart_internal_fn.isBarType = function (d) { + var isBarType = 'isBarType'; + c3_chart_internal_fn[isBarType] = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'bar'; }; - c3_chart_internal_fn.isScatterType = function (d) { + var isScatterType = 'isScatterType'; + c3_chart_internal_fn[isScatterType] = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'scatter'; }; - c3_chart_internal_fn.isPieType = function (d) { + var isPieType = 'isPieType'; + c3_chart_internal_fn[isPieType] = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'pie'; }; - c3_chart_internal_fn.isGaugeType = function (d) { + var isGaugeType = 'isGaugeType'; + c3_chart_internal_fn[isGaugeType] = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'gauge'; }; - c3_chart_internal_fn.isDonutType = function (d) { + var isDonutType = 'isDonutType'; + c3_chart_internal_fn[isDonutType] = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'donut'; }; - c3_chart_internal_fn.isArcType = function (d) { - return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); + var isArcType = 'isArcType'; + c3_chart_internal_fn[isArcType] = function (d) { + return this[isPieType](d) || this[isDonutType](d) || this[isGaugeType](d); }; - c3_chart_internal_fn.lineData = function (d) { - return this.isLineType(d) ? [d] : []; + var lineData = 'lineData'; + c3_chart_internal_fn[lineData] = function (d) { + return this[isLineType](d) ? [d] : []; }; - c3_chart_internal_fn.arcData = function (d) { - return this.isArcType(d.data) ? [d] : []; + var arcData = 'arcData'; + c3_chart_internal_fn[arcData] = function (d) { + return this[isArcType](d.data) ? [d] : []; }; /* not used function scatterData(d) { return isScatterType(d) ? d.values : []; } */ - c3_chart_internal_fn.barData = function (d) { - return this.isBarType(d) ? d.values : []; + var barData = 'barData'; + c3_chart_internal_fn[barData] = function (d) { + return this[isBarType](d) ? d.values : []; }; - c3_chart_internal_fn.lineOrScatterData = function (d) { - return this.isLineType(d) || this.isScatterType(d) ? d.values : []; + var lineOrScatterData = 'lineOrScatterData'; + c3_chart_internal_fn[lineOrScatterData] = function (d) { + return this[isLineType](d) || this[isScatterType](d) ? d.values : []; }; - c3_chart_internal_fn.barOrLineData = function (d) { - return this.isBarType(d) || this.isLineType(d) ? d.values : []; + var barOrLineData = 'barOrLineData'; + c3_chart_internal_fn[barOrLineData] = function (d) { + return this[isBarType](d) || this[isLineType](d) ? d.values : []; }; @@ -3638,14 +3848,15 @@ /** * c3.date.js */ - c3_chart_internal_fn.parseDate = function (date) { + var parseDate = 'parseDate'; + c3_chart_internal_fn[parseDate] = function (date) { var $$ = this, parsedDate; if (date instanceof Date) { parsedDate = date; } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); + parsedDate = $$[dataTimeFormat](config[__data_x_format]).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -3657,7 +3868,8 @@ /** * c3.color.js */ - c3_chart_internal_fn.generateColor = function (colors, pattern, callback) { + var generateColor = 'generateColor'; + c3_chart_internal_fn[generateColor] = function (colors, pattern, callback) { var ids = []; return function (d) { @@ -3680,7 +3892,8 @@ return callback instanceof Function ? callback(color, d) : color; }; }; - c3_chart_internal_fn.generateLevelColor = function (colors, threshold) { + var generateLevelColor = 'generateLevelColor'; + c3_chart_internal_fn[generateLevelColor] = function (colors, threshold) { var asValue = threshold.unit === 'value', values = threshold.values && threshold.values.length ? threshold.values : [], max = threshold.max || 100; @@ -3701,15 +3914,17 @@ /** * c3.scale.js */ - c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { + var getScale = 'getScale'; + c3_chart_internal_fn[getScale] = function (min, max, forTimeseries) { return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); }; - c3_chart_internal_fn.getX = function (min, max, domain, offset) { + var getX = 'getX'; + c3_chart_internal_fn[getX] = function (min, max, domain, offset) { var $$ = this, - scale = $$.getScale(min, max, $$.isTimeSeries), + scale = $$[getScale](min, max, $$[isTimeSeries]), _scale = domain ? scale.domain(domain) : scale, key; // Define customized scale if categorized axis - if ($$.isCategorized) { + if ($$[isCategorized]) { offset = offset || function () { return 0; }; scale = function (d, raw) { var v = _scale(d) + offset(d); @@ -3729,7 +3944,7 @@ return _scale.domain(); }; // define custom domain() for categorized axis - if ($$.isCategorized) { + if ($$[isCategorized]) { scale.domain = function (domain) { if (!arguments.length) { domain = this.orgDomain(); @@ -3741,18 +3956,22 @@ } return scale; }; - c3_chart_internal_fn.getY = function (min, max, domain) { - var scale = this.getScale(min, max); + var getY = 'getY'; + c3_chart_internal_fn[getY] = function (min, max, domain) { + var scale = this[getScale](min, max); if (domain) { scale.domain(domain); } return scale; }; - c3_chart_internal_fn.getYScale = function (id) { - return this.getAxisId(id) === 'y2' ? this.y2 : this.y; + var getYScale = 'getYScale'; + c3_chart_internal_fn[getYScale] = function (id) { + return this[getAxisId](id) === 'y2' ? this.y2 : this.y; }; - c3_chart_internal_fn.getSubYScale = function (id) { - return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; + var getSubYScale = 'getSubYScale'; + c3_chart_internal_fn[getSubYScale] = function (id) { + return this[getAxisId](id) === 'y2' ? this.subY2 : this.subY; }; - c3_chart_internal_fn.updateScales = function () { + var updateScales = 'updateScales', x = 'x', y = 'y', subX = 'subX'; + c3_chart_internal_fn[updateScales] = function () { var $$ = this, config = $$.config, forInit = !$$.x; // update edges @@ -3765,19 +3984,19 @@ $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; // update scales - $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); - $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); - $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); - $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); - $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); - $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); + $$[x] = $$[getX]($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); + $$[y] = $$[getY]($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); + $$.y2 = $$[getY]($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); + $$[subX] = $$[getX]($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); + $$.subY = $$[getY]($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); + $$.subY2 = $$[getY]($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes - $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickFormat = $$[getXAxisTickFormat](); $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); - $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); - $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); + $$.xAxis = $$[getXAxis]($$.x, $$[xOrient], $$.xAxisTickFormat, $$.xAxisTickValues); + $$.subXAxis = $$[getXAxis]($$.subX, $$[subXOrient], $$.xAxisTickFormat, $$.xAxisTickValues); + $$.yAxis = $$[getYAxis]($$.y, $$[yOrient], config[__axis_y_tick_format], config[__axis_y_ticks]); + $$.y2Axis = $$[getYAxis]($$.y2, $$[y2Orient], config[__axis_y2_tick_format], config[__axis_y2_ticks]); // Set initialized scales to brush and zoom if (!forInit) { if ($$.brush) { $$.brush.scale($$.subX); } @@ -3785,7 +4004,7 @@ } // update for arc if (isFunction($$.updateArc)) { - $$.updateArc(); + $$[updateArc](); } }; @@ -3793,12 +4012,13 @@ /** * c3.domain.js */ - c3_chart_internal_fn.getYDomainMin = function (targets) { + var getYDomainMin = 'getYDomainMin'; + c3_chart_internal_fn[getYDomainMin] = function (targets) { var $$ = this, config = $$.config, - ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + ids = $$[mapToIds](targets), ys = $$[getValuesAsIdKeyed](targets), j, k, baseId, idsInGroup, id, hasNegativeValue; if (config[__data_groups].length > 0) { - hasNegativeValue = $$.hasNegativeValueInTargets(targets); + hasNegativeValue = $$[hasNegativeValueInTargets](targets); for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); @@ -3815,7 +4035,7 @@ id = idsInGroup[k]; if (! ys[id]) { continue; } ys[id].forEach(function (v, i) { - if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + if ($$[getAxisId](id) === $$[getAxisId](baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { ys[baseId][i] += +v; } }); @@ -3824,12 +4044,13 @@ } return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); }; - c3_chart_internal_fn.getYDomainMax = function (targets) { + var getYDomainMax = 'getYDomainMax'; + c3_chart_internal_fn[getYDomainMax] = function (targets) { var $$ = this, config = $$.config, - ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + ids = $$[mapToIds](targets), ys = $$[getValuesAsIdKeyed](targets), j, k, baseId, idsInGroup, id, hasPositiveValue; if (config[__data_groups].length > 0) { - hasPositiveValue = $$.hasPositiveValueInTargets(targets); + hasPositiveValue = $$[hasPositiveValueInTargets](targets); for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); @@ -3846,7 +4067,7 @@ id = idsInGroup[k]; if (! ys[id]) { continue; } ys[id].forEach(function (v, i) { - if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + if ($$[getAxisId](id) === $$[getAxisId](baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { ys[baseId][i] += +v; } }); @@ -3855,19 +4076,20 @@ } return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - c3_chart_internal_fn.getYDomain = function (targets, axisId) { + var getYDomain = 'getYDomain'; + c3_chart_internal_fn[getYDomain] = function (targets, axisId) { var $$ = this, config = $$.config, - yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), + yTargets = targets.filter(function (d) { return $$[getAxisId](d.id) === axisId; }), yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], - yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), - yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), + yDomainMin = isValue(yMin) ? yMin : $$[getYDomainMin](yTargets), + yDomainMax = isValue(yMax) ? yMax : $$[getYDomainMax](yTargets), domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$.hasBarType(yTargets) && config[__bar_zerobased]) || ($$.hasAreaType(yTargets) && config[__area_zerobased]), - showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], - showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; + isZeroBased = ($$[hasType](yTargets, TYPE_BAR) && config[__bar_zerobased]) || ($$[hasType](yTargets, TYPE_AREA) && config[__area_zerobased]), + showHorizontalDataLabel = $$[hasDataLabel]() && config[__axis_rotated], + showVerticalDataLabel = $$[hasDataLabel]() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } @@ -3893,23 +4115,23 @@ } // add padding for data label if (showHorizontalDataLabel) { - lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + lengths = $$[getDataLabelLength](yDomainMin, yDomainMax, axisId, 'width'); diff = diffDomain($$.y.range()); ratio = [lengths[0] / diff, lengths[1] / diff]; padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); } else if (showVerticalDataLabel) { - lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + lengths = $$[getDataLabelLength](yDomainMin, yDomainMax, axisId, 'height'); padding_top += lengths[1]; padding_bottom += lengths[0]; } if (axisId === 'y' && config[__axis_y_padding]) { - padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); + padding_top = $$[getAxisPadding](config[__axis_y_padding], 'top', padding, domainLength); + padding_bottom = $$[getAxisPadding](config[__axis_y_padding], 'bottom', padding, domainLength); } if (axisId === 'y2' && config[__axis_y2_padding]) { - padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); + padding_top = $$[getAxisPadding](config[__axis_y2_padding], 'top', padding, domainLength); + padding_bottom = $$[getAxisPadding](config[__axis_y2_padding], 'bottom', padding, domainLength); } // Bar/Area chart should be 0-based if all positive|negative if (isZeroBased) { @@ -3918,26 +4140,29 @@ } return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; - c3_chart_internal_fn.getXDomainMin = function (targets) { + var getXDomainMin = 'getXDomainMin'; + c3_chart_internal_fn[getXDomainMin] = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_min] ? - ($$.isTimeSeries ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : + ($$[isTimeSeries] ? this[parseDate](config[__axis_x_min]) : config[__axis_x_min]) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; - c3_chart_internal_fn.getXDomainMax = function (targets) { + var getXDomainMax = 'getXDomainMax'; + c3_chart_internal_fn[getXDomainMax] = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_max] ? - ($$.isTimeSeries ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : + ($$[isTimeSeries] ? this[parseDate](config[__axis_x_max]) : config[__axis_x_max]) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; - c3_chart_internal_fn.getXDomainPadding = function (targets) { + var getXDomainPadding = 'getXDomainPadding'; + c3_chart_internal_fn[getXDomainPadding] = function (targets) { var $$ = this, config = $$.config, - edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], + edgeX = this[getEdgeX](targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; - if ($$.isCategorized) { + if ($$[isCategorized]) { padding = 0; - } else if ($$.hasBarType(targets)) { - maxDataCount = $$.getMaxDataCount(); + } else if ($$[hasType](targets, TYPE_BAR)) { + maxDataCount = $$[getMaxDataCount](); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { padding = diff * 0.01; @@ -3952,29 +4177,31 @@ } return {left: paddingLeft, right: paddingRight}; }; - c3_chart_internal_fn.getXDomain = function (targets) { + var getXDomain = 'getXDomain'; + c3_chart_internal_fn[getXDomain] = function (targets) { var $$ = this, - xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], + xDomain = [$$[getXDomainMin](targets), $$[getXDomainMax](targets)], firstX = xDomain[0], lastX = xDomain[1], - padding = $$.getXDomainPadding(targets), + padding = $$[getXDomainPadding](targets), min = 0, max = 0; // show center of x domain if min and max are the same - if ((firstX - lastX) === 0 && !$$.isCategorized) { - firstX = $$.isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; - lastX = $$.isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; + if ((firstX - lastX) === 0 && !$$[isCategorized]) { + firstX = $$[isTimeSeries] ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$[isTimeSeries] ? new Date(lastX.getTime() * 1.5) : 0.5; } if (firstX || firstX === 0) { - min = $$.isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + min = $$[isTimeSeries] ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; } if (lastX || lastX === 0) { - max = $$.isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + max = $$[isTimeSeries] ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; } return [min, max]; }; - c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + var updateXDomain = 'updateXDomain'; + c3_chart_internal_fn[updateXDomain] = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { var $$ = this, config = $$.config; if (withUpdateOrgXDomain) { - $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); + $$.x.domain(domain ? domain : $$.d3.extent($$[getXDomain](targets))); $$.orgXDomain = $$.x.domain(); if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } $$.subX.domain($$.x.domain()); @@ -3990,13 +4217,14 @@ - c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { + var getXAxis = 'getXAxis'; + c3_chart_internal_fn[getXAxis] = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, - axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); + axis = c3_axis($$.d3, $$[isCategorized]).scale(scale).orient(orient); // Set tick axis.tickFormat(tickFormat).tickValues(tickValues); - if ($$.isCategorized) { + if ($$[isCategorized]) { axis.tickCentered(config[__axis_x_tick_centered]); if (isEmpty(config[__axis_x_tick_culling])) { config[__axis_x_tick_culling] = false; @@ -4004,36 +4232,40 @@ } else { // TODO: move this to c3_axis axis.tickOffset = function () { - var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), + var edgeX = $$[getEdgeX]($$.data.targets), diff = $$[x](edgeX[1]) - $$[x](edgeX[0]), base = diff ? diff : (config[__axis_rotated] ? $$.height : $$.width); - return (base / $$.getMaxDataCount()) / 2; + return (base / $$[getMaxDataCount]()) / 2; }; } return axis; }; - c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks) { + var getYAxis = 'getYAxis'; + c3_chart_internal_fn[getYAxis] = function (scale, orient, tickFormat, ticks) { return c3_axis(this.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); }; - c3_chart_internal_fn.getAxisId = function (id) { + var getAxisId = 'getAxisId'; + c3_chart_internal_fn[getAxisId] = function (id) { var config = this.config; return id in config[__data_axes] ? config[__data_axes][id] : 'y'; }; - c3_chart_internal_fn.getXAxisTickFormat = function () { + var getXAxisTickFormat = 'getXAxisTickFormat'; + c3_chart_internal_fn[getXAxisTickFormat] = function () { var $$ = this, config = $$.config, - format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + 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) { + } else if ($$[isTimeSeries]) { format = function (date) { - return date ? $$.axisTimeFormat(config[__axis_x_tick_format])(date) : ""; + return date ? $$[axisTimeFormat](config[__axis_x_tick_format])(date) : ""; }; } } return function (v) { return format.call($$, v); }; }; - c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { + var getAxisLabelOptionByAxisId = 'getAxisLabelOptionByAxisId'; + c3_chart_internal_fn[getAxisLabelOptionByAxisId] = function (axisId) { var $$ = this, config = $$.config, option; if (axisId === 'y') { option = config[__axis_y_label]; @@ -4044,13 +4276,15 @@ } return option; }; - c3_chart_internal_fn.getAxisLabelText = function (axisId) { - var option = this.getAxisLabelOptionByAxisId(axisId); + var getAxisLabelText = 'getAxisLabelText'; + c3_chart_internal_fn[getAxisLabelText] = function (axisId) { + var option = this[getAxisLabelOptionByAxisId](axisId); return isString(option) ? option : option ? option.text : null; }; - c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { + var setAxisLabelText = 'setAxisLabelText'; + c3_chart_internal_fn[setAxisLabelText] = function (axisId, text) { var $$ = this, config = $$.config, - option = $$.getAxisLabelOptionByAxisId(axisId); + option = $$[getAxisLabelOptionByAxisId](axisId); if (isString(option)) { if (axisId === 'y') { config[__axis_y_label] = text; @@ -4063,8 +4297,9 @@ option.text = text; } }; - c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { - var option = this.getAxisLabelOptionByAxisId(axisId), + var getAxisLabelPosition = 'getAxisLabelPosition'; + c3_chart_internal_fn[getAxisLabelPosition] = function (axisId, defaultPosition) { + var option = this[getAxisLabelOptionByAxisId](axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { isInner: position.indexOf('inner') >= 0, @@ -4077,28 +4312,36 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - c3_chart_internal_fn.getXAxisLabelPosition = function () { - return this.getAxisLabelPosition('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); + var getXAxisLabelPosition = 'getXAxisLabelPosition'; + c3_chart_internal_fn[getXAxisLabelPosition] = function () { + return this[getAxisLabelPosition]('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); }; - c3_chart_internal_fn.getYAxisLabelPosition = function () { - return this.getAxisLabelPosition('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); + var getYAxisLabelPosition = 'getYAxisLabelPosition'; + c3_chart_internal_fn[getYAxisLabelPosition] = function () { + return this[getAxisLabelPosition]('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - c3_chart_internal_fn.getY2AxisLabelPosition = function () { - return this.getAxisLabelPosition('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); + var getY2AxisLabelPosition = 'getY2AxisLabelPosition'; + c3_chart_internal_fn[getY2AxisLabelPosition] = function () { + return this[getAxisLabelPosition]('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - c3_chart_internal_fn.getAxisLabelPositionById = function (id) { - return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); + var getAxisLabelPositionById = 'getAxisLabelPositionById'; + c3_chart_internal_fn[getAxisLabelPositionById] = function (id) { + return id === 'y2' ? this[getY2AxisLabelPosition]() : id === 'y' ? this[getYAxisLabelPosition]() : this[getXAxisLabelPosition](); }; - c3_chart_internal_fn.textForXAxisLabel = function () { - return this.getAxisLabelText('x'); + var textForXAxisLabel = 'textForXAxisLabel'; + c3_chart_internal_fn[textForXAxisLabel] = function () { + return this[getAxisLabelText]('x'); }; - c3_chart_internal_fn.textForYAxisLabel = function () { - return this.getAxisLabelText('y'); + var textForYAxisLabel = 'textForYAxisLabel'; + c3_chart_internal_fn[textForYAxisLabel] = function () { + return this[getAxisLabelText]('y'); }; - c3_chart_internal_fn.textForY2AxisLabel = function () { - return this.getAxisLabelText('y2'); + var textForY2AxisLabel = 'textForY2AxisLabel'; + c3_chart_internal_fn[textForY2AxisLabel] = function () { + return this[getAxisLabelText]('y2'); }; - c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { + var xForAxisLabel = 'xForAxisLabel'; + c3_chart_internal_fn[xForAxisLabel] = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -4106,107 +4349,125 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - c3_chart_internal_fn.dxForAxisLabel = function (forHorizontal, position) { + var dxForAxisLabel = 'dxForAxisLabel'; + c3_chart_internal_fn[dxForAxisLabel] = function (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"; } }; - c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { + var textAnchorForAxisLabel = 'textAnchorForAxisLabel'; + c3_chart_internal_fn[textAnchorForAxisLabel] = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - c3_chart_internal_fn.xForXAxisLabel = function () { - return this.xForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); + var xForXAxisLabel = 'xForXAxisLabel'; + c3_chart_internal_fn[xForXAxisLabel] = function () { + return this[xForAxisLabel](!this.config[__axis_rotated], this[getXAxisLabelPosition]()); }; - c3_chart_internal_fn.xForYAxisLabel = function () { - return this.xForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); + var xForYAxisLabel = 'xForYAxisLabel'; + c3_chart_internal_fn[xForYAxisLabel] = function () { + return this[xForAxisLabel](this.config[__axis_rotated], this[getYAxisLabelPosition]()); }; - c3_chart_internal_fn.xForY2AxisLabel = function () { - return this.xForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); + var xForY2AxisLabel = 'xForY2AxisLabel'; + c3_chart_internal_fn[xForY2AxisLabel] = function () { + return this[xForAxisLabel](this.config[__axis_rotated], this[getY2AxisLabelPosition]()); }; - c3_chart_internal_fn.dxForXAxisLabel = function () { - return this.dxForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); + var dxForXAxisLabel = 'dxForXAxisLabel'; + c3_chart_internal_fn[dxForXAxisLabel] = function () { + return this[dxForAxisLabel](!this.config[__axis_rotated], this[getXAxisLabelPosition]()); }; - c3_chart_internal_fn.dxForYAxisLabel = function () { - return this.dxForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); + var dxForYAxisLabel = 'dxForYAxisLabel'; + c3_chart_internal_fn[dxForYAxisLabel] = function () { + return this[dxForAxisLabel](this.config[__axis_rotated], this[getYAxisLabelPosition]()); }; - c3_chart_internal_fn.dxForY2AxisLabel = function () { - return this.dxForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); + var dxForY2AxisLabel = 'dxForY2AxisLabel'; + c3_chart_internal_fn[dxForY2AxisLabel] = function () { + return this[dxForAxisLabel](this.config[__axis_rotated], this[getY2AxisLabelPosition]()); }; - c3_chart_internal_fn.dyForXAxisLabel = function () { + var dyForXAxisLabel = 'dyForXAxisLabel'; + c3_chart_internal_fn[dyForXAxisLabel] = function () { var $$ = this, config = $$.config, - position = $$.getXAxisLabelPosition(); + position = $$[getXAxisLabelPosition](); if (config[__axis_rotated]) { - return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); + return position.isInner ? "1.2em" : -25 - $$[getMaxTickWidth]('x'); } else { return position.isInner ? "-0.5em" : config[__axis_x_height] ? config[__axis_x_height] - 10 : "3em"; } }; - c3_chart_internal_fn.dyForYAxisLabel = function () { + var dyForYAxisLabel = 'dyForYAxisLabel'; + c3_chart_internal_fn[dyForYAxisLabel] = function () { var $$ = this, - position = $$.getYAxisLabelPosition(); + position = $$[getYAxisLabelPosition](); if ($$.config[__axis_rotated]) { return position.isInner ? "-0.5em" : "3em"; } else { - return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); + return position.isInner ? "1.2em" : -20 - $$[getMaxTickWidth]('y'); } }; - c3_chart_internal_fn.dyForY2AxisLabel = function () { + var dyForY2AxisLabel = 'dyForY2AxisLabel'; + c3_chart_internal_fn[dyForY2AxisLabel] = function () { var $$ = this, - position = $$.getY2AxisLabelPosition(); + position = $$[getY2AxisLabelPosition](); if ($$.config[__axis_rotated]) { return position.isInner ? "1.2em" : "-2.2em"; } else { - return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); + return position.isInner ? "-0.5em" : 30 + this[getMaxTickWidth]('y2'); } }; - c3_chart_internal_fn.textAnchorForXAxisLabel = function () { + var textAnchorForXAxisLabel = 'textAnchorForXAxisLabel'; + c3_chart_internal_fn[textAnchorForXAxisLabel] = function () { var $$ = this; - return $$.textAnchorForAxisLabel(!$$.config[__axis_rotated], $$.getXAxisLabelPosition()); + return $$[textAnchorForAxisLabel](!$$.config[__axis_rotated], $$[getXAxisLabelPosition]()); }; - c3_chart_internal_fn.textAnchorForYAxisLabel = function () { + var textAnchorForYAxisLabel = 'textAnchorForYAxisLabel'; + c3_chart_internal_fn[textAnchorForYAxisLabel] = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getYAxisLabelPosition()); + return $$[textAnchorForAxisLabel]($$.config[__axis_rotated], $$[getYAxisLabelPosition]()); }; - c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { + var textAnchorForY2AxisLabel = 'textAnchorForY2AxisLabel'; + c3_chart_internal_fn[textAnchorForY2AxisLabel] = function () { var $$ = this; - return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getY2AxisLabelPosition()); + return $$[textAnchorForAxisLabel]($$.config[__axis_rotated], $$[getY2AxisLabelPosition]()); }; - c3_chart_internal_fn.xForRotatedTickText = function (r) { + var xForRotatedTickText = 'xForRotatedTickText'; + c3_chart_internal_fn[xForRotatedTickText] = function (r) { return 10 * Math.sin(Math.PI * (r / 180)); }; - c3_chart_internal_fn.yForRotatedTickText = function (r) { + var yForRotatedTickText = 'yForRotatedTickText'; + c3_chart_internal_fn[yForRotatedTickText] = function (r) { return 11.5 - 2.5 * (r / 15); }; - c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) { + var rotateTickText = 'rotateTickText'; + c3_chart_internal_fn[rotateTickText] = function (axis, transition, rotate) { axis.selectAll('.tick text') - .style("text-anchor", "start"); + .style(CSS_TEXT_ANCHOR, "start"); transition.selectAll('.tick text') - .attr("y", this.yForRotatedTickText(rotate)) - .attr("x", this.xForRotatedTickText(rotate)) - .attr("transform", "rotate(" + rotate + ")"); + .attr("y", this[yForRotatedTickText](rotate)) + .attr("x", this[xForRotatedTickText](rotate)) + .attr(CSS_TRANSFORM, "rotate(" + rotate + ")"); }; - c3_chart_internal_fn.getMaxTickWidth = function (id) { + var getMaxTickWidth = 'getMaxTickWidth'; + c3_chart_internal_fn[getMaxTickWidth] = function (id) { var $$ = this, config = $$.config, maxWidth = 0, targetsToShow, scale, axis; if ($$.svg) { - targetsToShow = $$.filterTargetsToShow($$.data.targets); + targetsToShow = $$[filterTargetsToShow]($$.data.targets); if (id === 'y') { - scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); - axis = $$.getYAxis(scale, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + scale = $$.y.copy().domain($$[getYDomain](targetsToShow, 'y')); + axis = $$[getYAxis](scale, $$[yOrient], config[__axis_y_tick_format], config[__axis_y_ticks]); } else if (id === 'y2') { - scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); - axis = $$.getYAxis(scale, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); + scale = $$.y2.copy().domain($$[getYDomain](targetsToShow, 'y2')); + axis = $$[getYAxis](scale, $$[y2Orient], config[__axis_y2_tick_format], config[__axis_y2_ticks]); } else { - scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); - axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); + scale = $$.x.copy().domain($$[getXDomain](targetsToShow)); + axis = $$[getXAxis](scale, $$[xOrient], $$[getXAxisTickFormat](), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4215,38 +4476,41 @@ }); }).remove(); } - $$.currentMaxTickWidth = maxWidth <= 0 ? $$.currentMaxTickWidth : maxWidth; - return $$.currentMaxTickWidth; + $$[currentMaxTickWidth] = maxWidth <= 0 ? $$[currentMaxTickWidth] : maxWidth; + return $$[currentMaxTickWidth]; }; - c3_chart_internal_fn.updateAxisLabels = function (withTransition) { + var updateAxisLabels = 'updateAxisLabels'; + c3_chart_internal_fn[updateAxisLabels] = function (withTransition) { var $$ = this; - var axisXLabel = $$.main.select('.' + CLASS.axisX + ' .' + CLASS.axisXLabel), - axisYLabel = $$.main.select('.' + CLASS.axisY + ' .' + CLASS.axisYLabel), - axisY2Label = $$.main.select('.' + CLASS.axisY2 + ' .' + CLASS.axisY2Label); + 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", generateCall($$.xForXAxisLabel, $$)) - .attr("dx", generateCall($$.dxForXAxisLabel, $$)) - .attr("dy", generateCall($$.dyForXAxisLabel, $$)) + .attr("x", generateCall($$[xForXAxisLabel], $$)) + .attr("dx", generateCall($$[dxForXAxisLabel], $$)) + .attr("dy", generateCall($$[dyForXAxisLabel], $$)) .text(generateCall($$.textForXAxisLabel, $$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", generateCall($$.xForYAxisLabel, $$)) - .attr("dx", generateCall($$.dxForYAxisLabel, $$)) - .attr("dy", generateCall($$.dyForYAxisLabel, $$)) - .text(generateCall($$.textForYAxisLabel, $$)); + .attr("x", generateCall($$[xForYAxisLabel], $$)) + .attr("dx", generateCall($$[dxForYAxisLabel], $$)) + .attr("dy", generateCall($$[dyForYAxisLabel], $$)) + .text(generateCall($$[textForYAxisLabel], $$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", generateCall($$.xForY2AxisLabel, $$)) - .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) - .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) - .text(generateCall($$.textForY2AxisLabel, $$)); + .attr("x", generateCall($$[xForY2AxisLabel], $$)) + .attr("dx", generateCall($$[dxForY2AxisLabel], $$)) + .attr("dy", generateCall($$[dyForY2AxisLabel], $$)) + .text(generateCall($$[textForY2AxisLabel], $$)); }; - c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { + var getAxisPadding = 'getAxisPadding'; + c3_chart_internal_fn[getAxisPadding] = function (padding, key, defaultValue, all) { var ratio = padding.unit === 'ratio' ? all : 1; return isValue(padding[key]) ? padding[key] * ratio : defaultValue; }; - c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { + var generateTickValues = 'generateTickValues'; + c3_chart_internal_fn[generateTickValues] = function (xs, tickCount) { var $$ = this; var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { @@ -4265,12 +4529,12 @@ tickValues = [start]; for (i = 0; i < count; i++) { tickValue = +start + interval * (i + 1); - tickValues.push($$.isTimeSeries ? new Date(tickValue) : tickValue); + tickValues.push($$[isTimeSeries] ? new Date(tickValue) : tickValue); } tickValues.push(end); } } - if (!$$.isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + if (!$$[isTimeSeries]) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; @@ -4278,47 +4542,52 @@ /** * c3.region.js */ - c3_chart_internal_fn.regionX = function (d) { + var regionX = 'regionX'; + c3_chart_internal_fn[regionX] = function (d) { var $$ = this, config = $$.config, xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.start) : d.start) : 0); } return xPos; }; - c3_chart_internal_fn.regionY = function (d) { + var regionY = 'regionY'; + c3_chart_internal_fn[regionY] = function (d) { var $$ = this, config = $$.config, yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; + yPos = config[__axis_rotated] ? ('start' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.start) : d.start) : 0) : 0; } return yPos; }; - c3_chart_internal_fn.regionWidth = function (d) { + var regionWidth = 'regionWidth'; + c3_chart_internal_fn[regionWidth] = function (d) { var $$ = this, config = $$.config, - start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + start = $$[regionX](d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; - c3_chart_internal_fn.regionHeight = function (d) { + var regionHeight = 'regionHeight'; + c3_chart_internal_fn[regionHeight] = function (d) { var $$ = this, config = $$.config, - start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + start = this[regionY](d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; + end = config[__axis_rotated] ? ('end' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; - c3_chart_internal_fn.isRegionOnX = function (d) { + var isRegionOnX = 'isRegionOnX'; + c3_chart_internal_fn[isRegionOnX] = function (d) { return !d.axis || d.axis === 'x'; }; @@ -4327,36 +4596,40 @@ //-- c3.arc.js --// - c3_chart_internal_fn.initPie = function () { + var initPie = 'initPie', pie = 'pie'; + c3_chart_internal_fn[initPie] = function () { var $$ = this, d3 = $$.d3, config = $$.config; - $$.pie = d3.layout.pie().value(function (d) { + $$[pie] = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); }); if (!config[__data_order] || !config[__pie_sort] || !config[__donut_sort]) { - $$.pie.sort(null); + $$[pie].sort(null); } }; - c3_chart_internal_fn.updateRadius = function () { + var updateRadius = 'updateRadius'; + c3_chart_internal_fn[updateRadius] = function () { var $$ = this, config = $$.config, w = config[__gauge_width] || config[__donut_width]; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; }; - c3_chart_internal_fn.updateArc = function () { + var updateArc = 'updateArc', svgArc = 'svgArc', svgArcExpanded = 'svgArcExpanded', svgArcExpandedSub = 'svgArcExpandedSub'; + c3_chart_internal_fn[updateArc] = function () { var $$ = this; - $$.svgArc = $$.getSvgArc(); - $$.svgArcExpanded = $$.getSvgArcExpanded(); - $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); + $$[svgArc] = $$[getSvgArc](); + $$[svgArcExpanded] = $$[getSvgArcExpanded](); + $$[svgArcExpandedSub] = $$[getSvgArcExpanded](0.98); }; - c3_chart_internal_fn.updateAngle = function (d) { + var updateAngle = 'updateAngle'; + c3_chart_internal_fn[updateAngle] = function (d) { var $$ = this, config = $$.config, found = false, index = 0; - $$.pie($$.filterTargetsToShow($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { + $$[pie]($$[filterTargetsToShow]($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { found = true; d = t; @@ -4367,7 +4640,7 @@ if (isNaN(d.endAngle)) { d.endAngle = d.startAngle; } - if ($$.isGaugeType(d.data)) { + if ($$[isGaugeType](d.data)) { var gMin = config[__gauge_min], gMax = config[__gauge_max], gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; @@ -4377,13 +4650,14 @@ return found ? d : null; }; - c3_chart_internal_fn.getSvgArc = function () { + var getSvgArc = 'getSvgArc'; + c3_chart_internal_fn[getSvgArc] = function () { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { var updated; if (withoutUpdate) { return arc(d); } // for interpolate - updated = $$.updateAngle(d); + updated = $$[updateAngle](d); return updated ? arc(updated) : "M 0 0"; }; // TODO: extends all function @@ -4391,24 +4665,27 @@ return newArc; }; - c3_chart_internal_fn.getSvgArcExpanded = function (rate) { + var getSvgArcExpanded = 'getSvgArcExpanded'; + c3_chart_internal_fn[getSvgArcExpanded] = function (rate) { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { - var updated = $$.updateAngle(d); + var updated = $$[updateAngle](d); return updated ? arc(updated) : "M 0 0"; }; }; - c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { - return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; + var getArc = 'getArc'; + c3_chart_internal_fn[getArc] = function (d, withoutUpdate, force) { + return force || this[isArcType](d.data) ? this[svgArc](d, withoutUpdate) : "M 0 0"; }; - c3_chart_internal_fn.transformForArcLabel = function (d) { + var transformForArcLabel = 'transformForArcLabel'; + c3_chart_internal_fn[transformForArcLabel] = function (d) { var $$ = this, - updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; - if (updated && !$$.hasGaugeType($$.data.targets)) { + updated = $$[updateAngle](d), c, x, y, h, ratio, translate = ""; + if (updated && !$$[hasType]($$.data.targets, TYPE_GAUGE)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4420,195 +4697,209 @@ return translate; }; - c3_chart_internal_fn.getArcRatio = function (d) { + var getArcRatio = 'getArcRatio'; + c3_chart_internal_fn[getArcRatio] = function (d) { var $$ = this, - whole = $$.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); + whole = $$[hasType]($$.data.targets, TYPE_GAUGE) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; - c3_chart_internal_fn.convertToArcData = function (d) { - return this.addName({ + var convertToArcData = 'convertToArcData'; + c3_chart_internal_fn[convertToArcData] = function (d) { + return this[addName]({ id: d.data.id, value: d.value, - ratio: this.getArcRatio(d), + ratio: this[getArcRatio](d), index: d.index }); }; - c3_chart_internal_fn.textForArcLabel = function (d) { + var textForArcLabel = 'textForArcLabel'; + c3_chart_internal_fn[textForArcLabel] = function (d) { var $$ = this, updated, value, ratio, format; - if (! $$.shouldShowArcLabel()) { return ""; } - updated = $$.updateAngle(d); + if (! $$[shouldShowArcLabel]()) { return ""; } + updated = $$[updateAngle](d); value = updated ? updated.value : null; - ratio = $$.getArcRatio(updated); - if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } - format = $$.getArcLabelFormat(); - return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); + ratio = $$[getArcRatio](updated); + if (! $$[hasType]($$.data.targets, TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } + format = $$[getArcLabelFormat](); + return format ? format(value, ratio) : $$[defaultArcValueFormat](value, ratio); }; - c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { + var expandArc = 'expandArc'; + c3_chart_internal_fn[expandArc] = function (id, withoutFadeOut) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), - noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); + target = $$.svg.selectAll('.' + CLASS[chartArc] + $$[selectorTarget](id)), + noneTargets = $$.svg.selectAll('.' + CLASS[arc]).filter(function (data) { return data.data.id !== id; }); - if ($$.shouldExpand(id)) { + if ($$[shouldExpand](id)) { target.selectAll('path') .transition().duration(50) - .attr("d", $$.svgArcExpanded) + .attr("d", $$[svgArcExpanded]) .transition().duration(100) - .attr("d", $$.svgArcExpandedSub) + .attr("d", $$[svgArcExpandedSub]) .each(function (d) { - if ($$.isDonutType(d.data)) { + if ($$[isDonutType](d.data)) { // callback here } }); } if (!withoutFadeOut) { - noneTargets.style("opacity", 0.3); + noneTargets.style(CSS_OPACITY, 0.3); } }; - c3_chart_internal_fn.unexpandArc = function (id) { + var unexpandArc = 'unexpandArc'; + c3_chart_internal_fn[unexpandArc] = function (id) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); - target.selectAll('path.' + CLASS.arc) + target = $$.svg.selectAll('.' + CLASS[chartArc] + $$[selectorTarget](id)); + target.selectAll('path.' + CLASS[arc]) .transition().duration(50) .attr("d", $$.svgArc); - $$.svg.selectAll('.' + CLASS.arc) - .style("opacity", 1); + $$.svg.selectAll('.' + CLASS[arc]) + .style(CSS_OPACITY, 1); }; - c3_chart_internal_fn.shouldExpand = function (id) { + var shouldExpand = 'shouldExpand'; + c3_chart_internal_fn[shouldExpand] = function (id) { 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 () { + var shouldShowArcLabel = 'shouldShowArcLabel'; + c3_chart_internal_fn[shouldShowArcLabel] = function () { var $$ = this, config = $$.config, shouldShow = true; - if ($$.hasDonutType($$.data.targets)) { + if ($$[hasType]($$.data.targets, TYPE_DONUT)) { shouldShow = config[__donut_label_show]; - } else if ($$.hasPieType($$.data.targets)) { + } else if ($$[hasType]($$.data.targets, TYPE_PIE)) { shouldShow = config[__pie_label_show]; } // when gauge, always true return shouldShow; }; - c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { + var meetsArcLabelThreshold = 'meetsArcLabelThreshold'; + c3_chart_internal_fn[meetsArcLabelThreshold] = function (ratio) { var $$ = this, config = $$.config, - threshold = $$.hasDonutType($$.data.targets) ? config[__donut_label_threshold] : config[__pie_label_threshold]; + threshold = $$[hasType]($$.data.targets, TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; - c3_chart_internal_fn.getArcLabelFormat = function () { + var getArcLabelFormat = 'getArcLabelFormat'; + c3_chart_internal_fn[getArcLabelFormat] = function () { var $$ = this, config = $$.config, format = config[__pie_label_format]; - if ($$.hasGaugeType($$.data.targets)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { format = config[__gauge_label_format]; - } else if ($$.hasDonutType($$.data.targets)) { + } else if ($$[hasType]($$.data.targets, TYPE_DONUT)) { format = config[__donut_label_format]; } return format; }; - c3_chart_internal_fn.getArcTitle = function () { + var getArcTitle = 'getArcTitle'; + c3_chart_internal_fn[getArcTitle] = function () { var $$ = this; - return $$.hasDonutType($$.data.targets) ? $$.config[__donut_title] : ""; + return $$[hasType]($$.data.targets, TYPE_DONUT) ? $$.config[__donut_title] : ""; }; - c3_chart_internal_fn.descByStartAngle = function (a, b) { + var descByStartAngle = 'descByStartAngle'; + c3_chart_internal_fn[descByStartAngle] = function (a, b) { return a.startAngle - b.startAngle; }; - c3_chart_internal_fn.updateTargetsForArc = function (targets) { + var updateTargetsForArc = 'updateTargetsForArc'; + c3_chart_internal_fn[updateTargetsForArc] = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; - mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) - .data($$.pie(targets)) - .attr("class", generateCall($$.classChartArc, $$)); + mainPieUpdate = main.select('.' + CLASS[chartArcs]).selectAll('.' + CLASS[chartArc]) + .data($$[pie](targets)) + .attr(CSS_CLASS, generateCall($$[classChartArc], $$)); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", generateCall($$.classChartArc, $$)); + .attr(CSS_CLASS, generateCall($$[classChartArc], $$)); mainPieEnter.append('g') - .attr('class', generateCall($$.classArcs, $$)); + .attr(CSS_CLASS, generateCall($$[classArcs], $$)); mainPieEnter.append("text") - .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") - .style("opacity", 0) - .style("text-anchor", "middle") - .style("pointer-events", "none"); + .attr("dy", $$[hasType]($$.data.targets, TYPE_GAUGE) ? "-0.35em" : ".35em") + .style(CSS_OPACITY, 0) + .style(CSS_TEXT_ANCHOR, "middle") + .style(CSS_POINTER_EVENTS, "none"); // MEMO: can not keep same color..., but not bad to update color in redraw //mainPieUpdate.exit().remove(); }; - c3_chart_internal_fn.initArc = function () { + var initArc = 'initArc'; + c3_chart_internal_fn[initArc] = function () { var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartArcs) - .attr("transform", $$.translate.arc); + arcs = $$.main.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartArcs]) + .attr(CSS_TRANSFORM, $$[translate].arc); arcs.append('text') - .attr('class', CLASS.chartArcsTitle) - .style("text-anchor", "middle") - .text($$.getArcTitle()); + .attr(CSS_CLASS, CLASS[chartArcsTitle]) + .style(CSS_TEXT_ANCHOR, "middle") + .text($$[getArcTitle]()); }; - c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { + var redrawArc = 'redrawArc'; + c3_chart_internal_fn[redrawArc] = function (duration, durationForExit, withTransform) { var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; - mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) - .data(generateCall($$.arcData, $$)); + mainArc = main.selectAll('.' + CLASS[arcs]).selectAll('.' + CLASS[arc]) + .data(generateCall($$[arcData], $$)); mainArc.enter().append('path') - .attr("class", generateCall($$.classArc, $$)) - .style("fill", function (d) { return $$.color(d.data); }) + .attr(CSS_CLASS, generateCall($$[classArc], $$)) + .style("fill", function (d) { return $$[color](d.data); }) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) - .style("opacity", 0) + .style(CSS_OPACITY, 0) .each(function (d) { - if ($$.isGaugeType(d.data)) { + if ($$[isGaugeType](d.data)) { d.startAngle = d.endAngle = -1 * (Math.PI / 2); } this._current = d; }) .on('mouseover', function (d) { var updated, arcData; - if ($$.transiting) { // skip while transiting + if ($$[transiting]) { // skip while transiting return; } - updated = $$.updateAngle(d); - arcData = $$.convertToArcData(updated); + updated = $$[updateAngle](d); + arcData = $$[convertToArcData](updated); // transitions - $$.expandArc(updated.data.id); - $$.toggleFocusLegend(updated.data.id, true); + $$[expandArc](updated.data.id); + $$[toggleFocusLegend](updated.data.id, true); $$.config[__data_onmouseover](arcData, this); }) .on('mousemove', function (d) { - var updated = $$.updateAngle(d), - arcData = $$.convertToArcData(updated), + var updated = $$[updateAngle](d), + arcData = $$[convertToArcData](updated), selectedData = [arcData]; - $$.showTooltip(selectedData, d3.mouse(this)); + $$[showTooltip](selectedData, d3.mouse(this)); }) .on('mouseout', function (d) { var updated, arcData; - if ($$.transiting) { // skip while transiting + if ($$[transiting]) { // skip while transiting return; } - updated = $$.updateAngle(d); - arcData = $$.convertToArcData(updated); + updated = $$[updateAngle](d); + arcData = $$[convertToArcData](updated); // transitions - $$.unexpandArc(updated.data.id); - $$.revertLegend(); - $$.hideTooltip(); + $$[unexpandArc](updated.data.id); + $$[revertLegend](); + $$[hideTooltip](); $$.config[__data_onmouseout](arcData, this); }) .on('click', function (d, i) { - var updated = $$.updateAngle(d), - arcData = $$.convertToArcData(updated); - $$.toggleShape(this, arcData, i); // onclick called in toogleShape() + var updated = $$[updateAngle](d), + arcData = $$[convertToArcData](updated); + $$[toggleShape](this, arcData, i); // onclick called in toogleShape() }); mainArc - .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) - .style("opacity", function (d) { return d === this._current ? 0 : 1; }) - .each(function () { $$.transiting = true; }) + .attr(CSS_TRANSFORM, function (d) { return !$$[isGaugeType](d.data) && withTransform ? "scale(0)" : ""; }) + .style(CSS_OPACITY, function (d) { return d === this._current ? 0 : 1; }) + .each(function () { $$[transiting] = true; }) .transition().duration(duration) .attrTween("d", function (d) { - var updated = $$.updateAngle(d), interpolate; + var updated = $$[updateAngle](d), interpolate; if (! updated) { return function () { return "M 0 0"; }; } @@ -4623,65 +4914,66 @@ } interpolate = d3.interpolate(this._current, updated); this._current = interpolate(0); - return function (t) { return $$.getArc(interpolate(t), true); }; + return function (t) { return $$[getArc](interpolate(t), true); }; }) - .attr("transform", withTransform ? "scale(1)" : "") + .attr(CSS_TRANSFORM, withTransform ? "scale(1)" : "") .style("fill", function (d) { - return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); + return $$[levelColor] ? $$[levelColor](d.data.values[0].value) : $$[color](d.data.id); }) // Where gauge reading color would receive customization. - .style("opacity", 1) + .style(CSS_OPACITY, 1) .call($$.endall, function () { - $$.transiting = false; + $$[transiting] = false; }); mainArc.exit().transition().duration(durationForExit) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); - main.selectAll('.' + CLASS.chartArc).select('text') - .style("opacity", 0) - .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) - .text(generateCall($$.textForArcLabel, $$)) - .attr("transform", generateCall($$.transformForArcLabel, $$)) + main.selectAll('.' + CLASS[chartArc]).select('text') + .style(CSS_OPACITY, 0) + .attr(CSS_CLASS, function (d) { return $$[isGaugeType](d.data) ? CLASS[gaugeValue] : ''; }) + .text(generateCall($$[textForArcLabel], $$)) + .attr(CSS_TRANSFORM, generateCall($$[transformForArcLabel], $$)) .transition().duration(duration) - .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); - main.select('.' + CLASS.chartArcsTitle) - .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); + .style(CSS_OPACITY, function (d) { return $$[isTargetToShow](d.data.id) && $$[isArcType](d.data) ? 1 : 0; }); + main.select('.' + CLASS[chartArcsTitle]) + .style(CSS_OPACITY, $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? 1 : 0); }; //-- gauge.js --// - c3_chart_internal_fn.initGauge = function () { + var initGauge = 'initGauge'; + c3_chart_internal_fn[initGauge] = function () { var $$ = this, config = $$.config, arcs; - if ($$.hasGaugeType($$.data.targets)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { arcs.append('path') - .attr("class", CLASS.chartArcsBackground) + .attr(CSS_CLASS, CLASS[chartArcsBackground]) .attr("d", function () { var d = { data: [{value: config[__gauge_max]}], startAngle: -1 * (Math.PI / 2), endAngle: Math.PI / 2 }; - return $$.getArc(d, true, true); + return $$[getArc](d, true, true); }); arcs.append("text") .attr("dy", ".75em") - .attr("class", CLASS.chartArcsGaugeUnit) - .style("text-anchor", "middle") - .style("pointer-events", "none") + .attr(CSS_CLASS, CLASS[chartArcsGaugeUnit]) + .style(CSS_TEXT_ANCHOR, "middle") + .style(CSS_POINTER_EVENTS, "none") .text(config[__gauge_label_show] ? config[__gauge_units] : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMin) - .style("text-anchor", "middle") - .style("pointer-events", "none") + .attr(CSS_CLASS, CLASS[chartArcsGaugeMin]) + .style(CSS_TEXT_ANCHOR, "middle") + .style(CSS_POINTER_EVENTS, "none") .text(config[__gauge_label_show] ? config[__gauge_min] : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMax) - .style("text-anchor", "middle") - .style("pointer-events", "none") + .attr(CSS_CLASS, CLASS[chartArcsGaugeMax]) + .style(CSS_TEXT_ANCHOR, "middle") + .style(CSS_POINTER_EVENTS, "none") .text(config[__gauge_label_show] ? config[__gauge_max] : ''); } }; @@ -4690,61 +4982,66 @@ /** * c3.cache.js */ - c3_chart_internal_fn.hasCaches = function (ids) { + var hasCaches = 'hasCaches'; + c3_chart_internal_fn[hasCaches] = function (ids) { for (var i = 0; i < ids.length; i++) { if (! (ids[i] in this.cache)) { return false; } } return true; }; - c3_chart_internal_fn.addCache = function (id, target) { - this.cache[id] = this.cloneTarget(target); + var addCache = 'addCache'; + c3_chart_internal_fn[addCache] = function (id, target) { + this.cache[id] = this[cloneTarget](target); }; - c3_chart_internal_fn.getCaches = function (ids) { + var getCaches = 'getCaches'; + c3_chart_internal_fn[getCaches] = function (ids) { var targets = [], i; for (i = 0; i < ids.length; i++) { - if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } + if (ids[i] in this.cache) { targets.push(this[cloneTarget](this.cache[ids[i]])); } } return targets; }; //-- subchart.js --// - c3_chart_internal_fn.initBrush = function () { + var initBrush = 'initBrush'; + c3_chart_internal_fn[initBrush] = function () { var $$ = this, d3 = $$.d3; - $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); + $$.brush = d3.svg.brush().on("brush", function () { $$[redrawForBrush](); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } + if ($$.context) { $$.context.select('.' + CLASS[brush]).call(this); } return this; }; $$.brush.scale = function (scale) { - return $$.config[__axis_rotated] ? this.y(scale) : this.x(scale); + return $$.config[__axis_rotated] ? this[y](scale) : this[x](scale); }; }; - c3_chart_internal_fn.initSubchart = function () { + var initSubchart = 'initSubchart'; + c3_chart_internal_fn[initSubchart] = function () { var $$ = this, config = $$.config, - context = $$.context = $$.svg.append("g").attr("transform", $$.translate.context); + context = $$.context = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].context); if (!config[__subchart_show]) { - context.style('visibility', 'hidden'); + context.style(CSS_VISIBILITY, 'hidden'); } // Define g for chart area context.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS.chart); + .attr("clip-path", $$[clipPath]) + .attr(CSS_CLASS, CLASS[chart]); // Define g for bar chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); + context.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartBars]); // Define g for line chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); + context.select('.' + CLASS[chart]).append("g") + .attr(CSS_CLASS, CLASS[chartLines]); // Add extent rect for Brush context.append("g") - .attr("clip-path", $$.clipPath) - .attr("class", CLASS.brush) + .attr("clip-path", $$[clipPath]) + .attr(CSS_CLASS, CLASS[brush]) .call($$.brush) .selectAll("rect") .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); @@ -4752,42 +5049,44 @@ // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = context.append("g") - .attr("class", CLASS.axisX) - .attr("transform", $$.translate.subx) - .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); + .attr(CSS_CLASS, CLASS[axisX]) + .attr(CSS_TRANSFORM, $$[translate].subx) + .attr("clip-path", config[__axis_rotated] ? "" : $$[clipPathForXAxis]); }; - c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { + var updateTargetsForSubchart = 'updateTargetsForSubchart'; + c3_chart_internal_fn[updateTargetsForSubchart] = function (targets) { var $$ = this, context = $$.context, config = $$.config, contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + contextBarUpdate = context.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); + .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); contextBarEnter = contextBarUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', generateCall($$.classChartBar, $$)); + .style(CSS_OPACITY, 0) + .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); // Bars for each data contextBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)); + .attr(CSS_CLASS, generateCall($$[classBars], $$)); //-- Line --// - contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + contextLineUpdate = context.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); + .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); contextLineEnter = contextLineUpdate.enter().append('g') - .style('opacity', 0) - .attr('class', generateCall($$.classChartLine, $$)); + .style(CSS_OPACITY, 0) + .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); // Lines for each data contextLineEnter.append("g") - .attr("class", generateCall($$.classLines, $$)); + .attr(CSS_CLASS, generateCall($$[classLines], $$)); // Area contextLineEnter.append("g") - .attr("class", generateCall($$.classAreas, $$)); + .attr(CSS_CLASS, generateCall($$[classAreas], $$)); } }; - c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { + var redrawSubchart = 'redrawSubchart'; + c3_chart_internal_fn[redrawSubchart] = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { var $$ = this, d3 = $$.d3, context = $$.context, config = $$.config, contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; @@ -4802,7 +5101,7 @@ // rotate tick text if needed if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { - $$.rotateTickText($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); + $$[rotateTickText]($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); } // extent rect @@ -4810,60 +5109,61 @@ $$.brush.extent($$.x.orgDomain()).update(); } // setup drawer - MEMO: this must be called after axis updated - drawAreaOnSub = $$.generateDrawArea(areaIndices, true); - drawBarOnSub = $$.generateDrawBar(barIndices, true); - drawLineOnSub = $$.generateDrawLine(lineIndices, true); + drawAreaOnSub = $$[generateDrawArea](areaIndices, true); + drawBarOnSub = $$[generateDrawBar](barIndices, true); + drawLineOnSub = $$[generateDrawLine](lineIndices, true); // bars - contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) - .data(generateCall($$.barData, $$)); + contextBar = context.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) + .data(generateCall($$[barData], $$)); contextBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) + .attr(CSS_CLASS, generateCall($$[classBar], $$)) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style("opacity", generateCall($$.initialOpacity, $$)) + .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) .transition().duration(duration) .attr('d', drawBarOnSub) - .style('opacity', 1); + .style(CSS_OPACITY, 1); contextBar.exit().transition().duration(duration) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); // lines - contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) - .data(generateCall($$.lineData, $$)); + contextLine = context.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) + .data(generateCall($$[lineData], $$)); contextLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) + .attr(CSS_CLASS, generateCall($$[classLine], $$)) .style('stroke', $$.color); contextLine - .style("opacity", generateCall($$.initialOpacity, $$)) + .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) .transition().duration(duration) .attr("d", drawLineOnSub) - .style('opacity', 1); + .style(CSS_OPACITY, 1); contextLine.exit().transition().duration(duration) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); // area - contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) - .data(generateCall($$.lineData, $$)); + contextArea = context.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) + .data(generateCall($$[lineData], $$)); contextArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) + .attr(CSS_CLASS, generateCall($$[classArea], $$)) .style("fill", $$.color) - .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + .style(CSS_OPACITY, function () { $$.orgAreaOpacity = +d3.select(this).style(CSS_OPACITY); return 0; }); contextArea - .style("opacity", 0) + .style(CSS_OPACITY, 0) .transition().duration(duration) .attr("d", drawAreaOnSub) .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity); + .style(CSS_OPACITY, $$.orgAreaOpacity); contextArea.exit().transition().duration(durationForExit) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); } } }; - c3_chart_internal_fn.redrawForBrush = function () { + var redrawForBrush = 'redrawForBrush'; + c3_chart_internal_fn[redrawForBrush] = function () { var $$ = this, x = $$.x; - $$.redraw({ + $$[redraw]({ withTransition: false, withY: false, withSubchart: false, @@ -4871,26 +5171,28 @@ }); $$.config[__subchart_onbrush].call($$, x.orgDomain()); }; - c3_chart_internal_fn.transformContext = function (withTransition, transitions) { + var transformContext = 'transformContext'; + c3_chart_internal_fn[transformContext] = function (withTransition, transitions) { var $$ = this, subXAxis; if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + CLASS.axisX); + subXAxis = $$.context.select('.' + CLASS[axisX]); if (withTransition) { subXAxis = subXAxis.transition(); } } - $$.context.attr("transform", $$.translate.context); - subXAxis.attr("transform", $$.translate.subx); + $$.context.attr(CSS_TRANSFORM, $$[translate].context); + subXAxis.attr(CSS_TRANSFORM, $$[translate].subx); }; /** * c3.zoom.js */ - c3_chart_internal_fn.updateZoom = function () { + var updateZoom = 'updateZoom'; + c3_chart_internal_fn[updateZoom] = function () { var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; - $$.main.select('.' + $$.CLASS.zoomRect).call(z); - $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); + $$.main.select('.' + CLASS[zoomRect]).call(z); + $$.main.selectAll('.' + CLASS[eventRect]).call(z); }; @@ -4908,9 +5210,6 @@ isString = c3_chart_internal_fn.isString = function (o) { return typeof o === 'string'; }, - isUndefined = c3_chart_internal_fn.isUndefined = function (v) { - return typeof v === 'undefined'; - }, isDefined = c3_chart_internal_fn.isDefined = function (v) { return typeof v !== 'undefined'; }, @@ -4949,7 +5248,8 @@ return function (d, i) { return f.call(context, d, i); }; }; - c3_chart_internal_fn.getTextRect = function (text, cls) { + var getTextRect = 'getTextRect'; + c3_chart_internal_fn[getTextRect] = function (text, cls) { var rect; this.d3.select('body').selectAll('.dummy') .data([text]) @@ -4959,71 +5259,80 @@ .each(function () { rect = this.getBoundingClientRect(); }) .remove(); return rect; - }, + }; /** * c3.selection.js */ - c3_chart_internal_fn.selectPoint = function (target, d, i) { + var selectPoint = 'selectPoint'; + c3_chart_internal_fn[selectPoint] = function (target, d, i) { var $$ = this, config = $$.config; config[__data_onselected](d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return $$.generateClass(CLASS.selectedCircle, i); }) + .attr(CSS_CLASS, function () { return $$[generateClass](CLASS[selectedCircle], i); }) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) - .attr("stroke", function () { return $$.color(d); }) - .attr("r", $$.pointSelectR(d) * 1.4) + .attr("stroke", function () { return $$[color](d); }) + .attr("r", $$[pointSelectR](d) * 1.4) .transition().duration(100) .attr("r", $$.pointSelectR); }; - c3_chart_internal_fn.unselectPoint = function (target, d, i) { + var unselectPoint = 'unselectPoint'; + c3_chart_internal_fn[unselectPoint] = function (target, d, i) { var $$ = this; $$.config[__data_onunselected](d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; - c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { - selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); + var togglePoint = 'togglePoint'; + c3_chart_internal_fn[togglePoint] = function (selected, target, d, i) { + selected ? this[selectPoint](target, d, i) : this[unselectPoint](target, d, i); }; - c3_chart_internal_fn.selectBar = function (target, d) { + var selectBar = 'selectBar'; + c3_chart_internal_fn[selectBar] = function (target, d) { var $$ = this; $$.config[__data_onselected].call($$, d, target.node()); target.transition().duration(100) - .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + .style("fill", function () { return $$.d3.rgb($$[color](d)).brighter(0.75); }); }; - c3_chart_internal_fn.unselectBar = function (target, d) { + var unselectBar = 'unselectBar'; + c3_chart_internal_fn[unselectBar] = function (target, d) { var $$ = this; $$.config[__data_onunselected].call($$, d, target.node()); target.transition().duration(100) - .style("fill", function () { return $$.color(d); }); + .style("fill", function () { return $$[color](d); }); }; - c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { - selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); + var toggleBar = 'toggleBar'; + c3_chart_internal_fn[toggleBar] = function (selected, target, d, i) { + selected ? this[selectBar](target, d, i) : this[unselectBar](target, d, i); }; - c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { - this.toggleBar(selected, target, d.data, i); + var toggleArc = 'toggleArc'; + c3_chart_internal_fn[toggleArc] = function (selected, target, d, i) { + this[toggleBar](selected, target, d.data, i); }; - c3_chart_internal_fn.getToggle = function (that) { + var getToggle = 'getToggle'; + c3_chart_internal_fn[getToggle] = function (that) { var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS.bar) ? $$.toggleBar : $$.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[bar]) ? $$.toggleBar : $$.toggleArc); }; - c3_chart_internal_fn.toggleShape = function (that, d, i) { + var toggleShape = 'toggleShape'; + c3_chart_internal_fn[toggleShape] = function (that, d, i) { var $$ = this, d3 = $$.d3, config = $$.config, - shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; + shape = d3.select(that), isSelected = shape.classed(CLASS[SELECTED]), isWithin, toggle; if (that.nodeName === 'circle') { - isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); + isWithin = $$[isWithinCircle](that, $$[pointSelectR](d) * 1.5); toggle = $$.togglePoint; } else if (that.nodeName === 'path') { - if (shape.classed(CLASS.bar)) { - isWithin = $$.isWithinBar(that); + if (shape.classed(CLASS[bar])) { + isWithin = $$[isWithinBar](that); toggle = $$.toggleBar; } else { // would be arc isWithin = true; @@ -5033,12 +5342,12 @@ if (config[__data_selection_grouped] || isWithin) { if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { 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) { var shape = d3.select(this); - if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } + if (shape.classed(CLASS[SELECTED])) { toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } }); } - shape.classed(CLASS.SELECTED, !isSelected); + shape.classed(CLASS[SELECTED], !isSelected); toggle(!isSelected, shape, d, i); } $$.config[__data_onclick](d, that); @@ -5049,7 +5358,8 @@ /** * c3.transition.js */ - c3_chart_internal_fn.generateAxisTransitions = function (duration) { + var generateAxisTransitions = 'generateAxisTransitions'; + c3_chart_internal_fn[generateAxisTransitions] = function (duration) { var $$ = this, axes = $$.axes; return { axisX: duration ? axes.x.transition().duration(duration) : axes.x, @@ -5058,7 +5368,8 @@ axisSubX: duration ? axes.subx.transition().duration(duration) : axes.subx }; }; - c3_chart_internal_fn.endall = function (transition, callback) { + var endall = 'endall'; + c3_chart_internal_fn[endall] = function (transition, callback) { var n = 0; transition .each(function () { ++n; }) @@ -5066,7 +5377,8 @@ if (!--n) { callback.apply(this, arguments); } }); }; - c3_chart_internal_fn.generateWait = function () { + var generateWait = 'generateWait'; + c3_chart_internal_fn[generateWait] = function () { var transitionsToWait = [], f = function (transition, callback) { var timer = setInterval(function () { @@ -5098,180 +5410,280 @@ /** * c3.transform.js */ - c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { + var transformTo = 'transformTo'; + c3_chart_internal_fn[transformTo] = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$.hasArcType($$.data.targets), + withTransitionForAxis = !$$[hasArcType]($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; - $$.transiting = false; - $$.setTargetType(targetIds, type); - $$.updateAndRedraw(options); + $$[transiting] = false; + $$[setTargetType](targetIds, type); + $$[updateAndRedraw](options); }; /** * c3.class.js */ - var CLASS = c3_chart_internal_fn.CLASS = { - target: 'c3-target', - chart : 'c3-chart', - chartLine: 'c3-chart-line', - chartLines: 'c3-chart-lines', - chartBar: 'c3-chart-bar', - chartBars: 'c3-chart-bars', - chartText: 'c3-chart-text', - chartTexts: 'c3-chart-texts', - chartArc: 'c3-chart-arc', - chartArcs: 'c3-chart-arcs', - chartArcsTitle: 'c3-chart-arcs-title', - chartArcsBackground: 'c3-chart-arcs-background', - chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', - chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', - chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', - selectedCircle: 'c3-selected-circle', - selectedCircles: 'c3-selected-circles', - eventRect: 'c3-event-rect', - eventRects: 'c3-event-rects', - eventRectsSingle: 'c3-event-rects-single', - eventRectsMultiple: 'c3-event-rects-multiple', - zoomRect: 'c3-zoom-rect', - brush: 'c3-brush', - focused: 'c3-focused', - region: 'c3-region', - regions: 'c3-regions', - tooltip: 'c3-tooltip', - tooltipName: 'c3-tooltip-name', - shape: 'c3-shape', - shapes: 'c3-shapes', - line: 'c3-line', - lines: 'c3-lines', - bar: 'c3-bar', - bars: 'c3-bars', - circle: 'c3-circle', - circles: 'c3-circles', - arc: 'c3-arc', - arcs: 'c3-arcs', - area: 'c3-area', - areas: 'c3-areas', - empty: 'c3-empty', - text: 'c3-text', - texts: 'c3-texts', - gaugeValue: 'c3-gauge-value', - grid: 'c3-grid', - xgrid: 'c3-xgrid', - xgrids: 'c3-xgrids', - xgridLine: 'c3-xgrid-line', - xgridLines: 'c3-xgrid-lines', - xgridFocus: 'c3-xgrid-focus', - ygrid: 'c3-ygrid', - ygrids: 'c3-ygrids', - ygridLine: 'c3-ygrid-line', - ygridLines: 'c3-ygrid-lines', - axis: 'c3-axis', - axisX: 'c3-axis-x', - axisXLabel: 'c3-axis-x-label', - axisY: 'c3-axis-y', - axisYLabel: 'c3-axis-y-label', - axisY2: 'c3-axis-y2', - axisY2Label: 'c3-axis-y2-label', - legendBackground: 'c3-legend-background', - legendItem: 'c3-legend-item', - legendItemEvent: 'c3-legend-item-event', - legendItemTile: 'c3-legend-item-tile', - legendItemHidden: 'c3-legend-item-hidden', - legendItemFocused: 'c3-legend-item-focused', - dragarea: 'c3-dragarea', - EXPANDED: '_expanded_', - SELECTED: '_selected_', - INCLUDED: '_included_' - }; - c3_chart_internal_fn.generateClass = function (prefix, targetId) { - return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); - }; - c3_chart_internal_fn.classText = function (d) { - return this.generateClass(CLASS.text, d.index); - }; - c3_chart_internal_fn.classTexts = function (d) { - return this.generateClass(CLASS.texts, d.id); - }; - c3_chart_internal_fn.classShape = function (d) { - return this.generateClass(CLASS.shape, d.index); - }; - c3_chart_internal_fn.classShapes = function (d) { - return this.generateClass(CLASS.shapes, d.id); - }; - c3_chart_internal_fn.classLine = function (d) { - return this.classShape(d) + this.generateClass(CLASS.line, d.id); - }; - c3_chart_internal_fn.classLines = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.lines, d.id); - }; - c3_chart_internal_fn.classCircle = function (d) { - return this.classShape(d) + this.generateClass(CLASS.circle, d.index); - }; - c3_chart_internal_fn.classCircles = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.circles, d.id); - }; - c3_chart_internal_fn.classBar = function (d) { - return this.classShape(d) + this.generateClass(CLASS.bar, d.index); - }; - c3_chart_internal_fn.classBars = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.bars, d.id); - }; - c3_chart_internal_fn.classArc = function (d) { - return this.classShape(d.data) + this.generateClass(CLASS.arc, d.data.id); - }; - c3_chart_internal_fn.classArcs = function (d) { - return this.classShapes(d.data) + this.generateClass(CLASS.arcs, d.data.id); - }; - c3_chart_internal_fn.classArea = function (d) { - return this.classShape(d) + this.generateClass(CLASS.area, d.id); - }; - c3_chart_internal_fn.classAreas = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.areas, d.id); - }; - c3_chart_internal_fn.classRegion = function (d, i) { - return this.generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); - }; - c3_chart_internal_fn.classEvent = function (d) { - return this.generateClass(CLASS.eventRect, d.index); - }; - c3_chart_internal_fn.classTarget = function (id) { + var target = 'target', + chart = 'chart ', + chartLine = 'chartLine', + chartLines = 'chartLines', + chartBar = 'chartBar', + chartBars = 'chartBars', + chartText = 'chartText', + chartTexts = 'chartTexts', + chartArc = 'chartArc', + chartArcs = 'chartArcs', + chartArcsTitle = 'chartArcsTitle', + chartArcsBackground = 'chartArcsBackground', + chartArcsGaugeUnit = 'chartArcsGaugeUnit', + chartArcsGaugeMax = 'chartArcsGaugeMax', + chartArcsGaugeMin = 'chartArcsGaugeMin', + selectedCircle = 'selectedCircle', + selectedCircles = 'selectedCircles', + eventRect = 'eventRect', + eventRects = 'eventRects', + eventRectsSingle = 'eventRectsSingle', + eventRectsMultiple = 'eventRectsMultiple', + zoomRect = 'zoomRect', + brush = 'brush', + focused = 'focused', + region = 'region', + regions = 'regions', + tooltip = 'tooltip', + tooltipName = 'tooltipName', + shape = 'shape', + shapes = 'shapes', + line = 'line', + lines = 'lines', + bar = 'bar', + bars = 'bars', + circle = 'circle', + circles = 'circles', + arc = 'arc', + arcs = 'arcs', + area = 'area', + areas = 'areas', + empty = 'empty', + text = 'text', + texts = 'texts', + gaugeValue = 'gaugeValue', + grid = 'grid', + xgrid = 'xgrid', + xgrids = 'xgrids', + xgridLine = 'xgridLine', + xgridLines = 'xgridLines', + xgridFocus = 'xgridFocus', + ygrid = 'ygrid', + ygrids = 'ygrids', + ygridLine = 'ygridLine', + ygridLines = 'ygridLines', + axis = 'axis', + axisX = 'axisX', + axisXLabel = 'axisXLabel', + axisY = 'axisY', + axisYLabel = 'axisYLabel', + axisY2 = 'axisY2', + axisY2Label = 'axisY2Label', + legendBackground = 'legendBackground', + legendItem = 'legendItem', + legendItemEvent = 'legendItemEvent', + legendItemTile = 'legendItemTile', + legendItemHidden = 'legendItemHidden', + legendItemFocused = 'legendItemFocused', + dragarea = 'dragarea', + EXPANDED = 'EXPANDED', + SELECTED = 'SELECTED', + INCLUDED = 'INCLUDED'; + + var CLASS = c3_chart_internal_fn.CLASS = {}; + CLASS[target] = 'c3-target'; + CLASS[chart] = 'c3-chart'; + CLASS[chartLine] = 'c3-chart-line'; + CLASS[chartLines] = 'c3-chart-lines'; + CLASS[chartBar] = 'c3-chart-bar'; + CLASS[chartBars] = 'c3-chart-bars'; + CLASS[chartText] = 'c3-chart-text'; + CLASS[chartTexts] = 'c3-chart-texts'; + CLASS[chartArc] = 'c3-chart-arc'; + CLASS[chartArcs] = 'c3-chart-arcs'; + CLASS[chartArcsTitle] = 'c3-chart-arcs-title'; + CLASS[chartArcsBackground] = 'c3-chart-arcs-background'; + CLASS[chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; + CLASS[chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; + CLASS[chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; + CLASS[selectedCircle] = 'c3-selected-circle'; + CLASS[selectedCircles] = 'c3-selected-circles'; + CLASS[eventRect] = 'c3-event-rect'; + CLASS[eventRects] = 'c3-event-rects'; + CLASS[eventRectsSingle] = 'c3-event-rects-single'; + CLASS[eventRectsMultiple] = 'c3-event-rects-multiple'; + CLASS[zoomRect] = 'c3-zoom-rect'; + CLASS[brush] = 'c3-brush'; + CLASS[focused] = 'c3-focused'; + CLASS[region] = 'c3-region'; + CLASS[regions] = 'c3-regions'; + CLASS[tooltip] = 'c3-tooltip'; + CLASS[tooltipName] = 'c3-tooltip-name'; + CLASS[shape] = 'c3-shape'; + CLASS[shapes] = 'c3-shapes'; + CLASS[line] = 'c3-line'; + CLASS[lines] = 'c3-lines'; + CLASS[bar] = 'c3-bar'; + CLASS[bars] = 'c3-bars'; + CLASS[circle] = 'c3-circle'; + CLASS[circles] = 'c3-circles'; + CLASS[arc] = 'c3-arc'; + CLASS[arcs] = 'c3-arcs'; + CLASS[area] = 'c3-area'; + CLASS[areas] = 'c3-areas'; + CLASS[empty] = 'c3-empty'; + CLASS[text] = 'c3-text'; + CLASS[texts] = 'c3-texts'; + CLASS[gaugeValue] = 'c3-gauge-value'; + CLASS[grid] = 'c3-grid'; + CLASS[xgrid] = 'c3-xgrid'; + CLASS[xgrids] = 'c3-xgrids'; + CLASS[xgridLine] = 'c3-xgrid-line'; + CLASS[xgridLines] = 'c3-xgrid-lines'; + CLASS[xgridFocus] = 'c3-xgrid-focus'; + CLASS[ygrid] = 'c3-ygrid'; + CLASS[ygrids] = 'c3-ygrids'; + CLASS[ygridLine] = 'c3-ygrid-line'; + CLASS[ygridLines] = 'c3-ygrid-lines'; + CLASS[axis] = 'c3-axis'; + CLASS[axisX] = 'c3-axis-x'; + CLASS[axisXLabel] = 'c3-axis-x-label'; + CLASS[axisY] = 'c3-axis-y'; + CLASS[axisYLabel] = 'c3-axis-y-label'; + CLASS[axisY2] = 'c3-axis-y2'; + CLASS[axisY2Label] = 'c3-axis-y2-label'; + CLASS[legendBackground] = 'c3-legend-background'; + CLASS[legendItem] = 'c3-legend-item'; + CLASS[legendItemEvent] = 'c3-legend-item-event'; + CLASS[legendItemTile] = 'c3-legend-item-tile'; + CLASS[legendItemHidden] = 'c3-legend-item-hidden'; + CLASS[legendItemFocused] = 'c3-legend-item-focused'; + CLASS[dragarea] = 'c3-dragarea'; + CLASS[EXPANDED] = '_expanded_'; + CLASS[SELECTED] = '_selected_'; + CLASS[INCLUDED] = '_included_'; + + var generateClass = 'generateClass'; + c3_chart_internal_fn[generateClass] = function (prefix, targetId) { + return " " + prefix + " " + prefix + this[getTargetSelectorSuffix](targetId); + }; + var classText = 'classText'; + c3_chart_internal_fn[classText] = function (d) { + return this[generateClass](CLASS[text], d.index); + }; + var classTexts = 'classTexts'; + c3_chart_internal_fn[classTexts] = function (d) { + return this[generateClass](CLASS[texts], d.id); + }; + var classShape = 'classShape'; + c3_chart_internal_fn[classShape] = function (d) { + return this[generateClass](CLASS[shape], d.index); + }; + var classShapes = 'classShapes'; + c3_chart_internal_fn[classShapes] = function (d) { + return this[generateClass](CLASS[shapes], d.id); + }; + var classLine = 'classLine'; + c3_chart_internal_fn[classLine] = function (d) { + return this[classShape](d) + this[generateClass](CLASS[line], d.id); + }; + var classLines = 'classLines'; + c3_chart_internal_fn[classLines] = function (d) { + return this[classShapes](d) + this[generateClass](CLASS[lines], d.id); + }; + var classCircle = 'classCircle'; + c3_chart_internal_fn[classCircle] = function (d) { + return this[classShape](d) + this[generateClass](CLASS[circle], d.index); + }; + var classCircles = 'classCircles'; + c3_chart_internal_fn[classCircles] = function (d) { + return this[classShapes](d) + this[generateClass](CLASS[circles], d.id); + }; + var classBar = 'classBar'; + c3_chart_internal_fn[classBar] = function (d) { + return this[classShape](d) + this[generateClass](CLASS[bar], d.index); + }; + var classBars = 'classBars'; + c3_chart_internal_fn[classBars] = function (d) { + return this[classShapes](d) + this[generateClass](CLASS[bars], d.id); + }; + var classArc = 'classArc'; + c3_chart_internal_fn[classArc] = function (d) { + return this[classShape](d.data) + this[generateClass](CLASS[arc], d.data.id); + }; + var classArcs = 'classArcs'; + c3_chart_internal_fn[classArcs] = function (d) { + return this[classShapes](d.data) + this[generateClass](CLASS[arcs], d.data.id); + }; + var classArea = 'classArea'; + c3_chart_internal_fn[classArea] = function (d) { + return this[classShape](d) + this[generateClass](CLASS[area], d.id); + }; + var classAreas = 'classAreas'; + c3_chart_internal_fn[classAreas] = function (d) { + return this[classShapes](d) + this[generateClass](CLASS[areas], d.id); + }; + var classRegion = 'classRegion'; + c3_chart_internal_fn[classRegion] = function (d, i) { + return this[generateClass](CLASS[region], i) + ' ' + (CSS_CLASS in d ? d.class : ''); + }; + var classEvent = 'classEvent'; + c3_chart_internal_fn[classEvent] = function (d) { + return this[generateClass](CLASS[eventRect], d.index); + }; + var classTarget = 'classTarget'; + c3_chart_internal_fn[classTarget] = function (id) { var $$ = this; var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; if (additionalClassSuffix) { - additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; + additionalClass = ' ' + CLASS[target] + '-' + additionalClassSuffix; } - return $$.generateClass(CLASS.target, id) + additionalClass; + return $$[generateClass](CLASS[target], id) + additionalClass; }; - c3_chart_internal_fn.classChartText = function (d) { - return CLASS.chartText + this.classTarget(d.id); + var classChartText = 'classChartText'; + c3_chart_internal_fn[classChartText] = function (d) { + return CLASS[chartText] + this[classTarget](d.id); }; - c3_chart_internal_fn.classChartLine = function (d) { - return CLASS.chartLine + this.classTarget(d.id); + var classChartLine = 'classChartLine'; + c3_chart_internal_fn[classChartLine] = function (d) { + return CLASS[chartLine] + this[classTarget](d.id); }; - c3_chart_internal_fn.classChartBar = function (d) { - return CLASS.chartBar + this.classTarget(d.id); + var classChartBar = 'classChartBar'; + c3_chart_internal_fn[classChartBar] = function (d) { + return CLASS[chartBar] + this[classTarget](d.id); }; - c3_chart_internal_fn.classChartArc = function (d) { - return CLASS.chartArc + this.classTarget(d.data.id); + var classChartArc = 'classChartArc'; + c3_chart_internal_fn[classChartArc] = function (d) { + return CLASS[chartArc] + this[classTarget](d.data.id); }; - c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { + var getTargetSelectorSuffix = 'getTargetSelectorSuffix'; + c3_chart_internal_fn[getTargetSelectorSuffix] = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; - c3_chart_internal_fn.selectorTarget = function (id) { - return '.' + CLASS.target + this.getTargetSelectorSuffix(id); + var selectorTarget = 'selectorTarget'; + c3_chart_internal_fn[selectorTarget] = function (id) { + return '.' + CLASS[target] + this[getTargetSelectorSuffix](id); }; - c3_chart_internal_fn.selectorTargets = function (ids) { + var selectorTargets = 'selectorTargets'; + c3_chart_internal_fn[selectorTargets] = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; + return ids.length ? ids.map(function (id) { return $$[selectorTarget](id); }) : null; }; - c3_chart_internal_fn.selectorLegend = function (id) { - return '.' + CLASS.legendItem + this.getTargetSelectorSuffix(id); + var selectorLegend = 'selectorLegend'; + c3_chart_internal_fn[selectorLegend] = function (id) { + return '.' + CLASS[legendItem] + this[getTargetSelectorSuffix](id); }; - c3_chart_internal_fn.selectorLegends = function (ids) { + var selectorLegends = 'selectorLegends'; + c3_chart_internal_fn[selectorLegends] = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; + return ids.length ? ids.map(function (id) { return $$[selectorLegend](id); }) : null; }; @@ -5279,32 +5691,38 @@ /** * c3.format.js */ - c3_chart_internal_fn.getYFormat = function (forArc) { + var getYFormat = 'getYFormat'; + c3_chart_internal_fn[getYFormat] = function (forArc) { var $$ = this, - formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { - var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; + var format = $$[getAxisId](id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); }; }; - c3_chart_internal_fn.yFormat = function (v) { + var yFormat = 'yFormat'; + c3_chart_internal_fn[yFormat] = function (v) { var $$ = this, config = $$.config, format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; return format(v); }; - c3_chart_internal_fn.y2Format = function (v) { + var y2Format = 'y2Format'; + c3_chart_internal_fn[y2Format] = function (v) { var $$ = this, config = $$.config, format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; return format(v); }; - c3_chart_internal_fn.defaultValueFormat = function (v) { + var defaultValueFormat = 'defaultValueFormat'; + c3_chart_internal_fn[defaultValueFormat] = function (v) { return isValue(v) ? +v : ""; }; - c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { + var defaultArcValueFormat = 'defaultArcValueFormat'; + c3_chart_internal_fn[defaultArcValueFormat] = function (v, ratio) { return (ratio * 100).toFixed(1) + '%'; }; - c3_chart_internal_fn.formatByAxisId = function (axisId) { + var formatByAxisId = 'formatByAxisId'; + c3_chart_internal_fn[formatByAxisId] = function (axisId) { var $$ = this.internal, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id @@ -5323,17 +5741,18 @@ /** * c3.drag.js */ - c3_chart_internal_fn.drag = function (mouse) { + var drag = 'drag'; + c3_chart_internal_fn[drag] = function (mouse) { var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection - sx = $$.dragStart[0]; - sy = $$.dragStart[1]; + sx = $$[dragStart][0]; + sy = $$[dragStart][1]; mx = mouse[0]; my = mouse[1]; minX = Math.min(sx, mx); @@ -5341,26 +5760,26 @@ minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); - main.select('.' + CLASS.dragarea) + main.select('.' + CLASS[dragarea]) .attr('x', minX) .attr('y', minY) .attr('width', maxX - minX) .attr('height', maxY - minY); // TODO: binary search when multiple xs - main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) + main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]) .filter(function (d) { return config[__data_selection_isselectable](d); }) .each(function (d, i) { var shape = d3.select(this), - isSelected = shape.classed(CLASS.SELECTED), - isIncluded = shape.classed(CLASS.INCLUDED), + isSelected = shape.classed(CLASS[SELECTED]), + isIncluded = shape.classed(CLASS[INCLUDED]), _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS.circle)) { + if (shape.classed(CLASS[circle])) { _x = shape.attr("cx") * 1; _y = shape.attr("cy") * 1; toggle = $$.togglePoint; isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; } - else if (shape.classed(CLASS.bar)) { + else if (shape.classed(CLASS[bar])) { box = getPathBox(this); _x = box.x; _y = box.y; @@ -5373,37 +5792,39 @@ return; } if (isWithin ^ isIncluded) { - shape.classed(CLASS.INCLUDED, !isIncluded); + shape.classed(CLASS[INCLUDED], !isIncluded); // TODO: included/unincluded callback here - shape.classed(CLASS.SELECTED, !isSelected); - $$.toggle(!isSelected, shape, d, i); + shape.classed(CLASS[SELECTED], !isSelected); + $$[toggle](!isSelected, shape, d, i); } }); }; - c3_chart_internal_fn.dragstart = function (mouse) { + var dragstart = 'dragstart'; + c3_chart_internal_fn[dragstart] = function (mouse) { var $$ = this, config = $$.config; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.dragStart = mouse; - $$.main.select('.' + CLASS.chart).append('rect') - .attr('class', CLASS.dragarea) - .style('opacity', 0.1); - $$.dragging = true; + $$[dragStart] = mouse; + $$.main.select('.' + CLASS[chart]).append('rect') + .attr(CSS_CLASS, CLASS[dragarea]) + .style(CSS_OPACITY, 0.1); + $$[dragging] = true; $$.config[__data_ondragstart](); }; - c3_chart_internal_fn.dragend = function () { + var dragend = 'dragend'; + c3_chart_internal_fn[dragend] = function () { var $$ = this, config = $$.config; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.main.select('.' + CLASS.dragarea) + $$.main.select('.' + CLASS[dragarea]) .transition().duration(100) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); - $$.main.selectAll('.' + CLASS.shape) - .classed(CLASS.INCLUDED, false); - $$.dragging = false; + $$.main.selectAll('.' + CLASS[shape]) + .classed(CLASS[INCLUDED], false); + $$[dragging] = false; $$.config[__data_ondragend](); }; @@ -5416,94 +5837,94 @@ */ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidates = $$.svg.selectAll($$[selectorTarget](targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), + candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); function focus(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 1); } this.revert(); this.defocus(); - focus(candidatesForNoneArc.classed(CLASS.focused, true)); + focus(candidatesForNoneArc.classed(CLASS[focused], true)); focus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { - $$.expandArc(targetId, true); + if ($$[hasArcType]($$.data.targets)) { + $$[expandArc](targetId, true); } - $$.toggleFocusLegend(targetId, true); + $$[toggleFocusLegend](targetId, true); }; c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidates = $$.svg.selectAll($$[selectorTarget](targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), + candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); function defocus(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); + $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 0.3); } this.revert(); - defocus(candidatesForNoneArc.classed(CLASS.focused, false)); + defocus(candidatesForNoneArc.classed(CLASS[focused], false)); defocus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { - $$.unexpandArc(targetId); + if ($$[hasArcType]($$.data.targets)) { + $$[unexpandArc](targetId); } - $$.toggleFocusLegend(targetId, false); + $$[toggleFocusLegend](targetId, false); }; c3_chart_fn.revert = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidates = $$.svg.selectAll($$[selectorTarget](targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), + candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); function revert(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 1); } - revert(candidatesForNoneArc.classed(CLASS.focused, false)); + revert(candidatesForNoneArc.classed(CLASS[focused], false)); revert(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { - $$.unexpandArc(targetId); + if ($$[hasArcType]($$.data.targets)) { + $$[unexpandArc](targetId); } - $$.revertLegend(); + $$[revertLegend](); }; c3_chart_fn.show = function (targetIds, options) { var $$ = this.internal; - targetIds = $$.mapToTargetIds(targetIds); + targetIds = $$[mapToTargetIds](targetIds); options = options || {}; - $$.removeHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) + $$[removeHiddenTargetIds](targetIds); + $$.svg.selectAll($$[selectorTargets](targetIds)) .transition() - .style('opacity', 1); + .style(CSS_OPACITY, 1); 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) { var $$ = this.internal; - targetIds = $$.mapToTargetIds(targetIds); + targetIds = $$[mapToTargetIds](targetIds); options = options || {}; - $$.addHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) + $$[addHiddenTargetIds](targetIds); + $$.svg.selectAll($$[selectorTargets](targetIds)) .transition() - .style('opacity', 0); + .style(CSS_OPACITY, 0); 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 (targetId) { var $$ = this.internal; - $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); + $$[isTargetToShow](targetId) ? this.hide(targetId) : this.show(targetId); }; c3_chart_fn.zoom = function () { @@ -5511,19 +5932,19 @@ c3_chart_fn.zoom.enable = function (enabled) { var $$ = this.internal; $$.config[__zoom_enabled] = enabled; - $$.updateAndRedraw(); + $$[updateAndRedraw](); }; c3_chart_fn.unzoom = function () { var $$ = this.internal; $$.brush.clear().update(); - $$.redraw({withUpdateXDomain: true}); + $$[redraw]({withUpdateXDomain: true}); }; c3_chart_fn.load = function (args) { var $$ = this.internal, config = $$.config; // update xs if specified if (args.xs) { - $$.addXs(args.xs); + $$[addXs](args.xs); } // update classes if exists if ('classes' in args) { @@ -5532,52 +5953,52 @@ }); } // update categories if exists - if ('categories' in args && $$.isCategorized) { + if ('categories' in args && $$[isCategorized]) { config[__axis_x_categories] = args.categories; } // use cache if exists - if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { - $$.load($$.getCaches(args.cacheIds), args.done); + if ('cacheIds' in args && $$[hasCaches](args.cacheIds)) { + $$[load]($$[getCaches](args.cacheIds), args.done); return; } // unload if needed if ('unload' in args) { // TODO: do not unload if target will load (included in url/rows/columns) - $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { - $$.loadFromArgs(args); + $$[unload]($$[mapToTargetIds]((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + $$[loadFromArgs](args); }); } else { - $$.loadFromArgs(args); + $$[loadFromArgs](args); } }; c3_chart_fn.unload = function (args) { var $$ = this.internal; args = args || {}; - $$.unload($$.mapToTargetIds(args.ids), function () { - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + $$[unload]($$[mapToTargetIds](args.ids), function () { + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); if (isFunction(args.done)) { args.done(); } }); }; c3_chart_fn.flow = function (args) { var $$ = this.internal, - targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), + targets, data, notfoundIds = [], orgDataCount = $$[getMaxDataCount](), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; if (args.json) { - data = $$.convertJsonToData(args.json, args.keys); + data = $$[convertJsonToData](args.json, args.keys); } else if (args.rows) { - data = $$.convertRowsToData(args.rows); + data = $$[convertRowsToData](args.rows); } else if (args.columns) { - data = $$.convertColumnsToData(args.columns); + data = $$[convertColumnsToData](args.columns); } else { return; } - targets = $$.convertDataToTargets(data, true); + targets = $$[convertDataToTargets](data, true); // Update/Add data $$.data.targets.forEach(function (t) { @@ -5593,7 +6014,7 @@ for (j = 0; j < length; j++) { targets[i].values[j].index = tail + j; - if (!$$.isTimeSeries) { + if (!$$[isTimeSeries]) { targets[i].values[j].x = tail + j; } } @@ -5616,7 +6037,7 @@ t.values.push({ id: t.id, index: tail + j, - x: $$.isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j, + x: $$[isTimeSeries] ? $$[getOtherTargetX](tail + j) : tail + j, value: null }); } @@ -5632,13 +6053,13 @@ missing.push({ id: t.id, index: i, - x: $$.isTimeSeries ? $$.getOtherTargetX(i) : i, + x: $$[isTimeSeries] ? $$[getOtherTargetX](i) : i, value: null }); } t.values.forEach(function (v) { v.index += tail; - if (!$$.isTimeSeries) { + if (!$$[isTimeSeries]) { v.x += tail; } }); @@ -5648,14 +6069,14 @@ $$.data.targets = $$.data.targets.concat(targets); // add remained // check data count because behavior needs to change when it's only one - dataCount = $$.getMaxDataCount(); + dataCount = $$[getMaxDataCount](); baseTarget = $$.data.targets[0]; baseValue = baseTarget.values[0]; // Update length to flow if needed if (isDefined(args.to)) { length = 0; - to = $$.isTimeSeries ? $$.parseDate(args.to) : args.to; + to = $$[isTimeSeries] ? $$[parseDate](args.to) : args.to; baseTarget.values.forEach(function (v) { if (v.x < to) { length++; } }); @@ -5665,69 +6086,69 @@ // If only one data, update the domain to flow from left edge of the chart if (!orgDataCount) { - if ($$.isTimeSeries) { + if ($$[isTimeSeries]) { if (baseTarget.values.length > 1) { diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; } else { - diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; + diff = baseValue.x - $$[getXDomain]($$.data.targets)[0]; } } else { diff = 1; } domain = [baseValue.x - diff, baseValue.x]; - $$.updateXDomain(null, true, true, domain); + $$[updateXDomain](null, true, true, domain); } else if (orgDataCount === 1) { - if ($$.isTimeSeries) { + if ($$[isTimeSeries]) { diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; - $$.updateXDomain(null, true, true, domain); + $$[updateXDomain](null, true, true, domain); } } // Set targets - $$.updateTargets($$.data.targets); + $$[updateTargets]($$.data.targets); // Redraw with new targets - $$.redraw({ + $$[redraw]({ flow: { index: baseValue.index, length: length, duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], done: args.done, - orgDataCount: orgDataCount, + orgDataCount: orgDataCount }, withLegend: true, - withTransition: orgDataCount > 1, + withTransition: orgDataCount > 1 }); }; c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( - $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) - .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) + $$.main.selectAll('.' + CLASS[shapes] + $$[getTargetSelectorSuffix](targetId)).selectAll('.' + CLASS[shape]) + .filter(function () { return d3.select(this).classed(CLASS[SELECTED]); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; c3_chart_fn.select = function (ids, indices, resetOther) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$[getToggle](this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); + isSelected = shape.classed(CLASS[SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d) && !isSelected) { - toggle(true, shape.classed(CLASS.SELECTED, true), d, i); + toggle(true, shape.classed(CLASS[SELECTED], true), d, i); } } else if (isDefined(resetOther) && resetOther) { if (isSelected) { - toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } } }); @@ -5735,19 +6156,19 @@ c3_chart_fn.unselect = function (ids, indices) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$[getToggle](this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); + isSelected = shape.classed(CLASS[SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d)) { if (isSelected) { - toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } } } @@ -5757,14 +6178,14 @@ c3_chart_fn.transform = function (type, targetIds) { var $$ = this.internal, options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; - $$.transformTo(targetIds, type, options); + $$[transformTo](targetIds, type, options); }; c3_chart_fn.groups = function (groups) { var $$ = this.internal, config = $$.config; - if (isUndefined(groups)) { return config[__data_groups]; } + if (!isDefined(groups)) { return config[__data_groups]; } config[__data_groups] = groups; - $$.redraw(); + $$[redraw](); return config[__data_groups]; }; @@ -5772,7 +6193,7 @@ var $$ = this.internal, config = $$.config; if (! grids) { return config[__grid_x_lines]; } config[__grid_x_lines] = grids; - $$.redraw(); + $$[redraw](); return config[__grid_x_lines]; }; c3_chart_fn.xgrids.add = function (grids) { @@ -5781,14 +6202,14 @@ }; c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple var $$ = this.internal; - $$.removeGridLines(params, true); + $$[removeGridLines](params, true); }; c3_chart_fn.ygrids = function (grids) { var $$ = this.internal, config = $$.config; if (! grids) { return config[__grid_y_lines]; } config[__grid_y_lines] = grids; - $$.redraw(); + $$[redraw](); return config[__grid_y_lines]; }; c3_chart_fn.ygrids.add = function (grids) { @@ -5797,21 +6218,21 @@ }; c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple var $$ = this.internal; - $$.removeGridLines(params, false); + $$[removeGridLines](params, false); }; c3_chart_fn.regions = function (regions) { var $$ = this.internal, config = $$.config; if (!regions) { return config[__regions]; } config[__regions] = regions; - $$.redraw(); + $$[redraw](); return config[__regions]; }; c3_chart_fn.regions.add = function (regions) { var $$ = this.internal, config = $$.config; if (!regions) { return config[__regions]; } config[__regions] = config[__regions].concat(regions); - $$.redraw(); + $$[redraw](); return config[__regions]; }; c3_chart_fn.regions.remove = function (options) { @@ -5819,12 +6240,12 @@ duration, classes, regions; options = options || {}; - duration = $$.getOption(options, "duration", config[__transition_duration]); - classes = $$.getOption(options, "classes", [CLASS.region]); + duration = $$[getOption](options, "duration", config[__transition_duration]); + 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) - .style('opacity', 0) + .style(CSS_OPACITY, 0) .remove(); config[__regions] = config[__regions].filter(function (region) { @@ -5857,7 +6278,7 @@ Object.keys(names).forEach(function (id) { config[__data_names][id] = names[id]; }); - $$.redraw({withLegend: true}); + $$[redraw]({withLegend: true}); return config[__data_names]; }; c3_chart_fn.data.colors = function (colors) { @@ -5866,14 +6287,14 @@ Object.keys(colors).forEach(function (id) { config[__data_colors][id] = colors[id]; }); - $$.redraw({withLegend: true}); + $$[redraw]({withLegend: true}); return config[__data_colors]; }; c3_chart_fn.category = function (i, category) { var $$ = this.internal, config = $$.config; if (arguments.length > 1) { config[__axis_x_categories][i] = category; - $$.redraw(); + $$[redraw](); } return config[__axis_x_categories][i]; }; @@ -5881,29 +6302,29 @@ var $$ = this.internal, config = $$.config; if (!arguments.length) { return config[__axis_x_categories]; } config[__axis_x_categories] = categories; - $$.redraw(); + $$[redraw](); return config[__axis_x_categories]; }; // TODO: fix c3_chart_fn.color = function (id) { var $$ = this.internal; - return $$.color(id); // more patterns + return $$[color](id); // more patterns }; c3_chart_fn.x = function (x) { var $$ = this.internal; if (arguments.length) { - $$.updateTargetX($$.data.targets, x); - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$[updateTargetX]($$.data.targets, x); + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } return $$.data.xs; }; c3_chart_fn.xs = function (xs) { var $$ = this.internal; if (arguments.length) { - $$.updateTargetXs($$.data.targets, xs); - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$[updateTargetXs]($$.data.targets, xs); + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } return $$.data.xs; }; @@ -5915,9 +6336,9 @@ var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { - $$.setAxisLabelText(axisId, labels[axisId]); + $$[setAxisLabelText](axisId, labels[axisId]); }); - $$.updateAxisLabels(); + $$[updateAxisLabels](); } // TODO: return some values? }; @@ -5931,7 +6352,7 @@ } else { config[__axis_y_max] = config[__axis_y2_max] = max; } - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.min = function (min) { @@ -5944,7 +6365,7 @@ } else { config[__axis_y_min] = config[__axis_y2_min] = min; } - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.range = function (range) { @@ -5959,13 +6380,13 @@ }; c3_chart_fn.legend.show = function (targetIds) { var $$ = this.internal; - $$.showLegend($$.mapToTargetIds(targetIds)); - $$.updateAndRedraw({withLegend: true}); + $$[showLegend]($$[mapToTargetIds](targetIds)); + $$[updateAndRedraw]({withLegend: true}); }; c3_chart_fn.legend.hide = function (targetIds) { var $$ = this.internal; - $$.hideLegend($$.mapToTargetIds(targetIds)); - $$.updateAndRedraw({withLegend: true}); + $$[hideLegend]($$[mapToTargetIds](targetIds)); + $$[updateAndRedraw]({withLegend: true}); }; c3_chart_fn.resize = function (size) { @@ -5977,7 +6398,7 @@ c3_chart_fn.flush = function () { var $$ = this.internal; - $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); + $$[updateAndRedraw]({withLegend: true, withTransition: false, withTransitionForTransform: false}); }; c3_chart_fn.destroy = function () { @@ -6002,12 +6423,12 @@ var tickOffset = 0, tickCulling = true, tickCentered; function axisX(selection, x) { - selection.attr("transform", function (d) { + selection.attr(CSS_TRANSFORM, function (d) { return "translate(" + Math.ceil(x(d) + tickOffset) + ", 0)"; }); } function axisY(selection, y) { - selection.attr("transform", function (d) { + selection.attr(CSS_TRANSFORM, function (d) { return "translate(0," + Math.ceil(y(d)) + ")"; }); } @@ -6047,15 +6468,15 @@ 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), + tickEnter = tick.enter().insert("g", ".domain").attr(CSS_CLASS, "tick").style(CSS_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 = d3.transition(tick).style("opacity", 1), + tickUpdate = d3.transition(tick).style(CSS_OPACITY, 1), tickTransform, tickX; var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), path = g.selectAll(".domain").data([ 0 ]), - pathUpdate = (path.enter().append("path").attr("class", "domain"), d3.transition(path)); + pathUpdate = (path.enter().append("path").attr(CSS_CLASS, "domain"), d3.transition(path)); tickEnter.append("line"); tickEnter.append("text"); @@ -6085,7 +6506,7 @@ textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding); lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", tickSize); textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding); - text.attr("dy", ".71em").style("text-anchor", "middle"); + text.attr("dy", ".71em").style(CSS_TEXT_ANCHOR, "middle"); pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); break; } @@ -6096,7 +6517,7 @@ textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); - text.attr("dy", "0em").style("text-anchor", "middle"); + text.attr("dy", "0em").style(CSS_TEXT_ANCHOR, "middle"); pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); break; } @@ -6107,7 +6528,7 @@ textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)); lineUpdate.attr("x2", -innerTickSize).attr("y2", 0); textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", tickOffset); - text.attr("dy", ".32em").style("text-anchor", "end"); + text.attr("dy", ".32em").style(CSS_TEXT_ANCHOR, "end"); pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); break; } @@ -6118,7 +6539,7 @@ textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding); lineUpdate.attr("x2", innerTickSize).attr("y2", 0); textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0); - text.attr("dy", ".32em").style("text-anchor", "start"); + text.attr("dy", ".32em").style(CSS_TEXT_ANCHOR, "start"); pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize); break; } From 7e3d23d1900a35ed1e559d4a5c52dff3daf674f9 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 01:25:30 +0100 Subject: [PATCH 12/44] Modify hasType interface --- c3.js | 80 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/c3.js b/c3.js index cdb64ab..abbb3c9 100644 --- a/c3.js +++ b/c3.js @@ -648,7 +648,7 @@ } // when gauge, hide legend // TODO: fix - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$[hasType](TYPE_GAUGE)) { config[__legend_show] = false; } @@ -842,7 +842,7 @@ } $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { return $$[addName](d.values[config[__tooltip_init_x]]); - }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]($$.data.targets)), $$.color)); + }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]()), $$.color)); $$.tooltip.style("top", config[__tooltip_init_position].top) .style("left", config[__tooltip_init_position].left) .style("display", "block"); @@ -895,7 +895,7 @@ var $$ = this, config = $$.config; var legendHeight = $$[getLegendHeight](), legendWidth = $$[getLegendWidth](), legendHeightForBottom = $$[isLegendRight] || $$[isLegendInset] ? 0 : legendHeight, - hasArc = $$[hasArcType]($$.data.targets), + hasArc = $$[hasArcType](), xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$[getHorizontalAxisHeight]('x'), subchartHeight = config[__subchart_show] && !hasArc ? (config[__subchart_size_height] + xAxisHeight) : 0; @@ -1047,7 +1047,7 @@ var areaIndices = $$[getShapeIndices]($$.isAreaType), barIndices = $$[getShapeIndices]($$.isBarType), lineIndices = $$[getShapeIndices]($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$[hasArcType]($$.data.targets); + var hideAxis = $$[hasArcType](); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$[filterTargetsToShow]($$.data.targets), tickValues, i, intervalForCulling; @@ -1666,7 +1666,7 @@ var index = d.index, selectedData, newData; if ($$[dragging]) { return; } // do nothing if dragging - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } selectedData = $$.data.targets.map(function (t) { return $$[addName]($$[getValueOnIndex](t.values, index)); @@ -1696,7 +1696,7 @@ }) .on('mouseout', function (d) { var index = d.index; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } $$[hideXGridFocus](); $$[hideTooltip](); // Undo expanded shapes @@ -1712,7 +1712,7 @@ eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); if ($$[dragging]) { return; } // do nothing when dragging - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } // Show tooltip selectedData = $$[filterTargetsToShow]($$.data.targets).map(function (t) { @@ -1765,7 +1765,7 @@ }) .on('click', function (d) { var index = d.index; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } if ($$[cancelClick]) { $$[cancelClick] = false; return; @@ -1791,7 +1791,7 @@ .attr('height', $$.height) .attr(CSS_CLASS, CLASS[eventRect]) .on('mouseout', function () { - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } $$[hideXGridFocus](); $$[hideTooltip](); $$[unexpandCircles](); @@ -2115,7 +2115,7 @@ leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$[hasArcType]($$.data.targets), + hasArc = $$[hasArcType](), svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$[getCurrentPaddingLeft]()); return svgLeft > 0 ? svgLeft : 0; }; @@ -2150,7 +2150,7 @@ return $$.config[__axis_rotated] ? $$.height : $$.width; } maxDataCount = $$[getMaxDataCount](); - ratio = ($$[hasType]($$.data.targets, TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); + ratio = ($$[hasType](TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2163,7 +2163,7 @@ c3_chart_internal_fn[showTooltip] = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$[hasArcType]($$.data.targets), + var forArc = $$[hasArcType](), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !config[__tooltip_show]) { return; @@ -2218,7 +2218,7 @@ var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if ($$[hasType]($$.data.targets, TYPE_SCATTER) || $$[hasArcType]($$.data.targets)) { return; } + if ($$[hasType](TYPE_SCATTER) || $$[hasArcType]()) { return; } var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); focusEl .style(CSS_VISIBILITY, "visible") @@ -3755,9 +3755,9 @@ } }; var hasType = 'hasType'; - c3_chart_internal_fn[hasType] = function (targets, type) { + c3_chart_internal_fn[hasType] = function (type, targets) { var $$ = this, config = $$.config, has = false; - targets.forEach(function (t) { + (targets || $$.data.targets).forEach(function (t) { if (config[__data_types][t.id] === type) { has = true; } if (!(t.id in config[__data_types]) && type === 'line') { has = true; } }); @@ -3765,7 +3765,7 @@ }; var hasArcType = 'hasArcType'; c3_chart_internal_fn[hasArcType] = function (targets) { - return this[hasType](targets, TYPE_PIE) || this[hasType](targets, TYPE_DONUT) || this[hasType](targets, TYPE_GAUGE); + return this[hasType](TYPE_PIE, targets) || this[hasType](TYPE_DONUT, targets) || this[hasType](TYPE_GAUGE, targets); }; var isLineType = 'isLineType'; @@ -4087,7 +4087,7 @@ domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$[hasType](yTargets, TYPE_BAR) && config[__bar_zerobased]) || ($$[hasType](yTargets, TYPE_AREA) && config[__area_zerobased]), + isZeroBased = ($$[hasType](TYPE_BAR, yTargets) && config[__bar_zerobased]) || ($$[hasType](TYPE_AREA, yTargets) && config[__area_zerobased]), showHorizontalDataLabel = $$[hasDataLabel]() && config[__axis_rotated], showVerticalDataLabel = $$[hasDataLabel]() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none @@ -4161,7 +4161,7 @@ maxDataCount, padding, paddingLeft, paddingRight; if ($$[isCategorized]) { padding = 0; - } else if ($$[hasType](targets, TYPE_BAR)) { + } else if ($$[hasType](TYPE_BAR, targets)) { maxDataCount = $$[getMaxDataCount](); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { @@ -4614,7 +4614,7 @@ $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$[hasType](TYPE_DONUT) || $$[hasType](TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; }; var updateArc = 'updateArc', svgArc = 'svgArc', svgArcExpanded = 'svgArcExpanded', svgArcExpandedSub = 'svgArcExpandedSub'; @@ -4685,7 +4685,7 @@ c3_chart_internal_fn[transformForArcLabel] = function (d) { var $$ = this, updated = $$[updateAngle](d), c, x, y, h, ratio, translate = ""; - if (updated && !$$[hasType]($$.data.targets, TYPE_GAUGE)) { + if (updated && !$$[hasType](TYPE_GAUGE)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4700,7 +4700,7 @@ var getArcRatio = 'getArcRatio'; c3_chart_internal_fn[getArcRatio] = function (d) { var $$ = this, - whole = $$[hasType]($$.data.targets, TYPE_GAUGE) ? Math.PI : (Math.PI * 2); + whole = $$[hasType](TYPE_GAUGE) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; @@ -4722,7 +4722,7 @@ updated = $$[updateAngle](d); value = updated ? updated.value : null; ratio = $$[getArcRatio](updated); - if (! $$[hasType]($$.data.targets, TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } + if (! $$[hasType](TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } format = $$[getArcLabelFormat](); return format ? format(value, ratio) : $$[defaultArcValueFormat](value, ratio); }; @@ -4770,9 +4770,9 @@ var shouldShowArcLabel = 'shouldShowArcLabel'; c3_chart_internal_fn[shouldShowArcLabel] = function () { var $$ = this, config = $$.config, shouldShow = true; - if ($$[hasType]($$.data.targets, TYPE_DONUT)) { + if ($$[hasType](TYPE_DONUT)) { shouldShow = config[__donut_label_show]; - } else if ($$[hasType]($$.data.targets, TYPE_PIE)) { + } else if ($$[hasType](TYPE_PIE)) { shouldShow = config[__pie_label_show]; } // when gauge, always true @@ -4782,7 +4782,7 @@ var meetsArcLabelThreshold = 'meetsArcLabelThreshold'; c3_chart_internal_fn[meetsArcLabelThreshold] = function (ratio) { var $$ = this, config = $$.config, - threshold = $$[hasType]($$.data.targets, TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; + threshold = $$[hasType](TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; @@ -4790,9 +4790,9 @@ c3_chart_internal_fn[getArcLabelFormat] = function () { var $$ = this, config = $$.config, format = config[__pie_label_format]; - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$[hasType](TYPE_GAUGE)) { format = config[__gauge_label_format]; - } else if ($$[hasType]($$.data.targets, TYPE_DONUT)) { + } else if ($$[hasType](TYPE_DONUT)) { format = config[__donut_label_format]; } return format; @@ -4801,7 +4801,7 @@ var getArcTitle = 'getArcTitle'; c3_chart_internal_fn[getArcTitle] = function () { var $$ = this; - return $$[hasType]($$.data.targets, TYPE_DONUT) ? $$.config[__donut_title] : ""; + return $$[hasType](TYPE_DONUT) ? $$.config[__donut_title] : ""; }; var descByStartAngle = 'descByStartAngle'; @@ -4820,7 +4820,7 @@ mainPieEnter.append('g') .attr(CSS_CLASS, generateCall($$[classArcs], $$)); mainPieEnter.append("text") - .attr("dy", $$[hasType]($$.data.targets, TYPE_GAUGE) ? "-0.35em" : ".35em") + .attr("dy", $$[hasType](TYPE_GAUGE) ? "-0.35em" : ".35em") .style(CSS_OPACITY, 0) .style(CSS_TEXT_ANCHOR, "middle") .style(CSS_POINTER_EVENTS, "none"); @@ -4935,7 +4935,7 @@ .transition().duration(duration) .style(CSS_OPACITY, function (d) { return $$[isTargetToShow](d.data.id) && $$[isArcType](d.data) ? 1 : 0; }); main.select('.' + CLASS[chartArcsTitle]) - .style(CSS_OPACITY, $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? 1 : 0); + .style(CSS_OPACITY, $$[hasType](TYPE_DONUT) || $$[hasType](TYPE_GAUGE) ? 1 : 0); }; @@ -4944,7 +4944,7 @@ var initGauge = 'initGauge'; c3_chart_internal_fn[initGauge] = function () { var $$ = this, config = $$.config, arcs; - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$[hasType](TYPE_GAUGE)) { arcs.append('path') .attr(CSS_CLASS, CLASS[chartArcsBackground]) .attr("d", function () { @@ -5413,7 +5413,7 @@ var transformTo = 'transformTo'; c3_chart_internal_fn[transformTo] = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$[hasArcType]($$.data.targets), + withTransitionForAxis = !$$[hasArcType](), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; $$[transiting] = false; @@ -5694,8 +5694,8 @@ var getYFormat = 'getYFormat'; c3_chart_internal_fn[getYFormat] = function (forArc) { var $$ = this, - formatForY = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$[hasType](TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$[hasType](TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { var format = $$[getAxisId](id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); @@ -5746,7 +5746,7 @@ var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection @@ -5803,7 +5803,7 @@ var dragstart = 'dragstart'; c3_chart_internal_fn[dragstart] = function (mouse) { var $$ = this, config = $$.config; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$[dragStart] = mouse; $$.main.select('.' + CLASS[chart]).append('rect') @@ -5816,7 +5816,7 @@ var dragend = 'dragend'; c3_chart_internal_fn[dragend] = function () { var $$ = this, config = $$.config; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$[hasArcType]()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.main.select('.' + CLASS[dragarea]) .transition().duration(100) @@ -5847,7 +5847,7 @@ this.defocus(); focus(candidatesForNoneArc.classed(CLASS[focused], true)); focus(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { + if ($$[hasArcType]()) { $$[expandArc](targetId, true); } $$[toggleFocusLegend](targetId, true); @@ -5864,7 +5864,7 @@ this.revert(); defocus(candidatesForNoneArc.classed(CLASS[focused], false)); defocus(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { + if ($$[hasArcType]()) { $$[unexpandArc](targetId); } $$[toggleFocusLegend](targetId, false); @@ -5880,7 +5880,7 @@ } revert(candidatesForNoneArc.classed(CLASS[focused], false)); revert(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { + if ($$[hasArcType]()) { $$[unexpandArc](targetId); } $$[revertLegend](); From 07b31a867948b911cc8b39789aba8e2414a7bd72 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 16:26:25 +0100 Subject: [PATCH 13/44] Revert "Modify hasType interface" This reverts commit 7e3d23d1900a35ed1e559d4a5c52dff3daf674f9. --- c3.js | 80 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/c3.js b/c3.js index abbb3c9..cdb64ab 100644 --- a/c3.js +++ b/c3.js @@ -648,7 +648,7 @@ } // when gauge, hide legend // TODO: fix - if ($$[hasType](TYPE_GAUGE)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { config[__legend_show] = false; } @@ -842,7 +842,7 @@ } $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { return $$[addName](d.values[config[__tooltip_init_x]]); - }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]()), $$.color)); + }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]($$.data.targets)), $$.color)); $$.tooltip.style("top", config[__tooltip_init_position].top) .style("left", config[__tooltip_init_position].left) .style("display", "block"); @@ -895,7 +895,7 @@ var $$ = this, config = $$.config; var legendHeight = $$[getLegendHeight](), legendWidth = $$[getLegendWidth](), legendHeightForBottom = $$[isLegendRight] || $$[isLegendInset] ? 0 : legendHeight, - hasArc = $$[hasArcType](), + hasArc = $$[hasArcType]($$.data.targets), xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$[getHorizontalAxisHeight]('x'), subchartHeight = config[__subchart_show] && !hasArc ? (config[__subchart_size_height] + xAxisHeight) : 0; @@ -1047,7 +1047,7 @@ var areaIndices = $$[getShapeIndices]($$.isAreaType), barIndices = $$[getShapeIndices]($$.isBarType), lineIndices = $$[getShapeIndices]($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$[hasArcType](); + var hideAxis = $$[hasArcType]($$.data.targets); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$[filterTargetsToShow]($$.data.targets), tickValues, i, intervalForCulling; @@ -1666,7 +1666,7 @@ var index = d.index, selectedData, newData; if ($$[dragging]) { return; } // do nothing if dragging - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } selectedData = $$.data.targets.map(function (t) { return $$[addName]($$[getValueOnIndex](t.values, index)); @@ -1696,7 +1696,7 @@ }) .on('mouseout', function (d) { var index = d.index; - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } $$[hideXGridFocus](); $$[hideTooltip](); // Undo expanded shapes @@ -1712,7 +1712,7 @@ eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); if ($$[dragging]) { return; } // do nothing when dragging - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } // Show tooltip selectedData = $$[filterTargetsToShow]($$.data.targets).map(function (t) { @@ -1765,7 +1765,7 @@ }) .on('click', function (d) { var index = d.index; - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } if ($$[cancelClick]) { $$[cancelClick] = false; return; @@ -1791,7 +1791,7 @@ .attr('height', $$.height) .attr(CSS_CLASS, CLASS[eventRect]) .on('mouseout', function () { - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } $$[hideXGridFocus](); $$[hideTooltip](); $$[unexpandCircles](); @@ -2115,7 +2115,7 @@ leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$[hasArcType](), + hasArc = $$[hasArcType]($$.data.targets), svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$[getCurrentPaddingLeft]()); return svgLeft > 0 ? svgLeft : 0; }; @@ -2150,7 +2150,7 @@ return $$.config[__axis_rotated] ? $$.height : $$.width; } maxDataCount = $$[getMaxDataCount](); - ratio = ($$[hasType](TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); + ratio = ($$[hasType]($$.data.targets, TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2163,7 +2163,7 @@ c3_chart_internal_fn[showTooltip] = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$[hasArcType](), + var forArc = $$[hasArcType]($$.data.targets), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !config[__tooltip_show]) { return; @@ -2218,7 +2218,7 @@ var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if ($$[hasType](TYPE_SCATTER) || $$[hasArcType]()) { return; } + if ($$[hasType]($$.data.targets, TYPE_SCATTER) || $$[hasArcType]($$.data.targets)) { return; } var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); focusEl .style(CSS_VISIBILITY, "visible") @@ -3755,9 +3755,9 @@ } }; var hasType = 'hasType'; - c3_chart_internal_fn[hasType] = function (type, targets) { + c3_chart_internal_fn[hasType] = function (targets, type) { var $$ = this, config = $$.config, has = false; - (targets || $$.data.targets).forEach(function (t) { + targets.forEach(function (t) { if (config[__data_types][t.id] === type) { has = true; } if (!(t.id in config[__data_types]) && type === 'line') { has = true; } }); @@ -3765,7 +3765,7 @@ }; var hasArcType = 'hasArcType'; c3_chart_internal_fn[hasArcType] = function (targets) { - return this[hasType](TYPE_PIE, targets) || this[hasType](TYPE_DONUT, targets) || this[hasType](TYPE_GAUGE, targets); + return this[hasType](targets, TYPE_PIE) || this[hasType](targets, TYPE_DONUT) || this[hasType](targets, TYPE_GAUGE); }; var isLineType = 'isLineType'; @@ -4087,7 +4087,7 @@ domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$[hasType](TYPE_BAR, yTargets) && config[__bar_zerobased]) || ($$[hasType](TYPE_AREA, yTargets) && config[__area_zerobased]), + isZeroBased = ($$[hasType](yTargets, TYPE_BAR) && config[__bar_zerobased]) || ($$[hasType](yTargets, TYPE_AREA) && config[__area_zerobased]), showHorizontalDataLabel = $$[hasDataLabel]() && config[__axis_rotated], showVerticalDataLabel = $$[hasDataLabel]() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none @@ -4161,7 +4161,7 @@ maxDataCount, padding, paddingLeft, paddingRight; if ($$[isCategorized]) { padding = 0; - } else if ($$[hasType](TYPE_BAR, targets)) { + } else if ($$[hasType](targets, TYPE_BAR)) { maxDataCount = $$[getMaxDataCount](); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { @@ -4614,7 +4614,7 @@ $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$[hasType](TYPE_DONUT) || $$[hasType](TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; }; var updateArc = 'updateArc', svgArc = 'svgArc', svgArcExpanded = 'svgArcExpanded', svgArcExpandedSub = 'svgArcExpandedSub'; @@ -4685,7 +4685,7 @@ c3_chart_internal_fn[transformForArcLabel] = function (d) { var $$ = this, updated = $$[updateAngle](d), c, x, y, h, ratio, translate = ""; - if (updated && !$$[hasType](TYPE_GAUGE)) { + if (updated && !$$[hasType]($$.data.targets, TYPE_GAUGE)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4700,7 +4700,7 @@ var getArcRatio = 'getArcRatio'; c3_chart_internal_fn[getArcRatio] = function (d) { var $$ = this, - whole = $$[hasType](TYPE_GAUGE) ? Math.PI : (Math.PI * 2); + whole = $$[hasType]($$.data.targets, TYPE_GAUGE) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; @@ -4722,7 +4722,7 @@ updated = $$[updateAngle](d); value = updated ? updated.value : null; ratio = $$[getArcRatio](updated); - if (! $$[hasType](TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } + if (! $$[hasType]($$.data.targets, TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } format = $$[getArcLabelFormat](); return format ? format(value, ratio) : $$[defaultArcValueFormat](value, ratio); }; @@ -4770,9 +4770,9 @@ var shouldShowArcLabel = 'shouldShowArcLabel'; c3_chart_internal_fn[shouldShowArcLabel] = function () { var $$ = this, config = $$.config, shouldShow = true; - if ($$[hasType](TYPE_DONUT)) { + if ($$[hasType]($$.data.targets, TYPE_DONUT)) { shouldShow = config[__donut_label_show]; - } else if ($$[hasType](TYPE_PIE)) { + } else if ($$[hasType]($$.data.targets, TYPE_PIE)) { shouldShow = config[__pie_label_show]; } // when gauge, always true @@ -4782,7 +4782,7 @@ var meetsArcLabelThreshold = 'meetsArcLabelThreshold'; c3_chart_internal_fn[meetsArcLabelThreshold] = function (ratio) { var $$ = this, config = $$.config, - threshold = $$[hasType](TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; + threshold = $$[hasType]($$.data.targets, TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; @@ -4790,9 +4790,9 @@ c3_chart_internal_fn[getArcLabelFormat] = function () { var $$ = this, config = $$.config, format = config[__pie_label_format]; - if ($$[hasType](TYPE_GAUGE)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { format = config[__gauge_label_format]; - } else if ($$[hasType](TYPE_DONUT)) { + } else if ($$[hasType]($$.data.targets, TYPE_DONUT)) { format = config[__donut_label_format]; } return format; @@ -4801,7 +4801,7 @@ var getArcTitle = 'getArcTitle'; c3_chart_internal_fn[getArcTitle] = function () { var $$ = this; - return $$[hasType](TYPE_DONUT) ? $$.config[__donut_title] : ""; + return $$[hasType]($$.data.targets, TYPE_DONUT) ? $$.config[__donut_title] : ""; }; var descByStartAngle = 'descByStartAngle'; @@ -4820,7 +4820,7 @@ mainPieEnter.append('g') .attr(CSS_CLASS, generateCall($$[classArcs], $$)); mainPieEnter.append("text") - .attr("dy", $$[hasType](TYPE_GAUGE) ? "-0.35em" : ".35em") + .attr("dy", $$[hasType]($$.data.targets, TYPE_GAUGE) ? "-0.35em" : ".35em") .style(CSS_OPACITY, 0) .style(CSS_TEXT_ANCHOR, "middle") .style(CSS_POINTER_EVENTS, "none"); @@ -4935,7 +4935,7 @@ .transition().duration(duration) .style(CSS_OPACITY, function (d) { return $$[isTargetToShow](d.data.id) && $$[isArcType](d.data) ? 1 : 0; }); main.select('.' + CLASS[chartArcsTitle]) - .style(CSS_OPACITY, $$[hasType](TYPE_DONUT) || $$[hasType](TYPE_GAUGE) ? 1 : 0); + .style(CSS_OPACITY, $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? 1 : 0); }; @@ -4944,7 +4944,7 @@ var initGauge = 'initGauge'; c3_chart_internal_fn[initGauge] = function () { var $$ = this, config = $$.config, arcs; - if ($$[hasType](TYPE_GAUGE)) { + if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { arcs.append('path') .attr(CSS_CLASS, CLASS[chartArcsBackground]) .attr("d", function () { @@ -5413,7 +5413,7 @@ var transformTo = 'transformTo'; c3_chart_internal_fn[transformTo] = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$[hasArcType](), + withTransitionForAxis = !$$[hasArcType]($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; $$[transiting] = false; @@ -5694,8 +5694,8 @@ var getYFormat = 'getYFormat'; c3_chart_internal_fn[getYFormat] = function (forArc) { var $$ = this, - formatForY = forArc && !$$[hasType](TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$[hasType](TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { var format = $$[getAxisId](id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); @@ -5746,7 +5746,7 @@ var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection @@ -5803,7 +5803,7 @@ var dragstart = 'dragstart'; c3_chart_internal_fn[dragstart] = function (mouse) { var $$ = this, config = $$.config; - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$[dragStart] = mouse; $$.main.select('.' + CLASS[chart]).append('rect') @@ -5816,7 +5816,7 @@ var dragend = 'dragend'; c3_chart_internal_fn[dragend] = function () { var $$ = this, config = $$.config; - if ($$[hasArcType]()) { return; } + if ($$[hasArcType]($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.main.select('.' + CLASS[dragarea]) .transition().duration(100) @@ -5847,7 +5847,7 @@ this.defocus(); focus(candidatesForNoneArc.classed(CLASS[focused], true)); focus(candidatesForArc); - if ($$[hasArcType]()) { + if ($$[hasArcType]($$.data.targets)) { $$[expandArc](targetId, true); } $$[toggleFocusLegend](targetId, true); @@ -5864,7 +5864,7 @@ this.revert(); defocus(candidatesForNoneArc.classed(CLASS[focused], false)); defocus(candidatesForArc); - if ($$[hasArcType]()) { + if ($$[hasArcType]($$.data.targets)) { $$[unexpandArc](targetId); } $$[toggleFocusLegend](targetId, false); @@ -5880,7 +5880,7 @@ } revert(candidatesForNoneArc.classed(CLASS[focused], false)); revert(candidatesForArc); - if ($$[hasArcType]()) { + if ($$[hasArcType]($$.data.targets)) { $$[unexpandArc](targetId); } $$[revertLegend](); From f9b46bb45b5931daa20824ac3e2646b10a4df7c2 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 16:26:40 +0100 Subject: [PATCH 14/44] Revert "Refactor for minify" This reverts commit 4fee43b694ee69ac3d5a3a8c15a219968893d871. --- c3.js | 3749 +++++++++++++++++++++++++-------------------------------- 1 file changed, 1664 insertions(+), 2085 deletions(-) diff --git a/c3.js b/c3.js index cdb64ab..515697f 100644 --- a/c3.js +++ b/c3.js @@ -9,8 +9,8 @@ function Chart(config) { var $$ = this.internal = new ChartInternal(config, this); - $$[loadConfig](config); - $$[init](); + $$.loadConfig(config); + $$.init(); } function ChartInternal(config, api) { @@ -35,22 +35,6 @@ c3_chart_fn = c3.chart.fn; c3_chart_internal_fn = c3.chart.internal.fn; - var CSS_CLASS = 'class', - CSS_OPACITY = 'opacity', - CSS_TRANSFORM = 'transform', - CSS_FILL_OPACITY = 'fill-opacity', - CSS_TEXT_ANCHOR = 'text-anchor', - CSS_VISIBILITY = 'visibility', - CSS_POINTER_EVENTS = 'pointer-events'; - - var TYPE_BAR = 'bar', - //TYPE_LINE = 'line', - TYPE_AREA = 'area', - TYPE_SCATTER = 'scatter', - TYPE_PIE = 'pie', - TYPE_DONUT = 'donut', - TYPE_GAUGE = 'gauge'; - /** * c3.config.js @@ -411,14 +395,14 @@ if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, 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 += ""; + text += ""; text += ""; text += ""; text += ""; @@ -429,8 +413,7 @@ config[__tooltip_init_x] = 0; config[__tooltip_init_position] = {top: '0px', left: '50px'}; - var loadConfig = 'loadConfig'; - c3_chart_internal_fn[loadConfig] = function (config) { + c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); @@ -459,117 +442,78 @@ - - var initZoom = 'initZoom';// should be define in c3.zoom.js - c3_chart_internal_fn[initZoom] = function () { + // should be define in c3.zoom.js + c3_chart_internal_fn.initZoom = function () { var $$ = this, d3 = $$.d3, config = $$.config; $$.zoom = d3.behavior.zoom() .on("zoomstart", function () { $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; }) - .on("zoom", $$[redrawForZoom]); + .on("zoom", $$.redrawForZoom); $$.zoom.scale = function (scale) { - return config[__axis_rotated] ? this[y](scale) : this[x](scale); + return config[__axis_rotated] ? this.y(scale) : this.x(scale); }; $$.zoom.orgScaleExtent = function () { var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; - return [extent[0], Math.max($$[getMaxDataCount]() / extent[1], extent[1])]; + return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; }; $$.zoom.updateScaleExtent = function () { var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), - extent = this.orgScaleExtent(); - this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + extent = $$.orgScaleExtent(); + $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); return this; }; }; - var init = 'init'; - c3_chart_internal_fn[init] = function () { + c3_chart_internal_fn.init = function () { var $$ = this, config = $$.config; 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); } else if (config[__data_json]) { - $$[initWithData]($$[convertJsonToData](config[__data_json], config[__data_keys])); + $$.initWithData($$.convertJsonToData(config[__data_json], config[__data_keys])); } else if (config[__data_rows]) { - $$[initWithData]($$[convertRowsToData](config[__data_rows])); + $$.initWithData($$.convertRowsToData(config[__data_rows])); } else if (config[__data_columns]) { - $$[initWithData]($$[convertColumnsToData](config[__data_columns])); + $$.initWithData($$.convertColumnsToData(config[__data_columns])); } else { throw Error('url or json or rows or columns is required.'); } }; - var initWithData = 'initWithData', - color = 'color', - isCustomX = 'isCustomX', - clipId = 'clipId', - clipIdForXAxis = 'clipIdForXAxis', - clipIdForYAxis = 'clipIdForYAxis', - clipPath = 'clipPath', - clipPathForXAxis = 'clipPathForXAxis', - clipPathForYAxis = 'clipPathForYAxis', - isTimeSeries = 'isTimeSeries', - isCategorized = 'isCategorized', - dragStart = 'dragStart', - dragging = 'dragging', - cancelClick = 'cancelClick', - mouseover = 'mouseover', - transiting = 'transiting', - defaultColorPattern = 'defaultColorPattern', - levelColor = 'levelColor', - dataTimeFormat = 'dataTimeFormat', - axisTimeFormat = 'axisTimeFormat', - defaultAxisTimeFormat = 'defaultAxisTimeFormat', - hiddenTargetIds = 'hiddenTargetIds', - hiddenLegendIds = 'hiddenLegendIds', - xOrient = 'xOrient', - yOrient = 'yOrient', - y2Orient = 'y2Orient', - subXOrient = 'subXOrient', - translate = 'translate', - isLegendRight = 'isLegendRight', - isLegendInset = 'isLegendInset', - isLegendTop = 'isLegendTop', - isLegendLeft = 'isLegendLeft', - legendStep = 'legendStep', - legendItemWidth = 'legendItemWidth', - legendItemHeight = 'legendItemHeight', - legendOpacityForHidden = 'legendOpacityForHidden', - currentMaxTickWidth = 'currentMaxTickWidth', - rotated_padding_left = 'rotated_padding_left', - rotated_padding_right = 'rotated_padding_right', - rotated_padding_top = 'rotated_padding_top', - withoutFadeIn = 'withoutFadeIn'; - c3_chart_internal_fn[initWithData] = function (data) { + c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; var main, legend, eventRect, i, binding = true; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist - $$[clipId] = "c3-" + (+new Date()) + '-clip', - $$[clipIdForXAxis] = $$[clipId] + '-xaxis', - $$[clipIdForYAxis] = $$[clipId] + '-yaxis', - $$[clipPath] = $$[getClipPath]($$.clipId), - $$[clipPathForXAxis] = $$[getClipPath]($$[clipIdForXAxis]), - $$[clipPathForYAxis] = $$[getClipPath]($$[clipIdForYAxis]); - - $$[isTimeSeries] = (config[__axis_x_type] === 'timeseries'); - $$[isCategorized] = (config[__axis_x_type].indexOf('categor') >= 0); - $$[isCustomX] = function () { return !$$[isTimeSeries] && (config[__data_x] || notEmpty(config[__data_xs])); }; - - $$[dragStart] = $$[dragging] = $$[cancelClick] = $$[mouseover] = $$[transiting] = false; - - $$[defaultColorPattern] = d3.scale.category10().range(); - $$[color] = $$[generateColor](config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$[defaultColorPattern], config[__data_color]); - $$[levelColor] = notEmpty(config[__color_threshold]) ? $$[generateLevelColor](config[__color_pattern], config[__color_threshold]) : null; - - $$[dataTimeFormat] = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; - $$[axisTimeFormat] = config[__axis_x_localtime] ? d3.time.format : d3.time.format.utc; - $$[defaultAxisTimeFormat] = $$[axisTimeFormat].multi([ + $$.clipId = "c3-" + (+new Date()) + '-clip', + $$.clipIdForXAxis = $$.clipId + '-xaxis', + $$.clipIdForYAxis = $$.clipId + '-yaxis', + $$.clipPath = $$.getClipPath($$.clipId), + $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), + $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); + + $$.isTimeSeries = (config[__axis_x_type] === 'timeseries'); + $$.isCategorized = (config[__axis_x_type].indexOf('categor') >= 0); + $$.isCustomX = function () { return !$$.isTimeSeries && (config[__data_x] || notEmpty(config[__data_xs])); }; + + $$.dragStart = null; + $$.dragging = false; + $$.cancelClick = false; + $$.mouseover = false; + $$.transiting = false; + + $$.defaultColorPattern = d3.scale.category10().range(); + $$.color = $$.generateColor(config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$.defaultColorPattern, config[__data_color]); + $$.levelColor = notEmpty(config[__color_threshold]) ? $$.generateLevelColor(config[__color_pattern], config[__color_threshold]) : null; + + $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.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(); }], @@ -580,15 +524,15 @@ ["%Y/%-m/%-d", function () { return true; }] ]); - $$[hiddenTargetIds] = []; - $$[hiddenLegendIds] = []; + $$.hiddenTargetIds = []; + $$.hiddenLegendIds = []; - $$[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"; + $$.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"; - $$[translate] = { + $$.translate = { main : function () { return "translate(" + asHalfPixel($$.margin.left) + "," + asHalfPixel($$.margin.top) + ")"; }, context : function () { return "translate(" + asHalfPixel($$.margin2.left) + "," + asHalfPixel($$.margin2.top) + ")"; }, legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, @@ -599,44 +543,44 @@ arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } }; - $$[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; - $$[legendOpacityForHidden] = 0.15; + $$.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; + $$.legendOpacityForHidden = 0.15; - $$[currentMaxTickWidth] = 0; + $$.currentMaxTickWidth = 0; - $$[rotated_padding_left] = 30; - $$[rotated_padding_right] = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; - $$[rotated_padding_top] = 5; + $$.rotated_padding_left = 30; + $$.rotated_padding_right = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; + $$.rotated_padding_top = 5; - $$[withoutFadeIn] = {}; + $$.withoutFadeIn = {}; if (isFunction($$.initPie)) { - $$[initPie](); + $$.initPie(); } if (isFunction($$.initBrush)) { - $$[initBrush](); + $$.initBrush(); } else { $$.axes.subx = d3.selectAll([]); } - if ($$[initZoom]) { $$[initZoom](); } + if ($$.initZoom) { $$.initZoom(); } $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { - $$.selectChart = d3.select(document.createElement('div')).style(CSS_OPACITY, 0); - $$[observeInserted]($$.selectChart); + $$.selectChart = d3.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); + $$.data.targets = $$.convertDataToTargets(data); if (config[__data_filter]) { $$.data.targets = $$.data.targets.filter(config[__data_filter]); @@ -644,22 +588,22 @@ // Set targets to hide if needed 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]); } // when gauge, hide legend // TODO: fix - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$.hasGaugeType($$.data.targets)) { config[__legend_show] = false; } // Init sizes and scales - $$[updateSizes](); - $$[updateScales](); + $$.updateSizes(); + $$.updateScales(); // Set domains for each scale - $$.x.domain(d3.extent($$[getXDomain]($$.data.targets))); - $$.y.domain($$[getYDomain]($$.data.targets, 'y')); - $$.y2.domain($$[getYDomain]($$.data.targets, 'y2')); + $$.x.domain(d3.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()); @@ -676,27 +620,27 @@ // Define svgs $$.svg = $$.selectChart.append("svg") .style("overflow", "hidden") - .on('mouseover', generateCall(config[__onmouseover], $$)) - .on('mouseout', generateCall(config[__onmouseout], $$)); + .on('mouseenter', function () { return config[__onmouseover].call($$); }) + .on('mouseleave', function () { return config[__onmouseout].call($$); }); // Define defs $$.defs = $$.svg.append("defs"); - $$.defs.append("clipPath").attr("id", $$[clipId]).append("rect"); - $$.defs.append("clipPath").attr("id", $$[clipIdForXAxis]).append("rect"); - $$.defs.append("clipPath").attr("id", $$[clipIdForYAxis]).append("rect"); - $$[updateSvgSize](); + $$.defs.append("clipPath").attr("id", $$.clipId).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForXAxis).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForYAxis).append("rect"); + $$.updateSvgSize(); // Define regions - main = $$.main = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].main); - legend = $$.legend = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].legend); + main = $$.main = $$.svg.append("g").attr("transform", $$.translate.main); + legend = $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); if (isFunction($$.initSubchart)) { - $$[initSubchart](); + $$.initSubchart(); } if (!config[__legend_show]) { - $$.legend.style(CSS_VISIBILITY, 'hidden'); - $$[hiddenLegendIds] = $$[mapToIds]($$.data.targets); + $$.legend.style('visibility', 'hidden'); + $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } // Define tooltip @@ -704,126 +648,126 @@ .style("position", "relative") .append("div") .style("position", "absolute") - .style(CSS_POINTER_EVENTS, "none") + .style("pointer-events", "none") .style("z-index", "10") .style("display", "none"); // MEMO: call here to update legend box and tranlate for all // MEMO: translate will be upated by this, so transform not needed in updateLegend() - $$[updateLegend]($$[mapToIds]($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); /*-- Main Region --*/ // text when empty main.append("text") - .attr(CSS_CLASS, CLASS[text] + ' ' + CLASS[empty]) - .attr(CSS_TEXT_ANCHOR, "middle") // horizontal centering of text at x position in all browsers. + .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 main.append('g') - .attr("clip-path", $$[clipPath]) - .attr(CSS_CLASS, CLASS[regions]); + .attr("clip-path", $$.clipPath) + .attr("class", CLASS.regions); // Grids $$.grid = main.append('g') - .attr("clip-path", $$[clipPath]) - .attr('class', CLASS[grid]); + .attr("clip-path", $$.clipPath) + .attr('class', CLASS.grid); if (config[__grid_x_show]) { - $$.grid.append("g").attr(CSS_CLASS, CLASS[xgrids]); + $$.grid.append("g").attr("class", CLASS.xgrids); } if (config[__grid_y_show]) { - $$.grid.append('g').attr(CSS_CLASS, CLASS[ygrids]); + $$.grid.append('g').attr('class', CLASS.ygrids); } - $$.grid.append('g').attr(CSS_CLASS, CLASS[xgridLines]); - $$.grid.append('g').attr(CSS_CLASS, CLASS[ygridLines]); + $$.grid.append('g').attr("class", CLASS.xgridLines); + $$.grid.append('g').attr('class', CLASS.ygridLines); if (config[__grid_focus_show]) { $$.grid.append('g') - .attr(CSS_CLASS, CLASS[xgridFocus]) + .attr("class", CLASS.xgridFocus) .append('line') - .attr(CSS_CLASS, CLASS[xgridFocus]); + .attr('class', CLASS.xgridFocus); } // Define g for chart area main.append('g') - .attr("clip-path", $$[clipPath]) - .attr(CSS_CLASS, CLASS[chart]); + .attr("clip-path", $$.clipPath) + .attr('class', CLASS.chart); // Cover whole with rects for events - eventRect = main.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[eventRects]) - .style(CSS_FILL_OPACITY, 0); + eventRect = main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.eventRects) + .style('fill-opacity', 0); // Define g for bar chart area - main.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartBars]); + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); // Define g for line chart area - main.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartLines]); + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); // Define g for arc chart area if (isFunction($$.initArc)) { - $$[initArc](); + $$.initArc(); } if (isFunction($$.initGauge)) { - $$[initGauge](); + $$.initGauge(); } - main.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartTexts]); + main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartTexts); // if zoom privileged, insert rect to forefront - main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS[regions]) - .attr(CSS_CLASS, CLASS[zoomRect]) + main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS.regions) + .attr('class', CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .on("dblclick.zoom", null); // Set default extent if defined if (config[__axis_x_default]) { - $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$[getXDomain]())); + $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); } // Add Axis $$.axes.x = main.append("g") - .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisX]) - .attr("clip-path", $$[clipPathForXAxis]) - .attr(CSS_TRANSFORM, $$[translate].x) - .style(CSS_VISIBILITY, config[__axis_x_show] ? 'visible' : 'hidden'); + .attr("class", CLASS.axis + ' ' + CLASS.axisX) + .attr("clip-path", $$.clipPathForXAxis) + .attr("transform", $$.translate.x) + .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); $$.axes.x.append("text") - .attr(CSS_CLASS, CLASS[axisXLabel]) - .attr(CSS_TRANSFORM, config[__axis_rotated] ? "rotate(-90)" : "") - .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForXAxisLabel], $$)); + .attr("class", CLASS.axisXLabel) + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); $$.axes.y = main.append("g") - .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisY]) - .attr("clip-path", $$[clipPathForYAxis]) - .attr(CSS_TRANSFORM, $$[translate].y) - .style(CSS_VISIBILITY, config[__axis_y_show] ? 'visible' : 'hidden'); + .attr("class", CLASS.axis + ' ' + CLASS.axisY) + .attr("clip-path", $$.clipPathForYAxis) + .attr("transform", $$.translate.y) + .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); $$.axes.y.append("text") - .attr(CSS_CLASS, CLASS[axisYLabel]) - .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") - .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForYAxisLabel], $$)); + .attr("class", CLASS.axisYLabel) + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); $$.axes.y2 = main.append("g") - .attr(CSS_CLASS, CLASS[axis] + ' ' + CLASS[axisY2]) + .attr("class", CLASS.axis + ' ' + CLASS.axisY2) // clip-path? - .attr(CSS_TRANSFORM, $$[translate].y2) - .style(CSS_VISIBILITY, config[__axis_y2_show] ? 'visible' : 'hidden'); + .attr("transform", $$.translate.y2) + .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); $$.axes.y2.append("text") - .attr(CSS_CLASS, CLASS[axisY2Label]) - .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") - .style(CSS_TEXT_ANCHOR, generateCall($$[textAnchorForY2AxisLabel], $$)); + .attr("class", CLASS.axisY2Label) + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); // Set targets - $$[updateTargets]($$.data.targets); + $$.updateTargets($$.data.targets); // Draw with targets if (binding) { - $$[updateDimension](); - $$[redraw]({ + $$.updateDimension(); + $$.redraw({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -833,16 +777,16 @@ // Show tooltip if needed if (config[__tooltip_init_show]) { - if ($$[isTimeSeries] && isString(config[__tooltip_init_x])) { - config[__tooltip_init_x] = $$[parseDate](config[__tooltip_init_x]); + if ($$.isTimeSeries && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); for (i = 0; i < $$.data.targets[0].values.length; i++) { if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } } config[__tooltip_init_x] = i; } $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { - return $$[addName](d.values[config[__tooltip_init_x]]); - }), $$[getXAxisTickFormat](), $$[getYFormat]($$[hasArcType]($$.data.targets)), $$.color)); + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); $$.tooltip.style("top", config[__tooltip_init_position].top) .style("left", config[__tooltip_init_position].left) .style("display", "block"); @@ -850,7 +794,7 @@ // Bind resize event if (window.onresize == null) { - window.onresize = $$[generateResize](); + window.onresize = $$.generateResize(); } if (window.onresize.add) { window.onresize.add(function () { @@ -869,8 +813,7 @@ }; - var smoothLines = 'smoothLines'; - c3_chart_internal_fn[smoothLines] = function (el, type) { + c3_chart_internal_fn.smoothLines = function (el, type) { var $$ = this; if (type === 'grid') { el.each(function () { @@ -890,38 +833,37 @@ }; - var updateSizes = 'updateSizes'; - c3_chart_internal_fn[updateSizes] = function () { + c3_chart_internal_fn.updateSizes = function () { var $$ = this, config = $$.config; - var legendHeight = $$[getLegendHeight](), legendWidth = $$[getLegendWidth](), - legendHeightForBottom = $$[isLegendRight] || $$[isLegendInset] ? 0 : legendHeight, - hasArc = $$[hasArcType]($$.data.targets), - xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$[getHorizontalAxisHeight]('x'), + var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), + legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, + hasArc = $$.hasArcType($$.data.targets), + xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), subchartHeight = config[__subchart_show] && !hasArc ? (config[__subchart_size_height] + xAxisHeight) : 0; - $$.currentWidth = $$[getCurrentWidth](); - $$.currentHeight = $$[getCurrentHeight](); + $$.currentWidth = $$.getCurrentWidth(); + $$.currentHeight = $$.getCurrentHeight(); // for main, context if (config[__axis_rotated]) { $$.margin = { - top: $$[getHorizontalAxisHeight]('y2') + $$[getCurrentPaddingTop](), - right: hasArc ? 0 : $$[getCurrentPaddingRight](), - bottom: $$[getHorizontalAxisHeight]('y') + legendHeightForBottom + $$[getCurrentPaddingBottom](), - left: subchartHeight + (hasArc ? 0 : $$[getCurrentPaddingLeft]()) + top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) }; $$.margin2 = { top: $$.margin.top, right: NaN, bottom: 20 + legendHeightForBottom, - left: $$[rotated_padding_left] + left: $$.rotated_padding_left }; } else { $$.margin = { - top: 4 + $$[getCurrentPaddingTop](), // for top tick text - right: hasArc ? 0 : $$[getCurrentPaddingRight](), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$[getCurrentPaddingBottom](), - left: hasArc ? 0 : $$[getCurrentPaddingLeft]() + top: 4 + $$.getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: hasArc ? 0 : $$.getCurrentPaddingLeft() }; $$.margin2 = { top: $$.currentHeight - subchartHeight - legendHeightForBottom, @@ -932,14 +874,14 @@ } // for legend var insetLegendPosition = { - 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 + 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 }; $$.margin3 = { - top: $$[isLegendRight] ? 0 : $$[isLegendInset] ? insetLegendPosition.top : $$.currentHeight - legendHeight, + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, right: NaN, bottom: 0, - left: $$[isLegendRight] ? $$.currentWidth - legendWidth : $$[isLegendInset] ? insetLegendPosition.left : 0 + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 }; $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; @@ -947,77 +889,76 @@ if ($$.width < 0) { $$.width = 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; if ($$.width2 < 0) { $$.width2 = 0; } if ($$.height2 < 0) { $$.height2 = 0; } // for arc - $$.arcWidth = $$.width - ($$[isLegendRight] ? legendWidth + 10 : 0); - $$.arcHeight = $$.height - ($$[isLegendRight] ? 0 : 10); + $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); + $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); if (isFunction($$.updateRadius)) { - $$[updateRadius](); + $$.updateRadius(); } - if ($$[isLegendRight] && hasArc) { + if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; } }; - var updateTargets = 'updateTargets'; - c3_chart_internal_fn[updateTargets] = function (targets) { + c3_chart_internal_fn.updateTargets = function (targets) { var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS[chartTexts]).selectAll('.' + CLASS[chartText]) + mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) .data(targets) - .attr(CSS_CLASS, generateCall($$[classChartText], $$)); + .attr('class', generateCall($$.classChartText, $$)); mainTextEnter = mainTextUpdate.enter().append('g') - .attr(CSS_CLASS, generateCall($$[classChartText], $$)) - .style(CSS_OPACITY, 0) - .style(CSS_POINTER_EVENTS, "none"); + .attr('class', generateCall($$.classChartText, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); mainTextEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classTexts], $$)); + .attr('class', generateCall($$.classTexts, $$)); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) + mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); + .attr('class', generateCall($$.classChartBar, $$)); mainBarEnter = mainBarUpdate.enter().append('g') - .attr(CSS_CLASS, generateCall($$[classChartBar], $$)) - .style(CSS_OPACITY, 0) - .style(CSS_POINTER_EVENTS, "none"); + .attr('class', generateCall($$.classChartBar, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); // Bars for each data mainBarEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classBars], $$)) + .attr("class", generateCall($$.classBars, $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); //-- Line --// - mainLineUpdate = main.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) + mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); + .attr('class', generateCall($$.classChartLine, $$)); mainLineEnter = mainLineUpdate.enter().append('g') - .attr(CSS_CLASS, generateCall($$[classChartLine], $$)) - .style(CSS_OPACITY, 0) - .style(CSS_POINTER_EVENTS, "none"); + .attr('class', generateCall($$.classChartLine, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); // Lines for each data mainLineEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classLines], $$)); + .attr("class", generateCall($$.classLines, $$)); // Areas mainLineEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classAreas], $$)); + .attr('class', generateCall($$.classAreas, $$)); // Circles for each data point on lines mainLineEnter.append('g') - .attr(CSS_CLASS, function (d) { return $$[generateClass](CLASS[selectedCircles], d.id); }); + .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); mainLineEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classCircles], $$)) + .attr("class", generateCall($$.classCircles, $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](t.id)).selectAll('.' + CLASS[selectedCircle]).each(function (d) { + main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { d.value = t.values[d.index].value; }); }); @@ -1025,32 +966,31 @@ //mainLineUpdate.exit().remove(); if (isFunction($$.updateTargetsForArc)) { - $$[updateTargetsForArc](targets); + $$.updateTargetsForArc(targets); } if (isFunction($$.updateTargetsForSubchart)) { - $$[updateTargetsForSubchart](targets); + $$.updateTargetsForSubchart(targets); } /*-- Show --*/ // Fade-in each chart - $$.svg.selectAll('.' + CLASS[target]).filter(function (d) { return $$[isTargetToShow](d.id); }) + $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) .transition().duration(config[__transition_duration]) - .style(CSS_OPACITY, 1); + .style("opacity", 1); }; - var redraw = 'redraw'; - 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 xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; - var areaIndices = $$[getShapeIndices]($$.isAreaType), barIndices = $$[getShapeIndices]($$.isBarType), lineIndices = $$[getShapeIndices]($$.isLineType), maxDataCountTarget, tickOffset; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$[hasArcType]($$.data.targets); + var hideAxis = $$.hasArcType($$.data.targets); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; - var targetsToShow = $$[filterTargetsToShow]($$.data.targets), tickValues, i, intervalForCulling; + var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); @@ -1069,23 +1009,23 @@ durationForExit = withTransitionForExit ? duration : 0; durationForAxis = withTransitionForAxis ? duration : 0; - transitions = transitions || $$[generateAxisTransitions](durationForAxis); + transitions = transitions || $$.generateAxisTransitions(durationForAxis); // update legend and transform each g if (withLegend && config[__legend_show]) { - $$[updateLegend]($$[mapToIds]($$.data.targets), options, transitions); + $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); } // MEMO: needed for grids calculation - if ($$[isCategorized] && targetsToShow.length === 0) { + if ($$.isCategorized && targetsToShow.length === 0) { $$.x.domain([0, $$.axes.x.selectAll('.tick').size()]); } if (targetsToShow.length) { - $$[updateXDomain](targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); + $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain); // update axis tick values according to options if (!config[__axis_x_tick_values] && (config[__axis_x_tick_fit] || config[__axis_x_tick_count])) { - tickValues = $$[generateTickValues]($$[mapTargetsToUniqueXs](targetsToShow), config[__axis_x_tick_count]); + tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config[__axis_x_tick_count]); $$.xAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues); } @@ -1094,21 +1034,21 @@ $$.subXAxis.tickValues([]); } - $$.y.domain($$[getYDomain](targetsToShow, 'y')); - $$.y2.domain($$[getYDomain](targetsToShow, 'y2')); + $$.y.domain($$.getYDomain(targetsToShow, 'y')); + $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); // axes - $$.axes.x.style(CSS_OPACITY, hideAxis ? 0 : 1); - $$.axes.y.style(CSS_OPACITY, hideAxis ? 0 : 1); - $$.axes.y2.style(CSS_OPACITY, hideAxis ? 0 : 1); - $$.axes.subx.style(CSS_OPACITY, hideAxis ? 0 : 1); + $$.axes.x.style("opacity", hideAxis ? 0 : 1); + $$.axes.y.style("opacity", hideAxis ? 0 : 1); + $$.axes.y2.style("opacity", hideAxis ? 0 : 1); + $$.axes.subx.style("opacity", hideAxis ? 0 : 1); transitions.axisX.call($$.xAxis); transitions.axisY.call($$.yAxis); transitions.axisY2.call($$.y2Axis); transitions.axisSubX.call($$.subXAxis); // Update axis label - $$[updateAxisLabels](withTransition); + $$.updateAxisLabels(withTransition); // show/hide if manual culling needed if (withUpdateXDomain && targetsToShow.length) { @@ -1119,28 +1059,28 @@ break; } } - $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').each(function (e) { + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { var index = tickValues.indexOf(e); if (index >= 0) { d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); } }); } else { - $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').style('display', 'block'); + $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); } } // rotate tick text if needed if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { - $$[rotateTickText]($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); + $$.rotateTickText($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); } // setup drawer - MEMO: these must be called after axis updated - drawArea = $$[generateDrawArea](areaIndices, false); - drawBar = $$[generateDrawBar](barIndices); - drawLine = $$[generateDrawLine](lineIndices, false); - xForText = $$[generateXYForText](barIndices, true); - yForText = $$[generateXYForText](barIndices, false); + drawArea = $$.generateDrawArea(areaIndices, false); + drawBar = $$.generateDrawBar(barIndices); + drawLine = $$.generateDrawLine(lineIndices, false); + xForText = $$.generateXYForText(barIndices, true); + yForText = $$.generateXYForText(barIndices, false); // Update sub domain $$.subY.domain($$.y.domain()); @@ -1150,221 +1090,221 @@ $$.tooltip.style("display", "none"); // xgrid focus - $$[updateXgridFocus](); + $$.updateXgridFocus(); // 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("y", $$.height / 2) .text(config[__data_empty_label_text]) .transition() - .style(CSS_OPACITY, targetsToShow.length ? 0 : 1); + .style('opacity', targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS[xgridFocus]).style(CSS_VISIBILITY, "hidden"); + main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); if (config[__grid_x_show]) { xgridAttr = config[__axis_rotated] ? { 'x1': 0, 'x2': $$.width, - 'y1': function (d) { return $$[x](d) - tickOffset; }, - 'y2': function (d) { return $$[x](d) - tickOffset; } + 'y1': function (d) { return $$.x(d) - tickOffset; }, + 'y2': function (d) { return $$.x(d) - tickOffset; } } : { - 'x1': function (d) { return $$[x](d) + tickOffset; }, - 'x2': function (d) { return $$[x](d) + tickOffset; }, + 'x1': function (d) { return $$.x(d) + tickOffset; }, + 'x2': function (d) { return $$.x(d) + tickOffset; }, 'y1': 0, 'y2': $$.height }; // this is used to flow flushXGrid = function (withoutUpdate) { - xgridData = $$[generateGridData](config[__grid_x_type], $$.x); - tickOffset = $$[isCategorized] ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS[xgrids]).selectAll('.' + CLASS[xgrid]) + xgridData = $$.generateGridData(config[__grid_x_type], $$.x); + tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; + xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) .data(xgridData); - xgrid.enter().append('line').attr(CSS_CLASS, CLASS[xgrid]); + xgrid.enter().append('line').attr("class", CLASS.xgrid); if (!withoutUpdate) { xgrid.attr(xgridAttr) - .style(CSS_OPACITY, function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); + .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); } xgrid.exit().remove(); }; flushXGrid(); } - xgridLines = main.select('.' + CLASS[xgridLines]).selectAll('.' + CLASS[xgridLine]) + xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) .data(config[__grid_x_lines]); // enter xgridLine = xgridLines.enter().append('g') - .attr(CSS_CLASS, function (d) { return CLASS[xgridLine] + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); xgridLine.append('line') - .style(CSS_OPACITY, 0); + .style("opacity", 0); xgridLine.append('text') - .attr(CSS_TEXT_ANCHOR, "end") - .attr(CSS_TRANSFORM, config[__axis_rotated] ? "" : "rotate(-90)") + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) - .style(CSS_OPACITY, 0); + .style("opacity", 0); // udpate // done in d3.transition() of the end of this function // exit xgridLines.exit().transition().duration(duration) - .style(CSS_OPACITY, 0) + .style("opacity", 0) .remove(); // Y-Grid if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS[ygrids]).selectAll('.' + CLASS[ygrid]) + ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) .data($$.y.ticks(config[__grid_y_ticks])); ygrid.enter().append('line') - .attr(CSS_CLASS, CLASS[ygrid]); + .attr('class', CLASS.ygrid); ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) .attr("x2", config[__axis_rotated] ? $$.y : $$.width) .attr("y1", config[__axis_rotated] ? 0 : $$.y) .attr("y2", config[__axis_rotated] ? $$.height : $$.y); ygrid.exit().remove(); - $$[smoothLines](ygrid, 'grid'); + $$.smoothLines(ygrid, 'grid'); } if (withY) { - ygridLines = main.select('.' + CLASS[ygridLines]).selectAll('.' + CLASS[ygridLine]) + ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) .data(config[__grid_y_lines]); // enter ygridLine = ygridLines.enter().append('g') - .attr(CSS_CLASS, function (d) { return CLASS[ygridLine] + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); ygridLine.append('line') - .style(CSS_OPACITY, 0); + .style("opacity", 0); ygridLine.append('text') - .attr(CSS_TEXT_ANCHOR, "end") - .attr(CSS_TRANSFORM, config[__axis_rotated] ? "rotate(-90)" : "") + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) .attr('dy', -5) - .style(CSS_OPACITY, 0); + .style("opacity", 0); // update - var yv_ = generateCall($$[yv], $$); + var yv_ = generateCall($$.yv, $$); ygridLines.select('line') .transition().duration(duration) .attr("x1", config[__axis_rotated] ? yv_ : 0) .attr("x2", config[__axis_rotated] ? yv_ : $$.width) .attr("y1", config[__axis_rotated] ? 0 : yv_) .attr("y2", config[__axis_rotated] ? $$.height : yv_) - .style(CSS_OPACITY, 1); + .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) .attr("x", config[__axis_rotated] ? 0 : $$.width) .attr("y", yv_) .text(function (d) { return d.text; }) - .style(CSS_OPACITY, 1); + .style("opacity", 1); // exit ygridLines.exit().transition().duration(duration) - .style(CSS_OPACITY, 0) + .style("opacity", 0) .remove(); } // rect for regions - mainRegion = main.select('.' + CLASS[regions]).selectAll('.' + CLASS[region]) + mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) .data(config[__regions]); mainRegion.enter().append('g') - .attr(CSS_CLASS, generateCall($$[classRegion], $$)) + .attr('class', generateCall($$.classRegion, $$)) .append('rect') - .style(CSS_FILL_OPACITY, 0); + .style("fill-opacity", 0); mainRegion.exit().transition().duration(duration) - .style(CSS_OPACITY, 0) + .style("opacity", 0) .remove(); // bars - mainBar = main.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) - .data(generateCall($$[barData], $$)); + mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(generateCall($$.barData, $$)); mainBar.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classBar], $$)) - .style("stroke", function (d) { return $$[color](d.id); }) - .style("fill", function (d) { return $$[color](d.id); }); + .attr("class", generateCall($$.classBar, $$)) + .style("stroke", function (d) { return $$.color(d.id); }) + .style("fill", function (d) { return $$.color(d.id); }); mainBar - .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)); + .style("opacity", generateCall($$.initialOpacity, $$)); mainBar.exit().transition().duration(durationForExit) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) - .data(generateCall($$[lineData], $$)); + mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(generateCall($$.lineData, $$)); mainLine.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classLine], $$)) + .attr('class', generateCall($$.classLine, $$)) .style("stroke", $$.color); mainLine - .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) - .attr(CSS_TRANSFORM, null); + .style("opacity", generateCall($$.initialOpacity, $$)) + .attr('transform', null); mainLine.exit().transition().duration(durationForExit) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); - mainArea = main.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) - .data(generateCall($$[lineData], $$)); + mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(generateCall($$.lineData, $$)); mainArea.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classArea], $$)) + .attr("class", generateCall($$.classArea, $$)) .style("fill", $$.color) - .style(CSS_OPACITY, function () { $$.orgAreaOpacity = +d3.select(this).style(CSS_OPACITY); return 0; }); + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); mainArea - .style(CSS_OPACITY, $$.orgAreaOpacity); + .style("opacity", $$.orgAreaOpacity); mainArea.exit().transition().duration(durationForExit) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS[circles]).selectAll('.' + CLASS[circle]) - .data(generateCall($$[lineOrScatterData], $$)); + mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) + .data(generateCall($$.lineOrScatterData, $$)); mainCircle.enter().append("circle") - .attr(CSS_CLASS, generateCall($$[classCircle], $$)) - .attr("r", generateCall($$[pointR], $$)) + .attr("class", generateCall($$.classCircle, $$)) + .attr("r", generateCall($$.pointR, $$)) .style("fill", $$.color); mainCircle - .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)); + .style("opacity", generateCall($$.initialOpacity, $$)); mainCircle.exit().remove(); } - if ($$[hasDataLabel]()) { - mainText = main.selectAll('.' + CLASS[texts]).selectAll('.' + CLASS[text]) - .data(generateCall($$[barOrLineData], $$)); + if ($$.hasDataLabel()) { + mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) + .data(generateCall($$.barOrLineData, $$)); mainText.enter().append('text') - .attr(CSS_CLASS, generateCall($$[classText], $$)) - .attr(CSS_TEXT_ANCHOR, function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .attr("class", generateCall($$.classText, $$)) + .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') - .style("fill", function (d) { return $$[color](d); }) - .style(CSS_FILL_OPACITY, 0); + .style("fill", function (d) { return $$.color(d); }) + .style("fill-opacity", 0); mainText - .text(function (d) { return $$[formatByAxisId]($$[getAxisId](d.id))(d.value, d.id); }); + .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); mainText.exit() .transition().duration(durationForExit) - .style(CSS_FILL_OPACITY, 0) + .style('fill-opacity', 0) .remove(); } // arc if (isFunction($$.redrawArc)) { - $$[redrawArc](duration, durationForExit, withTransform); + $$.redrawArc(duration, durationForExit, withTransform); } // subchart if (isFunction($$.redrawSubchart)) { - $$[redrawSubchart](withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); + $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } // circles for select - main.selectAll('.' + CLASS[selectedCircles]) - .filter(generateCall($$[isBarType], $$)) + main.selectAll('.' + CLASS.selectedCircles) + .filter(generateCall($$.isBarType, $$)) .selectAll('circle') .remove(); if (config[__interaction_enabled]) { // rect for mouseover - eventRect = main.select('.' + CLASS[eventRects]) + eventRect = main.select('.' + CLASS.eventRects) .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty(config[__data_xs]) && !$$[isSingleX](config[__data_xs])) { + if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { - if (!eventRect.classed(CLASS[eventRectsMultiple])) { - eventRect.classed(CLASS[eventRectsMultiple], true).classed(CLASS[eventRectsSingle], false) - .selectAll('.' + CLASS[eventRect]).remove(); + if (!eventRect.classed(CLASS.eventRectsMultiple)) { + eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) + .selectAll('.' + CLASS.eventRect).remove(); } - eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) .data([0]); // enter : only one rect will be added - $$[generateEventRectsForMultipleXs](eventRectUpdate.enter()); + $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); // update eventRectUpdate .attr('x', 0) @@ -1374,39 +1314,39 @@ // exit : not needed because always only one rect exists } else { - if (!eventRect.classed(CLASS[eventRectsSingle])) { - eventRect.classed(CLASS[eventRectsMultiple], false).classed(CLASS[eventRectsSingle], true) - .selectAll('.' + CLASS[eventRect]).remove(); + if (!eventRect.classed(CLASS.eventRectsSingle)) { + eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) + .selectAll('.' + CLASS.eventRect).remove(); } - if (($$[isCustomX]() || $$[isTimeSeries]) && !$$[isCategorized]) { + if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { rectW = function (d) { - var prevX = $$[getPrevX](d.index), nextX = $$[getNextX](d.index), dx = $$.data.xs[d.id][d.index], - w = ($$[x](nextX ? nextX : dx) - $$[x](prevX ? prevX : dx)) / 2; + var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], + w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; return w < 0 ? 0 : w; }; rectX = function (d) { - var prevX = $$[getPrevX](d.index), dx = $$.data.xs[d.id][d.index]; - return ($$[x](dx) + $$[x](prevX ? prevX : dx)) / 2; + var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; + return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; }; } else { - rectW = $$[getEventRectWidth](); + rectW = $$.getEventRectWidth(); rectX = function (d) { - return $$[x](d.x) - (rectW / 2); + return $$.x(d.x) - (rectW / 2); }; } // Set data - maxDataCountTarget = $$[getMaxDataCountTarget]($$.data.targets); - main.select('.' + CLASS[eventRects]) + maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); + main.select('.' + CLASS.eventRects) .datum(maxDataCountTarget ? maxDataCountTarget.values : []); // Update rects - eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) + eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) .data(function (d) { return d; }); // enter - $$[generateEventRectsForSingleX](eventRectUpdate.enter()); + $$.generateEventRectsForSingleX(eventRectUpdate.enter()); // update eventRectUpdate - .attr(CSS_CLASS, generateCall($$[classEvent], $$)) + .attr('class', generateCall($$.classEvent, $$)) .attr("x", config[__axis_rotated] ? 0 : rectX) .attr("y", config[__axis_rotated] ? rectX : 0) .attr("width", config[__axis_rotated] ? $$.width : rectW) @@ -1416,7 +1356,7 @@ } } - var xv_ = generateCall($$[xv], $$); + var xv_ = generateCall($$.xv, $$); // transition should be derived from one transition d3.transition().duration(duration).each(function () { @@ -1427,48 +1367,48 @@ transitions.push(mainBar.transition() .attr('d', drawBar) .style("fill", $$.color) - .style(CSS_OPACITY, 1)); + .style("opacity", 1)); transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) - .style(CSS_OPACITY, 1)); + .style("opacity", 1)); transitions.push(mainArea.transition() .attr("d", drawArea) .style("fill", $$.color) - .style(CSS_OPACITY, $$.orgAreaOpacity)); + .style("opacity", $$.orgAreaOpacity)); transitions.push(mainCircle.transition() - .style(CSS_OPACITY, generateCall($$[opacityForCircle], $$)) + .style('opacity', generateCall($$.opacityForCircle, $$)) .style("fill", $$.color) .attr("cx", cx) .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS[selectedCircle]).transition() + transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() .attr("cx", cx) .attr("cy", cy)); transitions.push(mainText.transition() .attr('x', xForText) .attr('y', yForText) .style("fill", $$.color) - .style(CSS_FILL_OPACITY, options.flow ? 0 : generateCall($$[opacityForText], $$))); + .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); transitions.push(mainRegion.selectAll('rect').transition() .attr("x", $$.regionX) .attr("y", $$.regionY) .attr("width", $$.regionWidth) .attr("height", $$.regionHeight) - .style(CSS_FILL_OPACITY, function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() .attr("x1", config[__axis_rotated] ? 0 : xv_) .attr("x2", config[__axis_rotated] ? $$.width : xv_) .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) .attr("y2", config[__axis_rotated] ? xv_ : $$.height) - .style(CSS_OPACITY, 1)); + .style("opacity", 1)); transitions.push(xgridLines.select('text').transition() .attr("x", config[__axis_rotated] ? $$.width : 0) .attr("y", xv_) .text(function (d) { return d.text; }) - .style(CSS_OPACITY, 1)); + .style("opacity", 1)); // Wait for end of transitions if called from flow API if (options.flow) { - waitForDraw = $$[generateWait](); + waitForDraw = $$.generateWait(); transitions.forEach(function (t) { waitForDraw.add(t); }); @@ -1478,12 +1418,12 @@ var translateX, scaleX = 1, transform, flowIndex = options.flow.index, flowLength = options.flow.length, - flowStart = $$[getValueOnIndex]($$.data.targets[0].values, flowIndex), - flowEnd = $$[getValueOnIndex]($$.data.targets[0].values, flowIndex + flowLength), + flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), orgDomain = $$.x.domain(), domain, durationForFlow = options.flow.duration || duration, done = options.flow.done || function () {}, - wait = $$[generateWait](); + wait = $$.generateWait(); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -1491,30 +1431,30 @@ }); // update x domain to generate axis elements for flow - domain = $$[updateXDomain](targetsToShow, true, true); + domain = $$.updateXDomain(targetsToShow, true, true); // update elements related to x scale if (flushXGrid) { flushXGrid(true); } // generate transform to flow if (!options.flow.orgDataCount) { // if empty if ($$.data.targets[0].values.length !== 1) { - translateX = $$[x](orgDomain[0]) - $$[x](domain[0]); + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); } else { - if ($$[isTimeSeries]) { - flowStart = $$[getValueOnIndex]($$.data.targets[0].values, 0); - flowEnd = $$[getValueOnIndex]($$.data.targets[0].values, $$.data.targets[0].values.length - 1); - translateX = $$[x](flowStart.x) - $$[x](flowEnd.x); + if ($$.isTimeSeries) { + flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); } else { translateX = diffDomain(domain) / 2; } } } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { - translateX = $$[x](orgDomain[0]) - $$[x](domain[0]); + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); } else { - if ($$[isTimeSeries]) { - translateX = ($$[x](orgDomain[0]) - $$[x](domain[0])); + if ($$.isTimeSeries) { + translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); } else { - translateX = ($$[x](flowStart.x) - $$[x](flowEnd.x)); + translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); } } scaleX = (diffDomain(orgDomain) / diffDomain(domain)); @@ -1522,14 +1462,14 @@ d3.transition().ease('linear').duration(durationForFlow).each(function () { wait.add($$.axes.x.transition().call($$.xAxis)); - wait.add(mainBar.transition().attr(CSS_TRANSFORM, transform)); - wait.add(mainLine.transition().attr(CSS_TRANSFORM, transform)); - wait.add(mainArea.transition().attr(CSS_TRANSFORM, transform)); - wait.add(mainCircle.transition().attr(CSS_TRANSFORM, transform)); - wait.add(mainText.transition().attr(CSS_TRANSFORM, transform)); - wait.add(mainRegion.filter($$.isRegionOnX).transition().attr(CSS_TRANSFORM, transform)); - wait.add(xgrid.transition().attr(CSS_TRANSFORM, transform)); - wait.add(xgridLines.transition().attr(CSS_TRANSFORM, transform)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); }) .call(wait, function () { var i, shapes = [], texts = [], eventRects = []; @@ -1537,22 +1477,22 @@ // remove flowed elements if (flowLength) { for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS[shape] + '-' + (flowIndex + i)); - texts.push('.' + CLASS[text] + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS[eventRect] + '-' + (flowIndex + i)); + shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); + texts.push('.' + CLASS.text + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); } - $$.svg.selectAll('.' + CLASS[shapes]).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS[texts]).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS[eventRects]).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS[xgrid]).remove(); + $$.svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS.xgrid).remove(); } // draw again for removing flowed elements and reverting attr xgrid - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr(xgridAttr); xgridLines - .attr(CSS_TRANSFORM, null); + .attr('transform', null); xgridLines.select('line') .attr("x1", config[__axis_rotated] ? 0 : xv_) .attr("x2", config[__axis_rotated] ? $$.width : xv_); @@ -1560,25 +1500,25 @@ .attr("x", config[__axis_rotated] ? $$.width : 0) .attr("y", xv_); mainBar - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr("d", drawBar); mainLine - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr("d", drawLine); mainArea - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr("d", drawArea); mainCircle - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY); mainText - .attr(CSS_TRANSFORM, null) + .attr('transform', null) .attr('x', xForText) .attr('y', yForText) - .style(CSS_FILL_OPACITY, generateCall($$[opacityForText], $$)); + .style('fill-opacity', generateCall($$.opacityForText, $$)); mainRegion - .attr(CSS_TRANSFORM, null); + .attr('transform', null); mainRegion.select('rect').filter($$.isRegionOnX) .attr("x", $$.regionX) .attr("width", $$.regionWidth); @@ -1594,20 +1534,18 @@ }); // update fadein condition - $$[mapToIds]($$.data.targets).forEach(function (id) { - $$[withoutFadeIn][id] = true; + $$.mapToIds($$.data.targets).forEach(function (id) { + $$.withoutFadeIn[id] = true; }); - $$[updateZoom](); + $$.updateZoom(); }; - - var redrawForZoom = 'redrawForZoom'; - c3_chart_internal_fn[redrawForZoom] = function () { + c3_chart_internal_fn.redrawForZoom = function () { var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; if (!config[__zoom_enabled]) { return; } - if ($$[filterTargetsToShow]($$.data.targets).length === 0) { + if ($$.filterTargetsToShow($$.data.targets).length === 0) { return; } if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { @@ -1615,21 +1553,20 @@ zoom.scale(x).updateScaleExtent(); return; } - if ($$[isCategorized] && x.orgDomain()[0] === orgXDomain[0]) { + if ($$.isCategorized && x.orgDomain()[0] === orgXDomain[0]) { x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); } - $$[redraw]({ + $$.redraw({ withTransition: false, withY: false, withSubchart: false }); if (d3.event.sourceEvent.type === 'mousemove') { - $$[cancelClick] = true; + $$.cancelClick = true; } config[__zoom_onzoom].call(c3, x.orgDomain()); }; - var updateAndRedraw = 'updateAndRedraw'; - c3_chart_internal_fn[updateAndRedraw] = function (options) { + c3_chart_internal_fn.updateAndRedraw = function (options) { var $$ = this, config = $$.config, transitions; options = options || {}; // same with redraw @@ -1642,34 +1579,33 @@ 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](); + $$.updateSizes(); // MEMO: called in updateLegend in redraw if withLegend if (!(options.withLegend && config[__legend_show])) { - transitions = $$[generateAxisTransitions](options.withTransitionForAxis ? config[__transition_duration] : 0); + transitions = $$.generateAxisTransitions(options.withTransitionForAxis ? config[__transition_duration] : 0); // Update scales - $$[updateScales](); - $$[updateSvgSize](); + $$.updateScales(); + $$.updateSvgSize(); // Update g positions - $$[transformAll](options.withTransitionForTransform, transitions); + $$.transformAll(options.withTransitionForTransform, transitions); } // Draw with new sizes & scales - $$[redraw](options, transitions); + $$.redraw(options, transitions); }; - var generateEventRectsForSingleX = 'generateEventRectsForSingleX'; - c3_chart_internal_fn[generateEventRectsForSingleX] = function (eventRectEnter) { + c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append("rect") - .attr(CSS_CLASS, generateCall($$[classEvent], $$)) + .attr("class", generateCall($$.classEvent, $$)) .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; - if ($$[dragging]) { return; } // do nothing if dragging - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$.dragging) { return; } // do nothing if dragging + if ($$.hasArcType($$.data.targets)) { return; } selectedData = $$.data.targets.map(function (t) { - return $$[addName]($$[getValueOnIndex](t.values, index)); + return $$.addName($$.getValueOnIndex(t.values, index)); }); // Sort selectedData as names order @@ -1686,69 +1622,69 @@ selectedData = newData.concat(selectedData); // Add remained // Expand shapes for selection - if (config[__point_focus_expand_enabled]) { $$[expandCircles](index); } - $$[expandBars](index); + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } + $$.expandBars(index); // Call event handler - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each( - generateCall(config[__data_onmouseover], $$) - ); + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + config[__data_onmouseover].call(c3, d); + }); }) .on('mouseout', function (d) { var index = d.index; - if ($$[hasArcType]($$.data.targets)) { return; } - $$[hideXGridFocus](); - $$[hideTooltip](); + if ($$.hasArcType($$.data.targets)) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); // Undo expanded shapes - $$[unexpandCircles](index); - $$[unexpandBars](); + $$.unexpandCircles(index); + $$.unexpandBars(); // Call event handler - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each( - generateCall(config[__data_onmouseout], $$) - ); + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + config[__data_onmouseout].call($$, d); + }); }) .on('mousemove', function (d) { var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); + eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); - if ($$[dragging]) { return; } // do nothing when dragging - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType($$.data.targets)) { return; } // Show tooltip - selectedData = $$[filterTargetsToShow]($$.data.targets).map(function (t) { - return $$[addName]($$[getValueOnIndex](t.values, index)); + selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); }); if (config[__tooltip_grouped]) { - $$[showTooltip](selectedData, d3.mouse(this)); - $$[showXGridFocus](selectedData); + $$.showTooltip(selectedData, d3.mouse(this)); + $$.showXGridFocus(selectedData); } if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { return; } - $$.main.selectAll('.' + CLASS[shape] + '-' + index) + $$.main.selectAll('.' + CLASS.shape + '-' + index) .each(function () { - d3.select(this).classed(CLASS[EXPANDED], true); + d3.select(this).classed(CLASS.EXPANDED, true); if (config[__data_selection_enabled]) { eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); } if (!config[__tooltip_grouped]) { - $$[hideXGridFocus](); - $$[hideTooltip](); + $$.hideXGridFocus(); + $$.hideTooltip(); if (!config[__data_selection_grouped]) { - $$[unexpandCircles](index); - $$[unexpandBars](); + $$.unexpandCircles(index); + $$.unexpandBars(); } } }) .filter(function (d) { if (this.nodeName === 'circle') { - return $$[isWithinCircle](this, $$[pointSelectR](d)); + return $$.isWithinCircle(this, $$.pointSelectR(d)); } else if (this.nodeName === 'path') { - return $$[isWithinBar](this); + return $$.isWithinBar(this); } }) .each(function (d) { @@ -1756,115 +1692,114 @@ eventRect.style('cursor', 'pointer'); } if (!config[__tooltip_grouped]) { - $$[showTooltip]([d], d3.mouse(this)); - $$[showXGridFocus]([d]); - if (config[__point_focus_expand_enabled]) { $$[expandCircles](index, d.id); } - $$[expandBars](index, d.id); + $$.showTooltip([d], d3.mouse(this)); + $$.showXGridFocus([d]); + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } + $$.expandBars(index, d.id); } }); }) .on('click', function (d) { var index = d.index; - if ($$[hasArcType]($$.data.targets)) { return; } - if ($$[cancelClick]) { - $$[cancelClick] = false; + if ($$.hasArcType($$.data.targets)) { return; } + if ($$.cancelClick) { + $$.cancelClick = false; return; } - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { $$[toggleShape](this, d, index); }); + $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); }) .call( d3.behavior.drag().origin(Object) - .on('drag', function () { $$[drag](d3.mouse(this)); }) - .on('dragstart', function () { $$[dragstart](d3.mouse(this)); }) - .on('dragend', function () { $$[dragend](); }) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) ) .on("dblclick.zoom", null); }; - var generateEventRectsForMultipleXs = 'generateEventRectsForMultipleXs'; - c3_chart_internal_fn[generateEventRectsForMultipleXs] = function (eventRectEnter) { + c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append('rect') .attr('x', 0) .attr('y', 0) .attr('width', $$.width) .attr('height', $$.height) - .attr(CSS_CLASS, CLASS[eventRect]) + .attr('class', CLASS.eventRect) .on('mouseout', function () { - if ($$[hasArcType]($$.data.targets)) { return; } - $$[hideXGridFocus](); - $$[hideTooltip](); - $$[unexpandCircles](); + if ($$.hasArcType($$.data.targets)) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + $$.unexpandCircles(); }) .on('mousemove', function () { - var targetsToShow = $$[filterTargetsToShow]($$.data.targets); + var targetsToShow = $$.filterTargetsToShow($$.data.targets); var mouse, closest, sameXData, selectedData; - if ($$[dragging]) { return; } // do nothing when dragging - if ($$[hasArcType](targetsToShow)) { return; } + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType(targetsToShow)) { return; } mouse = d3.mouse(this); - closest = $$[findClosestFromTargets](targetsToShow, mouse); + closest = $$.findClosestFromTargets(targetsToShow, mouse); if (! closest) { return; } - if ($$[isScatterType](closest)) { + if ($$.isScatterType(closest)) { sameXData = [closest]; } else { - sameXData = $$[filterSameX](targetsToShow, closest.x); + sameXData = $$.filterSameX(targetsToShow, closest.x); } // show tooltip when cursor is close to some point selectedData = sameXData.map(function (d) { - return $$[addName](d); + return $$.addName(d); }); - $$[showTooltip](selectedData, mouse); + $$.showTooltip(selectedData, mouse); // expand points if (config[__point_focus_expand_enabled]) { - $$[unexpandCircles](); - $$[expandCircles](closest.index, closest.id); + $$.unexpandCircles(); + $$.expandCircles(closest.index, closest.id); } // Show xgrid focus line - $$[showXGridFocus](selectedData); + $$.showXGridFocus(selectedData); // Show cursor as pointer if point is close to mouse position - if ($$[dist](closest, mouse) < 100) { - $$.svg.select('.' + CLASS[eventRect]).style('cursor', 'pointer'); - if (!$$[mouseover]) { + if ($$.dist(closest, mouse) < 100) { + $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); + if (!$$.mouseover) { config[__data_onmouseover].call($$, closest); - $$[mouseover] = true; + $$.mouseover = true; } - } else if ($$[mouseover]) { - $$.svg.select('.' + CLASS[eventRect]).style('cursor', null); + } else if ($$.mouseover) { + $$.svg.select('.' + CLASS.eventRect).style('cursor', null); config[__data_onmouseout].call($$, closest); - $$[mouseover] = false; + $$.mouseover = false; } }) .on('click', function () { - var targetsToShow = $$[filterTargetsToShow]($$.data.targets); + var targetsToShow = $$.filterTargetsToShow($$.data.targets); var mouse, closest; - if ($$[hasArcType](targetsToShow)) { return; } + if ($$.hasArcType(targetsToShow)) { return; } mouse = d3.mouse(this); - closest = $$[findClosestFromTargets](targetsToShow, mouse); + closest = $$.findClosestFromTargets(targetsToShow, mouse); if (! closest) { return; } // select if selection enabled - if ($$[dist](closest, mouse) < 100) { - $$.main.select('.' + CLASS[circles] + $$[getTargetSelectorSuffix](closest.id)).select('.' + CLASS[circle] + '-' + closest.index).each(function () { - $$[toggleShape](this, closest, closest.index); + if ($$.dist(closest, mouse) < 100) { + $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.toggleShape(this, closest, closest.index); }); } }) .call( d3.behavior.drag().origin(Object) - .on('drag', function () { $$[drag](d3.mouse(this)); }) - .on('dragstart', function () { $$[dragstart](d3.mouse(this)); }) - .on('dragend', function () { $$[dragend](); }) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) ) .on("dblclick.zoom", null); }; @@ -1876,101 +1811,90 @@ - var initialOpacity = 'initialOpacity'; - c3_chart_internal_fn[initialOpacity] = function (d) { - return d.value !== null && this[withoutFadeIn][d.id] ? 1 : 0; + c3_chart_internal_fn.initialOpacity = function (d) { + return d.value !== null && this.withoutFadeIn[d.id] ? 1 : 0; }; - var opacityForCircle = 'opacityForCircle'; - c3_chart_internal_fn[opacityForCircle] = function (d) { + c3_chart_internal_fn.opacityForCircle = function (d) { var $$ = this; - return isValue(d.value) ? $$[isScatterType](d) ? 0.5 : 1 : 0; + return isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 0; }; - var opacityForText = 'opacityForText'; - c3_chart_internal_fn[opacityForText] = function () { - return this[hasDataLabel]() ? 1 : 0; + c3_chart_internal_fn.opacityForText = function () { + return this.hasDataLabel() ? 1 : 0; }; - var xx = 'xx'; - c3_chart_internal_fn[xx] = function (d) { - return d ? this[x](d.x) : null; + c3_chart_internal_fn.xx = function (d) { + return d ? this.x(d.x) : null; }; - var xv = 'xv'; - c3_chart_internal_fn[xv] = function (d) { + c3_chart_internal_fn.xv = function (d) { var $$ = this; - return Math.ceil($$[x]($$[isTimeSeries] ? $$[parseDate](d.value) : d.value)); + return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); }; - var yv = 'yv'; - c3_chart_internal_fn[yv] = function (d) { + c3_chart_internal_fn.yv = function (d) { var $$ = this, yScale = d.axis && d.axis === 'y2' ? $$.y2 : $$.y; return Math.ceil(yScale(d.value)); }; - var subxx = 'subxx'; - c3_chart_internal_fn[subxx] = function (d) { - return d ? this[subX](d.x) : null; + c3_chart_internal_fn.subxx = function (d) { + return d ? this.subX(d.x) : null; }; - var transformMain = 'transformMain'; - c3_chart_internal_fn[transformMain] = function (withTransition, transitions) { + 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]); + xAxis = $$.main.select('.' + CLASS.axisX); if (withTransition) { xAxis = xAxis.transition(); } } if (transitions && transitions.axisY) { yAxis = transitions.axisY; } else { - yAxis = $$.main.select('.' + CLASS[axisY]); + yAxis = $$.main.select('.' + CLASS.axisY); if (withTransition) { yAxis = yAxis.transition(); } } if (transitions && transitions.axisY2) { y2Axis = transitions.axisY2; } else { - y2Axis = $$.main.select('.' + CLASS[axisY2]); + y2Axis = $$.main.select('.' + CLASS.axisY2); if (withTransition) { y2Axis = y2Axis.transition(); } } - (withTransition ? $$.main.transition() : $$.main).attr(CSS_TRANSFORM, $$[translate].main); - xAxis.attr(CSS_TRANSFORM, $$[translate].x); - yAxis.attr(CSS_TRANSFORM, $$[translate].y); - y2Axis.attr(CSS_TRANSFORM, $$[translate].y2); - $$.main.select('.' + CLASS[chartArcs]).attr(CSS_TRANSFORM, $$[translate].arc); + (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); + xAxis.attr("transform", $$.translate.x); + yAxis.attr("transform", $$.translate.y); + y2Axis.attr("transform", $$.translate.y2); + $$.main.select('.' + CLASS.chartArcs).attr("transform", $$.translate.arc); }; - var transformLegend = 'transformLegend'; - c3_chart_internal_fn[transformLegend] = function (withTransition) { + c3_chart_internal_fn.transformLegend = function (withTransition) { var $$ = this; - (withTransition ? $$.legend.transition() : $$.legend).attr(CSS_TRANSFORM, $$[translate].legend); + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); }; - var transformAll = 'transformAll'; - c3_chart_internal_fn[transformAll] = function (withTransition, transitions) { + c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; - $$[transformMain](withTransition, transitions); - if (config[__subchart_show]) { $$[transformContext](withTransition, transitions); } - $$[transformLegend](withTransition); + $$.transformMain(withTransition, transitions); + if (config[__subchart_show]) { $$.transformContext(withTransition, transitions); } + $$.transformLegend(withTransition); }; - var updateSvgSize = 'updateSvgSize'; - c3_chart_internal_fn[updateSvgSize] = function () { + c3_chart_internal_fn.updateSvgSize = function () { var $$ = this; $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); - $$.svg.select('#' + $$[clipId]).select('rect') + $$.svg.select('#' + $$.clipId).select('rect') .attr('width', $$.width) .attr('height', $$.height); - $$.svg.select('#' + $$[clipIdForXAxis]).select('rect') - .attr('x', generateCall($$[getXAxisClipX], $$)) - .attr('y', generateCall($$[getXAxisClipY], $$)) - .attr('width', generateCall($$[getXAxisClipWidth], $$)) - .attr('height', generateCall($$[getXAxisClipHeight], $$)); - $$.svg.select('#' + $$[clipIdForYAxis]).select('rect') - .attr('x', generateCall($$[getYAxisClipX], $$)) - .attr('y', generateCall($$[getYAxisClipY], $$)) - .attr('width', generateCall($$[getYAxisClipWidth], $$)) - .attr('height', generateCall($$[getYAxisClipHeight], $$)); - $$.svg.select('.' + CLASS[zoomRect]) + $$.svg.select('#' + $$.clipIdForXAxis).select('rect') + .attr('x', function () { return $$.getXAxisClipX(); }) + .attr('y', function () { return $$.getXAxisClipY(); }) + .attr('width', function () { return $$.getXAxisClipWidth(); }) + .attr('height', function () { return $$.getXAxisClipHeight(); }); + $$.svg.select('#' + $$.clipIdForYAxis).select('rect') + .attr('x', function () { return $$.getYAxisClipX(); }) + .attr('y', function () { return $$.getYAxisClipY(); }) + .attr('width', function () { return $$.getYAxisClipWidth(); }) + .attr('height', function () { return $$.getYAxisClipHeight(); }); + $$.svg.select('.' + CLASS.zoomRect) .attr('width', $$.width) .attr('height', $$.height); // MEMO: parent div's height will be bigger than svg when @@ -1978,8 +1902,7 @@ }; - var updateDimension = 'updateDimension'; - c3_chart_internal_fn[updateDimension] = function () { + c3_chart_internal_fn.updateDimension = function () { var $$ = this; if ($$.config[__axis_rotated]) { $$.axes.x.call($$.xAxis); @@ -1988,14 +1911,13 @@ $$.axes.y.call($$.yAxis); $$.axes.y2.call($$.y2Axis); } - $$[updateSizes](); - $$[updateScales](); - $$[updateSvgSize](); - $$[transformAll](false); + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); + $$.transformAll(false); }; - var observeInserted = 'observeInserted'; - c3_chart_internal_fn[observeInserted] = function (selection) { + c3_chart_internal_fn.observeInserted = function (selection) { var $$ = this, observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { if (mutation.type === 'childList' && mutation.previousSibling) { @@ -2005,8 +1927,8 @@ // parentNode will NOT be null when completed if (selection.node().parentNode) { window.clearInterval(interval); - $$[updateDimension](); - $$[redraw]({ + $$.updateDimension(); + $$.redraw({ withTransform: true, withUpdateXDomain: true, withUpdateOrgXDomain: true, @@ -2014,7 +1936,7 @@ withTransitionForTransform: false, withLegend: true }); - selection.transition().style(CSS_OPACITY, 1); + selection.transition().style('opacity', 1); } }, 10); } @@ -2024,8 +1946,7 @@ }; - var generateResize = 'generateResize'; - c3_chart_internal_fn[generateResize] = function () { + c3_chart_internal_fn.generateResize = function () { var resizeFunctions = []; function callResizeFunctions() { resizeFunctions.forEach(function (f) { @@ -2040,53 +1961,46 @@ - var getCurrentWidth = 'getCurrentWidth'; - c3_chart_internal_fn[getCurrentWidth] = function () { + c3_chart_internal_fn.getCurrentWidth = function () { var $$ = this, config = $$.config; - return config[__size_width] ? config[__size_width] : $$[getParentWidth](); + return config[__size_width] ? config[__size_width] : $$.getParentWidth(); }; - var getCurrentHeight = 'getCurrentHeight'; - c3_chart_internal_fn[getCurrentHeight] = function () { + c3_chart_internal_fn.getCurrentHeight = function () { var $$ = this, config = $$.config, - h = config[__size_height] ? config[__size_height] : $$[getParentHeight](); + h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); return h > 0 ? h : 320; }; - var getCurrentPaddingTop = 'getCurrentPaddingTop'; - c3_chart_internal_fn[getCurrentPaddingTop] = function () { + c3_chart_internal_fn.getCurrentPaddingTop = function () { var config = this.config; return isValue(config[__padding_top]) ? config[__padding_top] : 0; }; - var getCurrentPaddingBottom = 'getCurrentPaddingBottom'; - c3_chart_internal_fn[getCurrentPaddingBottom] = function () { + c3_chart_internal_fn.getCurrentPaddingBottom = function () { var config = this.config; return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; }; - var getCurrentPaddingLeft = 'getCurrentPaddingLeft'; - c3_chart_internal_fn[getCurrentPaddingLeft] = function () { + c3_chart_internal_fn.getCurrentPaddingLeft = function () { var $$ = this, config = $$.config; if (isValue(config[__padding_left])) { return config[__padding_left]; } else if (config[__axis_rotated]) { - return !config[__axis_x_show] ? 1 : Math.max(ceil10($$[getAxisWidthByAxisId]('x')), 40); + return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); } else { - return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$[getAxisWidthByAxisId]('y')); + return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); } }; - var getCurrentPaddingRight = 'getCurrentPaddingRight'; - c3_chart_internal_fn[getCurrentPaddingRight] = function () { + c3_chart_internal_fn.getCurrentPaddingRight = function () { var $$ = this, config = $$.config, - defaultPadding = 10, legendWidthOnRight = $$[isLegendRight] ? $$[getLegendWidth]() + 20 : 0; + defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; if (isValue(config[__padding_right])) { return config[__padding_right] + 1; // 1 is needed not to hide tick line } else if (config[__axis_rotated]) { return defaultPadding + legendWidthOnRight; } else { - return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$[getAxisWidthByAxisId]('y2'))) + legendWidthOnRight; + return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; - var getParentRectValue = 'getParentRectValue'; - c3_chart_internal_fn[getParentRectValue] = function (key) { + c3_chart_internal_fn.getParentRectValue = function (key) { var parent = this.selectChart.node(), v; while (parent && parent.tagName !== 'BODY') { v = parent.getBoundingClientRect()[key]; @@ -2097,60 +2011,54 @@ } return v; }; - var getParentWidth = 'getParentWidth'; - c3_chart_internal_fn[getParentWidth] = function () { - return this[getParentRectValue]('width'); + c3_chart_internal_fn.getParentWidth = function () { + return this.getParentRectValue('width'); }; - var getParentHeight = 'getParentHeight'; - c3_chart_internal_fn[getParentHeight] = function () { + c3_chart_internal_fn.getParentHeight = function () { var h = this.selectChart.style('height'); return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; }; - var getSvgLeft = 'getSvgLeft'; - c3_chart_internal_fn[getSvgLeft] = function () { + c3_chart_internal_fn.getSvgLeft = function () { var $$ = this, config = $$.config, - leftAxisClass = config[__axis_rotated] ? CLASS[axisX] : CLASS[axisY], + leftAxisClass = config[__axis_rotated] ? CLASS.axisX : CLASS.axisY, leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$[hasArcType]($$.data.targets), - svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$[getCurrentPaddingLeft]()); + hasArc = $$.hasArcType($$.data.targets), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); return svgLeft > 0 ? svgLeft : 0; }; - var getAxisWidthByAxisId = 'getAxisWidthByAxisId'; - c3_chart_internal_fn[getAxisWidthByAxisId] = function (id) { - var $$ = this, position = $$[getAxisLabelPositionById](id); - return position.isInner ? 20 + $$[getMaxTickWidth](id) : 40 + $$[getMaxTickWidth](id); + c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { + var $$ = this, position = $$.getAxisLabelPositionById(id); + return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); }; - var getHorizontalAxisHeight = 'getHorizontalAxisHeight'; - c3_chart_internal_fn[getHorizontalAxisHeight] = function (axisId) { + c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { var $$ = this, config = $$.config; if (axisId === 'x' && !config[__axis_x_show]) { return 0; } if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } - if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$[isLegendRight] && !$$[isLegendInset] ? 10 : 1; } - if (axisId === 'y2' && !config[__axis_y2_show]) { return $$[rotated_padding_top]; } - return ($$[getAxisLabelPositionById](axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } + return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); }; - var getEventRectWidth = 'getEventRectWidth'; - c3_chart_internal_fn[getEventRectWidth] = function () { + c3_chart_internal_fn.getEventRectWidth = function () { var $$ = this; - var target = $$[getMaxDataCountTarget]($$.data.targets), + var target = $$.getMaxDataCountTarget($$.data.targets), firstData, lastData, base, maxDataCount, ratio, w; if (!target) { return 0; } firstData = target.values[0], lastData = target.values[target.values.length - 1]; - base = $$[x](lastData.x) - $$[x](firstData.x); + base = $$.x(lastData.x) - $$.x(firstData.x); if (base === 0) { return $$.config[__axis_rotated] ? $$.height : $$.width; } - maxDataCount = $$[getMaxDataCount](); - ratio = ($$[hasType]($$.data.targets, TYPE_BAR) ? (maxDataCount - ($$[isCategorized] ? 0.25 : 1)) / maxDataCount : 1); + maxDataCount = $$.getMaxDataCount(); + ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2159,16 +2067,15 @@ /** * c3.tooltip.js */ - var showTooltip = 'showTooltip'; - c3_chart_internal_fn[showTooltip] = function (selectedData, mouse) { + c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$[hasArcType]($$.data.targets), + var forArc = $$.hasArcType($$.data.targets), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !config[__tooltip_show]) { return; } - $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$[getXAxisTickFormat](), $$[getYFormat](forArc), $$.color)).style("display", "block"); + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); // Get tooltip dimensions tWidth = $$.tooltip.property('offsetWidth'); @@ -2179,23 +2086,23 @@ tooltipTop = ($$.height / 2) + mouse[1] + 20; } else { if (config[__axis_rotated]) { - svgLeft = $$[getSvgLeft](); + svgLeft = $$.getSvgLeft(); tooltipLeft = svgLeft + mouse[0] + 100; tooltipRight = tooltipLeft + tWidth; - chartRight = $$[getCurrentWidth]() - $$[getCurrentPaddingRight](); - tooltipTop = $$[x](dataToShow[0].x) + 20; + chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = $$.x(dataToShow[0].x) + 20; } else { - svgLeft = $$[getSvgLeft](); - tooltipLeft = svgLeft + $$[getCurrentPaddingLeft]() + $$[x](dataToShow[0].x) + 20; + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; tooltipRight = tooltipLeft + tWidth; - chartRight = svgLeft + $$[getCurrentWidth]() - $$[getCurrentPaddingRight](); + chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); tooltipTop = mouse[1] + 15; } if (tooltipRight > chartRight) { tooltipLeft -= tooltipRight - chartRight; } - if (tooltipTop + tHeight > $$[getCurrentHeight]()) { + if (tooltipTop + tHeight > $$.getCurrentHeight()) { tooltipTop -= tHeight + 30; } } @@ -2204,8 +2111,7 @@ .style("top", tooltipTop + "px") .style("left", tooltipLeft + 'px'); }; - var hideTooltip = 'hideTooltip'; - c3_chart_internal_fn[hideTooltip] = function () { + c3_chart_internal_fn.hideTooltip = function () { this.tooltip.style("display", "none"); }; @@ -2213,40 +2119,36 @@ /** * c3.grid.js */ - var showXGridFocus = 'showXGridFocus'; - c3_chart_internal_fn[showXGridFocus] = function (selectedData) { + c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if ($$[hasType]($$.data.targets, TYPE_SCATTER) || $$[hasArcType]($$.data.targets)) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); + if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } + var focusEl = $$.main.selectAll('line.' + CLASS.xgridFocus); focusEl - .style(CSS_VISIBILITY, "visible") + .style("visibility", "visible") .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$[xx], $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$[xx], $$)); - $$[smoothLines](focusEl, 'grid'); + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + $$.smoothLines(focusEl, 'grid'); }; - var hideXGridFocus = 'hideXGridFocus'; - c3_chart_internal_fn[hideXGridFocus] = function () { - this.main.select('line.' + CLASS[xgridFocus]).style(CSS_VISIBILITY, "hidden"); + c3_chart_internal_fn.hideXGridFocus = function () { + this.main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); }; - var updateXgridFocus = 'updateXgridFocus'; - c3_chart_internal_fn[updateXgridFocus] = function () { + c3_chart_internal_fn.updateXgridFocus = function () { var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS[xgridFocus]) + $$.main.select('line.' + CLASS.xgridFocus) .attr("x1", config[__axis_rotated] ? 0 : -10) .attr("x2", config[__axis_rotated] ? $$.width : -10) .attr("y1", config[__axis_rotated] ? -10 : 0) .attr("y2", config[__axis_rotated] ? -10 : $$.height); }; - var generateGridData = 'generateGridData'; - c3_chart_internal_fn[generateGridData] = function (type, scale) { + c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS[axisX]).selectAll('.tick').size(); + tickNum = $$.main.select("." + CLASS.axisX).selectAll('.tick').size(); if (type === 'year') { - xDomain = $$[getXDomain](); + xDomain = $$.getXDomain(); firstYear = xDomain[0].getFullYear(); lastYear = xDomain[1].getFullYear(); for (i = firstYear; i <= lastYear; i++) { @@ -2260,28 +2162,26 @@ } return gridData; }; - var getGridFilterToRemove = 'getGridFilterToRemove'; - c3_chart_internal_fn[getGridFilterToRemove] = function (params) { + c3_chart_internal_fn.getGridFilterToRemove = function (params) { return params ? function (line) { var found = false; [].concat(params).forEach(function (param) { - if ((('value' in param && line.value === params.value) || (CSS_CLASS in param && line.class === params.class))) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { found = true; } }); return found; } : function () { return true; }; }; - var removeGridLines = 'removeGridLines'; - c3_chart_internal_fn[removeGridLines] = function (params, forX) { + c3_chart_internal_fn.removeGridLines = function (params, forX) { var $$ = this, config = $$.config, - toRemove = $$[getGridFilterToRemove](params), + toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS[xgridLines] : CLASS[ygridLines], - classLine = forX ? CLASS[xgridLine] : CLASS.ygridLine; + classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, + classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) .transition().duration(config[__transition_duration]) - .style(CSS_OPACITY, 0).remove(); + .style('opacity', 0).remove(); if (forX) { config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); } else { @@ -2293,101 +2193,89 @@ /** * c3.legend.js */ - var updateLegendStep = 'updateLegendStep'; - c3_chart_internal_fn[updateLegendStep] = function (step) { - this[legendStep] = step; + c3_chart_internal_fn.updateLegendStep = function (step) { + this.legendStep = step; }; - var updateLegendItemWidth = 'updateLegendItemWidth'; - c3_chart_internal_fn[updateLegendItemWidth] = function (w) { - this[legendItemWidth] = w; + c3_chart_internal_fn.updateLegendItemWidth = function (w) { + this.legendItemWidth = w; }; - var updateLegendItemHeight = 'updateLegendItemHeight'; - c3_chart_internal_fn[updateLegendItemHeight] = function (h) { - this[legendItemHeight] = h; + c3_chart_internal_fn.updateLegendItemHeight = function (h) { + this.legendItemHeight = h; }; - var getLegendWidth = 'getLegendWidth'; - c3_chart_internal_fn[getLegendWidth] = function () { + c3_chart_internal_fn.getLegendWidth = function () { var $$ = this; - return $$.config[__legend_show] ? $$[isLegendRight] || $$[isLegendInset] ? $$[legendItemWidth] * ($$[legendStep] + 1) : $$.currentWidth : 0; + return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; }; - var getLegendHeight = 'getLegendHeight'; - c3_chart_internal_fn[getLegendHeight] = function () { + c3_chart_internal_fn.getLegendHeight = function () { var $$ = this, config = $$.config, h = 0; if (config[__legend_show]) { - if ($$[isLegendRight]) { + if ($$.isLegendRight) { h = $$.currentHeight; - } else if ($$[isLegendInset]) { - h = config[__legend_inset_step] ? Math.max(20, $$[legendItemHeight]) * (config[__legend_inset_step] + 1) : $$.height; + } else if ($$.isLegendInset) { + h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; } else { - h = Math.max(20, $$[legendItemHeight]) * ($$[legendStep] + 1); + h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); } } return h; }; - var opacityForLegend = 'opacityForLegend'; - c3_chart_internal_fn[opacityForLegend] = function (legendItem) { + c3_chart_internal_fn.opacityForLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS[legendItemHidden]) ? $$[legendOpacityForHidden] : 1; + return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; }; - var opacityForUnfocusedLegend = 'opacityForUnfocusedLegend'; - c3_chart_internal_fn[opacityForUnfocusedLegend] = function (legendItem) { + c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS[legendItemHidden]) ? $$[legendOpacityForHidden] : 0.3; + return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; }; - var toggleFocusLegend = 'toggleFocusLegend'; - c3_chart_internal_fn[toggleFocusLegend] = function (id, focus) { + c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { var $$ = this; - $$.legend.selectAll('.' + CLASS[legendItem]) + $$.legend.selectAll('.' + CLASS.legendItem) .transition().duration(100) - .style(CSS_OPACITY, function (_id) { + .style('opacity', function (_id) { var This = $$.d3.select(this); if (id && _id !== id) { - return focus ? $$[opacityForUnfocusedLegend](This) : $$[opacityForLegend](This); + return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); } else { - return focus ? $$[opacityForLegend](This) : $$[opacityForUnfocusedLegend](This); + return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); } }); }; - var revertLegend = 'revertLegend'; - c3_chart_internal_fn[revertLegend] = function () { + c3_chart_internal_fn.revertLegend = function () { var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + CLASS[legendItem]) + $$.legend.selectAll('.' + CLASS.legendItem) .transition().duration(100) - .style(CSS_OPACITY, function () { return $$[opacityForLegend](d3.select(this)); }); + .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; - var showLegend = 'showLegend'; - c3_chart_internal_fn[showLegend] = function (targetIds) { + c3_chart_internal_fn.showLegend = function (targetIds) { var $$ = this, config = $$.config; if (!config[__legend_show]) { config[__legend_show] = true; - $$.legend.style(CSS_VISIBILITY, 'visible'); + $$.legend.style('visibility', 'visible'); } - $$[removeHiddenLegendIds](targetIds); - $$.legend.selectAll($$[selectorLegends](targetIds)) - .style(CSS_VISIBILITY, 'visible') + $$.removeHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('visibility', 'visible') .transition() - .style(CSS_OPACITY, function () { return $$[opacityForLegend]($$.d3.select(this)); }); + .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); }; - var hideLegend = 'hideLegend'; - c3_chart_internal_fn[hideLegend] = function (targetIds) { + c3_chart_internal_fn.hideLegend = function (targetIds) { var $$ = this, config = $$.config; if (config[__legend_show] && isEmpty(targetIds)) { config[__legend_show] = false; - $$.legend.style(CSS_VISIBILITY, 'hidden'); + $$.legend.style('visibility', 'hidden'); } - $$[addHiddenLegendIds](targetIds); - $$.legend.selectAll($$[selectorLegends](targetIds)) - .style(CSS_OPACITY, 0) - .style(CSS_VISIBILITY, 'hidden'); + $$.addHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('opacity', 0) + .style('visibility', 'hidden'); }; - var updateLegend = 'updateLegend'; - c3_chart_internal_fn[updateLegend] = function (targetIds, options, transitions) { + c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { var $$ = this, config = $$.config; var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + CLASS[legendItemFocused]).size(); + var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); var texts, rects, tiles; options = options || {}; @@ -2395,11 +2283,11 @@ withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$[getTextRect](textElement.textContent, CLASS[legendItem]), + var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, - itemLength = $$[isLegendRight] || $$[isLegendInset] ? itemHeight : itemWidth, - areaLength = $$[isLegendRight] || $$[isLegendInset] ? $$[getLegendHeight]() : $$[getLegendWidth](), + itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, + areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), margin, maxLength; // MEMO: care about condifion of step, totalLength @@ -2413,7 +2301,7 @@ } } steps[id] = step; - margins[step] = $$[isLegendInset] ? 10 : margin; + margins[step] = $$.isLegendInset ? 10 : margin; offsets[id] = totalLength; totalLength += itemLength; } @@ -2425,7 +2313,7 @@ maxHeight = 0; } - if (config[__legend_show] && !$$[isLegendToShow](id)) { + if (config[__legend_show] && !$$.isLegendToShow(id)) { widths[id] = heights[id] = steps[id] = offsets[id] = 0; return; } @@ -2435,7 +2323,7 @@ if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } - maxLength = $$[isLegendRight] || $$[isLegendInset] ? maxHeight : maxWidth; + maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; if (config[__legend_equally]) { Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); @@ -2454,10 +2342,10 @@ } } - if ($$[isLegendRight]) { + if ($$.isLegendRight) { xForLegend = function (id) { return maxWidth * steps[id]; }; yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else if ($$[isLegendInset]) { + } else if ($$.isLegendInset) { xForLegend = function (id) { return maxWidth * steps[id] + 10; }; yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; } else { @@ -2470,18 +2358,18 @@ yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; // Define g for legend area - l = $$.legend.selectAll('.' + CLASS[legendItem]) + l = $$.legend.selectAll('.' + CLASS.legendItem) .data(targetIds) .enter().append('g') - .attr(CSS_CLASS, function (id) { return $$[generateClass](CLASS[legendItem], id); }) - .style(CSS_VISIBILITY, function (id) { return $$[isLegendToShow](id) ? 'visible' : 'hidden'; }) + .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) + .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { - $$.d3.select(this).classed(CLASS[legendItemFocused], true); - if (!$$[transiting]) { + $$.d3.select(this).classed(CLASS.legendItemFocused, true); + if (!$$.transiting) { $$.api.focus(id); } if (isFunction(config[__legend_item_onmouseover])) { @@ -2489,8 +2377,8 @@ } }) .on('mouseout', function (id) { - $$.d3.select(this).classed(CLASS[legendItemFocused], false); - if (!$$[transiting]) { + $$.d3.select(this).classed(CLASS.legendItemFocused, false); + if (!$$.transiting) { $$.api.revert(); } if (isFunction(config[__legend_item_onmouseout])) { @@ -2500,28 +2388,28 @@ l.append('text') .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) .each(function (id, i) { updatePositions(this, id, i === 0); }) - .style(CSS_POINTER_EVENTS, "none") - .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendText : -200) - .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegendText); + .style("pointer-events", "none") + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); l.append('rect') - .attr(CSS_CLASS, CLASS[legendItemEvent]) - .style(CSS_FILL_OPACITY, 0) - .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendRect : -200) - .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegendRect); + .attr("class", CLASS.legendItemEvent) + .style('fill-opacity', 0) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); l.append('rect') - .attr(CSS_CLASS, CLASS[legendItemTile]) - .style(CSS_POINTER_EVENTS, "none") + .attr("class", CLASS.legendItemTile) + .style("pointer-events", "none") .style('fill', $$.color) - .attr('x', $$[isLegendRight] || $$[isLegendInset] ? xForLegendText : -200) - .attr('y', $$[isLegendRight] || $$[isLegendInset] ? -200 : yForLegend) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) .attr('width', 10) .attr('height', 10); // Set background for inset legend - if ($$[isLegendInset] && maxWidth !== 0) { - $$.legend.insert('g', '.' + CLASS[legendItem]) - .attr(CSS_CLASS, CLASS[legendBackground]) + if ($$.isLegendInset && maxWidth !== 0) { + $$.legend.insert('g', '.' + CLASS.legendItem) + .attr("class", CLASS.legendBackground) .append('rect') - .attr('height', $$[getLegendHeight]() - 10) + .attr('height', $$.getLegendHeight() - 10) .attr('width', maxWidth * (step + 1) + 10); } @@ -2533,7 +2421,7 @@ .attr('x', xForLegendText) .attr('y', yForLegendText); - rects = $$.legend.selectAll('rect.' + CLASS[legendItemEvent]) + rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent) .data(targetIds); (withTransition ? rects.transition() : rects) .attr('width', function (id) { return widths[id]; }) @@ -2541,7 +2429,7 @@ .attr('x', xForLegendRect) .attr('y', yForLegendRect); - tiles = $$.legend.selectAll('rect.' + CLASS[legendItemTile]) + tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) .data(targetIds); (withTransition ? tiles.transition() : tiles) .style('fill', $$.color) @@ -2549,157 +2437,134 @@ .attr('y', yForLegend); // toggle legend state - $$.legend.selectAll('.' + CLASS[legendItem]) - .classed(CLASS[legendItemHidden], function (id) { return !$$[isTargetToShow](id); }) + $$.legend.selectAll('.' + CLASS.legendItem) + .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) .transition() - .style(CSS_OPACITY, function (id) { + .style('opacity', function (id) { var This = $$.d3.select(this); - if ($$[isTargetToShow](id)) { - return !hasFocused || This.classed(CLASS[legendItemFocused]) ? $$[opacityForLegend](This) : $$[opacityForUnfocusedLegend](This); + if ($$.isTargetToShow(id)) { + return !hasFocused || This.classed(CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); } else { - return $$[legendOpacityForHidden]; + return $$.legendOpacityForHidden; } }); // Update all to reflect change of legend - $$[updateLegendItemWidth](maxWidth); - $$[updateLegendItemHeight](maxHeight); - $$[updateLegendStep](step); + $$.updateLegendItemWidth(maxWidth); + $$.updateLegendItemHeight(maxHeight); + $$.updateLegendStep(step); // Update size and scale - $$[updateSizes](); - $$[updateScales](); - $$[updateSvgSize](); + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); // Update g positions - $$[transformAll](withTransitionForTransform, transitions); + $$.transformAll(withTransitionForTransform, transitions); }; - var getClipPath = 'getClipPath'; - c3_chart_internal_fn[getClipPath] = function (id) { + c3_chart_internal_fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; }; - var getAxisClipX = 'getAxisClipX'; - c3_chart_internal_fn[getAxisClipX] = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { // axis line width + padding for left return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); }; - var getAxisClipY = 'getAxisClipY'; - c3_chart_internal_fn[getAxisClipY] = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { return forHorizontal ? -20 : -4; }; - var getXAxisClipX = 'getXAxisClipX'; - c3_chart_internal_fn[getXAxisClipX] = function () { + c3_chart_internal_fn.getXAxisClipX = function () { var $$ = this; - return $$[getAxisClipX](!$$.config[__axis_rotated]); + return $$.getAxisClipX(!$$.config[__axis_rotated]); }; - var getXAxisClipY = 'getXAxisClipY'; - c3_chart_internal_fn[getXAxisClipY] = function () { + c3_chart_internal_fn.getXAxisClipY = function () { var $$ = this; - return $$[getAxisClipY](!$$.config[__axis_rotated]); + return $$.getAxisClipY(!$$.config[__axis_rotated]); }; - var getYAxisClipX = 'getYAxisClipX'; - c3_chart_internal_fn[getYAxisClipX] = function () { + c3_chart_internal_fn.getYAxisClipX = function () { var $$ = this; - return $$[getAxisClipX]($$.config[__axis_rotated]); + return $$.getAxisClipX($$.config[__axis_rotated]); }; - var getYAxisClipY = 'getYAxisClipY'; - c3_chart_internal_fn[getYAxisClipY] = function () { + c3_chart_internal_fn.getYAxisClipY = function () { var $$ = this; - return $$[getAxisClipY]($$.config[__axis_rotated]); + return $$.getAxisClipY($$.config[__axis_rotated]); }; - var getAxisClipWidth = 'getAxisClipWidth'; - c3_chart_internal_fn[getAxisClipWidth] = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { var $$ = this; // width + axis line width + padding for left/right return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; - var getAxisClipHeight = 'getAxisClipHeight'; - c3_chart_internal_fn[getAxisClipHeight] = function (forHorizontal) { + c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { var $$ = this, config = $$.config; return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; }; - var getXAxisClipWidth = 'getXAxisClipWidth'; - c3_chart_internal_fn[getXAxisClipWidth] = function () { + c3_chart_internal_fn.getXAxisClipWidth = function () { var $$ = this; - return $$[getAxisClipWidth](!$$.config[__axis_rotated]); + return $$.getAxisClipWidth(!$$.config[__axis_rotated]); }; - var getXAxisClipHeight = 'getXAxisClipHeight'; - c3_chart_internal_fn[getXAxisClipHeight] = function () { + c3_chart_internal_fn.getXAxisClipHeight = function () { var $$ = this; - return $$[getAxisClipHeight](!$$.config[__axis_rotated]); + return $$.getAxisClipHeight(!$$.config[__axis_rotated]); }; - var getYAxisClipWidth = 'getYAxisClipWidth'; - c3_chart_internal_fn[getYAxisClipWidth] = function () { + c3_chart_internal_fn.getYAxisClipWidth = function () { var $$ = this; - return $$[getAxisClipWidth]($$.config[__axis_rotated]); + return $$.getAxisClipWidth($$.config[__axis_rotated]); }; - var getYAxisClipHeight = 'getYAxisClipHeight'; - c3_chart_internal_fn[getYAxisClipHeight] = function () { + c3_chart_internal_fn.getYAxisClipHeight = function () { var $$ = this; - return $$[getAxisClipHeight]($$.config[__axis_rotated]); + return $$.getAxisClipHeight($$.config[__axis_rotated]); }; /** * $$.data.js */ - var isX = 'isX'; - c3_chart_internal_fn[isX] = function (key) { + c3_chart_internal_fn.isX = function (key) { var $$ = this, config = $$.config; return (config[__data_x] && key === config[__data_x]) || (notEmpty(config[__data_xs]) && hasValue(config[__data_xs], key)); }; - var isNotX = 'isNotX'; - c3_chart_internal_fn[isNotX] = function (key) { - return !this[isX](key); + c3_chart_internal_fn.isNotX = function (key) { + return !this.isX(key); }; - var getXKey = 'getXKey'; - c3_chart_internal_fn[getXKey] = function (id) { + c3_chart_internal_fn.getXKey = function (id) { var $$ = this, config = $$.config; return config[__data_x] ? config[__data_x] : notEmpty(config[__data_xs]) ? config[__data_xs][id] : null; }; - var getXValuesOfXKey = 'getXValuesOfXKey'; - c3_chart_internal_fn[getXValuesOfXKey] = function (key, targets) { + c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { var $$ = this, - xValues, ids = targets && notEmpty(targets) ? $$[mapToIds](targets) : []; + xValues, ids = targets && notEmpty(targets) ? $$.mapToIds(targets) : []; ids.forEach(function (id) { - if ($$[getXKey](id) === key) { + if ($$.getXKey(id) === key) { xValues = $$.data.xs[id]; } }); return xValues; }; - var getXValue = 'getXValue'; - c3_chart_internal_fn[getXValue] = function (id, i) { + c3_chart_internal_fn.getXValue = function (id, i) { var $$ = this; return id in $$.data.xs && $$.data.xs[id] && isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; }; - var getOtherTargetXs = 'getOtherTargetXs'; - c3_chart_internal_fn[getOtherTargetXs] = function () { + c3_chart_internal_fn.getOtherTargetXs = function () { var $$ = this, idsForX = Object.keys($$.data.xs); return idsForX.length ? $$.data.xs[idsForX[0]] : null; }; - var getOtherTargetX = 'getOtherTargetX'; - c3_chart_internal_fn[getOtherTargetX] = function (index) { - var xs = this[getOtherTargetXs](); + c3_chart_internal_fn.getOtherTargetX = function (index) { + var xs = this.getOtherTargetXs(); return xs && index < xs.length ? xs[index] : null; }; - var addXs = 'addXs'; - c3_chart_internal_fn[addXs] = function (xs) { + c3_chart_internal_fn.addXs = function (xs) { var $$ = this; Object.keys(xs).forEach(function (id) { $$.config[__data_xs][id] = xs[id]; }); }; - var isSingleX = 'isSingleX'; - c3_chart_internal_fn[isSingleX] = function (xs) { + c3_chart_internal_fn.isSingleX = function (xs) { return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; }; - var addName = 'addName'; - c3_chart_internal_fn[addName] = function (data) { + c3_chart_internal_fn.addName = function (data) { var $$ = this, name; if (data) { name = $$.config[__data_names][data.id]; @@ -2707,59 +2572,53 @@ } return data; }; - var getValueOnIndex = 'getValueOnIndex'; - c3_chart_internal_fn[getValueOnIndex] = function (values, index) { + c3_chart_internal_fn.getValueOnIndex = function (values, index) { var valueOnIndex = values.filter(function (v) { return v.index === index; }); return valueOnIndex.length ? valueOnIndex[0] : null; }; - var updateTargetX = 'updateTargetX'; - c3_chart_internal_fn[updateTargetX] = function (targets, x) { + c3_chart_internal_fn.updateTargetX = function (targets, x) { var $$ = this; targets.forEach(function (t) { t.values.forEach(function (v, i) { - v.x = $$[generateTargetX](x[i], t.id, i); + v.x = $$.generateTargetX(x[i], t.id, i); }); $$.data.xs[t.id] = x; }); }; - var updateTargetXs = 'updateTargetXs'; - c3_chart_internal_fn[updateTargetXs] = function (targets, xs) { + c3_chart_internal_fn.updateTargetXs = function (targets, xs) { var $$ = this; targets.forEach(function (t) { if (xs[t.id]) { - $$[updateTargetX]([t], xs[t.id]); + $$.updateTargetX([t], xs[t.id]); } }); }; - var generateTargetX = 'generateTargetX'; - c3_chart_internal_fn[generateTargetX] = function (rawX, id, index) { + c3_chart_internal_fn.generateTargetX = function (rawX, id, index) { var $$ = this, x; - if ($$[isTimeSeries]) { - x = rawX ? $$[parseDate](rawX) : $$[parseDate]($$[getXValue](id, index)); + if ($$.isTimeSeries) { + x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); } - else if ($$[isCustomX]() && !$$[isCategorized]) { - x = isValue(rawX) ? +rawX : $$[getXValue](id, index); + else if ($$.isCustomX() && !$$.isCategorized) { + x = isValue(rawX) ? +rawX : $$.getXValue(id, index); } else { x = index; } return x; }; - var convertUrlToData = 'convertUrlToData'; - c3_chart_internal_fn[convertUrlToData] = function (url, mimeType, keys, done) { + c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { var $$ = this, type = mimeType ? mimeType : 'csv'; $$.d3.xhr(url, function (error, data) { var d; if (type === 'json') { - d = $$[convertJsonToData](JSON.parse(data.response), keys); + d = $$.convertJsonToData(JSON.parse(data.response), keys); } else { - d = $$[convertCsvToData](data.response); + d = $$.convertCsvToData(data.response); } done(d); }); }; - var cloneTarget = 'cloneTarget'; - c3_chart_internal_fn[cloneTarget] = function (target) { + c3_chart_internal_fn.cloneTarget = function (target) { return { id : target.id, id_org : target.id_org, @@ -2768,23 +2627,19 @@ }) }; }; - var getPrevX = 'getPrevX'; - c3_chart_internal_fn[getPrevX] = function (i) { - var $$ = this, value = $$[getValueOnIndex]($$.data.targets[0].values, i - 1); + c3_chart_internal_fn.getPrevX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); return value ? value.x : null; }; - var getNextX = 'getNextX'; - c3_chart_internal_fn[getNextX] = function (i) { - var $$ = this, value = $$[getValueOnIndex]($$.data.targets[0].values, i + 1); + c3_chart_internal_fn.getNextX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); return value ? value.x : null; }; - var getMaxDataCount = 'getMaxDataCount'; - c3_chart_internal_fn[getMaxDataCount] = function () { + c3_chart_internal_fn.getMaxDataCount = function () { var $$ = this; return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); }; - var getMaxDataCountTarget = 'getMaxDataCountTarget'; - c3_chart_internal_fn[getMaxDataCountTarget] = function (targets) { + c3_chart_internal_fn.getMaxDataCountTarget = function (targets) { var length = targets.length, max = 0, maxTarget; if (length > 1) { targets.forEach(function (t) { @@ -2798,27 +2653,23 @@ } return maxTarget; }; - var getEdgeX = 'getEdgeX'; - c3_chart_internal_fn[getEdgeX] = function (targets) { - var target = this[getMaxDataCountTarget](targets), firstData, lastData; + c3_chart_internal_fn.getEdgeX = function (targets) { + var target = this.getMaxDataCountTarget(targets), firstData, lastData; if (!target) { return [0, 0]; } firstData = target.values[0], lastData = target.values[target.values.length - 1]; return [firstData.x, lastData.x]; }; - var mapToIds = 'mapToIds'; - c3_chart_internal_fn[mapToIds] = function (targets) { + c3_chart_internal_fn.mapToIds = function (targets) { return targets.map(function (d) { return d.id; }); }; - var mapToTargetIds = 'mapToTargetIds'; - c3_chart_internal_fn[mapToTargetIds] = function (ids) { + c3_chart_internal_fn.mapToTargetIds = function (ids) { var $$ = this; - return ids ? (isString(ids) ? [ids] : ids) : $$[mapToIds]($$.data.targets); + return ids ? (isString(ids) ? [ids] : ids) : $$.mapToIds($$.data.targets); }; - var hasTarget = 'hasTarget'; - c3_chart_internal_fn[hasTarget] = function (targets, id) { - var ids = this[mapToIds](targets), i; + c3_chart_internal_fn.hasTarget = function (targets, id) { + var ids = this.mapToIds(targets), i; for (i = 0; i < ids.length; i++) { if (ids[i] === id) { return true; @@ -2826,43 +2677,34 @@ } return false; }; - var isTargetToShow = 'isTargetToShow'; - c3_chart_internal_fn[isTargetToShow] = function (targetId) { - return this[hiddenTargetIds].indexOf(targetId) < 0; + c3_chart_internal_fn.isTargetToShow = function (targetId) { + return this.hiddenTargetIds.indexOf(targetId) < 0; }; - var isLegendToShow = 'isLegendToShow'; - c3_chart_internal_fn[isLegendToShow] = function (targetId) { - return this[hiddenLegendIds].indexOf(targetId) < 0; + c3_chart_internal_fn.isLegendToShow = function (targetId) { + return this.hiddenLegendIds.indexOf(targetId) < 0; }; - var filterTargetsToShow = 'filterTargetsToShow'; - c3_chart_internal_fn[filterTargetsToShow] = function (targets) { + c3_chart_internal_fn.filterTargetsToShow = function (targets) { var $$ = this; - return targets.filter(function (t) { return $$[isTargetToShow](t.id); }); + return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); }; - var mapTargetsToUniqueXs = 'mapTargetsToUniqueXs'; - c3_chart_internal_fn[mapTargetsToUniqueXs] = function (targets) { + c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { var $$ = this; var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); - return $$[isTimeSeries] ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); + return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); }; - var addHiddenTargetIds = 'addHiddenTargetIds'; - c3_chart_internal_fn[addHiddenTargetIds] = function (targetIds) { - this[hiddenTargetIds] = this[hiddenTargetIds].concat(targetIds); + c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); }; - var removeHiddenTargetIds = 'removeHiddenTargetIds'; - c3_chart_internal_fn[removeHiddenTargetIds] = function (targetIds) { - this[hiddenTargetIds] = this[hiddenTargetIds].filter(function (id) { return targetIds.indexOf(id) < 0; }); + c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - var addHiddenLegendIds = 'addHiddenLegendIds'; - c3_chart_internal_fn[addHiddenLegendIds] = function (targetIds) { - this[hiddenLegendIds] = this[hiddenLegendIds].concat(targetIds); + c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); }; - var removeHiddenLegendIds = 'removeHiddenLegendIds'; - c3_chart_internal_fn[removeHiddenLegendIds] = function (targetIds) { - this[hiddenLegendIds] = this[hiddenLegendIds].filter(function (id) { return targetIds.indexOf(id) < 0; }); + c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); }; - var getValuesAsIdKeyed = 'getValuesAsIdKeyed'; - c3_chart_internal_fn[getValuesAsIdKeyed] = function (targets) { + c3_chart_internal_fn.getValuesAsIdKeyed = function (targets) { var ys = {}; targets.forEach(function (t) { ys[t.id] = []; @@ -2872,8 +2714,7 @@ }); return ys; }; - var checkValueInTargets = 'checkValueInTargets'; - c3_chart_internal_fn[checkValueInTargets] = function (targets, checker) { + c3_chart_internal_fn.checkValueInTargets = function (targets, checker) { var ids = Object.keys(targets), i, j, values; for (i = 0; i < ids.length; i++) { values = targets[ids[i]].values; @@ -2885,27 +2726,22 @@ } return false; }; - var hasNegativeValueInTargets = 'hasNegativeValueInTargets'; - c3_chart_internal_fn[hasNegativeValueInTargets] = function (targets) { - return this[checkValueInTargets](targets, function (v) { return v < 0; }); + c3_chart_internal_fn.hasNegativeValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v < 0; }); }; - var hasPositiveValueInTargets = 'hasPositiveValueInTargets'; - c3_chart_internal_fn[hasPositiveValueInTargets] = function (targets) { - return this[checkValueInTargets](targets, function (v) { return v > 0; }); + c3_chart_internal_fn.hasPositiveValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v > 0; }); }; - var isOrderDesc = 'isOrderDesc'; - c3_chart_internal_fn[isOrderDesc] = function () { + c3_chart_internal_fn.isOrderDesc = function () { var config = this.config; return config[__data_order] && config[__data_order].toLowerCase() === 'desc'; }; - var isOrderAsc = 'isOrderAsc'; - c3_chart_internal_fn[isOrderAsc] = function () { + c3_chart_internal_fn.isOrderAsc = function () { var config = this.config; return config[__data_order] && config[__data_order].toLowerCase() === 'asc'; }; - var orderTargets = 'orderTargets'; - c3_chart_internal_fn[orderTargets] = function (targets) { - var $$ = this, config = $$.config, orderAsc = $$[isOrderAsc](), orderDesc = $$[isOrderDesc](); + c3_chart_internal_fn.orderTargets = function (targets) { + var $$ = this, config = $$.config, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); if (orderAsc || orderDesc) { targets.sort(function (t1, t2) { var reducer = function (p, c) { return p + Math.abs(c.value); }; @@ -2918,16 +2754,13 @@ } // TODO: accept name array for order return targets; }; - var filterSameX = 'filterSameX'; - c3_chart_internal_fn[filterSameX] = function (targets, x) { + c3_chart_internal_fn.filterSameX = function (targets, x) { return this.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); }; - var filterRemoveNull = 'filterRemoveNull'; - c3_chart_internal_fn[filterRemoveNull] = function (data) { + c3_chart_internal_fn.filterRemoveNull = function (data) { return data.filter(function (d) { return isValue(d.value); }); }; - var hasDataLabel = 'hasDataLabel'; - c3_chart_internal_fn[hasDataLabel] = function () { + c3_chart_internal_fn.hasDataLabel = function () { var config = this.config; if (typeof config[__data_labels] === 'boolean' && config[__data_labels]) { return true; @@ -2936,35 +2769,31 @@ } return false; }; - var getDataLabelLength = 'getDataLabelLength'; - c3_chart_internal_fn[getDataLabelLength] = function (min, max, axisId, key) { + c3_chart_internal_fn.getDataLabelLength = function (min, max, axisId, key) { var $$ = this, lengths = [0, 0], paddingCoef = 1.3; $$.selectChart.select('svg').selectAll('.dummy') .data([min, max]) .enter().append('text') - .text(function (d) { return $$[formatByAxisId](axisId)(d); }) + .text(function (d) { return $$.formatByAxisId(axisId)(d); }) .each(function (d, i) { lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; }) .remove(); return lengths; }; - var isNoneArc = 'isNoneArc'; - c3_chart_internal_fn[isNoneArc] = function (d) { - return this[hasTarget](this.data.targets, d.id); - }; - var isArc = 'isArc'; - c3_chart_internal_fn[isArc] = function (d) { - return 'data' in d && this[hasTarget](this.data.targets, d.data.id); + c3_chart_internal_fn.isNoneArc = function (d) { + return this.hasTarget(this.data.targets, d.id); + }, + c3_chart_internal_fn.isArc = function (d) { + return 'data' in d && this.hasTarget(this.data.targets, d.data.id); }; /** * c3.data.convert.js */ - var convertCsvToData = 'convertCsvToData'; - c3_chart_internal_fn[convertCsvToData] = function (csv) { + c3_chart_internal_fn.convertCsvToData = function (csv) { var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { d = [{}]; @@ -2976,8 +2805,7 @@ } return d; }; - var convertJsonToData = 'convertJsonToData'; - c3_chart_internal_fn[convertJsonToData] = function (json, keys) { + c3_chart_internal_fn.convertJsonToData = function (json, keys) { var $$ = this, new_rows = [], targetKeys, data; if (keys) { // when keys specified, json would be an array that includes objects @@ -2991,27 +2819,26 @@ var new_row = []; targetKeys.forEach(function (key) { // convert undefined to null because undefined data will be removed in convertDataToTargets() - var v = !isDefined(o[key]) ? null : o[key]; + var v = isUndefined(o[key]) ? null : o[key]; new_row.push(v); }); new_rows.push(new_row); }); - data = $$[convertRowsToData](new_rows); + data = $$.convertRowsToData(new_rows); } else { Object.keys(json).forEach(function (key) { new_rows.push([key].concat(json[key])); }); - data = $$[convertColumnsToData](new_rows); + data = $$.convertColumnsToData(new_rows); } return data; }; - var convertRowsToData = 'convertRowsToData'; - c3_chart_internal_fn[convertRowsToData] = function (rows) { + c3_chart_internal_fn.convertRowsToData = function (rows) { var keys = rows[0], new_row = {}, new_rows = [], i, j; for (i = 1; i < rows.length; i++) { new_row = {}; for (j = 0; j < rows[i].length; j++) { - if (!isDefined(rows[i][j])) { + if (isUndefined(rows[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_row[keys[j]] = rows[i][j]; @@ -3020,16 +2847,15 @@ } return new_rows; }; - var convertColumnsToData = 'convertColumnsToData'; - c3_chart_internal_fn[convertColumnsToData] = function (columns) { + c3_chart_internal_fn.convertColumnsToData = function (columns) { var new_rows = [], i, j, key; for (i = 0; i < columns.length; i++) { key = columns[i][0]; for (j = 1; j < columns[i].length; j++) { - if (!isDefined(new_rows[j - 1])) { + if (isUndefined(new_rows[j - 1])) { new_rows[j - 1] = {}; } - if (!isDefined(columns[i][j])) { + if (isUndefined(columns[i][j])) { throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); } new_rows[j - 1][key] = columns[i][j]; @@ -3037,8 +2863,7 @@ } return new_rows; }; - var convertDataToTargets = 'convertDataToTargets'; - c3_chart_internal_fn[convertDataToTargets] = function (data, appendXs) { + c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { var $$ = this, config = $$.config, ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), xs = $$.d3.keys(data[0]).filter($$.isX, $$), @@ -3046,24 +2871,24 @@ // save x for update data by load when custom x and c3.x API ids.forEach(function (id) { - var xKey = $$[getXKey](id); + var xKey = $$.getXKey(id); - if ($$[isCustomX]() || $$[isTimeSeries]) { + if ($$.isCustomX() || $$.isTimeSeries) { // if included in input data if (xs.indexOf(xKey) >= 0) { $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( data.map(function (d) { return d[xKey]; }) .filter(isValue) - .map(function (rawX, i) { return $$[generateTargetX](rawX, id, i); }) + .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }) ); } // if not included in input data, find from preloaded data of other id's x else if (config[__data_x]) { - $$.data.xs[id] = $$[getOtherTargetXs](); + $$.data.xs[id] = $$.getOtherTargetXs(); } // if not included in input data, find from preloaded data else if (notEmpty(config[__data_xs])) { - $$.data.xs[id] = $$[getXValuesOfXKey](xKey, $$.data.targets); + $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); } // MEMO: if no x included, use same x of current will be used } else { @@ -3085,14 +2910,14 @@ id: convertedId, id_org: id, values: data.map(function (d, i) { - var xKey = $$[getXKey](id), rawX = d[xKey], x = $$[generateTargetX](rawX, id, i); + var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); // use x as categories if custom x and categorized - if ($$[isCustomX]() && $$[isCategorized] && index === 0 && rawX) { + if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { if (i === 0) { config[__axis_x_categories] = []; } config[__axis_x_categories].push(rawX); } // mark as x = undefined if value is undefined and filter to remove after mapped - if (!isDefined(d[id]) || $$.data.xs[id].length <= i) { + if (isUndefined(d[id]) || $$.data.xs[id].length <= i) { x = undefined; } return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; @@ -3122,12 +2947,12 @@ // set target types 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 targets.forEach(function (d) { - $$[addCache](d.id_org, d); + $$.addCache(d.id_org, d); }); return targets; @@ -3136,8 +2961,7 @@ /** * c3.data.load.js */ - var load = 'load'; - c3_chart_internal_fn[load] = function (targets, args) { + c3_chart_internal_fn.load = function (targets, args) { var $$ = this; if (targets) { // filter loading targets if needed @@ -3147,7 +2971,7 @@ // set type if args.types || args.type specified if (args.type || args.types) { targets.forEach(function (t) { - $$[setTargetType](t.id, args.types ? args.types[t.id] : args.type); + $$.setTargetType(t.id, args.types ? args.types[t.id] : args.type); }); } // Update/Add data @@ -3164,62 +2988,60 @@ } // Set targets - $$[updateTargets]($$.data.targets); + $$.updateTargets($$.data.targets); // Redraw with new targets - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); if (isFunction(args.done)) { args.done(); } }; - var loadFromArgs = 'loadFromArgs'; - c3_chart_internal_fn[loadFromArgs] = function (args) { + c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; if (args.data) { - $$[load]($$[convertDataToTargets](args.data), args); + $$.load($$.convertDataToTargets(args.data), args); } else if (args.url) { - $$[convertUrlToData](args.url, args.mimeType, args.keys, function (data) { - $$[load]($$[convertDataToTargets](data), args); + $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { + $$.load($$.convertDataToTargets(data), args); }); } else if (args.json) { - $$[load]($$[convertDataToTargets]($$[convertJsonToData](args.json, args.keys)), args); + $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); } else if (args.rows) { - $$[load]($$[convertDataToTargets]($$[convertRowsToData](args.rows)), args); + $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); } else if (args.columns) { - $$[load]($$[convertDataToTargets]($$[convertColumnsToData](args.columns)), args); + $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); } else { - $$[load](null, args); + $$.load(null, args); } }; - var unload = 'unload'; - c3_chart_internal_fn[unload] = function (targetIds, done) { + c3_chart_internal_fn.unload = function (targetIds, done) { var $$ = this; if (!isFunction(done)) { done = function () {}; } // filter existing target - targetIds = targetIds.filter(function (id) { return $$[hasTarget]($$.data.targets, id); }); + targetIds = targetIds.filter(function (id) { return $$.hasTarget($$.data.targets, id); }); // If no target, call done and return if (!targetIds || targetIds.length === 0) { done(); return; } - $$.svg.selectAll(targetIds.map(function (id) { return $$[selectorTarget](id); })) + $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) .transition() - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove() .call($$.endall, done); targetIds.forEach(function (id) { // Reset fadein for future load - $$[withoutFadeIn][id] = false; + $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS[legendItem] + $$[getTargetSelectorSuffix](id)).remove(); + $$.legend.selectAll('.' + CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -3231,8 +3053,7 @@ /** * c3.data.category.js */ - var categoryName = 'categoryName'; - c3_chart_internal_fn[categoryName] = function (i) { + c3_chart_internal_fn.categoryName = function (i) { var config = this.config; return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; }; @@ -3241,11 +3062,10 @@ /** * c3.shape.js */ - var getShapeIndices = 'getShapeIndices'; - c3_chart_internal_fn[getShapeIndices] = function (typeFilter) { + c3_chart_internal_fn.getShapeIndices = function (typeFilter) { var $$ = this, config = $$.config, indices = {}, i = 0, j, k; - $$[filterTargetsToShow]($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { + $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { for (j = 0; j < config[__data_groups].length; j++) { if (config[__data_groups][j].indexOf(d.id) < 0) { continue; } for (k = 0; k < config[__data_groups][j].length; k++) { @@ -3255,34 +3075,31 @@ } } } - if (!isDefined(indices[d.id])) { indices[d.id] = i++; } + if (isUndefined(indices[d.id])) { indices[d.id] = i++; } }); indices.__max__ = i - 1; return indices; }; - var getShapeX = 'getShapeX'; - c3_chart_internal_fn[getShapeX] = function (offset, targetsNum, indices, isSub) { + c3_chart_internal_fn.getShapeX = function (offset, targetsNum, indices, isSub) { var $$ = this, scale = isSub ? $$.subX : $$.x; return function (d) { var index = d.id in indices ? indices[d.id] : 0; return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; }; }; - var getShapeY = 'getShapeY'; - c3_chart_internal_fn[getShapeY] = function (isSub) { + c3_chart_internal_fn.getShapeY = function (isSub) { var $$ = this; return function (d) { - var scale = isSub ? $$[getSubYScale](d.id) : $$[getYScale](d.id); + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); return scale(d.value); }; }; - var getShapeOffset = 'getShapeOffset'; - c3_chart_internal_fn[getShapeOffset] = function (typeFilter, indices, isSub) { + c3_chart_internal_fn.getShapeOffset = function (typeFilter, indices, isSub) { var $$ = this, - targets = $$[orderTargets]($$[filterTargetsToShow]($$.data.targets.filter(typeFilter, $$))), + targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), targetIds = targets.map(function (t) { return t.id; }); return function (d, i) { - var scale = isSub ? $$[getSubYScale](d.id) : $$[getYScale](d.id), + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id), y0 = scale(0), offset = y0; targets.forEach(function (t) { if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } @@ -3294,86 +3111,72 @@ }; }; - var getInterpolate = 'getInterpolate'; - c3_chart_internal_fn[getInterpolate] = function (d) { + c3_chart_internal_fn.getInterpolate = function (d) { var $$ = this; - return $$[isSplineType](d) ? "cardinal" : $$[isStepType](d) ? "step-after" : "linear"; + return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; - var circleX = 'circleX'; - c3_chart_internal_fn[circleX] = function (d) { - return d.x || d.x === 0 ? this[x](d.x) : null; + c3_chart_internal_fn.circleX = function (d) { + return d.x || d.x === 0 ? this.x(d.x) : null; }; - var circleY = 'circleY'; - c3_chart_internal_fn[circleY] = function (d, i) { + c3_chart_internal_fn.circleY = function (d, i) { var $$ = this, - lineIndices = $$[getShapeIndices]($$.isLineType), getPoint = $$[generateGetLinePoint](lineIndices); - return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$[getYScale](d.id)(d.value); + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); }; - var getCircles = 'getCircles'; - c3_chart_internal_fn[getCircles] = function (i, id) { + c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS[circles] + $$[getTargetSelectorSuffix](id)) : $$.main).selectAll('.' + CLASS[circle] + (isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); }; - var expandCircles = 'expandCircles'; - c3_chart_internal_fn[expandCircles] = function (i, id) { + c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this; - $$[getCircles](i, id) - .classed(CLASS[EXPANDED], true) - .attr('r', generateCall($$[pointExpandedR], $$)); + $$.getCircles(i, id) + .classed(CLASS.EXPANDED, true) + .attr('r', generateCall($$.pointExpandedR, $$)); }; - var unexpandCircles = 'unexpandCircles'; - c3_chart_internal_fn[unexpandCircles] = function (i) { + c3_chart_internal_fn.unexpandCircles = function (i) { var $$ = this; - $$[getCircles](i) - .filter(function () { return $$.d3.select(this).classed(CLASS[EXPANDED]); }) - .classed(CLASS[EXPANDED], false) - .attr('r', generateCall($$[pointR], $$)); + $$.getCircles(i) + .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) + .classed(CLASS.EXPANDED, false) + .attr('r', generateCall($$.pointR, $$)); }; - var pointR = 'pointR'; - c3_chart_internal_fn[pointR] = function (d) { + c3_chart_internal_fn.pointR = function (d) { var $$ = this, config = $$.config; - return config[__point_show] && !$$[isStepType](d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; + return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; }; - var pointExpandedR = 'pointExpandedR'; - c3_chart_internal_fn[pointExpandedR] = function (d) { + c3_chart_internal_fn.pointExpandedR = function (d) { var $$ = this, config = $$.config; - return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$[pointR](d) * 1.75) : $$[pointR](d); + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); }; - var pointSelectR = 'pointSelectR'; - c3_chart_internal_fn[pointSelectR] = function (d) { + c3_chart_internal_fn.pointSelectR = function (d) { var $$ = this, config = $$.config; - return config[__point_select_r] ? config[__point_select_r] : $$[pointR](d) * 4; + return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; }; - var getBarW = 'getBarW'; - c3_chart_internal_fn[getBarW] = function (axis, barTargetsNum) { + c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { var $$ = this, config = $$.config, w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; }; - var getBars = 'getBars'; - c3_chart_internal_fn[getBars] = function (i) { + c3_chart_internal_fn.getBars = function (i) { var $$ = this; - return $$.main.selectAll('.' + CLASS[bar] + (isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); }; - var expandBars = 'expandBars'; - c3_chart_internal_fn[expandBars] = function (i) { + c3_chart_internal_fn.expandBars = function (i) { var $$ = this; - $$[getBars](i).classed(CLASS[EXPANDED], true); + $$.getBars(i).classed(CLASS.EXPANDED, true); }; - var unexpandBars = 'unexpandBars'; - c3_chart_internal_fn[unexpandBars] = function (i) { + c3_chart_internal_fn.unexpandBars = function (i) { var $$ = this; - $$[getBars](i).classed(CLASS[EXPANDED], false); + $$.getBars(i).classed(CLASS.EXPANDED, false); }; - var generateDrawBar = 'generateDrawBar'; - c3_chart_internal_fn[generateDrawBar] = function (barIndices, isSub) { + c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { var $$ = this, config = $$.config, - getPoints = $$[generateGetBarPoints](barIndices, isSub); + getPoints = $$.generateGetBarPoints(barIndices, isSub); return function (d, i) { // 4 points that make a bar var points = getPoints(d, i); @@ -3391,14 +3194,13 @@ return path; }; }; - var generateGetBarPoints = 'generateGetBarPoints'; - c3_chart_internal_fn[generateGetBarPoints] = function (barIndices, isSub) { + c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { var $$ = this, barTargetsNum = barIndices.__max__ + 1, - barW = $$[getBarW]($$.xAxis, barTargetsNum), - barX = $$[getShapeX](barW, barTargetsNum, barIndices, !!isSub), - barY = $$[getShapeY](!!isSub), - barOffset = $$[getShapeOffset]($$.isBarType, barIndices, !!isSub), + barW = $$.getBarW($$.xAxis, barTargetsNum), + barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = $$.getShapeY(!!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3418,10 +3220,9 @@ }; }; - var generateDrawArea = 'generateDrawArea'; - c3_chart_internal_fn[generateDrawArea] = function (areaIndices, isSub) { + c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { var $$ = this, config = $$.config, area = $$.d3.svg.area(), - getPoint = $$[generateGetAreaPoint](areaIndices, isSub), + getPoint = $$.generateGetAreaPoint(areaIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, value0 = function (d, i) { @@ -3434,13 +3235,13 @@ area = config[__axis_rotated] ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); return function (d) { - var data = $$[filterRemoveNull](d.values), x0 = 0, y0 = 0, path; - if ($$[isAreaType](d)) { - path = area.interpolate($$[getInterpolate](d))(data); + var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + if ($$.isAreaType(d)) { + path = area.interpolate($$.getInterpolate(d))(data); } else { if (data[0]) { - x0 = $$[x](data[0].x); - y0 = $$[getYScale](d.id)(data[0].value); + x0 = $$.x(data[0].x); + y0 = $$.getYScale(d.id)(data[0].value); } path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; } @@ -3448,11 +3249,10 @@ }; }; - var generateDrawLine = 'generateDrawLine'; - c3_chart_internal_fn[generateDrawLine] = function (lineIndices, isSub) { + c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { var $$ = this, config = $$.config, line = $$.d3.svg.line(), - getPoint = $$[generateGetLinePoint](lineIndices, isSub), + getPoint = $$.generateGetLinePoint(lineIndices, isSub), yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, yValue = function (d, i) { @@ -3462,13 +3262,13 @@ line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } return function (d) { - var data = config[__line_connect_null] ? $$[filterRemoveNull](d.values) : d.values, + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; - if ($$[isLineType](d)) { + if ($$.isLineType(d)) { if (config[__data_regions][d.id]) { - path = $$[lineWithRegions](data, x, y, config[__data_regions][d.id]); + path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); } else { - path = line.interpolate($$[getInterpolate](d))(data); + path = line.interpolate($$.getInterpolate(d))(data); } } else { if (data[0]) { @@ -3481,46 +3281,42 @@ }; }; - var generateXYForText = 'generateXYForText'; - c3_chart_internal_fn[generateXYForText] = function (barIndices, forX) { + c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { var $$ = this, - getPoints = $$[generateGetBarPoints](barIndices, false), + getPoints = $$.generateGetBarPoints(barIndices, false), getter = forX ? $$.getXForText : $$.getYForText; return function (d, i) { return getter(getPoints(d, i), d, this); }; }; - var getXForText = 'getXForText'; - c3_chart_internal_fn[getXForText] = function (points, d, textElement) { + c3_chart_internal_fn.getXForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), xPos, padding; if (config[__axis_rotated]) { - padding = $$[isBarType](d) ? 4 : 6; + padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; } return xPos > $$.width ? $$.width - box.width : xPos; }; - var getYForText = 'getYForText'; - c3_chart_internal_fn[getYForText] = function (points, d, textElement) { + c3_chart_internal_fn.getYForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), yPos; if (config[__axis_rotated]) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { - yPos = points[2][1] + (d.value < 0 ? box.height : $$[isBarType](d) ? -3 : -6); + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); } return yPos < box.height ? box.height : yPos; }; - var generateGetAreaPoint = 'generateGetAreaPoint'; - c3_chart_internal_fn[generateGetAreaPoint] = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, config = $$.config, areaTargetsNum = areaIndices.__max__ + 1, - x = $$[getShapeX](0, areaTargetsNum, areaIndices, !!isSub), - y = $$[getShapeY](!!isSub), - areaOffset = $$[getShapeOffset]($$.isAreaType, areaIndices, !!isSub), + x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = $$.getShapeY(!!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3538,13 +3334,12 @@ }; }; - var generateGetLinePoint = 'generateGetLinePoint'; - c3_chart_internal_fn[generateGetLinePoint] = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, config = $$.config, lineTargetsNum = lineIndices.__max__ + 1, - x = $$[getShapeX](0, lineTargetsNum, lineIndices, !!isSub), - y = $$[getShapeY](!!isSub), - lineOffset = $$[getShapeOffset]($$.isLineType, lineIndices, !!isSub), + x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), + y = $$.getShapeY(!!isSub), + lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), yScale = isSub ? $$.getSubYScale : $$.getYScale; return function (d, i) { var y0 = yScale.call($$, d.id)(0), @@ -3562,8 +3357,7 @@ }; - var lineWithRegions = 'lineWithRegions'; - c3_chart_internal_fn[lineWithRegions] = function (d, x, y, _regions) { + c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { var $$ = this, config = $$.config, prev = -1, i, j, s = "M", sWithRegion, @@ -3575,15 +3369,15 @@ if (isDefined(_regions)) { for (i = 0; i < _regions.length; i++) { regions[i] = {}; - if (!isDefined(_regions[i].start)) { + if (isUndefined(_regions[i].start)) { regions[i].start = d[0].x; } else { - regions[i].start = $$[isTimeSeries] ? $$[parseDate](_regions[i].start) : _regions[i].start; + regions[i].start = $$.isTimeSeries ? $$.parseDate(_regions[i].start) : _regions[i].start; } - if (!isDefined(_regions[i].end)) { + if (isUndefined(_regions[i].end)) { regions[i].end = d[d.length - 1].x; } else { - regions[i].end = $$[isTimeSeries] ? $$[parseDate](_regions[i].end) : _regions[i].end; + regions[i].end = $$.isTimeSeries ? $$.parseDate(_regions[i].end) : _regions[i].end; } } } @@ -3593,7 +3387,7 @@ yValue = config[__axis_rotated] ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; // Define svg generator function for region - if ($$[isTimeSeries]) { + if ($$.isTimeSeries) { sWithRegion = function (d0, d1, j, diff) { var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, xv0 = new Date(x0 + x_diff * j), @@ -3610,13 +3404,13 @@ for (i = 0; i < d.length; i++) { // Draw as normal - if (!isDefined(regions) || ! $$[isWithinRegions](d[i].x, regions)) { + if (isUndefined(regions) || ! $$.isWithinRegions(d[i].x, regions)) { s += " " + xValue(d[i]) + " " + yValue(d[i]); } // Draw with region // TODO: Fix for horizotal charts else { - xp = $$[getScale](d[i - 1].x, d[i].x, $$[isTimeSeries]); - yp = $$[getScale](d[i - 1].value, d[i].value); + xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); + yp = $$.getScale(d[i - 1].value, d[i].value); dx = x(d[i].x) - x(d[i - 1].x); dy = y(d[i].value) - y(d[i - 1].value); @@ -3636,15 +3430,13 @@ - var isWithinCircle = 'isWithinCircle'; - c3_chart_internal_fn[isWithinCircle] = function (_this, _r) { + c3_chart_internal_fn.isWithinCircle = function (_this, _r) { var d3 = this.d3, mouse = d3.mouse(_this), d3_this = d3.select(_this), cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; - var isWithinBar = 'isWithinBar'; - c3_chart_internal_fn[isWithinBar] = function (_this) { + c3_chart_internal_fn.isWithinBar = function (_this) { var d3 = this.d3, mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), @@ -3652,8 +3444,7 @@ sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; }; - var isWithinRegions = 'isWithinRegions'; - c3_chart_internal_fn[isWithinRegions] = function (x, regions) { + c3_chart_internal_fn.isWithinRegions = function (x, regions) { var i; for (i = 0; i < regions.length; i++) { if (regions[i].start < x && x <= regions[i].end) { return true; } @@ -3664,8 +3455,7 @@ - var findSameXOfValues = 'findSameXOfValues'; - c3_chart_internal_fn[findSameXOfValues] = function (values, index) { + c3_chart_internal_fn.findSameXOfValues = function (values, index) { var i, targetX = values[index].x, sames = []; for (i = index - 1; i >= 0; i--) { if (targetX !== values[i].x) { break; } @@ -3678,14 +3468,13 @@ return sames; }; - var findClosestOfValues = 'findClosestOfValues'; - c3_chart_internal_fn[findClosestOfValues] = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x var $$ = this, min = _min ? _min : 0, max = _max ? _max : values.length - 1, med = Math.floor((max - min) / 2) + min, value = values[med], - diff = $$[x](value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], + diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], candidates; // Update range for search @@ -3697,35 +3486,33 @@ // Get candidates that has same min and max index candidates = []; if (values[min].x || values[min].x === 0) { - candidates = candidates.concat($$[findSameXOfValues](values, min)); + candidates = candidates.concat($$.findSameXOfValues(values, min)); } if (values[max].x || values[max].x === 0) { - candidates = candidates.concat($$[findSameXOfValues](values, max)); + candidates = candidates.concat($$.findSameXOfValues(values, max)); } // Determine the closest and return - return $$[findClosest](candidates, pos); + return $$.findClosest(candidates, pos); } - return $$[findClosestOfValues](values, pos, min, max); + return $$.findClosestOfValues(values, pos, min, max); }; - var findClosestFromTargets = 'findClosestFromTargets'; - c3_chart_internal_fn[findClosestFromTargets] = function (targets, pos) { + c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { var $$ = this, candidates; // map to array of closest points of each target candidates = targets.map(function (target) { - return $$[findClosestOfValues](target.values, pos); + return $$.findClosestOfValues(target.values, pos); }); // decide closest point and return - return $$[findClosest](candidates, pos); + return $$.findClosest(candidates, pos); }; - var findClosest = 'findClosest'; - c3_chart_internal_fn[findClosest] = function (values, pos) { + c3_chart_internal_fn.findClosest = function (values, pos) { var $$ = this, minDist, closest; values.forEach(function (v) { - var d = $$[dist](v, pos); + var d = $$.dist(v, pos); if (d < minDist || ! minDist) { minDist = d; closest = v; @@ -3733,29 +3520,26 @@ }); return closest; }; - var dist = 'dist'; - c3_chart_internal_fn[dist] = function (data, pos) { + c3_chart_internal_fn.dist = function (data, pos) { var $$ = this, config = $$.config, - yScale = $$[getAxisId](data.id) === 'y' ? $$.y : $$.y2, + yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, xIndex = config[__axis_rotated] ? 1 : 0, yIndex = config[__axis_rotated] ? 0 : 1; - return Math.pow($$[x](data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); }; - var setTargetType = 'setTargetType'; - c3_chart_internal_fn[setTargetType] = function (targetIds, type) { + c3_chart_internal_fn.setTargetType = function (targetIds, type) { var $$ = this, config = $$.config; - $$[mapToTargetIds](targetIds).forEach(function (id) { - $$[withoutFadeIn][id] = (type === config[__data_types][id]); + $$.mapToTargetIds(targetIds).forEach(function (id) { + $$.withoutFadeIn[id] = (type === config[__data_types][id]); config[__data_types][id] = type; }); if (!targetIds) { config[__data_type] = type; } }; - var hasType = 'hasType'; - c3_chart_internal_fn[hasType] = function (targets, type) { + c3_chart_internal_fn.hasType = function (targets, type) { var $$ = this, config = $$.config, has = false; targets.forEach(function (t) { if (config[__data_types][t.id] === type) { has = true; } @@ -3763,84 +3547,90 @@ }); return has; }; - var hasArcType = 'hasArcType'; - c3_chart_internal_fn[hasArcType] = function (targets) { - return this[hasType](targets, TYPE_PIE) || this[hasType](targets, TYPE_DONUT) || this[hasType](targets, TYPE_GAUGE); + /* not used + function hasLineType(targets) { + return hasType(targets, 'line'); + } + */ + c3_chart_internal_fn.hasAreaType = function (targets) { + return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); }; - - var isLineType = 'isLineType'; - c3_chart_internal_fn[isLineType] = function (d) { + c3_chart_internal_fn.hasBarType = function (targets) { + return this.hasType(targets, 'bar'); + }; + c3_chart_internal_fn.hasScatterType = function (targets) { + return this.hasType(targets, 'scatter'); + }; + c3_chart_internal_fn.hasPieType = function (targets) { + return this.config[__data_type] === 'pie' || this.hasType(targets, 'pie'); + }; + c3_chart_internal_fn.hasGaugeType = function (targets) { + return this.hasType(targets, 'gauge'); + }; + c3_chart_internal_fn.hasDonutType = function (targets) { + return this.config[__data_type] === 'donut' || this.hasType(targets, 'donut'); + }; + c3_chart_internal_fn.hasArcType = function (targets) { + return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); + }; + c3_chart_internal_fn.isLineType = function (d) { var config = this.config, id = isString(d) ? d : d.id; return !config[__data_types][id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(config[__data_types][id]) >= 0; }; - var isStepType = 'isStepType'; - c3_chart_internal_fn[isStepType] = function (d) { + c3_chart_internal_fn.isStepType = function (d) { var id = isString(d) ? d : d.id; return ['step', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - var isSplineType = 'isSplineType'; - c3_chart_internal_fn[isSplineType] = function (d) { + c3_chart_internal_fn.isSplineType = function (d) { var id = isString(d) ? d : d.id; return ['spline', 'area-spline'].indexOf(this.config[__data_types][id]) >= 0; }; - var isAreaType = 'isAreaType'; - c3_chart_internal_fn[isAreaType] = function (d) { + c3_chart_internal_fn.isAreaType = function (d) { var id = isString(d) ? d : d.id; return ['area', 'area-spline', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; }; - var isBarType = 'isBarType'; - c3_chart_internal_fn[isBarType] = function (d) { + c3_chart_internal_fn.isBarType = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'bar'; }; - var isScatterType = 'isScatterType'; - c3_chart_internal_fn[isScatterType] = function (d) { + c3_chart_internal_fn.isScatterType = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'scatter'; }; - var isPieType = 'isPieType'; - c3_chart_internal_fn[isPieType] = function (d) { + c3_chart_internal_fn.isPieType = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'pie'; }; - var isGaugeType = 'isGaugeType'; - c3_chart_internal_fn[isGaugeType] = function (d) { + c3_chart_internal_fn.isGaugeType = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'gauge'; }; - var isDonutType = 'isDonutType'; - c3_chart_internal_fn[isDonutType] = function (d) { + c3_chart_internal_fn.isDonutType = function (d) { var id = isString(d) ? d : d.id; return this.config[__data_types][id] === 'donut'; }; - var isArcType = 'isArcType'; - c3_chart_internal_fn[isArcType] = function (d) { - return this[isPieType](d) || this[isDonutType](d) || this[isGaugeType](d); + c3_chart_internal_fn.isArcType = function (d) { + return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); }; - var lineData = 'lineData'; - c3_chart_internal_fn[lineData] = function (d) { - return this[isLineType](d) ? [d] : []; + c3_chart_internal_fn.lineData = function (d) { + return this.isLineType(d) ? [d] : []; }; - var arcData = 'arcData'; - c3_chart_internal_fn[arcData] = function (d) { - return this[isArcType](d.data) ? [d] : []; + c3_chart_internal_fn.arcData = function (d) { + return this.isArcType(d.data) ? [d] : []; }; /* not used function scatterData(d) { return isScatterType(d) ? d.values : []; } */ - var barData = 'barData'; - c3_chart_internal_fn[barData] = function (d) { - return this[isBarType](d) ? d.values : []; + c3_chart_internal_fn.barData = function (d) { + return this.isBarType(d) ? d.values : []; }; - var lineOrScatterData = 'lineOrScatterData'; - c3_chart_internal_fn[lineOrScatterData] = function (d) { - return this[isLineType](d) || this[isScatterType](d) ? d.values : []; + c3_chart_internal_fn.lineOrScatterData = function (d) { + return this.isLineType(d) || this.isScatterType(d) ? d.values : []; }; - var barOrLineData = 'barOrLineData'; - c3_chart_internal_fn[barOrLineData] = function (d) { - return this[isBarType](d) || this[isLineType](d) ? d.values : []; + c3_chart_internal_fn.barOrLineData = function (d) { + return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; @@ -3848,15 +3638,14 @@ /** * c3.date.js */ - var parseDate = 'parseDate'; - c3_chart_internal_fn[parseDate] = function (date) { + c3_chart_internal_fn.parseDate = function (date) { var $$ = this, parsedDate; if (date instanceof Date) { parsedDate = date; } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = $$[dataTimeFormat](config[__data_x_format]).parse(date); + parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -3868,8 +3657,7 @@ /** * c3.color.js */ - var generateColor = 'generateColor'; - c3_chart_internal_fn[generateColor] = function (colors, pattern, callback) { + c3_chart_internal_fn.generateColor = function (colors, pattern, callback) { var ids = []; return function (d) { @@ -3892,8 +3680,7 @@ return callback instanceof Function ? callback(color, d) : color; }; }; - var generateLevelColor = 'generateLevelColor'; - c3_chart_internal_fn[generateLevelColor] = function (colors, threshold) { + c3_chart_internal_fn.generateLevelColor = function (colors, threshold) { var asValue = threshold.unit === 'value', values = threshold.values && threshold.values.length ? threshold.values : [], max = threshold.max || 100; @@ -3914,17 +3701,15 @@ /** * c3.scale.js */ - var getScale = 'getScale'; - c3_chart_internal_fn[getScale] = function (min, max, forTimeseries) { + c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); }; - var getX = 'getX'; - c3_chart_internal_fn[getX] = function (min, max, domain, offset) { + c3_chart_internal_fn.getX = function (min, max, domain, offset) { var $$ = this, - scale = $$[getScale](min, max, $$[isTimeSeries]), + scale = $$.getScale(min, max, $$.isTimeSeries), _scale = domain ? scale.domain(domain) : scale, key; // Define customized scale if categorized axis - if ($$[isCategorized]) { + if ($$.isCategorized) { offset = offset || function () { return 0; }; scale = function (d, raw) { var v = _scale(d) + offset(d); @@ -3944,7 +3729,7 @@ return _scale.domain(); }; // define custom domain() for categorized axis - if ($$[isCategorized]) { + if ($$.isCategorized) { scale.domain = function (domain) { if (!arguments.length) { domain = this.orgDomain(); @@ -3956,22 +3741,18 @@ } return scale; }; - var getY = 'getY'; - c3_chart_internal_fn[getY] = function (min, max, domain) { - var scale = this[getScale](min, max); + c3_chart_internal_fn.getY = function (min, max, domain) { + var scale = this.getScale(min, max); if (domain) { scale.domain(domain); } return scale; }; - var getYScale = 'getYScale'; - c3_chart_internal_fn[getYScale] = function (id) { - return this[getAxisId](id) === 'y2' ? this.y2 : this.y; + c3_chart_internal_fn.getYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.y2 : this.y; }; - var getSubYScale = 'getSubYScale'; - c3_chart_internal_fn[getSubYScale] = function (id) { - return this[getAxisId](id) === 'y2' ? this.subY2 : this.subY; + c3_chart_internal_fn.getSubYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; }; - var updateScales = 'updateScales', x = 'x', y = 'y', subX = 'subX'; - c3_chart_internal_fn[updateScales] = function () { + c3_chart_internal_fn.updateScales = function () { var $$ = this, config = $$.config, forInit = !$$.x; // update edges @@ -3984,19 +3765,19 @@ $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; // update scales - $$[x] = $$[getX]($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); - $$[y] = $$[getY]($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); - $$.y2 = $$[getY]($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); - $$[subX] = $$[getX]($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); - $$.subY = $$[getY]($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); - $$.subY2 = $$[getY]($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); + $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); + $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); + $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); + $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); + $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); + $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); // update axes - $$.xAxisTickFormat = $$[getXAxisTickFormat](); + $$.xAxisTickFormat = $$.getXAxisTickFormat(); $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); - $$.xAxis = $$[getXAxis]($$.x, $$[xOrient], $$.xAxisTickFormat, $$.xAxisTickValues); - $$.subXAxis = $$[getXAxis]($$.subX, $$[subXOrient], $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$[getYAxis]($$.y, $$[yOrient], config[__axis_y_tick_format], config[__axis_y_ticks]); - $$.y2Axis = $$[getYAxis]($$.y2, $$[y2Orient], config[__axis_y2_tick_format], config[__axis_y2_ticks]); + $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); // Set initialized scales to brush and zoom if (!forInit) { if ($$.brush) { $$.brush.scale($$.subX); } @@ -4004,7 +3785,7 @@ } // update for arc if (isFunction($$.updateArc)) { - $$[updateArc](); + $$.updateArc(); } }; @@ -4012,13 +3793,12 @@ /** * c3.domain.js */ - var getYDomainMin = 'getYDomainMin'; - c3_chart_internal_fn[getYDomainMin] = function (targets) { + c3_chart_internal_fn.getYDomainMin = function (targets) { var $$ = this, config = $$.config, - ids = $$[mapToIds](targets), ys = $$[getValuesAsIdKeyed](targets), + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasNegativeValue; if (config[__data_groups].length > 0) { - hasNegativeValue = $$[hasNegativeValueInTargets](targets); + hasNegativeValue = $$.hasNegativeValueInTargets(targets); for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); @@ -4035,7 +3815,7 @@ id = idsInGroup[k]; if (! ys[id]) { continue; } ys[id].forEach(function (v, i) { - if ($$[getAxisId](id) === $$[getAxisId](baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { ys[baseId][i] += +v; } }); @@ -4044,13 +3824,12 @@ } return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); }; - var getYDomainMax = 'getYDomainMax'; - c3_chart_internal_fn[getYDomainMax] = function (targets) { + c3_chart_internal_fn.getYDomainMax = function (targets) { var $$ = this, config = $$.config, - ids = $$[mapToIds](targets), ys = $$[getValuesAsIdKeyed](targets), + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), j, k, baseId, idsInGroup, id, hasPositiveValue; if (config[__data_groups].length > 0) { - hasPositiveValue = $$[hasPositiveValueInTargets](targets); + hasPositiveValue = $$.hasPositiveValueInTargets(targets); for (j = 0; j < config[__data_groups].length; j++) { // Determine baseId idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); @@ -4067,7 +3846,7 @@ id = idsInGroup[k]; if (! ys[id]) { continue; } ys[id].forEach(function (v, i) { - if ($$[getAxisId](id) === $$[getAxisId](baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { ys[baseId][i] += +v; } }); @@ -4076,20 +3855,19 @@ } return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - var getYDomain = 'getYDomain'; - c3_chart_internal_fn[getYDomain] = function (targets, axisId) { + c3_chart_internal_fn.getYDomain = function (targets, axisId) { var $$ = this, config = $$.config, - yTargets = targets.filter(function (d) { return $$[getAxisId](d.id) === axisId; }), + yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], - yDomainMin = isValue(yMin) ? yMin : $$[getYDomainMin](yTargets), - yDomainMax = isValue(yMax) ? yMax : $$[getYDomainMax](yTargets), + yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), + yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$[hasType](yTargets, TYPE_BAR) && config[__bar_zerobased]) || ($$[hasType](yTargets, TYPE_AREA) && config[__area_zerobased]), - showHorizontalDataLabel = $$[hasDataLabel]() && config[__axis_rotated], - showVerticalDataLabel = $$[hasDataLabel]() && !config[__axis_rotated]; + isZeroBased = ($$.hasBarType(yTargets) && config[__bar_zerobased]) || ($$.hasAreaType(yTargets) && config[__area_zerobased]), + showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], + showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } @@ -4115,23 +3893,23 @@ } // add padding for data label if (showHorizontalDataLabel) { - lengths = $$[getDataLabelLength](yDomainMin, yDomainMax, axisId, 'width'); + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); diff = diffDomain($$.y.range()); ratio = [lengths[0] / diff, lengths[1] / diff]; padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); } else if (showVerticalDataLabel) { - lengths = $$[getDataLabelLength](yDomainMin, yDomainMax, axisId, 'height'); + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); padding_top += lengths[1]; padding_bottom += lengths[0]; } if (axisId === 'y' && config[__axis_y_padding]) { - padding_top = $$[getAxisPadding](config[__axis_y_padding], 'top', padding, domainLength); - padding_bottom = $$[getAxisPadding](config[__axis_y_padding], 'bottom', padding, domainLength); + padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); } if (axisId === 'y2' && config[__axis_y2_padding]) { - padding_top = $$[getAxisPadding](config[__axis_y2_padding], 'top', padding, domainLength); - padding_bottom = $$[getAxisPadding](config[__axis_y2_padding], 'bottom', padding, domainLength); + padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); } // Bar/Area chart should be 0-based if all positive|negative if (isZeroBased) { @@ -4140,29 +3918,26 @@ } return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; - var getXDomainMin = 'getXDomainMin'; - c3_chart_internal_fn[getXDomainMin] = function (targets) { + c3_chart_internal_fn.getXDomainMin = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_min] ? - ($$[isTimeSeries] ? this[parseDate](config[__axis_x_min]) : config[__axis_x_min]) : + ($$.isTimeSeries ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; - var getXDomainMax = 'getXDomainMax'; - c3_chart_internal_fn[getXDomainMax] = function (targets) { + c3_chart_internal_fn.getXDomainMax = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_max] ? - ($$[isTimeSeries] ? this[parseDate](config[__axis_x_max]) : config[__axis_x_max]) : + ($$.isTimeSeries ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; - var getXDomainPadding = 'getXDomainPadding'; - c3_chart_internal_fn[getXDomainPadding] = function (targets) { + c3_chart_internal_fn.getXDomainPadding = function (targets) { var $$ = this, config = $$.config, - edgeX = this[getEdgeX](targets), diff = edgeX[1] - edgeX[0], + edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; - if ($$[isCategorized]) { + if ($$.isCategorized) { padding = 0; - } else if ($$[hasType](targets, TYPE_BAR)) { - maxDataCount = $$[getMaxDataCount](); + } else if ($$.hasBarType(targets)) { + maxDataCount = $$.getMaxDataCount(); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { padding = diff * 0.01; @@ -4177,31 +3952,29 @@ } return {left: paddingLeft, right: paddingRight}; }; - var getXDomain = 'getXDomain'; - c3_chart_internal_fn[getXDomain] = function (targets) { + c3_chart_internal_fn.getXDomain = function (targets) { var $$ = this, - xDomain = [$$[getXDomainMin](targets), $$[getXDomainMax](targets)], + xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], firstX = xDomain[0], lastX = xDomain[1], - padding = $$[getXDomainPadding](targets), + padding = $$.getXDomainPadding(targets), min = 0, max = 0; // show center of x domain if min and max are the same - if ((firstX - lastX) === 0 && !$$[isCategorized]) { - firstX = $$[isTimeSeries] ? new Date(firstX.getTime() * 0.5) : -0.5; - lastX = $$[isTimeSeries] ? new Date(lastX.getTime() * 1.5) : 0.5; + if ((firstX - lastX) === 0 && !$$.isCategorized) { + firstX = $$.isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$.isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; } if (firstX || firstX === 0) { - min = $$[isTimeSeries] ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + min = $$.isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; } if (lastX || lastX === 0) { - max = $$[isTimeSeries] ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + max = $$.isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; } return [min, max]; }; - var updateXDomain = 'updateXDomain'; - c3_chart_internal_fn[updateXDomain] = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { var $$ = this, config = $$.config; if (withUpdateOrgXDomain) { - $$.x.domain(domain ? domain : $$.d3.extent($$[getXDomain](targets))); + $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); $$.orgXDomain = $$.x.domain(); if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } $$.subX.domain($$.x.domain()); @@ -4217,14 +3990,13 @@ - var getXAxis = 'getXAxis'; - c3_chart_internal_fn[getXAxis] = function (scale, orient, tickFormat, tickValues) { + c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, - axis = c3_axis($$.d3, $$[isCategorized]).scale(scale).orient(orient); + axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); // Set tick axis.tickFormat(tickFormat).tickValues(tickValues); - if ($$[isCategorized]) { + if ($$.isCategorized) { axis.tickCentered(config[__axis_x_tick_centered]); if (isEmpty(config[__axis_x_tick_culling])) { config[__axis_x_tick_culling] = false; @@ -4232,40 +4004,36 @@ } else { // TODO: move this to c3_axis axis.tickOffset = function () { - var edgeX = $$[getEdgeX]($$.data.targets), diff = $$[x](edgeX[1]) - $$[x](edgeX[0]), + var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), base = diff ? diff : (config[__axis_rotated] ? $$.height : $$.width); - return (base / $$[getMaxDataCount]()) / 2; + return (base / $$.getMaxDataCount()) / 2; }; } return axis; }; - var getYAxis = 'getYAxis'; - c3_chart_internal_fn[getYAxis] = function (scale, orient, tickFormat, ticks) { + c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks) { return c3_axis(this.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); }; - var getAxisId = 'getAxisId'; - c3_chart_internal_fn[getAxisId] = function (id) { + c3_chart_internal_fn.getAxisId = function (id) { var config = this.config; return id in config[__data_axes] ? config[__data_axes][id] : 'y'; }; - var getXAxisTickFormat = 'getXAxisTickFormat'; - c3_chart_internal_fn[getXAxisTickFormat] = function () { + c3_chart_internal_fn.getXAxisTickFormat = function () { var $$ = this, config = $$.config, - format = $$[isTimeSeries] ? $$[defaultAxisTimeFormat] : $$[isCategorized] ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + 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]) { + } else if ($$.isTimeSeries) { format = function (date) { - return date ? $$[axisTimeFormat](config[__axis_x_tick_format])(date) : ""; + return date ? $$.axisTimeFormat(config[__axis_x_tick_format])(date) : ""; }; } } return function (v) { return format.call($$, v); }; }; - var getAxisLabelOptionByAxisId = 'getAxisLabelOptionByAxisId'; - c3_chart_internal_fn[getAxisLabelOptionByAxisId] = function (axisId) { + c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { var $$ = this, config = $$.config, option; if (axisId === 'y') { option = config[__axis_y_label]; @@ -4276,15 +4044,13 @@ } return option; }; - var getAxisLabelText = 'getAxisLabelText'; - c3_chart_internal_fn[getAxisLabelText] = function (axisId) { - var option = this[getAxisLabelOptionByAxisId](axisId); + c3_chart_internal_fn.getAxisLabelText = function (axisId) { + var option = this.getAxisLabelOptionByAxisId(axisId); return isString(option) ? option : option ? option.text : null; }; - var setAxisLabelText = 'setAxisLabelText'; - c3_chart_internal_fn[setAxisLabelText] = function (axisId, text) { + c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { var $$ = this, config = $$.config, - option = $$[getAxisLabelOptionByAxisId](axisId); + option = $$.getAxisLabelOptionByAxisId(axisId); if (isString(option)) { if (axisId === 'y') { config[__axis_y_label] = text; @@ -4297,9 +4063,8 @@ option.text = text; } }; - var getAxisLabelPosition = 'getAxisLabelPosition'; - c3_chart_internal_fn[getAxisLabelPosition] = function (axisId, defaultPosition) { - var option = this[getAxisLabelOptionByAxisId](axisId), + c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { + var option = this.getAxisLabelOptionByAxisId(axisId), position = (option && typeof option === 'object' && option.position) ? option.position : defaultPosition; return { isInner: position.indexOf('inner') >= 0, @@ -4312,36 +4077,28 @@ isBottom: position.indexOf('bottom') >= 0 }; }; - var getXAxisLabelPosition = 'getXAxisLabelPosition'; - c3_chart_internal_fn[getXAxisLabelPosition] = function () { - return this[getAxisLabelPosition]('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); + c3_chart_internal_fn.getXAxisLabelPosition = function () { + return this.getAxisLabelPosition('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); }; - var getYAxisLabelPosition = 'getYAxisLabelPosition'; - c3_chart_internal_fn[getYAxisLabelPosition] = function () { - return this[getAxisLabelPosition]('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getYAxisLabelPosition = function () { + return this.getAxisLabelPosition('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - var getY2AxisLabelPosition = 'getY2AxisLabelPosition'; - c3_chart_internal_fn[getY2AxisLabelPosition] = function () { - return this[getAxisLabelPosition]('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); + c3_chart_internal_fn.getY2AxisLabelPosition = function () { + return this.getAxisLabelPosition('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); }; - var getAxisLabelPositionById = 'getAxisLabelPositionById'; - c3_chart_internal_fn[getAxisLabelPositionById] = function (id) { - return id === 'y2' ? this[getY2AxisLabelPosition]() : id === 'y' ? this[getYAxisLabelPosition]() : this[getXAxisLabelPosition](); + c3_chart_internal_fn.getAxisLabelPositionById = function (id) { + return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); }; - var textForXAxisLabel = 'textForXAxisLabel'; - c3_chart_internal_fn[textForXAxisLabel] = function () { - return this[getAxisLabelText]('x'); + c3_chart_internal_fn.textForXAxisLabel = function () { + return this.getAxisLabelText('x'); }; - var textForYAxisLabel = 'textForYAxisLabel'; - c3_chart_internal_fn[textForYAxisLabel] = function () { - return this[getAxisLabelText]('y'); + c3_chart_internal_fn.textForYAxisLabel = function () { + return this.getAxisLabelText('y'); }; - var textForY2AxisLabel = 'textForY2AxisLabel'; - c3_chart_internal_fn[textForY2AxisLabel] = function () { - return this[getAxisLabelText]('y2'); + c3_chart_internal_fn.textForY2AxisLabel = function () { + return this.getAxisLabelText('y2'); }; - var xForAxisLabel = 'xForAxisLabel'; - c3_chart_internal_fn[xForAxisLabel] = function (forHorizontal, position) { + c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { var $$ = this; if (forHorizontal) { return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; @@ -4349,125 +4106,107 @@ return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; } }; - var dxForAxisLabel = 'dxForAxisLabel'; - c3_chart_internal_fn[dxForAxisLabel] = function (forHorizontal, position) { + c3_chart_internal_fn.dxForAxisLabel = function (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"; } }; - var textAnchorForAxisLabel = 'textAnchorForAxisLabel'; - c3_chart_internal_fn[textAnchorForAxisLabel] = function (forHorizontal, position) { + c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { if (forHorizontal) { return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; } else { return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; } }; - var xForXAxisLabel = 'xForXAxisLabel'; - c3_chart_internal_fn[xForXAxisLabel] = function () { - return this[xForAxisLabel](!this.config[__axis_rotated], this[getXAxisLabelPosition]()); + c3_chart_internal_fn.xForXAxisLabel = function () { + return this.xForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); }; - var xForYAxisLabel = 'xForYAxisLabel'; - c3_chart_internal_fn[xForYAxisLabel] = function () { - return this[xForAxisLabel](this.config[__axis_rotated], this[getYAxisLabelPosition]()); + c3_chart_internal_fn.xForYAxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); }; - var xForY2AxisLabel = 'xForY2AxisLabel'; - c3_chart_internal_fn[xForY2AxisLabel] = function () { - return this[xForAxisLabel](this.config[__axis_rotated], this[getY2AxisLabelPosition]()); + c3_chart_internal_fn.xForY2AxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); }; - var dxForXAxisLabel = 'dxForXAxisLabel'; - c3_chart_internal_fn[dxForXAxisLabel] = function () { - return this[dxForAxisLabel](!this.config[__axis_rotated], this[getXAxisLabelPosition]()); + c3_chart_internal_fn.dxForXAxisLabel = function () { + return this.dxForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); }; - var dxForYAxisLabel = 'dxForYAxisLabel'; - c3_chart_internal_fn[dxForYAxisLabel] = function () { - return this[dxForAxisLabel](this.config[__axis_rotated], this[getYAxisLabelPosition]()); + c3_chart_internal_fn.dxForYAxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); }; - var dxForY2AxisLabel = 'dxForY2AxisLabel'; - c3_chart_internal_fn[dxForY2AxisLabel] = function () { - return this[dxForAxisLabel](this.config[__axis_rotated], this[getY2AxisLabelPosition]()); + c3_chart_internal_fn.dxForY2AxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); }; - var dyForXAxisLabel = 'dyForXAxisLabel'; - c3_chart_internal_fn[dyForXAxisLabel] = function () { + c3_chart_internal_fn.dyForXAxisLabel = function () { var $$ = this, config = $$.config, - position = $$[getXAxisLabelPosition](); + position = $$.getXAxisLabelPosition(); if (config[__axis_rotated]) { - return position.isInner ? "1.2em" : -25 - $$[getMaxTickWidth]('x'); + return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); } else { return position.isInner ? "-0.5em" : config[__axis_x_height] ? config[__axis_x_height] - 10 : "3em"; } }; - var dyForYAxisLabel = 'dyForYAxisLabel'; - c3_chart_internal_fn[dyForYAxisLabel] = function () { + c3_chart_internal_fn.dyForYAxisLabel = function () { var $$ = this, - position = $$[getYAxisLabelPosition](); + position = $$.getYAxisLabelPosition(); if ($$.config[__axis_rotated]) { return position.isInner ? "-0.5em" : "3em"; } else { - return position.isInner ? "1.2em" : -20 - $$[getMaxTickWidth]('y'); + return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); } }; - var dyForY2AxisLabel = 'dyForY2AxisLabel'; - c3_chart_internal_fn[dyForY2AxisLabel] = function () { + c3_chart_internal_fn.dyForY2AxisLabel = function () { var $$ = this, - position = $$[getY2AxisLabelPosition](); + position = $$.getY2AxisLabelPosition(); if ($$.config[__axis_rotated]) { return position.isInner ? "1.2em" : "-2.2em"; } else { - return position.isInner ? "-0.5em" : 30 + this[getMaxTickWidth]('y2'); + return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); } }; - var textAnchorForXAxisLabel = 'textAnchorForXAxisLabel'; - c3_chart_internal_fn[textAnchorForXAxisLabel] = function () { + c3_chart_internal_fn.textAnchorForXAxisLabel = function () { var $$ = this; - return $$[textAnchorForAxisLabel](!$$.config[__axis_rotated], $$[getXAxisLabelPosition]()); + return $$.textAnchorForAxisLabel(!$$.config[__axis_rotated], $$.getXAxisLabelPosition()); }; - var textAnchorForYAxisLabel = 'textAnchorForYAxisLabel'; - c3_chart_internal_fn[textAnchorForYAxisLabel] = function () { + c3_chart_internal_fn.textAnchorForYAxisLabel = function () { var $$ = this; - return $$[textAnchorForAxisLabel]($$.config[__axis_rotated], $$[getYAxisLabelPosition]()); + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getYAxisLabelPosition()); }; - var textAnchorForY2AxisLabel = 'textAnchorForY2AxisLabel'; - c3_chart_internal_fn[textAnchorForY2AxisLabel] = function () { + c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { var $$ = this; - return $$[textAnchorForAxisLabel]($$.config[__axis_rotated], $$[getY2AxisLabelPosition]()); + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getY2AxisLabelPosition()); }; - var xForRotatedTickText = 'xForRotatedTickText'; - c3_chart_internal_fn[xForRotatedTickText] = function (r) { + c3_chart_internal_fn.xForRotatedTickText = function (r) { return 10 * Math.sin(Math.PI * (r / 180)); }; - var yForRotatedTickText = 'yForRotatedTickText'; - c3_chart_internal_fn[yForRotatedTickText] = function (r) { + c3_chart_internal_fn.yForRotatedTickText = function (r) { return 11.5 - 2.5 * (r / 15); }; - var rotateTickText = 'rotateTickText'; - c3_chart_internal_fn[rotateTickText] = function (axis, transition, rotate) { + c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) { axis.selectAll('.tick text') - .style(CSS_TEXT_ANCHOR, "start"); + .style("text-anchor", "start"); transition.selectAll('.tick text') - .attr("y", this[yForRotatedTickText](rotate)) - .attr("x", this[xForRotatedTickText](rotate)) - .attr(CSS_TRANSFORM, "rotate(" + rotate + ")"); + .attr("y", this.yForRotatedTickText(rotate)) + .attr("x", this.xForRotatedTickText(rotate)) + .attr("transform", "rotate(" + rotate + ")"); }; - var getMaxTickWidth = 'getMaxTickWidth'; - c3_chart_internal_fn[getMaxTickWidth] = function (id) { + c3_chart_internal_fn.getMaxTickWidth = function (id) { var $$ = this, config = $$.config, maxWidth = 0, targetsToShow, scale, axis; if ($$.svg) { - targetsToShow = $$[filterTargetsToShow]($$.data.targets); + targetsToShow = $$.filterTargetsToShow($$.data.targets); if (id === 'y') { - scale = $$.y.copy().domain($$[getYDomain](targetsToShow, 'y')); - axis = $$[getYAxis](scale, $$[yOrient], config[__axis_y_tick_format], config[__axis_y_ticks]); + scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); + axis = $$.getYAxis(scale, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); } else if (id === 'y2') { - scale = $$.y2.copy().domain($$[getYDomain](targetsToShow, 'y2')); - axis = $$[getYAxis](scale, $$[y2Orient], config[__axis_y2_tick_format], config[__axis_y2_ticks]); + scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); + axis = $$.getYAxis(scale, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); } else { - scale = $$.x.copy().domain($$[getXDomain](targetsToShow)); - axis = $$[getXAxis](scale, $$[xOrient], $$[getXAxisTickFormat](), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); + scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); + axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); } $$.main.append("g").call(axis).each(function () { $$.d3.select(this).selectAll('text').each(function () { @@ -4476,41 +4215,38 @@ }); }).remove(); } - $$[currentMaxTickWidth] = maxWidth <= 0 ? $$[currentMaxTickWidth] : maxWidth; - return $$[currentMaxTickWidth]; + $$.currentMaxTickWidth = maxWidth <= 0 ? $$.currentMaxTickWidth : maxWidth; + return $$.currentMaxTickWidth; }; - var updateAxisLabels = 'updateAxisLabels'; - c3_chart_internal_fn[updateAxisLabels] = function (withTransition) { + c3_chart_internal_fn.updateAxisLabels = function (withTransition) { var $$ = this; - var axisXLabel = $$.main.select('.' + CLASS[axisX] + ' .' + CLASS[axisXLabel]), - axisYLabel = $$.main.select('.' + CLASS[axisY] + ' .' + CLASS[axisYLabel]), - axisY2Label = $$.main.select('.' + CLASS[axisY2] + ' .' + CLASS[axisY2Label]); + 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", generateCall($$[xForXAxisLabel], $$)) - .attr("dx", generateCall($$[dxForXAxisLabel], $$)) - .attr("dy", generateCall($$[dyForXAxisLabel], $$)) + .attr("x", generateCall($$.xForXAxisLabel, $$)) + .attr("dx", generateCall($$.dxForXAxisLabel, $$)) + .attr("dy", generateCall($$.dyForXAxisLabel, $$)) .text(generateCall($$.textForXAxisLabel, $$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", generateCall($$[xForYAxisLabel], $$)) - .attr("dx", generateCall($$[dxForYAxisLabel], $$)) - .attr("dy", generateCall($$[dyForYAxisLabel], $$)) - .text(generateCall($$[textForYAxisLabel], $$)); + .attr("x", generateCall($$.xForYAxisLabel, $$)) + .attr("dx", generateCall($$.dxForYAxisLabel, $$)) + .attr("dy", generateCall($$.dyForYAxisLabel, $$)) + .text(generateCall($$.textForYAxisLabel, $$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", generateCall($$[xForY2AxisLabel], $$)) - .attr("dx", generateCall($$[dxForY2AxisLabel], $$)) - .attr("dy", generateCall($$[dyForY2AxisLabel], $$)) - .text(generateCall($$[textForY2AxisLabel], $$)); + .attr("x", generateCall($$.xForY2AxisLabel, $$)) + .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) + .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) + .text(generateCall($$.textForY2AxisLabel, $$)); }; - var getAxisPadding = 'getAxisPadding'; - c3_chart_internal_fn[getAxisPadding] = function (padding, key, defaultValue, all) { + c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { var ratio = padding.unit === 'ratio' ? all : 1; return isValue(padding[key]) ? padding[key] * ratio : defaultValue; }; - var generateTickValues = 'generateTickValues'; - c3_chart_internal_fn[generateTickValues] = function (xs, tickCount) { + c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { var $$ = this; var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; if (tickCount) { @@ -4529,12 +4265,12 @@ tickValues = [start]; for (i = 0; i < count; i++) { tickValue = +start + interval * (i + 1); - tickValues.push($$[isTimeSeries] ? new Date(tickValue) : tickValue); + tickValues.push($$.isTimeSeries ? new Date(tickValue) : tickValue); } tickValues.push(end); } } - if (!$$[isTimeSeries]) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + if (!$$.isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; @@ -4542,52 +4278,47 @@ /** * c3.region.js */ - var regionX = 'regionX'; - c3_chart_internal_fn[regionX] = function (d) { + c3_chart_internal_fn.regionX = function (d) { var $$ = this, config = $$.config, xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.start) : d.start) : 0); + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); } return xPos; }; - var regionY = 'regionY'; - c3_chart_internal_fn[regionY] = function (d) { + c3_chart_internal_fn.regionY = function (d) { var $$ = this, config = $$.config, yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = config[__axis_rotated] ? ('start' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.start) : d.start) : 0) : 0; + yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; } return yPos; }; - var regionWidth = 'regionWidth'; - c3_chart_internal_fn[regionWidth] = function (d) { + c3_chart_internal_fn.regionWidth = function (d) { var $$ = this, config = $$.config, - start = $$[regionX](d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = config[__axis_rotated] ? $$.width : ('end' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.end) : d.end) : $$.width); + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; - var regionHeight = 'regionHeight'; - c3_chart_internal_fn[regionHeight] = function (d) { + c3_chart_internal_fn.regionHeight = function (d) { var $$ = this, config = $$.config, - start = this[regionY](d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = config[__axis_rotated] ? ('end' in d ? $$[x]($$[isTimeSeries] ? $$[parseDate](d.end) : d.end) : $$.height) : $$.height; + end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; - var isRegionOnX = 'isRegionOnX'; - c3_chart_internal_fn[isRegionOnX] = function (d) { + c3_chart_internal_fn.isRegionOnX = function (d) { return !d.axis || d.axis === 'x'; }; @@ -4596,40 +4327,36 @@ //-- c3.arc.js --// - var initPie = 'initPie', pie = 'pie'; - c3_chart_internal_fn[initPie] = function () { + c3_chart_internal_fn.initPie = function () { var $$ = this, d3 = $$.d3, config = $$.config; - $$[pie] = d3.layout.pie().value(function (d) { + $$.pie = d3.layout.pie().value(function (d) { return d.values.reduce(function (a, b) { return a + b.value; }, 0); }); if (!config[__data_order] || !config[__pie_sort] || !config[__donut_sort]) { - $$[pie].sort(null); + $$.pie.sort(null); } }; - var updateRadius = 'updateRadius'; - c3_chart_internal_fn[updateRadius] = function () { + c3_chart_internal_fn.updateRadius = function () { var $$ = this, config = $$.config, w = config[__gauge_width] || config[__donut_width]; $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; }; - var updateArc = 'updateArc', svgArc = 'svgArc', svgArcExpanded = 'svgArcExpanded', svgArcExpandedSub = 'svgArcExpandedSub'; - c3_chart_internal_fn[updateArc] = function () { + c3_chart_internal_fn.updateArc = function () { var $$ = this; - $$[svgArc] = $$[getSvgArc](); - $$[svgArcExpanded] = $$[getSvgArcExpanded](); - $$[svgArcExpandedSub] = $$[getSvgArcExpanded](0.98); + $$.svgArc = $$.getSvgArc(); + $$.svgArcExpanded = $$.getSvgArcExpanded(); + $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); }; - var updateAngle = 'updateAngle'; - c3_chart_internal_fn[updateAngle] = function (d) { + c3_chart_internal_fn.updateAngle = function (d) { var $$ = this, config = $$.config, found = false, index = 0; - $$[pie]($$[filterTargetsToShow]($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { + $$.pie($$.filterTargetsToShow($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { if (! found && t.data.id === d.data.id) { found = true; d = t; @@ -4640,7 +4367,7 @@ if (isNaN(d.endAngle)) { d.endAngle = d.startAngle; } - if ($$[isGaugeType](d.data)) { + if ($$.isGaugeType(d.data)) { var gMin = config[__gauge_min], gMax = config[__gauge_max], gF = Math.abs(gMin) + gMax, aTic = (Math.PI) / gF; @@ -4650,14 +4377,13 @@ return found ? d : null; }; - var getSvgArc = 'getSvgArc'; - c3_chart_internal_fn[getSvgArc] = function () { + c3_chart_internal_fn.getSvgArc = function () { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), newArc = function (d, withoutUpdate) { var updated; if (withoutUpdate) { return arc(d); } // for interpolate - updated = $$[updateAngle](d); + updated = $$.updateAngle(d); return updated ? arc(updated) : "M 0 0"; }; // TODO: extends all function @@ -4665,27 +4391,24 @@ return newArc; }; - var getSvgArcExpanded = 'getSvgArcExpanded'; - c3_chart_internal_fn[getSvgArcExpanded] = function (rate) { + c3_chart_internal_fn.getSvgArcExpanded = function (rate) { var $$ = this, arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); return function (d) { - var updated = $$[updateAngle](d); + var updated = $$.updateAngle(d); return updated ? arc(updated) : "M 0 0"; }; }; - var getArc = 'getArc'; - c3_chart_internal_fn[getArc] = function (d, withoutUpdate, force) { - return force || this[isArcType](d.data) ? this[svgArc](d, withoutUpdate) : "M 0 0"; + c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { + return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; }; - var transformForArcLabel = 'transformForArcLabel'; - c3_chart_internal_fn[transformForArcLabel] = function (d) { + c3_chart_internal_fn.transformForArcLabel = function (d) { var $$ = this, - updated = $$[updateAngle](d), c, x, y, h, ratio, translate = ""; - if (updated && !$$[hasType]($$.data.targets, TYPE_GAUGE)) { + updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !$$.hasGaugeType($$.data.targets)) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4697,209 +4420,195 @@ return translate; }; - var getArcRatio = 'getArcRatio'; - c3_chart_internal_fn[getArcRatio] = function (d) { + c3_chart_internal_fn.getArcRatio = function (d) { var $$ = this, - whole = $$[hasType]($$.data.targets, TYPE_GAUGE) ? Math.PI : (Math.PI * 2); + whole = $$.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; - var convertToArcData = 'convertToArcData'; - c3_chart_internal_fn[convertToArcData] = function (d) { - return this[addName]({ + c3_chart_internal_fn.convertToArcData = function (d) { + return this.addName({ id: d.data.id, value: d.value, - ratio: this[getArcRatio](d), + ratio: this.getArcRatio(d), index: d.index }); }; - var textForArcLabel = 'textForArcLabel'; - c3_chart_internal_fn[textForArcLabel] = function (d) { + c3_chart_internal_fn.textForArcLabel = function (d) { var $$ = this, updated, value, ratio, format; - if (! $$[shouldShowArcLabel]()) { return ""; } - updated = $$[updateAngle](d); + if (! $$.shouldShowArcLabel()) { return ""; } + updated = $$.updateAngle(d); value = updated ? updated.value : null; - ratio = $$[getArcRatio](updated); - if (! $$[hasType]($$.data.targets, TYPE_GAUGE) && ! $$[meetsArcLabelThreshold](ratio)) { return ""; } - format = $$[getArcLabelFormat](); - return format ? format(value, ratio) : $$[defaultArcValueFormat](value, ratio); + ratio = $$.getArcRatio(updated); + if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } + format = $$.getArcLabelFormat(); + return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; - var expandArc = 'expandArc'; - c3_chart_internal_fn[expandArc] = function (id, withoutFadeOut) { + c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS[chartArc] + $$[selectorTarget](id)), - noneTargets = $$.svg.selectAll('.' + CLASS[arc]).filter(function (data) { return data.data.id !== id; }); + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), + noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); - if ($$[shouldExpand](id)) { + if ($$.shouldExpand(id)) { target.selectAll('path') .transition().duration(50) - .attr("d", $$[svgArcExpanded]) + .attr("d", $$.svgArcExpanded) .transition().duration(100) - .attr("d", $$[svgArcExpandedSub]) + .attr("d", $$.svgArcExpandedSub) .each(function (d) { - if ($$[isDonutType](d.data)) { + if ($$.isDonutType(d.data)) { // callback here } }); } if (!withoutFadeOut) { - noneTargets.style(CSS_OPACITY, 0.3); + noneTargets.style("opacity", 0.3); } }; - var unexpandArc = 'unexpandArc'; - c3_chart_internal_fn[unexpandArc] = function (id) { + c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS[chartArc] + $$[selectorTarget](id)); - target.selectAll('path.' + CLASS[arc]) + target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); + target.selectAll('path.' + CLASS.arc) .transition().duration(50) .attr("d", $$.svgArc); - $$.svg.selectAll('.' + CLASS[arc]) - .style(CSS_OPACITY, 1); + $$.svg.selectAll('.' + CLASS.arc) + .style("opacity", 1); }; - var shouldExpand = 'shouldExpand'; - c3_chart_internal_fn[shouldExpand] = function (id) { + c3_chart_internal_fn.shouldExpand = function (id) { 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]); }; - var shouldShowArcLabel = 'shouldShowArcLabel'; - c3_chart_internal_fn[shouldShowArcLabel] = function () { + c3_chart_internal_fn.shouldShowArcLabel = function () { var $$ = this, config = $$.config, shouldShow = true; - if ($$[hasType]($$.data.targets, TYPE_DONUT)) { + if ($$.hasDonutType($$.data.targets)) { shouldShow = config[__donut_label_show]; - } else if ($$[hasType]($$.data.targets, TYPE_PIE)) { + } else if ($$.hasPieType($$.data.targets)) { shouldShow = config[__pie_label_show]; } // when gauge, always true return shouldShow; }; - var meetsArcLabelThreshold = 'meetsArcLabelThreshold'; - c3_chart_internal_fn[meetsArcLabelThreshold] = function (ratio) { + c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { var $$ = this, config = $$.config, - threshold = $$[hasType]($$.data.targets, TYPE_DONUT) ? config[__donut_label_threshold] : config[__pie_label_threshold]; + threshold = $$.hasDonutType($$.data.targets) ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; - var getArcLabelFormat = 'getArcLabelFormat'; - c3_chart_internal_fn[getArcLabelFormat] = function () { + c3_chart_internal_fn.getArcLabelFormat = function () { var $$ = this, config = $$.config, format = config[__pie_label_format]; - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$.hasGaugeType($$.data.targets)) { format = config[__gauge_label_format]; - } else if ($$[hasType]($$.data.targets, TYPE_DONUT)) { + } else if ($$.hasDonutType($$.data.targets)) { format = config[__donut_label_format]; } return format; }; - var getArcTitle = 'getArcTitle'; - c3_chart_internal_fn[getArcTitle] = function () { + c3_chart_internal_fn.getArcTitle = function () { var $$ = this; - return $$[hasType]($$.data.targets, TYPE_DONUT) ? $$.config[__donut_title] : ""; + return $$.hasDonutType($$.data.targets) ? $$.config[__donut_title] : ""; }; - var descByStartAngle = 'descByStartAngle'; - c3_chart_internal_fn[descByStartAngle] = function (a, b) { + c3_chart_internal_fn.descByStartAngle = function (a, b) { return a.startAngle - b.startAngle; }; - var updateTargetsForArc = 'updateTargetsForArc'; - c3_chart_internal_fn[updateTargetsForArc] = function (targets) { + c3_chart_internal_fn.updateTargetsForArc = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; - mainPieUpdate = main.select('.' + CLASS[chartArcs]).selectAll('.' + CLASS[chartArc]) - .data($$[pie](targets)) - .attr(CSS_CLASS, generateCall($$[classChartArc], $$)); + mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) + .data($$.pie(targets)) + .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter = mainPieUpdate.enter().append("g") - .attr(CSS_CLASS, generateCall($$[classChartArc], $$)); + .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classArcs], $$)); + .attr('class', generateCall($$.classArcs, $$)); mainPieEnter.append("text") - .attr("dy", $$[hasType]($$.data.targets, TYPE_GAUGE) ? "-0.35em" : ".35em") - .style(CSS_OPACITY, 0) - .style(CSS_TEXT_ANCHOR, "middle") - .style(CSS_POINTER_EVENTS, "none"); + .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") + .style("opacity", 0) + .style("text-anchor", "middle") + .style("pointer-events", "none"); // MEMO: can not keep same color..., but not bad to update color in redraw //mainPieUpdate.exit().remove(); }; - var initArc = 'initArc'; - c3_chart_internal_fn[initArc] = function () { + c3_chart_internal_fn.initArc = function () { var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartArcs]) - .attr(CSS_TRANSFORM, $$[translate].arc); + arcs = $$.main.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartArcs) + .attr("transform", $$.translate.arc); arcs.append('text') - .attr(CSS_CLASS, CLASS[chartArcsTitle]) - .style(CSS_TEXT_ANCHOR, "middle") - .text($$[getArcTitle]()); + .attr('class', CLASS.chartArcsTitle) + .style("text-anchor", "middle") + .text($$.getArcTitle()); }; - var redrawArc = 'redrawArc'; - 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, mainArc; - mainArc = main.selectAll('.' + CLASS[arcs]).selectAll('.' + CLASS[arc]) - .data(generateCall($$[arcData], $$)); + mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) + .data(generateCall($$.arcData, $$)); mainArc.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classArc], $$)) - .style("fill", function (d) { return $$[color](d.data); }) + .attr("class", generateCall($$.classArc, $$)) + .style("fill", function (d) { return $$.color(d.data); }) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) - .style(CSS_OPACITY, 0) + .style("opacity", 0) .each(function (d) { - if ($$[isGaugeType](d.data)) { + if ($$.isGaugeType(d.data)) { d.startAngle = d.endAngle = -1 * (Math.PI / 2); } this._current = d; }) .on('mouseover', function (d) { var updated, arcData; - if ($$[transiting]) { // skip while transiting + if ($$.transiting) { // skip while transiting return; } - updated = $$[updateAngle](d); - arcData = $$[convertToArcData](updated); + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); // transitions - $$[expandArc](updated.data.id); - $$[toggleFocusLegend](updated.data.id, true); + $$.expandArc(updated.data.id); + $$.toggleFocusLegend(updated.data.id, true); $$.config[__data_onmouseover](arcData, this); }) .on('mousemove', function (d) { - var updated = $$[updateAngle](d), - arcData = $$[convertToArcData](updated), + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated), selectedData = [arcData]; - $$[showTooltip](selectedData, d3.mouse(this)); + $$.showTooltip(selectedData, d3.mouse(this)); }) .on('mouseout', function (d) { var updated, arcData; - if ($$[transiting]) { // skip while transiting + if ($$.transiting) { // skip while transiting return; } - updated = $$[updateAngle](d); - arcData = $$[convertToArcData](updated); + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); // transitions - $$[unexpandArc](updated.data.id); - $$[revertLegend](); - $$[hideTooltip](); + $$.unexpandArc(updated.data.id); + $$.revertLegend(); + $$.hideTooltip(); $$.config[__data_onmouseout](arcData, this); }) .on('click', function (d, i) { - var updated = $$[updateAngle](d), - arcData = $$[convertToArcData](updated); - $$[toggleShape](this, arcData, i); // onclick called in toogleShape() + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated); + $$.toggleShape(this, arcData, i); // onclick called in toogleShape() }); mainArc - .attr(CSS_TRANSFORM, function (d) { return !$$[isGaugeType](d.data) && withTransform ? "scale(0)" : ""; }) - .style(CSS_OPACITY, function (d) { return d === this._current ? 0 : 1; }) - .each(function () { $$[transiting] = true; }) + .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .style("opacity", function (d) { return d === this._current ? 0 : 1; }) + .each(function () { $$.transiting = true; }) .transition().duration(duration) .attrTween("d", function (d) { - var updated = $$[updateAngle](d), interpolate; + var updated = $$.updateAngle(d), interpolate; if (! updated) { return function () { return "M 0 0"; }; } @@ -4914,66 +4623,65 @@ } interpolate = d3.interpolate(this._current, updated); this._current = interpolate(0); - return function (t) { return $$[getArc](interpolate(t), true); }; + return function (t) { return $$.getArc(interpolate(t), true); }; }) - .attr(CSS_TRANSFORM, withTransform ? "scale(1)" : "") + .attr("transform", withTransform ? "scale(1)" : "") .style("fill", function (d) { - return $$[levelColor] ? $$[levelColor](d.data.values[0].value) : $$[color](d.data.id); + return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); }) // Where gauge reading color would receive customization. - .style(CSS_OPACITY, 1) + .style("opacity", 1) .call($$.endall, function () { - $$[transiting] = false; + $$.transiting = false; }); mainArc.exit().transition().duration(durationForExit) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); - main.selectAll('.' + CLASS[chartArc]).select('text') - .style(CSS_OPACITY, 0) - .attr(CSS_CLASS, function (d) { return $$[isGaugeType](d.data) ? CLASS[gaugeValue] : ''; }) - .text(generateCall($$[textForArcLabel], $$)) - .attr(CSS_TRANSFORM, generateCall($$[transformForArcLabel], $$)) + main.selectAll('.' + CLASS.chartArc).select('text') + .style("opacity", 0) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .text(generateCall($$.textForArcLabel, $$)) + .attr("transform", generateCall($$.transformForArcLabel, $$)) .transition().duration(duration) - .style(CSS_OPACITY, function (d) { return $$[isTargetToShow](d.data.id) && $$[isArcType](d.data) ? 1 : 0; }); - main.select('.' + CLASS[chartArcsTitle]) - .style(CSS_OPACITY, $$[hasType]($$.data.targets, TYPE_DONUT) || $$[hasType]($$.data.targets, TYPE_GAUGE) ? 1 : 0); + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); + main.select('.' + CLASS.chartArcsTitle) + .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); }; //-- gauge.js --// - var initGauge = 'initGauge'; - c3_chart_internal_fn[initGauge] = function () { + c3_chart_internal_fn.initGauge = function () { var $$ = this, config = $$.config, arcs; - if ($$[hasType]($$.data.targets, TYPE_GAUGE)) { + if ($$.hasGaugeType($$.data.targets)) { arcs.append('path') - .attr(CSS_CLASS, CLASS[chartArcsBackground]) + .attr("class", CLASS.chartArcsBackground) .attr("d", function () { var d = { data: [{value: config[__gauge_max]}], startAngle: -1 * (Math.PI / 2), endAngle: Math.PI / 2 }; - return $$[getArc](d, true, true); + return $$.getArc(d, true, true); }); arcs.append("text") .attr("dy", ".75em") - .attr(CSS_CLASS, CLASS[chartArcsGaugeUnit]) - .style(CSS_TEXT_ANCHOR, "middle") - .style(CSS_POINTER_EVENTS, "none") + .attr("class", CLASS.chartArcsGaugeUnit) + .style("text-anchor", "middle") + .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_units] : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") - .attr(CSS_CLASS, CLASS[chartArcsGaugeMin]) - .style(CSS_TEXT_ANCHOR, "middle") - .style(CSS_POINTER_EVENTS, "none") + .attr("class", CLASS.chartArcsGaugeMin) + .style("text-anchor", "middle") + .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_min] : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") - .attr(CSS_CLASS, CLASS[chartArcsGaugeMax]) - .style(CSS_TEXT_ANCHOR, "middle") - .style(CSS_POINTER_EVENTS, "none") + .attr("class", CLASS.chartArcsGaugeMax) + .style("text-anchor", "middle") + .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_max] : ''); } }; @@ -4982,66 +4690,61 @@ /** * c3.cache.js */ - var hasCaches = 'hasCaches'; - c3_chart_internal_fn[hasCaches] = function (ids) { + c3_chart_internal_fn.hasCaches = function (ids) { for (var i = 0; i < ids.length; i++) { if (! (ids[i] in this.cache)) { return false; } } return true; }; - var addCache = 'addCache'; - c3_chart_internal_fn[addCache] = function (id, target) { - this.cache[id] = this[cloneTarget](target); + c3_chart_internal_fn.addCache = function (id, target) { + this.cache[id] = this.cloneTarget(target); }; - var getCaches = 'getCaches'; - c3_chart_internal_fn[getCaches] = function (ids) { + c3_chart_internal_fn.getCaches = function (ids) { var targets = [], i; for (i = 0; i < ids.length; i++) { - if (ids[i] in this.cache) { targets.push(this[cloneTarget](this.cache[ids[i]])); } + if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } } return targets; }; //-- subchart.js --// - var initBrush = 'initBrush'; - c3_chart_internal_fn[initBrush] = function () { + c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; - $$.brush = d3.svg.brush().on("brush", function () { $$[redrawForBrush](); }); + $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + CLASS[brush]).call(this); } + if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } return this; }; $$.brush.scale = function (scale) { - return $$.config[__axis_rotated] ? this[y](scale) : this[x](scale); + return $$.config[__axis_rotated] ? this.y(scale) : this.x(scale); }; }; - var initSubchart = 'initSubchart'; - c3_chart_internal_fn[initSubchart] = function () { + c3_chart_internal_fn.initSubchart = function () { var $$ = this, config = $$.config, - context = $$.context = $$.svg.append("g").attr(CSS_TRANSFORM, $$[translate].context); + context = $$.context = $$.svg.append("g").attr("transform", $$.translate.context); if (!config[__subchart_show]) { - context.style(CSS_VISIBILITY, 'hidden'); + context.style('visibility', 'hidden'); } // Define g for chart area context.append('g') - .attr("clip-path", $$[clipPath]) - .attr(CSS_CLASS, CLASS[chart]); + .attr("clip-path", $$.clipPath) + .attr('class', CLASS.chart); // Define g for bar chart area - context.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartBars]); + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartBars); // Define g for line chart area - context.select('.' + CLASS[chart]).append("g") - .attr(CSS_CLASS, CLASS[chartLines]); + context.select('.' + CLASS.chart).append("g") + .attr("class", CLASS.chartLines); // Add extent rect for Brush context.append("g") - .attr("clip-path", $$[clipPath]) - .attr(CSS_CLASS, CLASS[brush]) + .attr("clip-path", $$.clipPath) + .attr("class", CLASS.brush) .call($$.brush) .selectAll("rect") .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); @@ -5049,44 +4752,42 @@ // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = context.append("g") - .attr(CSS_CLASS, CLASS[axisX]) - .attr(CSS_TRANSFORM, $$[translate].subx) - .attr("clip-path", config[__axis_rotated] ? "" : $$[clipPathForXAxis]); + .attr("class", CLASS.axisX) + .attr("transform", $$.translate.subx) + .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); }; - var updateTargetsForSubchart = 'updateTargetsForSubchart'; - c3_chart_internal_fn[updateTargetsForSubchart] = function (targets) { + c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { var $$ = this, context = $$.context, config = $$.config, contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) + contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) .data(targets) - .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); + .attr('class', generateCall($$.classChartBar, $$)); contextBarEnter = contextBarUpdate.enter().append('g') - .style(CSS_OPACITY, 0) - .attr(CSS_CLASS, generateCall($$[classChartBar], $$)); + .style('opacity', 0) + .attr('class', generateCall($$.classChartBar, $$)); // Bars for each data contextBarEnter.append('g') - .attr(CSS_CLASS, generateCall($$[classBars], $$)); + .attr("class", generateCall($$.classBars, $$)); //-- Line --// - contextLineUpdate = context.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) + contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) .data(targets) - .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); + .attr('class', generateCall($$.classChartLine, $$)); contextLineEnter = contextLineUpdate.enter().append('g') - .style(CSS_OPACITY, 0) - .attr(CSS_CLASS, generateCall($$[classChartLine], $$)); + .style('opacity', 0) + .attr('class', generateCall($$.classChartLine, $$)); // Lines for each data contextLineEnter.append("g") - .attr(CSS_CLASS, generateCall($$[classLines], $$)); + .attr("class", generateCall($$.classLines, $$)); // Area contextLineEnter.append("g") - .attr(CSS_CLASS, generateCall($$[classAreas], $$)); + .attr("class", generateCall($$.classAreas, $$)); } }; - var redrawSubchart = 'redrawSubchart'; - 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, context = $$.context, config = $$.config, contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; @@ -5101,7 +4802,7 @@ // rotate tick text if needed if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { - $$[rotateTickText]($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); + $$.rotateTickText($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); } // extent rect @@ -5109,61 +4810,60 @@ $$.brush.extent($$.x.orgDomain()).update(); } // setup drawer - MEMO: this must be called after axis updated - drawAreaOnSub = $$[generateDrawArea](areaIndices, true); - drawBarOnSub = $$[generateDrawBar](barIndices, true); - drawLineOnSub = $$[generateDrawLine](lineIndices, true); + drawAreaOnSub = $$.generateDrawArea(areaIndices, true); + drawBarOnSub = $$.generateDrawBar(barIndices, true); + drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars - contextBar = context.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) - .data(generateCall($$[barData], $$)); + contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + .data(generateCall($$.barData, $$)); contextBar.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classBar], $$)) + .attr("class", generateCall($$.classBar, $$)) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) + .style("opacity", generateCall($$.initialOpacity, $$)) .transition().duration(duration) .attr('d', drawBarOnSub) - .style(CSS_OPACITY, 1); + .style('opacity', 1); contextBar.exit().transition().duration(duration) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); // lines - contextLine = context.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) - .data(generateCall($$[lineData], $$)); + contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + .data(generateCall($$.lineData, $$)); contextLine.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classLine], $$)) + .attr('class', generateCall($$.classLine, $$)) .style('stroke', $$.color); contextLine - .style(CSS_OPACITY, generateCall($$[initialOpacity], $$)) + .style("opacity", generateCall($$.initialOpacity, $$)) .transition().duration(duration) .attr("d", drawLineOnSub) - .style(CSS_OPACITY, 1); + .style('opacity', 1); contextLine.exit().transition().duration(duration) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); // area - contextArea = context.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) - .data(generateCall($$[lineData], $$)); + contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + .data(generateCall($$.lineData, $$)); contextArea.enter().append('path') - .attr(CSS_CLASS, generateCall($$[classArea], $$)) + .attr("class", generateCall($$.classArea, $$)) .style("fill", $$.color) - .style(CSS_OPACITY, function () { $$.orgAreaOpacity = +d3.select(this).style(CSS_OPACITY); return 0; }); + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea - .style(CSS_OPACITY, 0) + .style("opacity", 0) .transition().duration(duration) .attr("d", drawAreaOnSub) .style("fill", $$.color) - .style(CSS_OPACITY, $$.orgAreaOpacity); + .style("opacity", $$.orgAreaOpacity); contextArea.exit().transition().duration(durationForExit) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); } } }; - var redrawForBrush = 'redrawForBrush'; - c3_chart_internal_fn[redrawForBrush] = function () { + c3_chart_internal_fn.redrawForBrush = function () { var $$ = this, x = $$.x; - $$[redraw]({ + $$.redraw({ withTransition: false, withY: false, withSubchart: false, @@ -5171,28 +4871,26 @@ }); $$.config[__subchart_onbrush].call($$, x.orgDomain()); }; - var transformContext = 'transformContext'; - c3_chart_internal_fn[transformContext] = function (withTransition, transitions) { + c3_chart_internal_fn.transformContext = function (withTransition, transitions) { var $$ = this, subXAxis; if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + CLASS[axisX]); + subXAxis = $$.context.select('.' + CLASS.axisX); if (withTransition) { subXAxis = subXAxis.transition(); } } - $$.context.attr(CSS_TRANSFORM, $$[translate].context); - subXAxis.attr(CSS_TRANSFORM, $$[translate].subx); + $$.context.attr("transform", $$.translate.context); + subXAxis.attr("transform", $$.translate.subx); }; /** * c3.zoom.js */ - var updateZoom = 'updateZoom'; - c3_chart_internal_fn[updateZoom] = function () { + c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; - $$.main.select('.' + CLASS[zoomRect]).call(z); - $$.main.selectAll('.' + CLASS[eventRect]).call(z); + $$.main.select('.' + $$.CLASS.zoomRect).call(z); + $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); }; @@ -5210,6 +4908,9 @@ isString = c3_chart_internal_fn.isString = function (o) { return typeof o === 'string'; }, + isUndefined = c3_chart_internal_fn.isUndefined = function (v) { + return typeof v === 'undefined'; + }, isDefined = c3_chart_internal_fn.isDefined = function (v) { return typeof v !== 'undefined'; }, @@ -5248,8 +4949,7 @@ return function (d, i) { return f.call(context, d, i); }; }; - var getTextRect = 'getTextRect'; - c3_chart_internal_fn[getTextRect] = function (text, cls) { + c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; this.d3.select('body').selectAll('.dummy') .data([text]) @@ -5259,80 +4959,71 @@ .each(function () { rect = this.getBoundingClientRect(); }) .remove(); return rect; - }; + }, /** * c3.selection.js */ - var selectPoint = 'selectPoint'; - c3_chart_internal_fn[selectPoint] = function (target, d, i) { + c3_chart_internal_fn.selectPoint = function (target, d, i) { var $$ = this, config = $$.config; config[__data_onselected](d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .data([d]) .enter().append('circle') - .attr(CSS_CLASS, function () { return $$[generateClass](CLASS[selectedCircle], i); }) + .attr("class", function () { return $$.generateClass(CLASS.selectedCircle, i); }) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) - .attr("stroke", function () { return $$[color](d); }) - .attr("r", $$[pointSelectR](d) * 1.4) + .attr("stroke", function () { return $$.color(d); }) + .attr("r", $$.pointSelectR(d) * 1.4) .transition().duration(100) .attr("r", $$.pointSelectR); }; - var unselectPoint = 'unselectPoint'; - c3_chart_internal_fn[unselectPoint] = function (target, d, i) { + c3_chart_internal_fn.unselectPoint = function (target, d, i) { var $$ = this; $$.config[__data_onunselected](d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + CLASS[selectedCircles] + $$[getTargetSelectorSuffix](d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) + $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; - var togglePoint = 'togglePoint'; - c3_chart_internal_fn[togglePoint] = function (selected, target, d, i) { - selected ? this[selectPoint](target, d, i) : this[unselectPoint](target, d, i); + c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { + selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); }; - var selectBar = 'selectBar'; - c3_chart_internal_fn[selectBar] = function (target, d) { + c3_chart_internal_fn.selectBar = function (target, d) { var $$ = this; $$.config[__data_onselected].call($$, d, target.node()); target.transition().duration(100) - .style("fill", function () { return $$.d3.rgb($$[color](d)).brighter(0.75); }); + .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); }; - var unselectBar = 'unselectBar'; - c3_chart_internal_fn[unselectBar] = function (target, d) { + c3_chart_internal_fn.unselectBar = function (target, d) { var $$ = this; $$.config[__data_onunselected].call($$, d, target.node()); target.transition().duration(100) - .style("fill", function () { return $$[color](d); }); + .style("fill", function () { return $$.color(d); }); }; - var toggleBar = 'toggleBar'; - c3_chart_internal_fn[toggleBar] = function (selected, target, d, i) { - selected ? this[selectBar](target, d, i) : this[unselectBar](target, d, i); + c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { + selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); }; - var toggleArc = 'toggleArc'; - c3_chart_internal_fn[toggleArc] = function (selected, target, d, i) { - this[toggleBar](selected, target, d.data, i); + c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { + this.toggleBar(selected, target, d.data, i); }; - var getToggle = 'getToggle'; - c3_chart_internal_fn[getToggle] = function (that) { + c3_chart_internal_fn.getToggle = function (that) { var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[bar]) ? $$.toggleBar : $$.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS.bar) ? $$.toggleBar : $$.toggleArc); }; - var toggleShape = 'toggleShape'; - c3_chart_internal_fn[toggleShape] = function (that, d, i) { + c3_chart_internal_fn.toggleShape = function (that, d, i) { var $$ = this, d3 = $$.d3, config = $$.config, - shape = d3.select(that), isSelected = shape.classed(CLASS[SELECTED]), isWithin, toggle; + shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; if (that.nodeName === 'circle') { - isWithin = $$[isWithinCircle](that, $$[pointSelectR](d) * 1.5); + isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); toggle = $$.togglePoint; } else if (that.nodeName === 'path') { - if (shape.classed(CLASS[bar])) { - isWithin = $$[isWithinBar](that); + if (shape.classed(CLASS.bar)) { + isWithin = $$.isWithinBar(that); toggle = $$.toggleBar; } else { // would be arc isWithin = true; @@ -5342,12 +5033,12 @@ if (config[__data_selection_grouped] || isWithin) { if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { 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) { var shape = d3.select(this); - if (shape.classed(CLASS[SELECTED])) { toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } + if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } }); } - shape.classed(CLASS[SELECTED], !isSelected); + shape.classed(CLASS.SELECTED, !isSelected); toggle(!isSelected, shape, d, i); } $$.config[__data_onclick](d, that); @@ -5358,8 +5049,7 @@ /** * c3.transition.js */ - var generateAxisTransitions = 'generateAxisTransitions'; - c3_chart_internal_fn[generateAxisTransitions] = function (duration) { + c3_chart_internal_fn.generateAxisTransitions = function (duration) { var $$ = this, axes = $$.axes; return { axisX: duration ? axes.x.transition().duration(duration) : axes.x, @@ -5368,8 +5058,7 @@ axisSubX: duration ? axes.subx.transition().duration(duration) : axes.subx }; }; - var endall = 'endall'; - c3_chart_internal_fn[endall] = function (transition, callback) { + c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition .each(function () { ++n; }) @@ -5377,8 +5066,7 @@ if (!--n) { callback.apply(this, arguments); } }); }; - var generateWait = 'generateWait'; - c3_chart_internal_fn[generateWait] = function () { + c3_chart_internal_fn.generateWait = function () { var transitionsToWait = [], f = function (transition, callback) { var timer = setInterval(function () { @@ -5410,280 +5098,180 @@ /** * c3.transform.js */ - var transformTo = 'transformTo'; - c3_chart_internal_fn[transformTo] = function (targetIds, type, optionsForRedraw) { + c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$[hasArcType]($$.data.targets), + withTransitionForAxis = !$$.hasArcType($$.data.targets), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; - $$[transiting] = false; - $$[setTargetType](targetIds, type); - $$[updateAndRedraw](options); + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); }; /** * c3.class.js */ - var target = 'target', - chart = 'chart ', - chartLine = 'chartLine', - chartLines = 'chartLines', - chartBar = 'chartBar', - chartBars = 'chartBars', - chartText = 'chartText', - chartTexts = 'chartTexts', - chartArc = 'chartArc', - chartArcs = 'chartArcs', - chartArcsTitle = 'chartArcsTitle', - chartArcsBackground = 'chartArcsBackground', - chartArcsGaugeUnit = 'chartArcsGaugeUnit', - chartArcsGaugeMax = 'chartArcsGaugeMax', - chartArcsGaugeMin = 'chartArcsGaugeMin', - selectedCircle = 'selectedCircle', - selectedCircles = 'selectedCircles', - eventRect = 'eventRect', - eventRects = 'eventRects', - eventRectsSingle = 'eventRectsSingle', - eventRectsMultiple = 'eventRectsMultiple', - zoomRect = 'zoomRect', - brush = 'brush', - focused = 'focused', - region = 'region', - regions = 'regions', - tooltip = 'tooltip', - tooltipName = 'tooltipName', - shape = 'shape', - shapes = 'shapes', - line = 'line', - lines = 'lines', - bar = 'bar', - bars = 'bars', - circle = 'circle', - circles = 'circles', - arc = 'arc', - arcs = 'arcs', - area = 'area', - areas = 'areas', - empty = 'empty', - text = 'text', - texts = 'texts', - gaugeValue = 'gaugeValue', - grid = 'grid', - xgrid = 'xgrid', - xgrids = 'xgrids', - xgridLine = 'xgridLine', - xgridLines = 'xgridLines', - xgridFocus = 'xgridFocus', - ygrid = 'ygrid', - ygrids = 'ygrids', - ygridLine = 'ygridLine', - ygridLines = 'ygridLines', - axis = 'axis', - axisX = 'axisX', - axisXLabel = 'axisXLabel', - axisY = 'axisY', - axisYLabel = 'axisYLabel', - axisY2 = 'axisY2', - axisY2Label = 'axisY2Label', - legendBackground = 'legendBackground', - legendItem = 'legendItem', - legendItemEvent = 'legendItemEvent', - legendItemTile = 'legendItemTile', - legendItemHidden = 'legendItemHidden', - legendItemFocused = 'legendItemFocused', - dragarea = 'dragarea', - EXPANDED = 'EXPANDED', - SELECTED = 'SELECTED', - INCLUDED = 'INCLUDED'; - - var CLASS = c3_chart_internal_fn.CLASS = {}; - CLASS[target] = 'c3-target'; - CLASS[chart] = 'c3-chart'; - CLASS[chartLine] = 'c3-chart-line'; - CLASS[chartLines] = 'c3-chart-lines'; - CLASS[chartBar] = 'c3-chart-bar'; - CLASS[chartBars] = 'c3-chart-bars'; - CLASS[chartText] = 'c3-chart-text'; - CLASS[chartTexts] = 'c3-chart-texts'; - CLASS[chartArc] = 'c3-chart-arc'; - CLASS[chartArcs] = 'c3-chart-arcs'; - CLASS[chartArcsTitle] = 'c3-chart-arcs-title'; - CLASS[chartArcsBackground] = 'c3-chart-arcs-background'; - CLASS[chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; - CLASS[chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; - CLASS[chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; - CLASS[selectedCircle] = 'c3-selected-circle'; - CLASS[selectedCircles] = 'c3-selected-circles'; - CLASS[eventRect] = 'c3-event-rect'; - CLASS[eventRects] = 'c3-event-rects'; - CLASS[eventRectsSingle] = 'c3-event-rects-single'; - CLASS[eventRectsMultiple] = 'c3-event-rects-multiple'; - CLASS[zoomRect] = 'c3-zoom-rect'; - CLASS[brush] = 'c3-brush'; - CLASS[focused] = 'c3-focused'; - CLASS[region] = 'c3-region'; - CLASS[regions] = 'c3-regions'; - CLASS[tooltip] = 'c3-tooltip'; - CLASS[tooltipName] = 'c3-tooltip-name'; - CLASS[shape] = 'c3-shape'; - CLASS[shapes] = 'c3-shapes'; - CLASS[line] = 'c3-line'; - CLASS[lines] = 'c3-lines'; - CLASS[bar] = 'c3-bar'; - CLASS[bars] = 'c3-bars'; - CLASS[circle] = 'c3-circle'; - CLASS[circles] = 'c3-circles'; - CLASS[arc] = 'c3-arc'; - CLASS[arcs] = 'c3-arcs'; - CLASS[area] = 'c3-area'; - CLASS[areas] = 'c3-areas'; - CLASS[empty] = 'c3-empty'; - CLASS[text] = 'c3-text'; - CLASS[texts] = 'c3-texts'; - CLASS[gaugeValue] = 'c3-gauge-value'; - CLASS[grid] = 'c3-grid'; - CLASS[xgrid] = 'c3-xgrid'; - CLASS[xgrids] = 'c3-xgrids'; - CLASS[xgridLine] = 'c3-xgrid-line'; - CLASS[xgridLines] = 'c3-xgrid-lines'; - CLASS[xgridFocus] = 'c3-xgrid-focus'; - CLASS[ygrid] = 'c3-ygrid'; - CLASS[ygrids] = 'c3-ygrids'; - CLASS[ygridLine] = 'c3-ygrid-line'; - CLASS[ygridLines] = 'c3-ygrid-lines'; - CLASS[axis] = 'c3-axis'; - CLASS[axisX] = 'c3-axis-x'; - CLASS[axisXLabel] = 'c3-axis-x-label'; - CLASS[axisY] = 'c3-axis-y'; - CLASS[axisYLabel] = 'c3-axis-y-label'; - CLASS[axisY2] = 'c3-axis-y2'; - CLASS[axisY2Label] = 'c3-axis-y2-label'; - CLASS[legendBackground] = 'c3-legend-background'; - CLASS[legendItem] = 'c3-legend-item'; - CLASS[legendItemEvent] = 'c3-legend-item-event'; - CLASS[legendItemTile] = 'c3-legend-item-tile'; - CLASS[legendItemHidden] = 'c3-legend-item-hidden'; - CLASS[legendItemFocused] = 'c3-legend-item-focused'; - CLASS[dragarea] = 'c3-dragarea'; - CLASS[EXPANDED] = '_expanded_'; - CLASS[SELECTED] = '_selected_'; - CLASS[INCLUDED] = '_included_'; - - var generateClass = 'generateClass'; - c3_chart_internal_fn[generateClass] = function (prefix, targetId) { - return " " + prefix + " " + prefix + this[getTargetSelectorSuffix](targetId); - }; - var classText = 'classText'; - c3_chart_internal_fn[classText] = function (d) { - return this[generateClass](CLASS[text], d.index); - }; - var classTexts = 'classTexts'; - c3_chart_internal_fn[classTexts] = function (d) { - return this[generateClass](CLASS[texts], d.id); - }; - var classShape = 'classShape'; - c3_chart_internal_fn[classShape] = function (d) { - return this[generateClass](CLASS[shape], d.index); - }; - var classShapes = 'classShapes'; - c3_chart_internal_fn[classShapes] = function (d) { - return this[generateClass](CLASS[shapes], d.id); - }; - var classLine = 'classLine'; - c3_chart_internal_fn[classLine] = function (d) { - return this[classShape](d) + this[generateClass](CLASS[line], d.id); - }; - var classLines = 'classLines'; - c3_chart_internal_fn[classLines] = function (d) { - return this[classShapes](d) + this[generateClass](CLASS[lines], d.id); - }; - var classCircle = 'classCircle'; - c3_chart_internal_fn[classCircle] = function (d) { - return this[classShape](d) + this[generateClass](CLASS[circle], d.index); - }; - var classCircles = 'classCircles'; - c3_chart_internal_fn[classCircles] = function (d) { - return this[classShapes](d) + this[generateClass](CLASS[circles], d.id); - }; - var classBar = 'classBar'; - c3_chart_internal_fn[classBar] = function (d) { - return this[classShape](d) + this[generateClass](CLASS[bar], d.index); - }; - var classBars = 'classBars'; - c3_chart_internal_fn[classBars] = function (d) { - return this[classShapes](d) + this[generateClass](CLASS[bars], d.id); - }; - var classArc = 'classArc'; - c3_chart_internal_fn[classArc] = function (d) { - return this[classShape](d.data) + this[generateClass](CLASS[arc], d.data.id); - }; - var classArcs = 'classArcs'; - c3_chart_internal_fn[classArcs] = function (d) { - return this[classShapes](d.data) + this[generateClass](CLASS[arcs], d.data.id); - }; - var classArea = 'classArea'; - c3_chart_internal_fn[classArea] = function (d) { - return this[classShape](d) + this[generateClass](CLASS[area], d.id); - }; - var classAreas = 'classAreas'; - c3_chart_internal_fn[classAreas] = function (d) { - return this[classShapes](d) + this[generateClass](CLASS[areas], d.id); - }; - var classRegion = 'classRegion'; - c3_chart_internal_fn[classRegion] = function (d, i) { - return this[generateClass](CLASS[region], i) + ' ' + (CSS_CLASS in d ? d.class : ''); - }; - var classEvent = 'classEvent'; - c3_chart_internal_fn[classEvent] = function (d) { - return this[generateClass](CLASS[eventRect], d.index); - }; - var classTarget = 'classTarget'; - c3_chart_internal_fn[classTarget] = function (id) { + var CLASS = c3_chart_internal_fn.CLASS = { + target: 'c3-target', + chart : 'c3-chart', + chartLine: 'c3-chart-line', + chartLines: 'c3-chart-lines', + chartBar: 'c3-chart-bar', + chartBars: 'c3-chart-bars', + chartText: 'c3-chart-text', + chartTexts: 'c3-chart-texts', + chartArc: 'c3-chart-arc', + chartArcs: 'c3-chart-arcs', + chartArcsTitle: 'c3-chart-arcs-title', + chartArcsBackground: 'c3-chart-arcs-background', + chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', + chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', + chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', + selectedCircle: 'c3-selected-circle', + selectedCircles: 'c3-selected-circles', + eventRect: 'c3-event-rect', + eventRects: 'c3-event-rects', + eventRectsSingle: 'c3-event-rects-single', + eventRectsMultiple: 'c3-event-rects-multiple', + zoomRect: 'c3-zoom-rect', + brush: 'c3-brush', + focused: 'c3-focused', + region: 'c3-region', + regions: 'c3-regions', + tooltip: 'c3-tooltip', + tooltipName: 'c3-tooltip-name', + shape: 'c3-shape', + shapes: 'c3-shapes', + line: 'c3-line', + lines: 'c3-lines', + bar: 'c3-bar', + bars: 'c3-bars', + circle: 'c3-circle', + circles: 'c3-circles', + arc: 'c3-arc', + arcs: 'c3-arcs', + area: 'c3-area', + areas: 'c3-areas', + empty: 'c3-empty', + text: 'c3-text', + texts: 'c3-texts', + gaugeValue: 'c3-gauge-value', + grid: 'c3-grid', + xgrid: 'c3-xgrid', + xgrids: 'c3-xgrids', + xgridLine: 'c3-xgrid-line', + xgridLines: 'c3-xgrid-lines', + xgridFocus: 'c3-xgrid-focus', + ygrid: 'c3-ygrid', + ygrids: 'c3-ygrids', + ygridLine: 'c3-ygrid-line', + ygridLines: 'c3-ygrid-lines', + axis: 'c3-axis', + axisX: 'c3-axis-x', + axisXLabel: 'c3-axis-x-label', + axisY: 'c3-axis-y', + axisYLabel: 'c3-axis-y-label', + axisY2: 'c3-axis-y2', + axisY2Label: 'c3-axis-y2-label', + legendBackground: 'c3-legend-background', + legendItem: 'c3-legend-item', + legendItemEvent: 'c3-legend-item-event', + legendItemTile: 'c3-legend-item-tile', + legendItemHidden: 'c3-legend-item-hidden', + legendItemFocused: 'c3-legend-item-focused', + dragarea: 'c3-dragarea', + EXPANDED: '_expanded_', + SELECTED: '_selected_', + INCLUDED: '_included_' + }; + c3_chart_internal_fn.generateClass = function (prefix, targetId) { + return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); + }; + c3_chart_internal_fn.classText = function (d) { + return this.generateClass(CLASS.text, d.index); + }; + c3_chart_internal_fn.classTexts = function (d) { + return this.generateClass(CLASS.texts, d.id); + }; + c3_chart_internal_fn.classShape = function (d) { + return this.generateClass(CLASS.shape, d.index); + }; + c3_chart_internal_fn.classShapes = function (d) { + return this.generateClass(CLASS.shapes, d.id); + }; + c3_chart_internal_fn.classLine = function (d) { + return this.classShape(d) + this.generateClass(CLASS.line, d.id); + }; + c3_chart_internal_fn.classLines = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.lines, d.id); + }; + c3_chart_internal_fn.classCircle = function (d) { + return this.classShape(d) + this.generateClass(CLASS.circle, d.index); + }; + c3_chart_internal_fn.classCircles = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.circles, d.id); + }; + c3_chart_internal_fn.classBar = function (d) { + return this.classShape(d) + this.generateClass(CLASS.bar, d.index); + }; + c3_chart_internal_fn.classBars = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.bars, d.id); + }; + c3_chart_internal_fn.classArc = function (d) { + return this.classShape(d.data) + this.generateClass(CLASS.arc, d.data.id); + }; + c3_chart_internal_fn.classArcs = function (d) { + return this.classShapes(d.data) + this.generateClass(CLASS.arcs, d.data.id); + }; + c3_chart_internal_fn.classArea = function (d) { + return this.classShape(d) + this.generateClass(CLASS.area, d.id); + }; + c3_chart_internal_fn.classAreas = function (d) { + return this.classShapes(d) + this.generateClass(CLASS.areas, d.id); + }; + c3_chart_internal_fn.classRegion = function (d, i) { + return this.generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); + }; + c3_chart_internal_fn.classEvent = function (d) { + return this.generateClass(CLASS.eventRect, d.index); + }; + c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; if (additionalClassSuffix) { - additionalClass = ' ' + CLASS[target] + '-' + additionalClassSuffix; + additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; } - return $$[generateClass](CLASS[target], id) + additionalClass; + return $$.generateClass(CLASS.target, id) + additionalClass; }; - var classChartText = 'classChartText'; - c3_chart_internal_fn[classChartText] = function (d) { - return CLASS[chartText] + this[classTarget](d.id); + c3_chart_internal_fn.classChartText = function (d) { + return CLASS.chartText + this.classTarget(d.id); }; - var classChartLine = 'classChartLine'; - c3_chart_internal_fn[classChartLine] = function (d) { - return CLASS[chartLine] + this[classTarget](d.id); + c3_chart_internal_fn.classChartLine = function (d) { + return CLASS.chartLine + this.classTarget(d.id); }; - var classChartBar = 'classChartBar'; - c3_chart_internal_fn[classChartBar] = function (d) { - return CLASS[chartBar] + this[classTarget](d.id); + c3_chart_internal_fn.classChartBar = function (d) { + return CLASS.chartBar + this.classTarget(d.id); }; - var classChartArc = 'classChartArc'; - c3_chart_internal_fn[classChartArc] = function (d) { - return CLASS[chartArc] + this[classTarget](d.data.id); + c3_chart_internal_fn.classChartArc = function (d) { + return CLASS.chartArc + this.classTarget(d.data.id); }; - var getTargetSelectorSuffix = 'getTargetSelectorSuffix'; - c3_chart_internal_fn[getTargetSelectorSuffix] = function (targetId) { + c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; - var selectorTarget = 'selectorTarget'; - c3_chart_internal_fn[selectorTarget] = function (id) { - return '.' + CLASS[target] + this[getTargetSelectorSuffix](id); + c3_chart_internal_fn.selectorTarget = function (id) { + return '.' + CLASS.target + this.getTargetSelectorSuffix(id); }; - var selectorTargets = 'selectorTargets'; - c3_chart_internal_fn[selectorTargets] = function (ids) { + c3_chart_internal_fn.selectorTargets = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return $$[selectorTarget](id); }) : null; + return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; }; - var selectorLegend = 'selectorLegend'; - c3_chart_internal_fn[selectorLegend] = function (id) { - return '.' + CLASS[legendItem] + this[getTargetSelectorSuffix](id); + c3_chart_internal_fn.selectorLegend = function (id) { + return '.' + CLASS.legendItem + this.getTargetSelectorSuffix(id); }; - var selectorLegends = 'selectorLegends'; - c3_chart_internal_fn[selectorLegends] = function (ids) { + c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; - return ids.length ? ids.map(function (id) { return $$[selectorLegend](id); }) : null; + return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; }; @@ -5691,38 +5279,32 @@ /** * c3.format.js */ - var getYFormat = 'getYFormat'; - c3_chart_internal_fn[getYFormat] = function (forArc) { + c3_chart_internal_fn.getYFormat = function (forArc) { var $$ = this, - formatForY = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$[hasType]($$.data.targets, TYPE_GAUGE) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { - var format = $$[getAxisId](id) === 'y2' ? formatForY2 : formatForY; + var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); }; }; - var yFormat = 'yFormat'; - c3_chart_internal_fn[yFormat] = function (v) { + c3_chart_internal_fn.yFormat = function (v) { var $$ = this, config = $$.config, format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; return format(v); }; - var y2Format = 'y2Format'; - c3_chart_internal_fn[y2Format] = function (v) { + c3_chart_internal_fn.y2Format = function (v) { var $$ = this, config = $$.config, format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; return format(v); }; - var defaultValueFormat = 'defaultValueFormat'; - c3_chart_internal_fn[defaultValueFormat] = function (v) { + c3_chart_internal_fn.defaultValueFormat = function (v) { return isValue(v) ? +v : ""; }; - var defaultArcValueFormat = 'defaultArcValueFormat'; - c3_chart_internal_fn[defaultArcValueFormat] = function (v, ratio) { + c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { return (ratio * 100).toFixed(1) + '%'; }; - var formatByAxisId = 'formatByAxisId'; - c3_chart_internal_fn[formatByAxisId] = function (axisId) { + c3_chart_internal_fn.formatByAxisId = function (axisId) { var $$ = this.internal, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id @@ -5741,18 +5323,17 @@ /** * c3.drag.js */ - var drag = 'drag'; - c3_chart_internal_fn[drag] = function (mouse) { + c3_chart_internal_fn.drag = function (mouse) { var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection - sx = $$[dragStart][0]; - sy = $$[dragStart][1]; + sx = $$.dragStart[0]; + sy = $$.dragStart[1]; mx = mouse[0]; my = mouse[1]; minX = Math.min(sx, mx); @@ -5760,26 +5341,26 @@ minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); - main.select('.' + CLASS[dragarea]) + main.select('.' + CLASS.dragarea) .attr('x', minX) .attr('y', minY) .attr('width', maxX - minX) .attr('height', maxY - minY); // TODO: binary search when multiple xs - main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]) + main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) .filter(function (d) { return config[__data_selection_isselectable](d); }) .each(function (d, i) { var shape = d3.select(this), - isSelected = shape.classed(CLASS[SELECTED]), - isIncluded = shape.classed(CLASS[INCLUDED]), + isSelected = shape.classed(CLASS.SELECTED), + isIncluded = shape.classed(CLASS.INCLUDED), _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS[circle])) { + if (shape.classed(CLASS.circle)) { _x = shape.attr("cx") * 1; _y = shape.attr("cy") * 1; toggle = $$.togglePoint; isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; } - else if (shape.classed(CLASS[bar])) { + else if (shape.classed(CLASS.bar)) { box = getPathBox(this); _x = box.x; _y = box.y; @@ -5792,39 +5373,37 @@ return; } if (isWithin ^ isIncluded) { - shape.classed(CLASS[INCLUDED], !isIncluded); + shape.classed(CLASS.INCLUDED, !isIncluded); // TODO: included/unincluded callback here - shape.classed(CLASS[SELECTED], !isSelected); - $$[toggle](!isSelected, shape, d, i); + shape.classed(CLASS.SELECTED, !isSelected); + $$.toggle(!isSelected, shape, d, i); } }); }; - var dragstart = 'dragstart'; - c3_chart_internal_fn[dragstart] = function (mouse) { + c3_chart_internal_fn.dragstart = function (mouse) { var $$ = this, config = $$.config; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$[dragStart] = mouse; - $$.main.select('.' + CLASS[chart]).append('rect') - .attr(CSS_CLASS, CLASS[dragarea]) - .style(CSS_OPACITY, 0.1); - $$[dragging] = true; + $$.dragStart = mouse; + $$.main.select('.' + CLASS.chart).append('rect') + .attr('class', CLASS.dragarea) + .style('opacity', 0.1); + $$.dragging = true; $$.config[__data_ondragstart](); }; - var dragend = 'dragend'; - c3_chart_internal_fn[dragend] = function () { + c3_chart_internal_fn.dragend = function () { var $$ = this, config = $$.config; - if ($$[hasArcType]($$.data.targets)) { return; } + if ($$.hasArcType($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.main.select('.' + CLASS[dragarea]) + $$.main.select('.' + CLASS.dragarea) .transition().duration(100) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); - $$.main.selectAll('.' + CLASS[shape]) - .classed(CLASS[INCLUDED], false); - $$[dragging] = false; + $$.main.selectAll('.' + CLASS.shape) + .classed(CLASS.INCLUDED, false); + $$.dragging = false; $$.config[__data_ondragend](); }; @@ -5837,94 +5416,94 @@ */ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$[selectorTarget](targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), - candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function focus(targets) { - $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 1); + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } this.revert(); this.defocus(); - focus(candidatesForNoneArc.classed(CLASS[focused], true)); + focus(candidatesForNoneArc.classed(CLASS.focused, true)); focus(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { - $$[expandArc](targetId, true); + if ($$.hasArcType($$.data.targets)) { + $$.expandArc(targetId, true); } - $$[toggleFocusLegend](targetId, true); + $$.toggleFocusLegend(targetId, true); }; c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$[selectorTarget](targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), - candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function defocus(targets) { - $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 0.3); + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } this.revert(); - defocus(candidatesForNoneArc.classed(CLASS[focused], false)); + defocus(candidatesForNoneArc.classed(CLASS.focused, false)); defocus(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { - $$[unexpandArc](targetId); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); } - $$[toggleFocusLegend](targetId, false); + $$.toggleFocusLegend(targetId, false); }; c3_chart_fn.revert = function (targetId) { var $$ = this.internal, - candidates = $$.svg.selectAll($$[selectorTarget](targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$[isNoneArc], $$)), - candidatesForArc = candidates.filter(generateCall($$[isArc], $$)); + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); function revert(targets) { - $$[filterTargetsToShow](targets).transition().duration(100).style(CSS_OPACITY, 1); + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } - revert(candidatesForNoneArc.classed(CLASS[focused], false)); + revert(candidatesForNoneArc.classed(CLASS.focused, false)); revert(candidatesForArc); - if ($$[hasArcType]($$.data.targets)) { - $$[unexpandArc](targetId); + if ($$.hasArcType($$.data.targets)) { + $$.unexpandArc(targetId); } - $$[revertLegend](); + $$.revertLegend(); }; c3_chart_fn.show = function (targetIds, options) { var $$ = this.internal; - targetIds = $$[mapToTargetIds](targetIds); + targetIds = $$.mapToTargetIds(targetIds); options = options || {}; - $$[removeHiddenTargetIds](targetIds); - $$.svg.selectAll($$[selectorTargets](targetIds)) + $$.removeHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) .transition() - .style(CSS_OPACITY, 1); + .style('opacity', 1); 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) { var $$ = this.internal; - targetIds = $$[mapToTargetIds](targetIds); + targetIds = $$.mapToTargetIds(targetIds); options = options || {}; - $$[addHiddenTargetIds](targetIds); - $$.svg.selectAll($$[selectorTargets](targetIds)) + $$.addHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) .transition() - .style(CSS_OPACITY, 0); + .style('opacity', 0); 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 (targetId) { var $$ = this.internal; - $$[isTargetToShow](targetId) ? this.hide(targetId) : this.show(targetId); + $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); }; c3_chart_fn.zoom = function () { @@ -5932,19 +5511,19 @@ c3_chart_fn.zoom.enable = function (enabled) { var $$ = this.internal; $$.config[__zoom_enabled] = enabled; - $$[updateAndRedraw](); + $$.updateAndRedraw(); }; c3_chart_fn.unzoom = function () { var $$ = this.internal; $$.brush.clear().update(); - $$[redraw]({withUpdateXDomain: true}); + $$.redraw({withUpdateXDomain: true}); }; c3_chart_fn.load = function (args) { var $$ = this.internal, config = $$.config; // update xs if specified if (args.xs) { - $$[addXs](args.xs); + $$.addXs(args.xs); } // update classes if exists if ('classes' in args) { @@ -5953,52 +5532,52 @@ }); } // update categories if exists - if ('categories' in args && $$[isCategorized]) { + if ('categories' in args && $$.isCategorized) { config[__axis_x_categories] = args.categories; } // use cache if exists - if ('cacheIds' in args && $$[hasCaches](args.cacheIds)) { - $$[load]($$[getCaches](args.cacheIds), args.done); + if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { + $$.load($$.getCaches(args.cacheIds), args.done); return; } // unload if needed if ('unload' in args) { // TODO: do not unload if target will load (included in url/rows/columns) - $$[unload]($$[mapToTargetIds]((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { - $$[loadFromArgs](args); + $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + $$.loadFromArgs(args); }); } else { - $$[loadFromArgs](args); + $$.loadFromArgs(args); } }; c3_chart_fn.unload = function (args) { var $$ = this.internal; args = args || {}; - $$[unload]($$[mapToTargetIds](args.ids), function () { - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + $$.unload($$.mapToTargetIds(args.ids), function () { + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); if (isFunction(args.done)) { args.done(); } }); }; c3_chart_fn.flow = function (args) { var $$ = this.internal, - targets, data, notfoundIds = [], orgDataCount = $$[getMaxDataCount](), + targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; if (args.json) { - data = $$[convertJsonToData](args.json, args.keys); + data = $$.convertJsonToData(args.json, args.keys); } else if (args.rows) { - data = $$[convertRowsToData](args.rows); + data = $$.convertRowsToData(args.rows); } else if (args.columns) { - data = $$[convertColumnsToData](args.columns); + data = $$.convertColumnsToData(args.columns); } else { return; } - targets = $$[convertDataToTargets](data, true); + targets = $$.convertDataToTargets(data, true); // Update/Add data $$.data.targets.forEach(function (t) { @@ -6014,7 +5593,7 @@ for (j = 0; j < length; j++) { targets[i].values[j].index = tail + j; - if (!$$[isTimeSeries]) { + if (!$$.isTimeSeries) { targets[i].values[j].x = tail + j; } } @@ -6037,7 +5616,7 @@ t.values.push({ id: t.id, index: tail + j, - x: $$[isTimeSeries] ? $$[getOtherTargetX](tail + j) : tail + j, + x: $$.isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j, value: null }); } @@ -6053,13 +5632,13 @@ missing.push({ id: t.id, index: i, - x: $$[isTimeSeries] ? $$[getOtherTargetX](i) : i, + x: $$.isTimeSeries ? $$.getOtherTargetX(i) : i, value: null }); } t.values.forEach(function (v) { v.index += tail; - if (!$$[isTimeSeries]) { + if (!$$.isTimeSeries) { v.x += tail; } }); @@ -6069,14 +5648,14 @@ $$.data.targets = $$.data.targets.concat(targets); // add remained // check data count because behavior needs to change when it's only one - dataCount = $$[getMaxDataCount](); + dataCount = $$.getMaxDataCount(); baseTarget = $$.data.targets[0]; baseValue = baseTarget.values[0]; // Update length to flow if needed if (isDefined(args.to)) { length = 0; - to = $$[isTimeSeries] ? $$[parseDate](args.to) : args.to; + to = $$.isTimeSeries ? $$.parseDate(args.to) : args.to; baseTarget.values.forEach(function (v) { if (v.x < to) { length++; } }); @@ -6086,69 +5665,69 @@ // If only one data, update the domain to flow from left edge of the chart if (!orgDataCount) { - if ($$[isTimeSeries]) { + if ($$.isTimeSeries) { if (baseTarget.values.length > 1) { diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; } else { - diff = baseValue.x - $$[getXDomain]($$.data.targets)[0]; + diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; } } else { diff = 1; } domain = [baseValue.x - diff, baseValue.x]; - $$[updateXDomain](null, true, true, domain); + $$.updateXDomain(null, true, true, domain); } else if (orgDataCount === 1) { - if ($$[isTimeSeries]) { + if ($$.isTimeSeries) { diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; - $$[updateXDomain](null, true, true, domain); + $$.updateXDomain(null, true, true, domain); } } // Set targets - $$[updateTargets]($$.data.targets); + $$.updateTargets($$.data.targets); // Redraw with new targets - $$[redraw]({ + $$.redraw({ flow: { index: baseValue.index, length: length, duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], done: args.done, - orgDataCount: orgDataCount + orgDataCount: orgDataCount, }, withLegend: true, - withTransition: orgDataCount > 1 + withTransition: orgDataCount > 1, }); }; c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( - $$.main.selectAll('.' + CLASS[shapes] + $$[getTargetSelectorSuffix](targetId)).selectAll('.' + CLASS[shape]) - .filter(function () { return d3.select(this).classed(CLASS[SELECTED]); }) + $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) + .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; c3_chart_fn.select = function (ids, indices, resetOther) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$[getToggle](this), + $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[SELECTED]); + isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet - if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d) && !isSelected) { - toggle(true, shape.classed(CLASS[SELECTED], true), d, i); + toggle(true, shape.classed(CLASS.SELECTED, true), d, i); } } else if (isDefined(resetOther) && resetOther) { if (isSelected) { - toggle(false, shape.classed(CLASS[SELECTED], false), d, i); + toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } } }); @@ -6156,19 +5735,19 @@ c3_chart_fn.unselect = function (ids, indices) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$[getToggle](this), + $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[SELECTED]); + isSelected = shape.classed(CLASS.SELECTED); // line/area selection not supported yet - if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { + if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d)) { if (isSelected) { - toggle(false, shape.classed(CLASS[SELECTED], false), d, i); + toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } } } @@ -6178,14 +5757,14 @@ c3_chart_fn.transform = function (type, targetIds) { var $$ = this.internal, options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; - $$[transformTo](targetIds, type, options); + $$.transformTo(targetIds, type, options); }; c3_chart_fn.groups = function (groups) { var $$ = this.internal, config = $$.config; - if (!isDefined(groups)) { return config[__data_groups]; } + if (isUndefined(groups)) { return config[__data_groups]; } config[__data_groups] = groups; - $$[redraw](); + $$.redraw(); return config[__data_groups]; }; @@ -6193,7 +5772,7 @@ var $$ = this.internal, config = $$.config; if (! grids) { return config[__grid_x_lines]; } config[__grid_x_lines] = grids; - $$[redraw](); + $$.redraw(); return config[__grid_x_lines]; }; c3_chart_fn.xgrids.add = function (grids) { @@ -6202,14 +5781,14 @@ }; c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple var $$ = this.internal; - $$[removeGridLines](params, true); + $$.removeGridLines(params, true); }; c3_chart_fn.ygrids = function (grids) { var $$ = this.internal, config = $$.config; if (! grids) { return config[__grid_y_lines]; } config[__grid_y_lines] = grids; - $$[redraw](); + $$.redraw(); return config[__grid_y_lines]; }; c3_chart_fn.ygrids.add = function (grids) { @@ -6218,21 +5797,21 @@ }; c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple var $$ = this.internal; - $$[removeGridLines](params, false); + $$.removeGridLines(params, false); }; c3_chart_fn.regions = function (regions) { var $$ = this.internal, config = $$.config; if (!regions) { return config[__regions]; } config[__regions] = regions; - $$[redraw](); + $$.redraw(); return config[__regions]; }; c3_chart_fn.regions.add = function (regions) { var $$ = this.internal, config = $$.config; if (!regions) { return config[__regions]; } config[__regions] = config[__regions].concat(regions); - $$[redraw](); + $$.redraw(); return config[__regions]; }; c3_chart_fn.regions.remove = function (options) { @@ -6240,12 +5819,12 @@ duration, classes, regions; options = options || {}; - duration = $$[getOption](options, "duration", config[__transition_duration]); - classes = $$[getOption](options, "classes", [CLASS[region]]); + duration = $$.getOption(options, "duration", config[__transition_duration]); + 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) - .style(CSS_OPACITY, 0) + .style('opacity', 0) .remove(); config[__regions] = config[__regions].filter(function (region) { @@ -6278,7 +5857,7 @@ Object.keys(names).forEach(function (id) { config[__data_names][id] = names[id]; }); - $$[redraw]({withLegend: true}); + $$.redraw({withLegend: true}); return config[__data_names]; }; c3_chart_fn.data.colors = function (colors) { @@ -6287,14 +5866,14 @@ Object.keys(colors).forEach(function (id) { config[__data_colors][id] = colors[id]; }); - $$[redraw]({withLegend: true}); + $$.redraw({withLegend: true}); return config[__data_colors]; }; c3_chart_fn.category = function (i, category) { var $$ = this.internal, config = $$.config; if (arguments.length > 1) { config[__axis_x_categories][i] = category; - $$[redraw](); + $$.redraw(); } return config[__axis_x_categories][i]; }; @@ -6302,29 +5881,29 @@ var $$ = this.internal, config = $$.config; if (!arguments.length) { return config[__axis_x_categories]; } config[__axis_x_categories] = categories; - $$[redraw](); + $$.redraw(); return config[__axis_x_categories]; }; // TODO: fix c3_chart_fn.color = function (id) { var $$ = this.internal; - return $$[color](id); // more patterns + return $$.color(id); // more patterns }; c3_chart_fn.x = function (x) { var $$ = this.internal; if (arguments.length) { - $$[updateTargetX]($$.data.targets, x); - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$.updateTargetX($$.data.targets, x); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } return $$.data.xs; }; c3_chart_fn.xs = function (xs) { var $$ = this.internal; if (arguments.length) { - $$[updateTargetXs]($$.data.targets, xs); - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$.updateTargetXs($$.data.targets, xs); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } return $$.data.xs; }; @@ -6336,9 +5915,9 @@ var $$ = this.internal; if (arguments.length) { Object.keys(labels).forEach(function (axisId) { - $$[setAxisLabelText](axisId, labels[axisId]); + $$.setAxisLabelText(axisId, labels[axisId]); }); - $$[updateAxisLabels](); + $$.updateAxisLabels(); } // TODO: return some values? }; @@ -6352,7 +5931,7 @@ } else { config[__axis_y_max] = config[__axis_y2_max] = max; } - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.min = function (min) { @@ -6365,7 +5944,7 @@ } else { config[__axis_y_min] = config[__axis_y2_min] = min; } - $$[redraw]({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); } }; c3_chart_fn.axis.range = function (range) { @@ -6380,13 +5959,13 @@ }; c3_chart_fn.legend.show = function (targetIds) { var $$ = this.internal; - $$[showLegend]($$[mapToTargetIds](targetIds)); - $$[updateAndRedraw]({withLegend: true}); + $$.showLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); }; c3_chart_fn.legend.hide = function (targetIds) { var $$ = this.internal; - $$[hideLegend]($$[mapToTargetIds](targetIds)); - $$[updateAndRedraw]({withLegend: true}); + $$.hideLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); }; c3_chart_fn.resize = function (size) { @@ -6398,7 +5977,7 @@ c3_chart_fn.flush = function () { var $$ = this.internal; - $$[updateAndRedraw]({withLegend: true, withTransition: false, withTransitionForTransform: false}); + $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); }; c3_chart_fn.destroy = function () { @@ -6423,12 +6002,12 @@ var tickOffset = 0, tickCulling = true, tickCentered; function axisX(selection, x) { - selection.attr(CSS_TRANSFORM, function (d) { + selection.attr("transform", function (d) { return "translate(" + Math.ceil(x(d) + tickOffset) + ", 0)"; }); } function axisY(selection, y) { - selection.attr(CSS_TRANSFORM, function (d) { + selection.attr("transform", function (d) { return "translate(0," + Math.ceil(y(d)) + ")"; }); } @@ -6468,15 +6047,15 @@ var ticks = tickValues ? tickValues : generateTicks(scale1), tick = g.selectAll(".tick").data(ticks, scale1), - tickEnter = tick.enter().insert("g", ".domain").attr(CSS_CLASS, "tick").style(CSS_OPACITY, 1e-6), + 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 = d3.transition(tick).style(CSS_OPACITY, 1), + tickUpdate = d3.transition(tick).style("opacity", 1), tickTransform, tickX; var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), path = g.selectAll(".domain").data([ 0 ]), - pathUpdate = (path.enter().append("path").attr(CSS_CLASS, "domain"), d3.transition(path)); + pathUpdate = (path.enter().append("path").attr("class", "domain"), d3.transition(path)); tickEnter.append("line"); tickEnter.append("text"); @@ -6506,7 +6085,7 @@ textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding); lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", tickSize); textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding); - text.attr("dy", ".71em").style(CSS_TEXT_ANCHOR, "middle"); + text.attr("dy", ".71em").style("text-anchor", "middle"); pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); break; } @@ -6517,7 +6096,7 @@ textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); - text.attr("dy", "0em").style(CSS_TEXT_ANCHOR, "middle"); + text.attr("dy", "0em").style("text-anchor", "middle"); pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); break; } @@ -6528,7 +6107,7 @@ textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)); lineUpdate.attr("x2", -innerTickSize).attr("y2", 0); textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", tickOffset); - text.attr("dy", ".32em").style(CSS_TEXT_ANCHOR, "end"); + text.attr("dy", ".32em").style("text-anchor", "end"); pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); break; } @@ -6539,7 +6118,7 @@ textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding); lineUpdate.attr("x2", innerTickSize).attr("y2", 0); textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0); - text.attr("dy", ".32em").style(CSS_TEXT_ANCHOR, "start"); + text.attr("dy", ".32em").style("text-anchor", "start"); pathUpdate.attr("d", "M" + outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + outerTickSize); break; } From 63edd6d08a3a14aaf3afd686f5ae0467a4698c4c Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 16:43:31 +0100 Subject: [PATCH 15/44] Ref CLASS key --- c3.js | 654 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 363 insertions(+), 291 deletions(-) diff --git a/c3.js b/c3.js index 515697f..f77b690 100644 --- a/c3.js +++ b/c3.js @@ -395,14 +395,14 @@ if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - text += ""; + text += ""; text += ""; text += ""; text += ""; @@ -660,51 +660,51 @@ // text when empty 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("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE. // Regions main.append('g') .attr("clip-path", $$.clipPath) - .attr("class", CLASS.regions); + .attr("class", CLASS[regions]); // Grids $$.grid = main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS.grid); + .attr('class', CLASS[grid]); if (config[__grid_x_show]) { - $$.grid.append("g").attr("class", CLASS.xgrids); + $$.grid.append("g").attr("class", CLASS[xgrids]); } if (config[__grid_y_show]) { - $$.grid.append('g').attr('class', CLASS.ygrids); + $$.grid.append('g').attr('class', CLASS[ygrids]); } - $$.grid.append('g').attr("class", CLASS.xgridLines); - $$.grid.append('g').attr('class', CLASS.ygridLines); + $$.grid.append('g').attr("class", CLASS[xgridLines]); + $$.grid.append('g').attr('class', CLASS[ygridLines]); if (config[__grid_focus_show]) { $$.grid.append('g') - .attr("class", CLASS.xgridFocus) + .attr("class", CLASS[xgridFocus]) .append('line') - .attr('class', CLASS.xgridFocus); + .attr('class', CLASS[xgridFocus]); } // Define g for chart area main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS.chart); + .attr('class', CLASS[chart]); // Cover whole with rects for events - eventRect = main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.eventRects) + eventRect = main.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[eventRects]) .style('fill-opacity', 0); // Define g for bar chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); + main.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartBars]); // Define g for line chart area - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); + main.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartLines]); // Define g for arc chart area if (isFunction($$.initArc)) { @@ -714,12 +714,12 @@ $$.initGauge(); } - main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartTexts); + main.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartTexts]); // if zoom privileged, insert rect to forefront - main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS.regions) - .attr('class', CLASS.zoomRect) + main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS[regions]) + .attr('class', CLASS[zoomRect]) .attr('width', $$.width) .attr('height', $$.height) .style('opacity', 0) @@ -732,32 +732,32 @@ // Add Axis $$.axes.x = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisX) + .attr("class", CLASS[axis] + ' ' + CLASS[axisX]) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); $$.axes.x.append("text") - .attr("class", CLASS.axisXLabel) + .attr("class", CLASS[axisXLabel]) .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); $$.axes.y = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY) + .attr("class", CLASS[axis] + ' ' + CLASS[axisY]) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); $$.axes.y.append("text") - .attr("class", CLASS.axisYLabel) + .attr("class", CLASS[axisYLabel]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); $$.axes.y2 = main.append("g") - .attr("class", CLASS.axis + ' ' + CLASS.axisY2) + .attr("class", CLASS[axis] + ' ' + CLASS[axisY2]) // clip-path? .attr("transform", $$.translate.y2) .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); $$.axes.y2.append("text") - .attr("class", CLASS.axisY2Label) + .attr("class", CLASS[axisY2Label]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); @@ -913,7 +913,7 @@ /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS.chartTexts).selectAll('.' + CLASS.chartText) + mainTextUpdate = main.select('.' + CLASS[chartTexts]).selectAll('.' + CLASS[chartText]) .data(targets) .attr('class', generateCall($$.classChartText, $$)); mainTextEnter = mainTextUpdate.enter().append('g') @@ -924,7 +924,7 @@ .attr('class', generateCall($$.classTexts, $$)); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + mainBarUpdate = main.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) .data(targets) .attr('class', generateCall($$.classChartBar, $$)); mainBarEnter = mainBarUpdate.enter().append('g') @@ -937,7 +937,7 @@ .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); //-- Line --// - mainLineUpdate = main.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + mainLineUpdate = main.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) .data(targets) .attr('class', generateCall($$.classChartLine, $$)); mainLineEnter = mainLineUpdate.enter().append('g') @@ -952,13 +952,13 @@ .attr('class', generateCall($$.classAreas, $$)); // Circles for each data point on lines mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS.selectedCircles, d.id); }); + .attr("class", function (d) { return $$.generateClass(CLASS[selectedCircles], d.id); }); mainLineEnter.append('g') .attr("class", generateCall($$.classCircles, $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS.selectedCircle).each(function (d) { + main.selectAll('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[selectedCircle]).each(function (d) { d.value = t.values[d.index].value; }); }); @@ -975,7 +975,7 @@ /*-- Show --*/ // Fade-in each chart - $$.svg.selectAll('.' + CLASS.target).filter(function (d) { return $$.isTargetToShow(d.id); }) + $$.svg.selectAll('.' + CLASS[target]).filter(function (d) { return $$.isTargetToShow(d.id); }) .transition().duration(config[__transition_duration]) .style("opacity", 1); }; @@ -1059,14 +1059,14 @@ break; } } - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').each(function (e) { + $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').each(function (e) { var index = tickValues.indexOf(e); if (index >= 0) { d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); } }); } else { - $$.svg.selectAll('.' + CLASS.axisX + ' .tick text').style('display', 'block'); + $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').style('display', 'block'); } } @@ -1093,7 +1093,7 @@ $$.updateXgridFocus(); // 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("y", $$.height / 2) .text(config[__data_empty_label_text]) @@ -1101,7 +1101,7 @@ .style('opacity', targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + main.select('line.' + CLASS[xgridFocus]).style("visibility", "hidden"); if (config[__grid_x_show]) { xgridAttr = config[__axis_rotated] ? { 'x1': 0, @@ -1118,9 +1118,9 @@ flushXGrid = function (withoutUpdate) { xgridData = $$.generateGridData(config[__grid_x_type], $$.x); tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS.xgrids).selectAll('.' + CLASS.xgrid) + xgrid = main.select('.' + CLASS[xgrids]).selectAll('.' + CLASS[xgrid]) .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS.xgrid); + xgrid.enter().append('line').attr("class", CLASS[xgrid]); if (!withoutUpdate) { xgrid.attr(xgridAttr) .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); @@ -1129,11 +1129,11 @@ }; flushXGrid(); } - xgridLines = main.select('.' + CLASS.xgridLines).selectAll('.' + CLASS.xgridLine) + xgridLines = main.select('.' + CLASS[xgridLines]).selectAll('.' + CLASS[xgridLine]) .data(config[__grid_x_lines]); // enter xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS.xgridLine + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS[xgridLine] + (d.class ? ' ' + d.class : ''); }); xgridLine.append('line') .style("opacity", 0); xgridLine.append('text') @@ -1150,10 +1150,10 @@ .remove(); // Y-Grid if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS.ygrids).selectAll('.' + CLASS.ygrid) + ygrid = main.select('.' + CLASS[ygrids]).selectAll('.' + CLASS[ygrid]) .data($$.y.ticks(config[__grid_y_ticks])); ygrid.enter().append('line') - .attr('class', CLASS.ygrid); + .attr('class', CLASS[ygrid]); ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) .attr("x2", config[__axis_rotated] ? $$.y : $$.width) .attr("y1", config[__axis_rotated] ? 0 : $$.y) @@ -1162,11 +1162,11 @@ $$.smoothLines(ygrid, 'grid'); } if (withY) { - ygridLines = main.select('.' + CLASS.ygridLines).selectAll('.' + CLASS.ygridLine) + ygridLines = main.select('.' + CLASS[ygridLines]).selectAll('.' + CLASS[ygridLine]) .data(config[__grid_y_lines]); // enter ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS.ygridLine + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS[ygridLine] + (d.class ? ' ' + d.class : ''); }); ygridLine.append('line') .style("opacity", 0); ygridLine.append('text') @@ -1197,7 +1197,7 @@ } // rect for regions - mainRegion = main.select('.' + CLASS.regions).selectAll('.' + CLASS.region) + mainRegion = main.select('.' + CLASS[regions]).selectAll('.' + CLASS[region]) .data(config[__regions]); mainRegion.enter().append('g') .attr('class', generateCall($$.classRegion, $$)) @@ -1208,7 +1208,7 @@ .remove(); // bars - mainBar = main.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + mainBar = main.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) .data(generateCall($$.barData, $$)); mainBar.enter().append('path') .attr("class", generateCall($$.classBar, $$)) @@ -1221,7 +1221,7 @@ .remove(); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + mainLine = main.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) .data(generateCall($$.lineData, $$)); mainLine.enter().append('path') .attr('class', generateCall($$.classLine, $$)) @@ -1233,7 +1233,7 @@ .style('opacity', 0) .remove(); - mainArea = main.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + mainArea = main.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) .data(generateCall($$.lineData, $$)); mainArea.enter().append('path') .attr("class", generateCall($$.classArea, $$)) @@ -1246,7 +1246,7 @@ .remove(); if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle) + mainCircle = main.selectAll('.' + CLASS[circles]).selectAll('.' + CLASS[circle]) .data(generateCall($$.lineOrScatterData, $$)); mainCircle.enter().append("circle") .attr("class", generateCall($$.classCircle, $$)) @@ -1258,7 +1258,7 @@ } if ($$.hasDataLabel()) { - mainText = main.selectAll('.' + CLASS.texts).selectAll('.' + CLASS.text) + mainText = main.selectAll('.' + CLASS[texts]).selectAll('.' + CLASS[text]) .data(generateCall($$.barOrLineData, $$)); mainText.enter().append('text') .attr("class", generateCall($$.classText, $$)) @@ -1285,23 +1285,23 @@ } // circles for select - main.selectAll('.' + CLASS.selectedCircles) + main.selectAll('.' + CLASS[selectedCircles]) .filter(generateCall($$.isBarType, $$)) .selectAll('circle') .remove(); if (config[__interaction_enabled]) { // rect for mouseover - eventRect = main.select('.' + CLASS.eventRects) + eventRect = main.select('.' + CLASS[eventRects]) .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { - if (!eventRect.classed(CLASS.eventRectsMultiple)) { - eventRect.classed(CLASS.eventRectsMultiple, true).classed(CLASS.eventRectsSingle, false) - .selectAll('.' + CLASS.eventRect).remove(); + if (!eventRect.classed(CLASS[eventRectsMultiple])) { + eventRect.classed(CLASS[eventRectsMultiple], true).classed(CLASS[eventRectsSingle], false) + .selectAll('.' + CLASS[eventRect]).remove(); } - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) .data([0]); // enter : only one rect will be added $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); @@ -1314,9 +1314,9 @@ // exit : not needed because always only one rect exists } else { - if (!eventRect.classed(CLASS.eventRectsSingle)) { - eventRect.classed(CLASS.eventRectsMultiple, false).classed(CLASS.eventRectsSingle, true) - .selectAll('.' + CLASS.eventRect).remove(); + if (!eventRect.classed(CLASS[eventRectsSingle])) { + eventRect.classed(CLASS[eventRectsMultiple], false).classed(CLASS[eventRectsSingle], true) + .selectAll('.' + CLASS[eventRect]).remove(); } if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { @@ -1337,10 +1337,10 @@ } // Set data maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); - main.select('.' + CLASS.eventRects) + main.select('.' + CLASS[eventRects]) .datum(maxDataCountTarget ? maxDataCountTarget.values : []); // Update rects - eventRectUpdate = main.select('.' + CLASS.eventRects).selectAll('.' + CLASS.eventRect) + eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) .data(function (d) { return d; }); // enter $$.generateEventRectsForSingleX(eventRectUpdate.enter()); @@ -1381,7 +1381,7 @@ .style("fill", $$.color) .attr("cx", cx) .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS.selectedCircle).transition() + transitions.push(main.selectAll('.' + CLASS[selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); transitions.push(mainText.transition() @@ -1477,14 +1477,14 @@ // remove flowed elements if (flowLength) { for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS.shape + '-' + (flowIndex + i)); - texts.push('.' + CLASS.text + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS.eventRect + '-' + (flowIndex + i)); + shapes.push('.' + CLASS[shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[eventRect] + '-' + (flowIndex + i)); } - $$.svg.selectAll('.' + CLASS.shapes).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS.texts).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS.eventRects).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS.xgrid).remove(); + $$.svg.selectAll('.' + CLASS[shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[xgrid]).remove(); } // draw again for removing flowed elements and reverting attr @@ -1626,7 +1626,7 @@ $$.expandBars(index); // Call event handler - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { config[__data_onmouseover].call(c3, d); }); }) @@ -1639,13 +1639,13 @@ $$.unexpandCircles(index); $$.unexpandBars(); // Call event handler - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { config[__data_onmouseout].call($$, d); }); }) .on('mousemove', function (d) { var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS.eventRect + '-' + index); + eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); if ($$.dragging) { return; } // do nothing when dragging if ($$.hasArcType($$.data.targets)) { return; } @@ -1664,9 +1664,9 @@ return; } - $$.main.selectAll('.' + CLASS.shape + '-' + index) + $$.main.selectAll('.' + CLASS[shape] + '-' + index) .each(function () { - d3.select(this).classed(CLASS.EXPANDED, true); + d3.select(this).classed(CLASS[EXPANDED], true); if (config[__data_selection_enabled]) { eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); } @@ -1706,7 +1706,7 @@ $$.cancelClick = false; return; } - $$.main.selectAll('.' + CLASS.shape + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); + $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); }) .call( d3.behavior.drag().origin(Object) @@ -1724,7 +1724,7 @@ .attr('y', 0) .attr('width', $$.width) .attr('height', $$.height) - .attr('class', CLASS.eventRect) + .attr('class', CLASS[eventRect]) .on('mouseout', function () { if ($$.hasArcType($$.data.targets)) { return; } $$.hideXGridFocus(); @@ -1766,13 +1766,13 @@ // Show cursor as pointer if point is close to mouse position if ($$.dist(closest, mouse) < 100) { - $$.svg.select('.' + CLASS.eventRect).style('cursor', 'pointer'); + $$.svg.select('.' + CLASS[eventRect]).style('cursor', 'pointer'); if (!$$.mouseover) { config[__data_onmouseover].call($$, closest); $$.mouseover = true; } } else if ($$.mouseover) { - $$.svg.select('.' + CLASS.eventRect).style('cursor', null); + $$.svg.select('.' + CLASS[eventRect]).style('cursor', null); config[__data_onmouseout].call($$, closest); $$.mouseover = false; } @@ -1790,7 +1790,7 @@ // select if selection enabled if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS.circles + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS.circle + '-' + closest.index).each(function () { + $$.main.select('.' + CLASS[circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[circle] + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); } @@ -1845,26 +1845,26 @@ if (transitions && transitions.axisX) { xAxis = transitions.axisX; } else { - xAxis = $$.main.select('.' + CLASS.axisX); + xAxis = $$.main.select('.' + CLASS[axisX]); if (withTransition) { xAxis = xAxis.transition(); } } if (transitions && transitions.axisY) { yAxis = transitions.axisY; } else { - yAxis = $$.main.select('.' + CLASS.axisY); + yAxis = $$.main.select('.' + CLASS[axisY]); if (withTransition) { yAxis = yAxis.transition(); } } if (transitions && transitions.axisY2) { y2Axis = transitions.axisY2; } else { - y2Axis = $$.main.select('.' + CLASS.axisY2); + y2Axis = $$.main.select('.' + CLASS[axisY2]); if (withTransition) { y2Axis = y2Axis.transition(); } } (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); xAxis.attr("transform", $$.translate.x); yAxis.attr("transform", $$.translate.y); y2Axis.attr("transform", $$.translate.y2); - $$.main.select('.' + CLASS.chartArcs).attr("transform", $$.translate.arc); + $$.main.select('.' + CLASS[chartArcs]).attr("transform", $$.translate.arc); }; c3_chart_internal_fn.transformLegend = function (withTransition) { var $$ = this; @@ -1894,7 +1894,7 @@ .attr('y', function () { return $$.getYAxisClipY(); }) .attr('width', function () { return $$.getYAxisClipWidth(); }) .attr('height', function () { return $$.getYAxisClipHeight(); }); - $$.svg.select('.' + CLASS.zoomRect) + $$.svg.select('.' + CLASS[zoomRect]) .attr('width', $$.width) .attr('height', $$.height); // MEMO: parent div's height will be bigger than svg when @@ -2022,7 +2022,7 @@ c3_chart_internal_fn.getSvgLeft = function () { var $$ = this, config = $$.config, - leftAxisClass = config[__axis_rotated] ? CLASS.axisX : CLASS.axisY, + leftAxisClass = config[__axis_rotated] ? CLASS[axisX] : CLASS[axisY], leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), @@ -2124,7 +2124,7 @@ if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS.xgridFocus); + var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); focusEl .style("visibility", "visible") .data([dataToShow[0]]) @@ -2133,11 +2133,11 @@ $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { - this.main.select('line.' + CLASS.xgridFocus).style("visibility", "hidden"); + this.main.select('line.' + CLASS[xgridFocus]).style("visibility", "hidden"); }; c3_chart_internal_fn.updateXgridFocus = function () { var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS.xgridFocus) + $$.main.select('line.' + CLASS[xgridFocus]) .attr("x1", config[__axis_rotated] ? 0 : -10) .attr("x2", config[__axis_rotated] ? $$.width : -10) .attr("y1", config[__axis_rotated] ? -10 : 0) @@ -2146,7 +2146,7 @@ c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS.axisX).selectAll('.tick').size(); + tickNum = $$.main.select("." + CLASS[axisX]).selectAll('.tick').size(); if (type === 'year') { xDomain = $$.getXDomain(); firstYear = xDomain[0].getFullYear(); @@ -2177,8 +2177,8 @@ var $$ = this, config = $$.config, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS.xgridLines : CLASS.ygridLines, - classLine = forX ? CLASS.xgridLine : CLASS.ygridLine; + classLines = forX ? CLASS[xgridLines] : CLASS[ygridLines], + classLine = forX ? CLASS[xgridLine] : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) .transition().duration(config[__transition_duration]) .style('opacity', 0).remove(); @@ -2221,15 +2221,15 @@ }; c3_chart_internal_fn.opacityForLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 1; + return legendItem.classed(CLASS[legendItemHidden]) ? $$.legendOpacityForHidden : 1; }; c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS.legendItemHidden) ? $$.legendOpacityForHidden : 0.3; + return legendItem.classed(CLASS[legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; }; c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { var $$ = this; - $$.legend.selectAll('.' + CLASS.legendItem) + $$.legend.selectAll('.' + CLASS[legendItem]) .transition().duration(100) .style('opacity', function (_id) { var This = $$.d3.select(this); @@ -2242,7 +2242,7 @@ }; c3_chart_internal_fn.revertLegend = function () { var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + CLASS.legendItem) + $$.legend.selectAll('.' + CLASS[legendItem]) .transition().duration(100) .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; @@ -2275,7 +2275,7 @@ var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + CLASS.legendItemFocused).size(); + var hasFocused = $$.legend.selectAll('.' + CLASS[legendItemFocused]).size(); var texts, rects, tiles; options = options || {}; @@ -2283,7 +2283,7 @@ withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, CLASS.legendItem), + var box = $$.getTextRect(textElement.textContent, CLASS[legendItem]), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, @@ -2358,17 +2358,17 @@ yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; // Define g for legend area - l = $$.legend.selectAll('.' + CLASS.legendItem) + l = $$.legend.selectAll('.' + CLASS[legendItem]) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return $$.generateClass(CLASS.legendItem, id); }) + .attr('class', function (id) { return $$.generateClass(CLASS[legendItem], id); }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { - $$.d3.select(this).classed(CLASS.legendItemFocused, true); + $$.d3.select(this).classed(CLASS[legendItemFocused], true); if (!$$.transiting) { $$.api.focus(id); } @@ -2377,7 +2377,7 @@ } }) .on('mouseout', function (id) { - $$.d3.select(this).classed(CLASS.legendItemFocused, false); + $$.d3.select(this).classed(CLASS[legendItemFocused], false); if (!$$.transiting) { $$.api.revert(); } @@ -2392,12 +2392,12 @@ .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); l.append('rect') - .attr("class", CLASS.legendItemEvent) + .attr("class", CLASS[legendItemEvent]) .style('fill-opacity', 0) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); l.append('rect') - .attr("class", CLASS.legendItemTile) + .attr("class", CLASS[legendItemTile]) .style("pointer-events", "none") .style('fill', $$.color) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2406,8 +2406,8 @@ .attr('height', 10); // Set background for inset legend if ($$.isLegendInset && maxWidth !== 0) { - $$.legend.insert('g', '.' + CLASS.legendItem) - .attr("class", CLASS.legendBackground) + $$.legend.insert('g', '.' + CLASS[legendItem]) + .attr("class", CLASS[legendBackground]) .append('rect') .attr('height', $$.getLegendHeight() - 10) .attr('width', maxWidth * (step + 1) + 10); @@ -2421,7 +2421,7 @@ .attr('x', xForLegendText) .attr('y', yForLegendText); - rects = $$.legend.selectAll('rect.' + CLASS.legendItemEvent) + rects = $$.legend.selectAll('rect.' + CLASS[legendItemEvent]) .data(targetIds); (withTransition ? rects.transition() : rects) .attr('width', function (id) { return widths[id]; }) @@ -2429,7 +2429,7 @@ .attr('x', xForLegendRect) .attr('y', yForLegendRect); - tiles = $$.legend.selectAll('rect.' + CLASS.legendItemTile) + tiles = $$.legend.selectAll('rect.' + CLASS[legendItemTile]) .data(targetIds); (withTransition ? tiles.transition() : tiles) .style('fill', $$.color) @@ -2437,13 +2437,13 @@ .attr('y', yForLegend); // toggle legend state - $$.legend.selectAll('.' + CLASS.legendItem) - .classed(CLASS.legendItemHidden, function (id) { return !$$.isTargetToShow(id); }) + $$.legend.selectAll('.' + CLASS[legendItem]) + .classed(CLASS[legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) .transition() .style('opacity', function (id) { var This = $$.d3.select(this); if ($$.isTargetToShow(id)) { - return !hasFocused || This.classed(CLASS.legendItemFocused) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + return !hasFocused || This.classed(CLASS[legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); } else { return $$.legendOpacityForHidden; } @@ -3041,7 +3041,7 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS.legendItem + $$.getTargetSelectorSuffix(id)).remove(); + $$.legend.selectAll('.' + CLASS[legendItem] + $$.getTargetSelectorSuffix(id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -3127,19 +3127,19 @@ }; c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS.circles + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS.circle + (isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS[circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[circle] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this; $$.getCircles(i, id) - .classed(CLASS.EXPANDED, true) + .classed(CLASS[EXPANDED], true) .attr('r', generateCall($$.pointExpandedR, $$)); }; c3_chart_internal_fn.unexpandCircles = function (i) { var $$ = this; $$.getCircles(i) - .filter(function () { return $$.d3.select(this).classed(CLASS.EXPANDED); }) - .classed(CLASS.EXPANDED, false) + .filter(function () { return $$.d3.select(this).classed(CLASS[EXPANDED]); }) + .classed(CLASS[EXPANDED], false) .attr('r', generateCall($$.pointR, $$)); }; c3_chart_internal_fn.pointR = function (d) { @@ -3164,15 +3164,15 @@ }; c3_chart_internal_fn.getBars = function (i) { var $$ = this; - return $$.main.selectAll('.' + CLASS.bar + (isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + CLASS[bar] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandBars = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS.EXPANDED, true); + $$.getBars(i).classed(CLASS[EXPANDED], true); }; c3_chart_internal_fn.unexpandBars = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS.EXPANDED, false); + $$.getBars(i).classed(CLASS[EXPANDED], false); }; c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { var $$ = this, config = $$.config, @@ -4221,9 +4221,9 @@ c3_chart_internal_fn.updateAxisLabels = function (withTransition) { var $$ = this; - var axisXLabel = $$.main.select('.' + CLASS.axisX + ' .' + CLASS.axisXLabel), - axisYLabel = $$.main.select('.' + CLASS.axisY + ' .' + CLASS.axisYLabel), - axisY2Label = $$.main.select('.' + CLASS.axisY2 + ' .' + CLASS.axisY2Label); + 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", generateCall($$.xForXAxisLabel, $$)) .attr("dx", generateCall($$.dxForXAxisLabel, $$)) @@ -4449,8 +4449,8 @@ c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)), - noneTargets = $$.svg.selectAll('.' + CLASS.arc).filter(function (data) { return data.data.id !== id; }); + target = $$.svg.selectAll('.' + CLASS[chartArc] + $$.selectorTarget(id)), + noneTargets = $$.svg.selectAll('.' + CLASS[arc]).filter(function (data) { return data.data.id !== id; }); if ($$.shouldExpand(id)) { target.selectAll('path') @@ -4471,11 +4471,11 @@ c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS.chartArc + $$.selectorTarget(id)); - target.selectAll('path.' + CLASS.arc) + target = $$.svg.selectAll('.' + CLASS[chartArc] + $$.selectorTarget(id)); + target.selectAll('path.' + CLASS[arc]) .transition().duration(50) .attr("d", $$.svgArc); - $$.svg.selectAll('.' + CLASS.arc) + $$.svg.selectAll('.' + CLASS[arc]) .style("opacity", 1); }; @@ -4523,7 +4523,7 @@ c3_chart_internal_fn.updateTargetsForArc = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; - mainPieUpdate = main.select('.' + CLASS.chartArcs).selectAll('.' + CLASS.chartArc) + mainPieUpdate = main.select('.' + CLASS[chartArcs]).selectAll('.' + CLASS[chartArc]) .data($$.pie(targets)) .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter = mainPieUpdate.enter().append("g") @@ -4541,11 +4541,11 @@ c3_chart_internal_fn.initArc = function () { var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartArcs) + arcs = $$.main.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartArcs]) .attr("transform", $$.translate.arc); arcs.append('text') - .attr('class', CLASS.chartArcsTitle) + .attr('class', CLASS[chartArcsTitle]) .style("text-anchor", "middle") .text($$.getArcTitle()); }; @@ -4553,7 +4553,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; - mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc) + mainArc = main.selectAll('.' + CLASS[arcs]).selectAll('.' + CLASS[arc]) .data(generateCall($$.arcData, $$)); mainArc.enter().append('path') .attr("class", generateCall($$.classArc, $$)) @@ -4636,14 +4636,14 @@ mainArc.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); - main.selectAll('.' + CLASS.chartArc).select('text') + main.selectAll('.' + CLASS[chartArc]).select('text') .style("opacity", 0) - .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS.gaugeValue : ''; }) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[gaugeValue] : ''; }) .text(generateCall($$.textForArcLabel, $$)) .attr("transform", generateCall($$.transformForArcLabel, $$)) .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); - main.select('.' + CLASS.chartArcsTitle) + main.select('.' + CLASS[chartArcsTitle]) .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); }; @@ -4654,7 +4654,7 @@ var $$ = this, config = $$.config, arcs; if ($$.hasGaugeType($$.data.targets)) { arcs.append('path') - .attr("class", CLASS.chartArcsBackground) + .attr("class", CLASS[chartArcsBackground]) .attr("d", function () { var d = { data: [{value: config[__gauge_max]}], @@ -4665,21 +4665,21 @@ }); arcs.append("text") .attr("dy", ".75em") - .attr("class", CLASS.chartArcsGaugeUnit) + .attr("class", CLASS[chartArcsGaugeUnit]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_units] : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMin) + .attr("class", CLASS[chartArcsGaugeMin]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_min] : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") - .attr("class", CLASS.chartArcsGaugeMax) + .attr("class", CLASS[chartArcsGaugeMax]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_max] : ''); @@ -4713,7 +4713,7 @@ var $$ = this, d3 = $$.d3; $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + $$.CLASS.brush).call(this); } + if ($$.context) { $$.context.select('.' + $$.CLASS[brush]).call(this); } return this; }; $$.brush.scale = function (scale) { @@ -4731,20 +4731,20 @@ // Define g for chart area context.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS.chart); + .attr('class', CLASS[chart]); // Define g for bar chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartBars); + context.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartBars]); // Define g for line chart area - context.select('.' + CLASS.chart).append("g") - .attr("class", CLASS.chartLines); + context.select('.' + CLASS[chart]).append("g") + .attr("class", CLASS[chartLines]); // Add extent rect for Brush context.append("g") .attr("clip-path", $$.clipPath) - .attr("class", CLASS.brush) + .attr("class", CLASS[brush]) .call($$.brush) .selectAll("rect") .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); @@ -4752,7 +4752,7 @@ // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = context.append("g") - .attr("class", CLASS.axisX) + .attr("class", CLASS[axisX]) .attr("transform", $$.translate.subx) .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); }; @@ -4762,7 +4762,7 @@ if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS.chartBars).selectAll('.' + CLASS.chartBar) + contextBarUpdate = context.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) .data(targets) .attr('class', generateCall($$.classChartBar, $$)); contextBarEnter = contextBarUpdate.enter().append('g') @@ -4773,7 +4773,7 @@ .attr("class", generateCall($$.classBars, $$)); //-- Line --// - contextLineUpdate = context.select('.' + CLASS.chartLines).selectAll('.' + CLASS.chartLine) + contextLineUpdate = context.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) .data(targets) .attr('class', generateCall($$.classChartLine, $$)); contextLineEnter = contextLineUpdate.enter().append('g') @@ -4814,7 +4814,7 @@ drawBarOnSub = $$.generateDrawBar(barIndices, true); drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars - contextBar = context.selectAll('.' + CLASS.bars).selectAll('.' + CLASS.bar) + contextBar = context.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) .data(generateCall($$.barData, $$)); contextBar.enter().append('path') .attr("class", generateCall($$.classBar, $$)) @@ -4829,7 +4829,7 @@ .style('opacity', 0) .remove(); // lines - contextLine = context.selectAll('.' + CLASS.lines).selectAll('.' + CLASS.line) + contextLine = context.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) .data(generateCall($$.lineData, $$)); contextLine.enter().append('path') .attr('class', generateCall($$.classLine, $$)) @@ -4843,7 +4843,7 @@ .style('opacity', 0) .remove(); // area - contextArea = context.selectAll('.' + CLASS.areas).selectAll('.' + CLASS.area) + contextArea = context.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) .data(generateCall($$.lineData, $$)); contextArea.enter().append('path') .attr("class", generateCall($$.classArea, $$)) @@ -4876,7 +4876,7 @@ if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + CLASS.axisX); + subXAxis = $$.context.select('.' + CLASS[axisX]); if (withTransition) { subXAxis = subXAxis.transition(); } } $$.context.attr("transform", $$.translate.context); @@ -4889,8 +4889,8 @@ */ c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; - $$.main.select('.' + $$.CLASS.zoomRect).call(z); - $$.main.selectAll('.' + $$.CLASS.eventRect).call(z); + $$.main.select('.' + $$.CLASS[zoomRect]).call(z); + $$.main.selectAll('.' + $$.CLASS[eventRect]).call(z); }; @@ -4969,10 +4969,10 @@ var $$ = this, config = $$.config; config[__data_onselected](d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return $$.generateClass(CLASS.selectedCircle, i); }) + .attr("class", function () { return $$.generateClass(CLASS[selectedCircle], i); }) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) .attr("stroke", function () { return $$.color(d); }) @@ -4984,7 +4984,7 @@ var $$ = this; $$.config[__data_onunselected](d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + CLASS.selectedCircles + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS.selectedCircle + '-' + i) + $$.main.select('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; @@ -5012,17 +5012,17 @@ c3_chart_internal_fn.getToggle = function (that) { var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS.bar) ? $$.toggleBar : $$.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[bar]) ? $$.toggleBar : $$.toggleArc); }; c3_chart_internal_fn.toggleShape = function (that, d, i) { var $$ = this, d3 = $$.d3, config = $$.config, - shape = d3.select(that), isSelected = shape.classed(CLASS.SELECTED), isWithin, toggle; + shape = d3.select(that), isSelected = shape.classed(CLASS[SELECTED]), isWithin, toggle; if (that.nodeName === 'circle') { isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); toggle = $$.togglePoint; } else if (that.nodeName === 'path') { - if (shape.classed(CLASS.bar)) { + if (shape.classed(CLASS[bar])) { isWithin = $$.isWithinBar(that); toggle = $$.toggleBar; } else { // would be arc @@ -5033,12 +5033,12 @@ if (config[__data_selection_grouped] || isWithin) { if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { 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) { var shape = d3.select(this); - if (shape.classed(CLASS.SELECTED)) { toggle(false, shape.classed(CLASS.SELECTED, false), d, i); } + if (shape.classed(CLASS[SELECTED])) { toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } }); } - shape.classed(CLASS.SELECTED, !isSelected); + shape.classed(CLASS[SELECTED], !isSelected); toggle(!isSelected, shape, d, i); } $$.config[__data_onclick](d, that); @@ -5112,162 +5112,234 @@ /** * c3.class.js */ - var CLASS = c3_chart_internal_fn.CLASS = { - target: 'c3-target', - chart : 'c3-chart', - chartLine: 'c3-chart-line', - chartLines: 'c3-chart-lines', - chartBar: 'c3-chart-bar', - chartBars: 'c3-chart-bars', - chartText: 'c3-chart-text', - chartTexts: 'c3-chart-texts', - chartArc: 'c3-chart-arc', - chartArcs: 'c3-chart-arcs', - chartArcsTitle: 'c3-chart-arcs-title', - chartArcsBackground: 'c3-chart-arcs-background', - chartArcsGaugeUnit: 'c3-chart-arcs-gauge-unit', - chartArcsGaugeMax: 'c3-chart-arcs-gauge-max', - chartArcsGaugeMin: 'c3-chart-arcs-gauge-min', - selectedCircle: 'c3-selected-circle', - selectedCircles: 'c3-selected-circles', - eventRect: 'c3-event-rect', - eventRects: 'c3-event-rects', - eventRectsSingle: 'c3-event-rects-single', - eventRectsMultiple: 'c3-event-rects-multiple', - zoomRect: 'c3-zoom-rect', - brush: 'c3-brush', - focused: 'c3-focused', - region: 'c3-region', - regions: 'c3-regions', - tooltip: 'c3-tooltip', - tooltipName: 'c3-tooltip-name', - shape: 'c3-shape', - shapes: 'c3-shapes', - line: 'c3-line', - lines: 'c3-lines', - bar: 'c3-bar', - bars: 'c3-bars', - circle: 'c3-circle', - circles: 'c3-circles', - arc: 'c3-arc', - arcs: 'c3-arcs', - area: 'c3-area', - areas: 'c3-areas', - empty: 'c3-empty', - text: 'c3-text', - texts: 'c3-texts', - gaugeValue: 'c3-gauge-value', - grid: 'c3-grid', - xgrid: 'c3-xgrid', - xgrids: 'c3-xgrids', - xgridLine: 'c3-xgrid-line', - xgridLines: 'c3-xgrid-lines', - xgridFocus: 'c3-xgrid-focus', - ygrid: 'c3-ygrid', - ygrids: 'c3-ygrids', - ygridLine: 'c3-ygrid-line', - ygridLines: 'c3-ygrid-lines', - axis: 'c3-axis', - axisX: 'c3-axis-x', - axisXLabel: 'c3-axis-x-label', - axisY: 'c3-axis-y', - axisYLabel: 'c3-axis-y-label', - axisY2: 'c3-axis-y2', - axisY2Label: 'c3-axis-y2-label', - legendBackground: 'c3-legend-background', - legendItem: 'c3-legend-item', - legendItemEvent: 'c3-legend-item-event', - legendItemTile: 'c3-legend-item-tile', - legendItemHidden: 'c3-legend-item-hidden', - legendItemFocused: 'c3-legend-item-focused', - dragarea: 'c3-dragarea', - EXPANDED: '_expanded_', - SELECTED: '_selected_', - INCLUDED: '_included_' - }; + var target = 'target', + chart = 'chart ', + chartLine = 'chartLine', + chartLines = 'chartLines', + chartBar = 'chartBar', + chartBars = 'chartBars', + chartText = 'chartText', + chartTexts = 'chartTexts', + chartArc = 'chartArc', + chartArcs = 'chartArcs', + chartArcsTitle = 'chartArcsTitle', + chartArcsBackground = 'chartArcsBackground', + chartArcsGaugeUnit = 'chartArcsGaugeUnit', + chartArcsGaugeMax = 'chartArcsGaugeMax', + chartArcsGaugeMin = 'chartArcsGaugeMin', + selectedCircle = 'selectedCircle', + selectedCircles = 'selectedCircles', + eventRect = 'eventRect', + eventRects = 'eventRects', + eventRectsSingle = 'eventRectsSingle', + eventRectsMultiple = 'eventRectsMultiple', + zoomRect = 'zoomRect', + brush = 'brush', + focused = 'focused', + region = 'region', + regions = 'regions', + tooltip = 'tooltip', + tooltipName = 'tooltipName', + shape = 'shape', + shapes = 'shapes', + line = 'line', + lines = 'lines', + bar = 'bar', + bars = 'bars', + circle = 'circle', + circles = 'circles', + arc = 'arc', + arcs = 'arcs', + area = 'area', + areas = 'areas', + empty = 'empty', + text = 'text', + texts = 'texts', + gaugeValue = 'gaugeValue', + grid = 'grid', + xgrid = 'xgrid', + xgrids = 'xgrids', + xgridLine = 'xgridLine', + xgridLines = 'xgridLines', + xgridFocus = 'xgridFocus', + ygrid = 'ygrid', + ygrids = 'ygrids', + ygridLine = 'ygridLine', + ygridLines = 'ygridLines', + axis = 'axis', + axisX = 'axisX', + axisXLabel = 'axisXLabel', + axisY = 'axisY', + axisYLabel = 'axisYLabel', + axisY2 = 'axisY2', + axisY2Label = 'axisY2Label', + legendBackground = 'legendBackground', + legendItem = 'legendItem', + legendItemEvent = 'legendItemEvent', + legendItemTile = 'legendItemTile', + legendItemHidden = 'legendItemHidden', + legendItemFocused = 'legendItemFocused', + dragarea = 'dragarea', + EXPANDED = 'EXPANDED', + SELECTED = 'SELECTED', + INCLUDED = 'INCLUDED'; + + var CLASS = c3_chart_internal_fn.CLASS = {}; + CLASS[target] = 'c3-target'; + CLASS[chart] = 'c3-chart'; + CLASS[chartLine] = 'c3-chart-line'; + CLASS[chartLines] = 'c3-chart-lines'; + CLASS[chartBar] = 'c3-chart-bar'; + CLASS[chartBars] = 'c3-chart-bars'; + CLASS[chartText] = 'c3-chart-text'; + CLASS[chartTexts] = 'c3-chart-texts'; + CLASS[chartArc] = 'c3-chart-arc'; + CLASS[chartArcs] = 'c3-chart-arcs'; + CLASS[chartArcsTitle] = 'c3-chart-arcs-title'; + CLASS[chartArcsBackground] = 'c3-chart-arcs-background'; + CLASS[chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; + CLASS[chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; + CLASS[chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; + CLASS[selectedCircle] = 'c3-selected-circle'; + CLASS[selectedCircles] = 'c3-selected-circles'; + CLASS[eventRect] = 'c3-event-rect'; + CLASS[eventRects] = 'c3-event-rects'; + CLASS[eventRectsSingle] = 'c3-event-rects-single'; + CLASS[eventRectsMultiple] = 'c3-event-rects-multiple'; + CLASS[zoomRect] = 'c3-zoom-rect'; + CLASS[brush] = 'c3-brush'; + CLASS[focused] = 'c3-focused'; + CLASS[region] = 'c3-region'; + CLASS[regions] = 'c3-regions'; + CLASS[tooltip] = 'c3-tooltip'; + CLASS[tooltipName] = 'c3-tooltip-name'; + CLASS[shape] = 'c3-shape'; + CLASS[shapes] = 'c3-shapes'; + CLASS[line] = 'c3-line'; + CLASS[lines] = 'c3-lines'; + CLASS[bar] = 'c3-bar'; + CLASS[bars] = 'c3-bars'; + CLASS[circle] = 'c3-circle'; + CLASS[circles] = 'c3-circles'; + CLASS[arc] = 'c3-arc'; + CLASS[arcs] = 'c3-arcs'; + CLASS[area] = 'c3-area'; + CLASS[areas] = 'c3-areas'; + CLASS[empty] = 'c3-empty'; + CLASS[text] = 'c3-text'; + CLASS[texts] = 'c3-texts'; + CLASS[gaugeValue] = 'c3-gauge-value'; + CLASS[grid] = 'c3-grid'; + CLASS[xgrid] = 'c3-xgrid'; + CLASS[xgrids] = 'c3-xgrids'; + CLASS[xgridLine] = 'c3-xgrid-line'; + CLASS[xgridLines] = 'c3-xgrid-lines'; + CLASS[xgridFocus] = 'c3-xgrid-focus'; + CLASS[ygrid] = 'c3-ygrid'; + CLASS[ygrids] = 'c3-ygrids'; + CLASS[ygridLine] = 'c3-ygrid-line'; + CLASS[ygridLines] = 'c3-ygrid-lines'; + CLASS[axis] = 'c3-axis'; + CLASS[axisX] = 'c3-axis-x'; + CLASS[axisXLabel] = 'c3-axis-x-label'; + CLASS[axisY] = 'c3-axis-y'; + CLASS[axisYLabel] = 'c3-axis-y-label'; + CLASS[axisY2] = 'c3-axis-y2'; + CLASS[axisY2Label] = 'c3-axis-y2-label'; + CLASS[legendBackground] = 'c3-legend-background'; + CLASS[legendItem] = 'c3-legend-item'; + CLASS[legendItemEvent] = 'c3-legend-item-event'; + CLASS[legendItemTile] = 'c3-legend-item-tile'; + CLASS[legendItemHidden] = 'c3-legend-item-hidden'; + CLASS[legendItemFocused] = 'c3-legend-item-focused'; + CLASS[dragarea] = 'c3-dragarea'; + CLASS[EXPANDED] = '_expanded_'; + CLASS[SELECTED] = '_selected_'; + CLASS[INCLUDED] = '_included_'; + c3_chart_internal_fn.generateClass = function (prefix, targetId) { return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); }; c3_chart_internal_fn.classText = function (d) { - return this.generateClass(CLASS.text, d.index); + return this.generateClass(CLASS[text], d.index); }; c3_chart_internal_fn.classTexts = function (d) { - return this.generateClass(CLASS.texts, d.id); + return this.generateClass(CLASS[texts], d.id); }; c3_chart_internal_fn.classShape = function (d) { - return this.generateClass(CLASS.shape, d.index); + return this.generateClass(CLASS[shape], d.index); }; c3_chart_internal_fn.classShapes = function (d) { - return this.generateClass(CLASS.shapes, d.id); + return this.generateClass(CLASS[shapes], d.id); }; c3_chart_internal_fn.classLine = function (d) { - return this.classShape(d) + this.generateClass(CLASS.line, d.id); + return this.classShape(d) + this.generateClass(CLASS[line], d.id); }; c3_chart_internal_fn.classLines = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.lines, d.id); + return this.classShapes(d) + this.generateClass(CLASS[lines], d.id); }; c3_chart_internal_fn.classCircle = function (d) { - return this.classShape(d) + this.generateClass(CLASS.circle, d.index); + return this.classShape(d) + this.generateClass(CLASS[circle], d.index); }; c3_chart_internal_fn.classCircles = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.circles, d.id); + return this.classShapes(d) + this.generateClass(CLASS[circles], d.id); }; c3_chart_internal_fn.classBar = function (d) { - return this.classShape(d) + this.generateClass(CLASS.bar, d.index); + return this.classShape(d) + this.generateClass(CLASS[bar], d.index); }; c3_chart_internal_fn.classBars = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.bars, d.id); + return this.classShapes(d) + this.generateClass(CLASS[bars], d.id); }; c3_chart_internal_fn.classArc = function (d) { - return this.classShape(d.data) + this.generateClass(CLASS.arc, d.data.id); + return this.classShape(d.data) + this.generateClass(CLASS[arc], d.data.id); }; c3_chart_internal_fn.classArcs = function (d) { - return this.classShapes(d.data) + this.generateClass(CLASS.arcs, d.data.id); + return this.classShapes(d.data) + this.generateClass(CLASS[arcs], d.data.id); }; c3_chart_internal_fn.classArea = function (d) { - return this.classShape(d) + this.generateClass(CLASS.area, d.id); + return this.classShape(d) + this.generateClass(CLASS[area], d.id); }; c3_chart_internal_fn.classAreas = function (d) { - return this.classShapes(d) + this.generateClass(CLASS.areas, d.id); + return this.classShapes(d) + this.generateClass(CLASS[areas], d.id); }; c3_chart_internal_fn.classRegion = function (d, i) { - return this.generateClass(CLASS.region, i) + ' ' + ('class' in d ? d.class : ''); + return this.generateClass(CLASS[region], i) + ' ' + ('class' in d ? d.class : ''); }; c3_chart_internal_fn.classEvent = function (d) { - return this.generateClass(CLASS.eventRect, d.index); + return this.generateClass(CLASS[eventRect], d.index); }; c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; if (additionalClassSuffix) { - additionalClass = ' ' + CLASS.target + '-' + additionalClassSuffix; + additionalClass = ' ' + CLASS[target] + '-' + additionalClassSuffix; } - return $$.generateClass(CLASS.target, id) + additionalClass; + return $$.generateClass(CLASS[target], id) + additionalClass; }; c3_chart_internal_fn.classChartText = function (d) { - return CLASS.chartText + this.classTarget(d.id); + return CLASS[chartText] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartLine = function (d) { - return CLASS.chartLine + this.classTarget(d.id); + return CLASS[chartLine] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartBar = function (d) { - return CLASS.chartBar + this.classTarget(d.id); + return CLASS[chartBar] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartArc = function (d) { - return CLASS.chartArc + this.classTarget(d.data.id); + return CLASS[chartArc] + this.classTarget(d.data.id); }; c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; c3_chart_internal_fn.selectorTarget = function (id) { - return '.' + CLASS.target + this.getTargetSelectorSuffix(id); + return '.' + CLASS[target] + this.getTargetSelectorSuffix(id); }; c3_chart_internal_fn.selectorTargets = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; }; c3_chart_internal_fn.selectorLegend = function (id) { - return '.' + CLASS.legendItem + this.getTargetSelectorSuffix(id); + return '.' + CLASS[legendItem] + this.getTargetSelectorSuffix(id); }; c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; @@ -5341,26 +5413,26 @@ minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); - main.select('.' + CLASS.dragarea) + main.select('.' + CLASS[dragarea]) .attr('x', minX) .attr('y', minY) .attr('width', maxX - minX) .attr('height', maxY - minY); // TODO: binary search when multiple xs - main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape) + main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]) .filter(function (d) { return config[__data_selection_isselectable](d); }) .each(function (d, i) { var shape = d3.select(this), - isSelected = shape.classed(CLASS.SELECTED), - isIncluded = shape.classed(CLASS.INCLUDED), + isSelected = shape.classed(CLASS[SELECTED]), + isIncluded = shape.classed(CLASS[INCLUDED]), _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS.circle)) { + if (shape.classed(CLASS[circle])) { _x = shape.attr("cx") * 1; _y = shape.attr("cy") * 1; toggle = $$.togglePoint; isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; } - else if (shape.classed(CLASS.bar)) { + else if (shape.classed(CLASS[bar])) { box = getPathBox(this); _x = box.x; _y = box.y; @@ -5373,9 +5445,9 @@ return; } if (isWithin ^ isIncluded) { - shape.classed(CLASS.INCLUDED, !isIncluded); + shape.classed(CLASS[INCLUDED], !isIncluded); // TODO: included/unincluded callback here - shape.classed(CLASS.SELECTED, !isSelected); + shape.classed(CLASS[SELECTED], !isSelected); $$.toggle(!isSelected, shape, d, i); } }); @@ -5386,8 +5458,8 @@ if ($$.hasArcType($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.dragStart = mouse; - $$.main.select('.' + CLASS.chart).append('rect') - .attr('class', CLASS.dragarea) + $$.main.select('.' + CLASS[chart]).append('rect') + .attr('class', CLASS[dragarea]) .style('opacity', 0.1); $$.dragging = true; $$.config[__data_ondragstart](); @@ -5397,12 +5469,12 @@ var $$ = this, config = $$.config; if ($$.hasArcType($$.data.targets)) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.main.select('.' + CLASS.dragarea) + $$.main.select('.' + CLASS[dragarea]) .transition().duration(100) .style('opacity', 0) .remove(); - $$.main.selectAll('.' + CLASS.shape) - .classed(CLASS.INCLUDED, false); + $$.main.selectAll('.' + CLASS[shape]) + .classed(CLASS[INCLUDED], false); $$.dragging = false; $$.config[__data_ondragend](); }; @@ -5424,7 +5496,7 @@ } this.revert(); this.defocus(); - focus(candidatesForNoneArc.classed(CLASS.focused, true)); + focus(candidatesForNoneArc.classed(CLASS[focused], true)); focus(candidatesForArc); if ($$.hasArcType($$.data.targets)) { $$.expandArc(targetId, true); @@ -5441,7 +5513,7 @@ $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } this.revert(); - defocus(candidatesForNoneArc.classed(CLASS.focused, false)); + defocus(candidatesForNoneArc.classed(CLASS[focused], false)); defocus(candidatesForArc); if ($$.hasArcType($$.data.targets)) { $$.unexpandArc(targetId); @@ -5457,7 +5529,7 @@ function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } - revert(candidatesForNoneArc.classed(CLASS.focused, false)); + revert(candidatesForNoneArc.classed(CLASS[focused], false)); revert(candidatesForArc); if ($$.hasArcType($$.data.targets)) { $$.unexpandArc(targetId); @@ -5704,30 +5776,30 @@ c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( - $$.main.selectAll('.' + CLASS.shapes + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS.shape) - .filter(function () { return d3.select(this).classed(CLASS.SELECTED); }) + $$.main.selectAll('.' + CLASS[shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[shape]) + .filter(function () { return d3.select(this).classed(CLASS[SELECTED]); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; c3_chart_fn.select = function (ids, indices, resetOther) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); + isSelected = shape.classed(CLASS[SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d) && !isSelected) { - toggle(true, shape.classed(CLASS.SELECTED, true), d, i); + toggle(true, shape.classed(CLASS[SELECTED], true), d, i); } } else if (isDefined(resetOther) && resetOther) { if (isSelected) { - toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } } }); @@ -5735,19 +5807,19 @@ c3_chart_fn.unselect = function (ids, indices) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS.shapes).selectAll('.' + CLASS.shape).each(function (d, i) { + $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS.SELECTED); + isSelected = shape.classed(CLASS[SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS.line) || shape.classed(CLASS.area)) { + if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d)) { if (isSelected) { - toggle(false, shape.classed(CLASS.SELECTED, false), d, i); + toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } } } @@ -5820,9 +5892,9 @@ options = options || {}; 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) .style('opacity', 0) .remove(); From e2a31ff8d527f2687b060cd303040bf4c9aa0c0c Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 17:05:06 +0100 Subject: [PATCH 16/44] Refactor hasType --- c3.js | 110 +++++++++++++++++++++++----------------------------------- 1 file changed, 44 insertions(+), 66 deletions(-) diff --git a/c3.js b/c3.js index f77b690..b6a69bb 100644 --- a/c3.js +++ b/c3.js @@ -592,7 +592,7 @@ } // when gauge, hide legend // TODO: fix - if ($$.hasGaugeType($$.data.targets)) { + if ($$.hasType('gauge')) { config[__legend_show] = false; } @@ -786,7 +786,7 @@ } $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { return $$.addName(d.values[config[__tooltip_init_x]]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType($$.data.targets)), $$.color)); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); $$.tooltip.style("top", config[__tooltip_init_position].top) .style("left", config[__tooltip_init_position].left) .style("display", "block"); @@ -837,7 +837,7 @@ var $$ = this, config = $$.config; var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, - hasArc = $$.hasArcType($$.data.targets), + hasArc = $$.hasArcType(), xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), subchartHeight = config[__subchart_show] && !hasArc ? (config[__subchart_size_height] + xAxisHeight) : 0; @@ -987,7 +987,7 @@ var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; - var hideAxis = $$.hasArcType($$.data.targets); + var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; @@ -1602,7 +1602,7 @@ var index = d.index, selectedData, newData; if ($$.dragging) { return; } // do nothing if dragging - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } selectedData = $$.data.targets.map(function (t) { return $$.addName($$.getValueOnIndex(t.values, index)); @@ -1632,7 +1632,7 @@ }) .on('mouseout', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } $$.hideXGridFocus(); $$.hideTooltip(); // Undo expanded shapes @@ -1648,7 +1648,7 @@ eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } // Show tooltip selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { @@ -1701,7 +1701,7 @@ }) .on('click', function (d) { var index = d.index; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } if ($$.cancelClick) { $$.cancelClick = false; return; @@ -1726,7 +1726,7 @@ .attr('height', $$.height) .attr('class', CLASS[eventRect]) .on('mouseout', function () { - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } $$.hideXGridFocus(); $$.hideTooltip(); $$.unexpandCircles(); @@ -2026,7 +2026,7 @@ leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$.hasArcType($$.data.targets), + hasArc = $$.hasArcType(), svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); return svgLeft > 0 ? svgLeft : 0; }; @@ -2058,7 +2058,7 @@ return $$.config[__axis_rotated] ? $$.height : $$.width; } maxDataCount = $$.getMaxDataCount(); - ratio = ($$.hasBarType($$.data.targets) ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2070,7 +2070,7 @@ c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$.hasArcType($$.data.targets), + var forArc = $$.hasArcType(), dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (dataToShow.length === 0 || !config[__tooltip_show]) { return; @@ -2123,7 +2123,7 @@ var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists - if ($$.hasScatterType($$.data.targets) || $$.hasArcType($$.data.targets)) { return; } + if ($$.hasType('scatter') || $$.hasArcType()) { return; } var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); focusEl .style("visibility", "visible") @@ -3539,39 +3539,17 @@ config[__data_type] = type; } }; - c3_chart_internal_fn.hasType = function (targets, type) { - var $$ = this, config = $$.config, has = false; - targets.forEach(function (t) { - if (config[__data_types][t.id] === type) { has = true; } - if (!(t.id in config[__data_types]) && type === 'line') { has = true; } + c3_chart_internal_fn.hasType = function (type, targets) { + var $$ = this, types = $$.config[__data_types], has = false; + (targets || $$.data.targets).forEach(function (t) { + if ((types[t.id] && types[t.id].indexOf(type) >= 0) || (!(t.id in types) && type === 'line')) { + has = true; + } }); return has; }; - /* not used - function hasLineType(targets) { - return hasType(targets, 'line'); - } - */ - c3_chart_internal_fn.hasAreaType = function (targets) { - return this.hasType(targets, 'area') || this.hasType(targets, 'area-spline') || this.hasType(targets, 'area-step'); - }; - c3_chart_internal_fn.hasBarType = function (targets) { - return this.hasType(targets, 'bar'); - }; - c3_chart_internal_fn.hasScatterType = function (targets) { - return this.hasType(targets, 'scatter'); - }; - c3_chart_internal_fn.hasPieType = function (targets) { - return this.config[__data_type] === 'pie' || this.hasType(targets, 'pie'); - }; - c3_chart_internal_fn.hasGaugeType = function (targets) { - return this.hasType(targets, 'gauge'); - }; - c3_chart_internal_fn.hasDonutType = function (targets) { - return this.config[__data_type] === 'donut' || this.hasType(targets, 'donut'); - }; c3_chart_internal_fn.hasArcType = function (targets) { - return this.hasPieType(targets) || this.hasDonutType(targets) || this.hasGaugeType(targets); + return this.hasType('pie', targets) || this.hasType('donut', targets) || this.hasType('gauge', targets); }; c3_chart_internal_fn.isLineType = function (d) { var config = this.config, id = isString(d) ? d : d.id; @@ -3865,7 +3843,7 @@ domainLength, padding, padding_top, padding_bottom, center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$.hasBarType(yTargets) && config[__bar_zerobased]) || ($$.hasAreaType(yTargets) && config[__area_zerobased]), + isZeroBased = ($$.hasType('bar', yTargets) && config[__bar_zerobased]) || ($$.hasType('area', yTargets) && config[__area_zerobased]), showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; if (yTargets.length === 0) { // use current domain if target of axisId is none @@ -3936,7 +3914,7 @@ maxDataCount, padding, paddingLeft, paddingRight; if ($$.isCategorized) { padding = 0; - } else if ($$.hasBarType(targets)) { + } else if ($$.hasType('bar', targets)) { maxDataCount = $$.getMaxDataCount(); padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; } else { @@ -4343,7 +4321,7 @@ $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; $$.radius = $$.radiusExpanded * 0.95; $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; - $$.innerRadius = $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? $$.radius * $$.innerRadiusRatio : 0; + $$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0; }; c3_chart_internal_fn.updateArc = function () { @@ -4408,7 +4386,7 @@ c3_chart_internal_fn.transformForArcLabel = function (d) { var $$ = this, updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; - if (updated && !$$.hasGaugeType($$.data.targets)) { + if (updated && !$$.hasType('gauge')) { c = this.svgArc.centroid(updated); x = isNaN(c[0]) ? 0 : c[0]; y = isNaN(c[1]) ? 0 : c[1]; @@ -4422,7 +4400,7 @@ c3_chart_internal_fn.getArcRatio = function (d) { var $$ = this, - whole = $$.hasGaugeType($$.data.targets) ? Math.PI : (Math.PI * 2); + whole = $$.hasType('gauge') ? Math.PI : (Math.PI * 2); return d ? (d.endAngle - d.startAngle) / whole : null; }; @@ -4442,7 +4420,7 @@ updated = $$.updateAngle(d); value = updated ? updated.value : null; ratio = $$.getArcRatio(updated); - if (! $$.hasGaugeType($$.data.targets) && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } + if (! $$.hasType('gauge') && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } format = $$.getArcLabelFormat(); return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); }; @@ -4486,9 +4464,9 @@ c3_chart_internal_fn.shouldShowArcLabel = function () { var $$ = this, config = $$.config, shouldShow = true; - if ($$.hasDonutType($$.data.targets)) { + if ($$.hasType('donut')) { shouldShow = config[__donut_label_show]; - } else if ($$.hasPieType($$.data.targets)) { + } else if ($$.hasType('pie')) { shouldShow = config[__pie_label_show]; } // when gauge, always true @@ -4497,16 +4475,16 @@ c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { var $$ = this, config = $$.config, - threshold = $$.hasDonutType($$.data.targets) ? config[__donut_label_threshold] : config[__pie_label_threshold]; + threshold = $$.hasType('donut') ? config[__donut_label_threshold] : config[__pie_label_threshold]; return ratio >= threshold; }; c3_chart_internal_fn.getArcLabelFormat = function () { var $$ = this, config = $$.config, format = config[__pie_label_format]; - if ($$.hasGaugeType($$.data.targets)) { + if ($$.hasType('gauge')) { format = config[__gauge_label_format]; - } else if ($$.hasDonutType($$.data.targets)) { + } else if ($$.hasType('donut')) { format = config[__donut_label_format]; } return format; @@ -4514,7 +4492,7 @@ c3_chart_internal_fn.getArcTitle = function () { var $$ = this; - return $$.hasDonutType($$.data.targets) ? $$.config[__donut_title] : ""; + return $$.hasType('donut') ? $$.config[__donut_title] : ""; }; c3_chart_internal_fn.descByStartAngle = function (a, b) { @@ -4531,7 +4509,7 @@ mainPieEnter.append('g') .attr('class', generateCall($$.classArcs, $$)); mainPieEnter.append("text") - .attr("dy", $$.hasGaugeType($$.data.targets) ? "-0.35em" : ".35em") + .attr("dy", $$.hasType('gauge') ? "-0.35em" : ".35em") .style("opacity", 0) .style("text-anchor", "middle") .style("pointer-events", "none"); @@ -4644,7 +4622,7 @@ .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS[chartArcsTitle]) - .style("opacity", $$.hasDonutType($$.data.targets) || $$.hasGaugeType($$.data.targets) ? 1 : 0); + .style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0); }; @@ -4652,7 +4630,7 @@ c3_chart_internal_fn.initGauge = function () { var $$ = this, config = $$.config, arcs; - if ($$.hasGaugeType($$.data.targets)) { + if ($$.hasType('gauge')) { arcs.append('path') .attr("class", CLASS[chartArcsBackground]) .attr("d", function () { @@ -5100,7 +5078,7 @@ */ c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { var $$ = this, - withTransitionForAxis = !$$.hasArcType($$.data.targets), + withTransitionForAxis = !$$.hasArcType(), options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; options.withTransitionForTransform = false; $$.transiting = false; @@ -5353,8 +5331,8 @@ */ c3_chart_internal_fn.getYFormat = function (forArc) { var $$ = this, - formatForY = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$.hasGaugeType($$.data.targets) ? $$.defaultArcValueFormat : $$.y2Format; + formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.y2Format; return function (v, ratio, id) { var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; return format.call($$, v, ratio); @@ -5399,7 +5377,7 @@ var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var sx, sy, mx, my, minX, maxX, minY, maxY; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection @@ -5455,7 +5433,7 @@ c3_chart_internal_fn.dragstart = function (mouse) { var $$ = this, config = $$.config; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.dragStart = mouse; $$.main.select('.' + CLASS[chart]).append('rect') @@ -5467,7 +5445,7 @@ c3_chart_internal_fn.dragend = function () { var $$ = this, config = $$.config; - if ($$.hasArcType($$.data.targets)) { return; } + if ($$.hasArcType()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.main.select('.' + CLASS[dragarea]) .transition().duration(100) @@ -5498,7 +5476,7 @@ this.defocus(); focus(candidatesForNoneArc.classed(CLASS[focused], true)); focus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if ($$.hasArcType()) { $$.expandArc(targetId, true); } $$.toggleFocusLegend(targetId, true); @@ -5515,7 +5493,7 @@ this.revert(); defocus(candidatesForNoneArc.classed(CLASS[focused], false)); defocus(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if ($$.hasArcType()) { $$.unexpandArc(targetId); } $$.toggleFocusLegend(targetId, false); @@ -5531,7 +5509,7 @@ } revert(candidatesForNoneArc.classed(CLASS[focused], false)); revert(candidatesForArc); - if ($$.hasArcType($$.data.targets)) { + if ($$.hasArcType()) { $$.unexpandArc(targetId); } $$.revertLegend(); From 39afb5e81458b0978b343be49a0af0c6be4f36e2 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 19:14:59 +0100 Subject: [PATCH 17/44] Fix trivial --- c3.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/c3.js b/c3.js index b6a69bb..a242774 100644 --- a/c3.js +++ b/c3.js @@ -1885,15 +1885,15 @@ .attr('width', $$.width) .attr('height', $$.height); $$.svg.select('#' + $$.clipIdForXAxis).select('rect') - .attr('x', function () { return $$.getXAxisClipX(); }) - .attr('y', function () { return $$.getXAxisClipY(); }) - .attr('width', function () { return $$.getXAxisClipWidth(); }) - .attr('height', function () { return $$.getXAxisClipHeight(); }); + .attr('x', generateCall($$.getXAxisClipX, $$)) + .attr('y', generateCall($$.getXAxisClipY, $$)) + .attr('width', generateCall($$.getXAxisClipWidth, $$)) + .attr('height', generateCall($$.getXAxisClipHeight, $$)); $$.svg.select('#' + $$.clipIdForYAxis).select('rect') - .attr('x', function () { return $$.getYAxisClipX(); }) - .attr('y', function () { return $$.getYAxisClipY(); }) - .attr('width', function () { return $$.getYAxisClipWidth(); }) - .attr('height', function () { return $$.getYAxisClipHeight(); }); + .attr('x', generateCall($$.getYAxisClipX, $$)) + .attr('y', generateCall($$.getYAxisClipY, $$)) + .attr('width', generateCall($$.getYAxisClipWidth, $$)) + .attr('height', generateCall($$.getYAxisClipHeight, $$)); $$.svg.select('.' + CLASS[zoomRect]) .attr('width', $$.width) .attr('height', $$.height); From 6ea5dbc67f35c5928c45585bf42122ab1bcd35e7 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 19:30:34 +0100 Subject: [PATCH 18/44] Fix class ref name --- c3.js | 720 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 360 insertions(+), 360 deletions(-) diff --git a/c3.js b/c3.js index a242774..92e7eb8 100644 --- a/c3.js +++ b/c3.js @@ -395,14 +395,14 @@ if (! text) { title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); + text = "
" + title + "
" + (title || title === 0 ? "" : ""); } name = nameFormat(d[i].name); value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - text += ""; + text += ""; text += ""; text += ""; text += ""; @@ -660,51 +660,51 @@ // text when empty 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("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE. // Regions main.append('g') .attr("clip-path", $$.clipPath) - .attr("class", CLASS[regions]); + .attr("class", CLASS[_regions]); // Grids $$.grid = main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS[grid]); + .attr('class', CLASS[_grid]); if (config[__grid_x_show]) { - $$.grid.append("g").attr("class", CLASS[xgrids]); + $$.grid.append("g").attr("class", CLASS[_xgrids]); } if (config[__grid_y_show]) { - $$.grid.append('g').attr('class', CLASS[ygrids]); + $$.grid.append('g').attr('class', CLASS[_ygrids]); } - $$.grid.append('g').attr("class", CLASS[xgridLines]); - $$.grid.append('g').attr('class', CLASS[ygridLines]); + $$.grid.append('g').attr("class", CLASS[_xgridLines]); + $$.grid.append('g').attr('class', CLASS[_ygridLines]); if (config[__grid_focus_show]) { $$.grid.append('g') - .attr("class", CLASS[xgridFocus]) + .attr("class", CLASS[_xgridFocus]) .append('line') - .attr('class', CLASS[xgridFocus]); + .attr('class', CLASS[_xgridFocus]); } // Define g for chart area main.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS[chart]); + .attr('class', CLASS[_chart]); // Cover whole with rects for events - eventRect = main.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[eventRects]) + eventRect = main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_eventRects]) .style('fill-opacity', 0); // Define g for bar chart area - main.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartBars]); + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); // Define g for line chart area - main.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartLines]); + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); // Define g for arc chart area if (isFunction($$.initArc)) { @@ -714,12 +714,12 @@ $$.initGauge(); } - main.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartTexts]); + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartTexts]); // if zoom privileged, insert rect to forefront - main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS[regions]) - .attr('class', CLASS[zoomRect]) + main.insert('rect', config[__zoom_privileged] ? null : 'g.' + CLASS[_regions]) + .attr('class', CLASS[_zoomRect]) .attr('width', $$.width) .attr('height', $$.height) .style('opacity', 0) @@ -732,32 +732,32 @@ // Add Axis $$.axes.x = main.append("g") - .attr("class", CLASS[axis] + ' ' + CLASS[axisX]) + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisX]) .attr("clip-path", $$.clipPathForXAxis) .attr("transform", $$.translate.x) .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); $$.axes.x.append("text") - .attr("class", CLASS[axisXLabel]) + .attr("class", CLASS[_axisXLabel]) .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); $$.axes.y = main.append("g") - .attr("class", CLASS[axis] + ' ' + CLASS[axisY]) + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) .attr("clip-path", $$.clipPathForYAxis) .attr("transform", $$.translate.y) .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); $$.axes.y.append("text") - .attr("class", CLASS[axisYLabel]) + .attr("class", CLASS[_axisYLabel]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); $$.axes.y2 = main.append("g") - .attr("class", CLASS[axis] + ' ' + CLASS[axisY2]) + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY2]) // clip-path? .attr("transform", $$.translate.y2) .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); $$.axes.y2.append("text") - .attr("class", CLASS[axisY2Label]) + .attr("class", CLASS[_axisY2Label]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); @@ -913,7 +913,7 @@ /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS[chartTexts]).selectAll('.' + CLASS[chartText]) + mainTextUpdate = main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) .data(targets) .attr('class', generateCall($$.classChartText, $$)); mainTextEnter = mainTextUpdate.enter().append('g') @@ -924,7 +924,7 @@ .attr('class', generateCall($$.classTexts, $$)); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) + mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) .data(targets) .attr('class', generateCall($$.classChartBar, $$)); mainBarEnter = mainBarUpdate.enter().append('g') @@ -937,7 +937,7 @@ .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); //-- Line --// - mainLineUpdate = main.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) + mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) .data(targets) .attr('class', generateCall($$.classChartLine, $$)); mainLineEnter = mainLineUpdate.enter().append('g') @@ -952,13 +952,13 @@ .attr('class', generateCall($$.classAreas, $$)); // Circles for each data point on lines mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS[selectedCircles], d.id); }); + .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); mainLineEnter.append('g') .attr("class", generateCall($$.classCircles, $$)) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); // Update date for selected circles targets.forEach(function (t) { - main.selectAll('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[selectedCircle]).each(function (d) { + main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { d.value = t.values[d.index].value; }); }); @@ -975,7 +975,7 @@ /*-- Show --*/ // Fade-in each chart - $$.svg.selectAll('.' + CLASS[target]).filter(function (d) { return $$.isTargetToShow(d.id); }) + $$.svg.selectAll('.' + CLASS[_target]).filter(function (d) { return $$.isTargetToShow(d.id); }) .transition().duration(config[__transition_duration]) .style("opacity", 1); }; @@ -1059,14 +1059,14 @@ break; } } - $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').each(function (e) { + $$.svg.selectAll('.' + CLASS[_axisX] + ' .tick text').each(function (e) { var index = tickValues.indexOf(e); if (index >= 0) { d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); } }); } else { - $$.svg.selectAll('.' + CLASS[axisX] + ' .tick text').style('display', 'block'); + $$.svg.selectAll('.' + CLASS[_axisX] + ' .tick text').style('display', 'block'); } } @@ -1093,7 +1093,7 @@ $$.updateXgridFocus(); // 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("y", $$.height / 2) .text(config[__data_empty_label_text]) @@ -1101,7 +1101,7 @@ .style('opacity', targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS[xgridFocus]).style("visibility", "hidden"); + main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); if (config[__grid_x_show]) { xgridAttr = config[__axis_rotated] ? { 'x1': 0, @@ -1118,9 +1118,9 @@ flushXGrid = function (withoutUpdate) { xgridData = $$.generateGridData(config[__grid_x_type], $$.x); tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS[xgrids]).selectAll('.' + CLASS[xgrid]) + xgrid = main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS[xgrid]); + xgrid.enter().append('line').attr("class", CLASS[_xgrid]); if (!withoutUpdate) { xgrid.attr(xgridAttr) .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); @@ -1129,11 +1129,11 @@ }; flushXGrid(); } - xgridLines = main.select('.' + CLASS[xgridLines]).selectAll('.' + CLASS[xgridLine]) + xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) .data(config[__grid_x_lines]); // enter xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS[xgridLine] + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); xgridLine.append('line') .style("opacity", 0); xgridLine.append('text') @@ -1150,10 +1150,10 @@ .remove(); // Y-Grid if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS[ygrids]).selectAll('.' + CLASS[ygrid]) + ygrid = main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) .data($$.y.ticks(config[__grid_y_ticks])); ygrid.enter().append('line') - .attr('class', CLASS[ygrid]); + .attr('class', CLASS[_ygrid]); ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) .attr("x2", config[__axis_rotated] ? $$.y : $$.width) .attr("y1", config[__axis_rotated] ? 0 : $$.y) @@ -1162,11 +1162,11 @@ $$.smoothLines(ygrid, 'grid'); } if (withY) { - ygridLines = main.select('.' + CLASS[ygridLines]).selectAll('.' + CLASS[ygridLine]) + ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) .data(config[__grid_y_lines]); // enter ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS[ygridLine] + (d.class ? ' ' + d.class : ''); }); + .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); ygridLine.append('line') .style("opacity", 0); ygridLine.append('text') @@ -1197,7 +1197,7 @@ } // rect for regions - mainRegion = main.select('.' + CLASS[regions]).selectAll('.' + CLASS[region]) + mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) .data(config[__regions]); mainRegion.enter().append('g') .attr('class', generateCall($$.classRegion, $$)) @@ -1208,7 +1208,7 @@ .remove(); // bars - mainBar = main.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) + mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) .data(generateCall($$.barData, $$)); mainBar.enter().append('path') .attr("class", generateCall($$.classBar, $$)) @@ -1221,7 +1221,7 @@ .remove(); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) + mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) .data(generateCall($$.lineData, $$)); mainLine.enter().append('path') .attr('class', generateCall($$.classLine, $$)) @@ -1233,7 +1233,7 @@ .style('opacity', 0) .remove(); - mainArea = main.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) + mainArea = main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) .data(generateCall($$.lineData, $$)); mainArea.enter().append('path') .attr("class", generateCall($$.classArea, $$)) @@ -1246,7 +1246,7 @@ .remove(); if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS[circles]).selectAll('.' + CLASS[circle]) + mainCircle = main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) .data(generateCall($$.lineOrScatterData, $$)); mainCircle.enter().append("circle") .attr("class", generateCall($$.classCircle, $$)) @@ -1258,7 +1258,7 @@ } if ($$.hasDataLabel()) { - mainText = main.selectAll('.' + CLASS[texts]).selectAll('.' + CLASS[text]) + mainText = main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) .data(generateCall($$.barOrLineData, $$)); mainText.enter().append('text') .attr("class", generateCall($$.classText, $$)) @@ -1285,23 +1285,23 @@ } // circles for select - main.selectAll('.' + CLASS[selectedCircles]) + main.selectAll('.' + CLASS[_selectedCircles]) .filter(generateCall($$.isBarType, $$)) .selectAll('circle') .remove(); if (config[__interaction_enabled]) { // rect for mouseover - eventRect = main.select('.' + CLASS[eventRects]) + eventRect = main.select('.' + CLASS[_eventRects]) .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { - if (!eventRect.classed(CLASS[eventRectsMultiple])) { - eventRect.classed(CLASS[eventRectsMultiple], true).classed(CLASS[eventRectsSingle], false) - .selectAll('.' + CLASS[eventRect]).remove(); + if (!eventRect.classed(CLASS[_eventRectsMultiple])) { + eventRect.classed(CLASS[_eventRectsMultiple], true).classed(CLASS[_eventRectsSingle], false) + .selectAll('.' + CLASS[_eventRect]).remove(); } - eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) + eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) .data([0]); // enter : only one rect will be added $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); @@ -1314,9 +1314,9 @@ // exit : not needed because always only one rect exists } else { - if (!eventRect.classed(CLASS[eventRectsSingle])) { - eventRect.classed(CLASS[eventRectsMultiple], false).classed(CLASS[eventRectsSingle], true) - .selectAll('.' + CLASS[eventRect]).remove(); + if (!eventRect.classed(CLASS[_eventRectsSingle])) { + eventRect.classed(CLASS[_eventRectsMultiple], false).classed(CLASS[_eventRectsSingle], true) + .selectAll('.' + CLASS[_eventRect]).remove(); } if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { @@ -1337,10 +1337,10 @@ } // Set data maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); - main.select('.' + CLASS[eventRects]) + main.select('.' + CLASS[_eventRects]) .datum(maxDataCountTarget ? maxDataCountTarget.values : []); // Update rects - eventRectUpdate = main.select('.' + CLASS[eventRects]).selectAll('.' + CLASS[eventRect]) + eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) .data(function (d) { return d; }); // enter $$.generateEventRectsForSingleX(eventRectUpdate.enter()); @@ -1381,7 +1381,7 @@ .style("fill", $$.color) .attr("cx", cx) .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS[selectedCircle]).transition() + transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); transitions.push(mainText.transition() @@ -1477,14 +1477,14 @@ // remove flowed elements if (flowLength) { for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS[shape] + '-' + (flowIndex + i)); - texts.push('.' + CLASS[text] + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS[eventRect] + '-' + (flowIndex + i)); + shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); } - $$.svg.selectAll('.' + CLASS[shapes]).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS[texts]).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS[eventRects]).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS[xgrid]).remove(); + $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[_xgrid]).remove(); } // draw again for removing flowed elements and reverting attr @@ -1626,7 +1626,7 @@ $$.expandBars(index); // Call event handler - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { config[__data_onmouseover].call(c3, d); }); }) @@ -1639,13 +1639,13 @@ $$.unexpandCircles(index); $$.unexpandBars(); // Call event handler - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { config[__data_onmouseout].call($$, d); }); }) .on('mousemove', function (d) { var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS[eventRect] + '-' + index); + eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); if ($$.dragging) { return; } // do nothing when dragging if ($$.hasArcType()) { return; } @@ -1664,9 +1664,9 @@ return; } - $$.main.selectAll('.' + CLASS[shape] + '-' + index) + $$.main.selectAll('.' + CLASS[_shape] + '-' + index) .each(function () { - d3.select(this).classed(CLASS[EXPANDED], true); + d3.select(this).classed(CLASS[_EXPANDED], true); if (config[__data_selection_enabled]) { eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); } @@ -1706,7 +1706,7 @@ $$.cancelClick = false; return; } - $$.main.selectAll('.' + CLASS[shape] + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); }) .call( d3.behavior.drag().origin(Object) @@ -1724,7 +1724,7 @@ .attr('y', 0) .attr('width', $$.width) .attr('height', $$.height) - .attr('class', CLASS[eventRect]) + .attr('class', CLASS[_eventRect]) .on('mouseout', function () { if ($$.hasArcType()) { return; } $$.hideXGridFocus(); @@ -1766,13 +1766,13 @@ // Show cursor as pointer if point is close to mouse position if ($$.dist(closest, mouse) < 100) { - $$.svg.select('.' + CLASS[eventRect]).style('cursor', 'pointer'); + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); if (!$$.mouseover) { config[__data_onmouseover].call($$, closest); $$.mouseover = true; } } else if ($$.mouseover) { - $$.svg.select('.' + CLASS[eventRect]).style('cursor', null); + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); config[__data_onmouseout].call($$, closest); $$.mouseover = false; } @@ -1790,7 +1790,7 @@ // select if selection enabled if ($$.dist(closest, mouse) < 100) { - $$.main.select('.' + CLASS[circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[circle] + '-' + closest.index).each(function () { + $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); } @@ -1845,26 +1845,26 @@ if (transitions && transitions.axisX) { xAxis = transitions.axisX; } else { - xAxis = $$.main.select('.' + CLASS[axisX]); + xAxis = $$.main.select('.' + CLASS[_axisX]); if (withTransition) { xAxis = xAxis.transition(); } } if (transitions && transitions.axisY) { yAxis = transitions.axisY; } else { - yAxis = $$.main.select('.' + CLASS[axisY]); + yAxis = $$.main.select('.' + CLASS[_axisY]); if (withTransition) { yAxis = yAxis.transition(); } } if (transitions && transitions.axisY2) { y2Axis = transitions.axisY2; } else { - y2Axis = $$.main.select('.' + CLASS[axisY2]); + y2Axis = $$.main.select('.' + CLASS[_axisY2]); if (withTransition) { y2Axis = y2Axis.transition(); } } (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); xAxis.attr("transform", $$.translate.x); yAxis.attr("transform", $$.translate.y); y2Axis.attr("transform", $$.translate.y2); - $$.main.select('.' + CLASS[chartArcs]).attr("transform", $$.translate.arc); + $$.main.select('.' + CLASS[_chartArcs]).attr("transform", $$.translate.arc); }; c3_chart_internal_fn.transformLegend = function (withTransition) { var $$ = this; @@ -1894,7 +1894,7 @@ .attr('y', generateCall($$.getYAxisClipY, $$)) .attr('width', generateCall($$.getYAxisClipWidth, $$)) .attr('height', generateCall($$.getYAxisClipHeight, $$)); - $$.svg.select('.' + CLASS[zoomRect]) + $$.svg.select('.' + CLASS[_zoomRect]) .attr('width', $$.width) .attr('height', $$.height); // MEMO: parent div's height will be bigger than svg when @@ -2022,7 +2022,7 @@ c3_chart_internal_fn.getSvgLeft = function () { var $$ = this, config = $$.config, - leftAxisClass = config[__axis_rotated] ? CLASS[axisX] : CLASS[axisY], + leftAxisClass = config[__axis_rotated] ? CLASS[_axisX] : CLASS[_axisY], leftAxis = $$.main.select('.' + leftAxisClass).node(), svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, chartRect = $$.selectChart.node().getBoundingClientRect(), @@ -2124,7 +2124,7 @@ if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists if ($$.hasType('scatter') || $$.hasArcType()) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[xgridFocus]); + var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); focusEl .style("visibility", "visible") .data([dataToShow[0]]) @@ -2133,11 +2133,11 @@ $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { - this.main.select('line.' + CLASS[xgridFocus]).style("visibility", "hidden"); + this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); }; c3_chart_internal_fn.updateXgridFocus = function () { var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS[xgridFocus]) + $$.main.select('line.' + CLASS[_xgridFocus]) .attr("x1", config[__axis_rotated] ? 0 : -10) .attr("x2", config[__axis_rotated] ? $$.width : -10) .attr("y1", config[__axis_rotated] ? -10 : 0) @@ -2146,7 +2146,7 @@ c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS[axisX]).selectAll('.tick').size(); + tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); if (type === 'year') { xDomain = $$.getXDomain(); firstYear = xDomain[0].getFullYear(); @@ -2177,8 +2177,8 @@ var $$ = this, config = $$.config, toRemove = $$.getGridFilterToRemove(params), toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS[xgridLines] : CLASS[ygridLines], - classLine = forX ? CLASS[xgridLine] : CLASS.ygridLine; + classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], + classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) .transition().duration(config[__transition_duration]) .style('opacity', 0).remove(); @@ -2221,15 +2221,15 @@ }; c3_chart_internal_fn.opacityForLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS[legendItemHidden]) ? $$.legendOpacityForHidden : 1; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 1; }; c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { var $$ = this; - return legendItem.classed(CLASS[legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; }; c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { var $$ = this; - $$.legend.selectAll('.' + CLASS[legendItem]) + $$.legend.selectAll('.' + CLASS[_legendItem]) .transition().duration(100) .style('opacity', function (_id) { var This = $$.d3.select(this); @@ -2242,7 +2242,7 @@ }; c3_chart_internal_fn.revertLegend = function () { var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + CLASS[legendItem]) + $$.legend.selectAll('.' + CLASS[_legendItem]) .transition().duration(100) .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); }; @@ -2275,7 +2275,7 @@ var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + CLASS[legendItemFocused]).size(); + var hasFocused = $$.legend.selectAll('.' + CLASS[_legendItemFocused]).size(); var texts, rects, tiles; options = options || {}; @@ -2283,7 +2283,7 @@ withTransitionForTransform = getOption(options, "withTransitionForTransform", true); function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, CLASS[legendItem]), + var box = $$.getTextRect(textElement.textContent, CLASS[_legendItem]), itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, @@ -2358,17 +2358,17 @@ yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; // Define g for legend area - l = $$.legend.selectAll('.' + CLASS[legendItem]) + l = $$.legend.selectAll('.' + CLASS[_legendItem]) .data(targetIds) .enter().append('g') - .attr('class', function (id) { return $$.generateClass(CLASS[legendItem], id); }) + .attr('class', function (id) { return $$.generateClass(CLASS[_legendItem], id); }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { - $$.d3.select(this).classed(CLASS[legendItemFocused], true); + $$.d3.select(this).classed(CLASS[_legendItemFocused], true); if (!$$.transiting) { $$.api.focus(id); } @@ -2377,7 +2377,7 @@ } }) .on('mouseout', function (id) { - $$.d3.select(this).classed(CLASS[legendItemFocused], false); + $$.d3.select(this).classed(CLASS[_legendItemFocused], false); if (!$$.transiting) { $$.api.revert(); } @@ -2392,12 +2392,12 @@ .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); l.append('rect') - .attr("class", CLASS[legendItemEvent]) + .attr("class", CLASS[_legendItemEvent]) .style('fill-opacity', 0) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); l.append('rect') - .attr("class", CLASS[legendItemTile]) + .attr("class", CLASS[_legendItemTile]) .style("pointer-events", "none") .style('fill', $$.color) .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) @@ -2406,8 +2406,8 @@ .attr('height', 10); // Set background for inset legend if ($$.isLegendInset && maxWidth !== 0) { - $$.legend.insert('g', '.' + CLASS[legendItem]) - .attr("class", CLASS[legendBackground]) + $$.legend.insert('g', '.' + CLASS[_legendItem]) + .attr("class", CLASS[_legendBackground]) .append('rect') .attr('height', $$.getLegendHeight() - 10) .attr('width', maxWidth * (step + 1) + 10); @@ -2421,7 +2421,7 @@ .attr('x', xForLegendText) .attr('y', yForLegendText); - rects = $$.legend.selectAll('rect.' + CLASS[legendItemEvent]) + rects = $$.legend.selectAll('rect.' + CLASS[_legendItemEvent]) .data(targetIds); (withTransition ? rects.transition() : rects) .attr('width', function (id) { return widths[id]; }) @@ -2429,7 +2429,7 @@ .attr('x', xForLegendRect) .attr('y', yForLegendRect); - tiles = $$.legend.selectAll('rect.' + CLASS[legendItemTile]) + tiles = $$.legend.selectAll('rect.' + CLASS[_legendItemTile]) .data(targetIds); (withTransition ? tiles.transition() : tiles) .style('fill', $$.color) @@ -2437,13 +2437,13 @@ .attr('y', yForLegend); // toggle legend state - $$.legend.selectAll('.' + CLASS[legendItem]) - .classed(CLASS[legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) + $$.legend.selectAll('.' + CLASS[_legendItem]) + .classed(CLASS[_legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) .transition() .style('opacity', function (id) { var This = $$.d3.select(this); if ($$.isTargetToShow(id)) { - return !hasFocused || This.classed(CLASS[legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + return !hasFocused || This.classed(CLASS[_legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); } else { return $$.legendOpacityForHidden; } @@ -3041,7 +3041,7 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS[legendItem] + $$.getTargetSelectorSuffix(id)).remove(); + $$.legend.selectAll('.' + CLASS[_legendItem] + $$.getTargetSelectorSuffix(id)).remove(); // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; @@ -3127,19 +3127,19 @@ }; c3_chart_internal_fn.getCircles = function (i, id) { var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS[circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[circle] + (isValue(i) ? '-' + i : '')); + return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { var $$ = this; $$.getCircles(i, id) - .classed(CLASS[EXPANDED], true) + .classed(CLASS[_EXPANDED], true) .attr('r', generateCall($$.pointExpandedR, $$)); }; c3_chart_internal_fn.unexpandCircles = function (i) { var $$ = this; $$.getCircles(i) - .filter(function () { return $$.d3.select(this).classed(CLASS[EXPANDED]); }) - .classed(CLASS[EXPANDED], false) + .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) + .classed(CLASS[_EXPANDED], false) .attr('r', generateCall($$.pointR, $$)); }; c3_chart_internal_fn.pointR = function (d) { @@ -3164,15 +3164,15 @@ }; c3_chart_internal_fn.getBars = function (i) { var $$ = this; - return $$.main.selectAll('.' + CLASS[bar] + (isValue(i) ? '-' + i : '')); + return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandBars = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS[EXPANDED], true); + $$.getBars(i).classed(CLASS[_EXPANDED], true); }; c3_chart_internal_fn.unexpandBars = function (i) { var $$ = this; - $$.getBars(i).classed(CLASS[EXPANDED], false); + $$.getBars(i).classed(CLASS[_EXPANDED], false); }; c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { var $$ = this, config = $$.config, @@ -4199,9 +4199,9 @@ c3_chart_internal_fn.updateAxisLabels = function (withTransition) { var $$ = this; - var axisXLabel = $$.main.select('.' + CLASS[axisX] + ' .' + CLASS[axisXLabel]), - axisYLabel = $$.main.select('.' + CLASS[axisY] + ' .' + CLASS[axisYLabel]), - axisY2Label = $$.main.select('.' + CLASS[axisY2] + ' .' + CLASS[axisY2Label]); + 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", generateCall($$.xForXAxisLabel, $$)) .attr("dx", generateCall($$.dxForXAxisLabel, $$)) @@ -4427,8 +4427,8 @@ c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS[chartArc] + $$.selectorTarget(id)), - noneTargets = $$.svg.selectAll('.' + CLASS[arc]).filter(function (data) { return data.data.id !== id; }); + target = $$.svg.selectAll('.' + CLASS[_chartArc] + $$.selectorTarget(id)), + noneTargets = $$.svg.selectAll('.' + CLASS[_arc]).filter(function (data) { return data.data.id !== id; }); if ($$.shouldExpand(id)) { target.selectAll('path') @@ -4449,11 +4449,11 @@ c3_chart_internal_fn.unexpandArc = function (id) { var $$ = this, - target = $$.svg.selectAll('.' + CLASS[chartArc] + $$.selectorTarget(id)); - target.selectAll('path.' + CLASS[arc]) + target = $$.svg.selectAll('.' + CLASS[_chartArc] + $$.selectorTarget(id)); + target.selectAll('path.' + CLASS[_arc]) .transition().duration(50) .attr("d", $$.svgArc); - $$.svg.selectAll('.' + CLASS[arc]) + $$.svg.selectAll('.' + CLASS[_arc]) .style("opacity", 1); }; @@ -4501,7 +4501,7 @@ c3_chart_internal_fn.updateTargetsForArc = function (targets) { var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; - mainPieUpdate = main.select('.' + CLASS[chartArcs]).selectAll('.' + CLASS[chartArc]) + mainPieUpdate = main.select('.' + CLASS[_chartArcs]).selectAll('.' + CLASS[_chartArc]) .data($$.pie(targets)) .attr("class", generateCall($$.classChartArc, $$)); mainPieEnter = mainPieUpdate.enter().append("g") @@ -4519,11 +4519,11 @@ c3_chart_internal_fn.initArc = function () { var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartArcs]) + arcs = $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartArcs]) .attr("transform", $$.translate.arc); arcs.append('text') - .attr('class', CLASS[chartArcsTitle]) + .attr('class', CLASS[_chartArcsTitle]) .style("text-anchor", "middle") .text($$.getArcTitle()); }; @@ -4531,7 +4531,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; - mainArc = main.selectAll('.' + CLASS[arcs]).selectAll('.' + CLASS[arc]) + mainArc = main.selectAll('.' + CLASS[_arcs]).selectAll('.' + CLASS[_arc]) .data(generateCall($$.arcData, $$)); mainArc.enter().append('path') .attr("class", generateCall($$.classArc, $$)) @@ -4614,14 +4614,14 @@ mainArc.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); - main.selectAll('.' + CLASS[chartArc]).select('text') + main.selectAll('.' + CLASS[_chartArc]).select('text') .style("opacity", 0) - .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[gaugeValue] : ''; }) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[_gaugeValue] : ''; }) .text(generateCall($$.textForArcLabel, $$)) .attr("transform", generateCall($$.transformForArcLabel, $$)) .transition().duration(duration) .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); }; @@ -4632,7 +4632,7 @@ var $$ = this, config = $$.config, arcs; if ($$.hasType('gauge')) { arcs.append('path') - .attr("class", CLASS[chartArcsBackground]) + .attr("class", CLASS[_chartArcsBackground]) .attr("d", function () { var d = { data: [{value: config[__gauge_max]}], @@ -4643,21 +4643,21 @@ }); arcs.append("text") .attr("dy", ".75em") - .attr("class", CLASS[chartArcsGaugeUnit]) + .attr("class", CLASS[_chartArcsGaugeUnit]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_units] : ''); arcs.append("text") .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") .attr("dy", "1.2em") - .attr("class", CLASS[chartArcsGaugeMin]) + .attr("class", CLASS[_chartArcsGaugeMin]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_min] : ''); arcs.append("text") .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") .attr("dy", "1.2em") - .attr("class", CLASS[chartArcsGaugeMax]) + .attr("class", CLASS[_chartArcsGaugeMax]) .style("text-anchor", "middle") .style("pointer-events", "none") .text(config[__gauge_label_show] ? config[__gauge_max] : ''); @@ -4691,7 +4691,7 @@ var $$ = this, d3 = $$.d3; $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); $$.brush.update = function () { - if ($$.context) { $$.context.select('.' + $$.CLASS[brush]).call(this); } + if ($$.context) { $$.context.select('.' + $$.CLASS[_brush]).call(this); } return this; }; $$.brush.scale = function (scale) { @@ -4709,20 +4709,20 @@ // Define g for chart area context.append('g') .attr("clip-path", $$.clipPath) - .attr('class', CLASS[chart]); + .attr('class', CLASS[_chart]); // Define g for bar chart area - context.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartBars]); + context.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); // Define g for line chart area - context.select('.' + CLASS[chart]).append("g") - .attr("class", CLASS[chartLines]); + context.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); // Add extent rect for Brush context.append("g") .attr("clip-path", $$.clipPath) - .attr("class", CLASS[brush]) + .attr("class", CLASS[_brush]) .call($$.brush) .selectAll("rect") .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); @@ -4730,7 +4730,7 @@ // ATTENTION: This must be called AFTER chart added // Add Axis $$.axes.subx = context.append("g") - .attr("class", CLASS[axisX]) + .attr("class", CLASS[_axisX]) .attr("transform", $$.translate.subx) .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); }; @@ -4740,7 +4740,7 @@ if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS[chartBars]).selectAll('.' + CLASS[chartBar]) + contextBarUpdate = context.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) .data(targets) .attr('class', generateCall($$.classChartBar, $$)); contextBarEnter = contextBarUpdate.enter().append('g') @@ -4751,7 +4751,7 @@ .attr("class", generateCall($$.classBars, $$)); //-- Line --// - contextLineUpdate = context.select('.' + CLASS[chartLines]).selectAll('.' + CLASS[chartLine]) + contextLineUpdate = context.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) .data(targets) .attr('class', generateCall($$.classChartLine, $$)); contextLineEnter = contextLineUpdate.enter().append('g') @@ -4792,7 +4792,7 @@ drawBarOnSub = $$.generateDrawBar(barIndices, true); drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars - contextBar = context.selectAll('.' + CLASS[bars]).selectAll('.' + CLASS[bar]) + contextBar = context.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) .data(generateCall($$.barData, $$)); contextBar.enter().append('path') .attr("class", generateCall($$.classBar, $$)) @@ -4807,7 +4807,7 @@ .style('opacity', 0) .remove(); // lines - contextLine = context.selectAll('.' + CLASS[lines]).selectAll('.' + CLASS[line]) + contextLine = context.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) .data(generateCall($$.lineData, $$)); contextLine.enter().append('path') .attr('class', generateCall($$.classLine, $$)) @@ -4821,7 +4821,7 @@ .style('opacity', 0) .remove(); // area - contextArea = context.selectAll('.' + CLASS[areas]).selectAll('.' + CLASS[area]) + contextArea = context.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) .data(generateCall($$.lineData, $$)); contextArea.enter().append('path') .attr("class", generateCall($$.classArea, $$)) @@ -4854,7 +4854,7 @@ if (transitions && transitions.axisSubX) { subXAxis = transitions.axisSubX; } else { - subXAxis = $$.context.select('.' + CLASS[axisX]); + subXAxis = $$.context.select('.' + CLASS[_axisX]); if (withTransition) { subXAxis = subXAxis.transition(); } } $$.context.attr("transform", $$.translate.context); @@ -4867,8 +4867,8 @@ */ c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; - $$.main.select('.' + $$.CLASS[zoomRect]).call(z); - $$.main.selectAll('.' + $$.CLASS[eventRect]).call(z); + $$.main.select('.' + $$.CLASS[_zoomRect]).call(z); + $$.main.selectAll('.' + $$.CLASS[_eventRect]).call(z); }; @@ -4947,10 +4947,10 @@ var $$ = this, config = $$.config; config[__data_onselected](d, target.node()); // add selected-circle on low layer g - $$.main.select('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) .data([d]) .enter().append('circle') - .attr("class", function () { return $$.generateClass(CLASS[selectedCircle], i); }) + .attr("class", function () { return $$.generateClass(CLASS[_selectedCircle], i); }) .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) .attr("stroke", function () { return $$.color(d); }) @@ -4962,7 +4962,7 @@ var $$ = this; $$.config[__data_onunselected](d, target.node()); // remove selected-circle from low layer g - $$.main.select('.' + CLASS[selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[selectedCircle] + '-' + i) + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) .transition().duration(100).attr('r', 0) .remove(); }; @@ -4990,17 +4990,17 @@ c3_chart_internal_fn.getToggle = function (that) { var $$ = this; // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[bar]) ? $$.toggleBar : $$.toggleArc); + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[_bar]) ? $$.toggleBar : $$.toggleArc); }; c3_chart_internal_fn.toggleShape = function (that, d, i) { var $$ = this, d3 = $$.d3, config = $$.config, - shape = d3.select(that), isSelected = shape.classed(CLASS[SELECTED]), isWithin, toggle; + shape = d3.select(that), isSelected = shape.classed(CLASS[_SELECTED]), isWithin, toggle; if (that.nodeName === 'circle') { isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); toggle = $$.togglePoint; } else if (that.nodeName === 'path') { - if (shape.classed(CLASS[bar])) { + if (shape.classed(CLASS[_bar])) { isWithin = $$.isWithinBar(that); toggle = $$.toggleBar; } else { // would be arc @@ -5011,12 +5011,12 @@ if (config[__data_selection_grouped] || isWithin) { if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { 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) { var shape = d3.select(this); - if (shape.classed(CLASS[SELECTED])) { toggle(false, shape.classed(CLASS[SELECTED], false), d, i); } + if (shape.classed(CLASS[_SELECTED])) { toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); } }); } - shape.classed(CLASS[SELECTED], !isSelected); + shape.classed(CLASS[_SELECTED], !isSelected); toggle(!isSelected, shape, d, i); } $$.config[__data_onclick](d, that); @@ -5090,234 +5090,234 @@ /** * c3.class.js */ - var target = 'target', - chart = 'chart ', - chartLine = 'chartLine', - chartLines = 'chartLines', - chartBar = 'chartBar', - chartBars = 'chartBars', - chartText = 'chartText', - chartTexts = 'chartTexts', - chartArc = 'chartArc', - chartArcs = 'chartArcs', - chartArcsTitle = 'chartArcsTitle', - chartArcsBackground = 'chartArcsBackground', - chartArcsGaugeUnit = 'chartArcsGaugeUnit', - chartArcsGaugeMax = 'chartArcsGaugeMax', - chartArcsGaugeMin = 'chartArcsGaugeMin', - selectedCircle = 'selectedCircle', - selectedCircles = 'selectedCircles', - eventRect = 'eventRect', - eventRects = 'eventRects', - eventRectsSingle = 'eventRectsSingle', - eventRectsMultiple = 'eventRectsMultiple', - zoomRect = 'zoomRect', - brush = 'brush', - focused = 'focused', - region = 'region', - regions = 'regions', - tooltip = 'tooltip', - tooltipName = 'tooltipName', - shape = 'shape', - shapes = 'shapes', - line = 'line', - lines = 'lines', - bar = 'bar', - bars = 'bars', - circle = 'circle', - circles = 'circles', - arc = 'arc', - arcs = 'arcs', - area = 'area', - areas = 'areas', - empty = 'empty', - text = 'text', - texts = 'texts', - gaugeValue = 'gaugeValue', - grid = 'grid', - xgrid = 'xgrid', - xgrids = 'xgrids', - xgridLine = 'xgridLine', - xgridLines = 'xgridLines', - xgridFocus = 'xgridFocus', - ygrid = 'ygrid', - ygrids = 'ygrids', - ygridLine = 'ygridLine', - ygridLines = 'ygridLines', - axis = 'axis', - axisX = 'axisX', - axisXLabel = 'axisXLabel', - axisY = 'axisY', - axisYLabel = 'axisYLabel', - axisY2 = 'axisY2', - axisY2Label = 'axisY2Label', - legendBackground = 'legendBackground', - legendItem = 'legendItem', - legendItemEvent = 'legendItemEvent', - legendItemTile = 'legendItemTile', - legendItemHidden = 'legendItemHidden', - legendItemFocused = 'legendItemFocused', - dragarea = 'dragarea', - EXPANDED = 'EXPANDED', - SELECTED = 'SELECTED', - INCLUDED = 'INCLUDED'; + var _target = 'target', + _chart = 'chart ', + _chartLine = 'chartLine', + _chartLines = 'chartLines', + _chartBar = 'chartBar', + _chartBars = 'chartBars', + _chartText = 'chartText', + _chartTexts = 'chartTexts', + _chartArc = 'chartArc', + _chartArcs = 'chartArcs', + _chartArcsTitle = 'chartArcsTitle', + _chartArcsBackground = 'chartArcsBackground', + _chartArcsGaugeUnit = 'chartArcsGaugeUnit', + _chartArcsGaugeMax = 'chartArcsGaugeMax', + _chartArcsGaugeMin = 'chartArcsGaugeMin', + _selectedCircle = 'selectedCircle', + _selectedCircles = 'selectedCircles', + _eventRect = 'eventRect', + _eventRects = 'eventRects', + _eventRectsSingle = 'eventRectsSingle', + _eventRectsMultiple = 'eventRectsMultiple', + _zoomRect = 'zoomRect', + _brush = 'brush', + _focused = 'focused', + _region = 'region', + _regions = 'regions', + _tooltip = 'tooltip', + _tooltipName = 'tooltipName', + _shape = 'shape', + _shapes = 'shapes', + _line = 'line', + _lines = 'lines', + _bar = 'bar', + _bars = 'bars', + _circle = 'circle', + _circles = 'circles', + _arc = 'arc', + _arcs = 'arcs', + _area = 'area', + _areas = 'areas', + _empty = 'empty', + _text = 'text', + _texts = 'texts', + _gaugeValue = 'gaugeValue', + _grid = 'grid', + _xgrid = 'xgrid', + _xgrids = 'xgrids', + _xgridLine = 'xgridLine', + _xgridLines = 'xgridLines', + _xgridFocus = 'xgridFocus', + _ygrid = 'ygrid', + _ygrids = 'ygrids', + _ygridLine = 'ygridLine', + _ygridLines = 'ygridLines', + _axis = 'axis', + _axisX = 'axisX', + _axisXLabel = 'axisXLabel', + _axisY = 'axisY', + _axisYLabel = 'axisYLabel', + _axisY2 = 'axisY2', + _axisY2Label = 'axisY2Label', + _legendBackground = 'legendBackground', + _legendItem = 'legendItem', + _legendItemEvent = 'legendItemEvent', + _legendItemTile = 'legendItemTile', + _legendItemHidden = 'legendItemHidden', + _legendItemFocused = 'legendItemFocused', + _dragarea = 'dragarea', + _EXPANDED = 'EXPANDED', + _SELECTED = 'SELECTED', + _INCLUDED = 'INCLUDED'; var CLASS = c3_chart_internal_fn.CLASS = {}; - CLASS[target] = 'c3-target'; - CLASS[chart] = 'c3-chart'; - CLASS[chartLine] = 'c3-chart-line'; - CLASS[chartLines] = 'c3-chart-lines'; - CLASS[chartBar] = 'c3-chart-bar'; - CLASS[chartBars] = 'c3-chart-bars'; - CLASS[chartText] = 'c3-chart-text'; - CLASS[chartTexts] = 'c3-chart-texts'; - CLASS[chartArc] = 'c3-chart-arc'; - CLASS[chartArcs] = 'c3-chart-arcs'; - CLASS[chartArcsTitle] = 'c3-chart-arcs-title'; - CLASS[chartArcsBackground] = 'c3-chart-arcs-background'; - CLASS[chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; - CLASS[chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; - CLASS[chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; - CLASS[selectedCircle] = 'c3-selected-circle'; - CLASS[selectedCircles] = 'c3-selected-circles'; - CLASS[eventRect] = 'c3-event-rect'; - CLASS[eventRects] = 'c3-event-rects'; - CLASS[eventRectsSingle] = 'c3-event-rects-single'; - CLASS[eventRectsMultiple] = 'c3-event-rects-multiple'; - CLASS[zoomRect] = 'c3-zoom-rect'; - CLASS[brush] = 'c3-brush'; - CLASS[focused] = 'c3-focused'; - CLASS[region] = 'c3-region'; - CLASS[regions] = 'c3-regions'; - CLASS[tooltip] = 'c3-tooltip'; - CLASS[tooltipName] = 'c3-tooltip-name'; - CLASS[shape] = 'c3-shape'; - CLASS[shapes] = 'c3-shapes'; - CLASS[line] = 'c3-line'; - CLASS[lines] = 'c3-lines'; - CLASS[bar] = 'c3-bar'; - CLASS[bars] = 'c3-bars'; - CLASS[circle] = 'c3-circle'; - CLASS[circles] = 'c3-circles'; - CLASS[arc] = 'c3-arc'; - CLASS[arcs] = 'c3-arcs'; - CLASS[area] = 'c3-area'; - CLASS[areas] = 'c3-areas'; - CLASS[empty] = 'c3-empty'; - CLASS[text] = 'c3-text'; - CLASS[texts] = 'c3-texts'; - CLASS[gaugeValue] = 'c3-gauge-value'; - CLASS[grid] = 'c3-grid'; - CLASS[xgrid] = 'c3-xgrid'; - CLASS[xgrids] = 'c3-xgrids'; - CLASS[xgridLine] = 'c3-xgrid-line'; - CLASS[xgridLines] = 'c3-xgrid-lines'; - CLASS[xgridFocus] = 'c3-xgrid-focus'; - CLASS[ygrid] = 'c3-ygrid'; - CLASS[ygrids] = 'c3-ygrids'; - CLASS[ygridLine] = 'c3-ygrid-line'; - CLASS[ygridLines] = 'c3-ygrid-lines'; - CLASS[axis] = 'c3-axis'; - CLASS[axisX] = 'c3-axis-x'; - CLASS[axisXLabel] = 'c3-axis-x-label'; - CLASS[axisY] = 'c3-axis-y'; - CLASS[axisYLabel] = 'c3-axis-y-label'; - CLASS[axisY2] = 'c3-axis-y2'; - CLASS[axisY2Label] = 'c3-axis-y2-label'; - CLASS[legendBackground] = 'c3-legend-background'; - CLASS[legendItem] = 'c3-legend-item'; - CLASS[legendItemEvent] = 'c3-legend-item-event'; - CLASS[legendItemTile] = 'c3-legend-item-tile'; - CLASS[legendItemHidden] = 'c3-legend-item-hidden'; - CLASS[legendItemFocused] = 'c3-legend-item-focused'; - CLASS[dragarea] = 'c3-dragarea'; - CLASS[EXPANDED] = '_expanded_'; - CLASS[SELECTED] = '_selected_'; - CLASS[INCLUDED] = '_included_'; + CLASS[_target] = 'c3-target'; + CLASS[_chart] = 'c3-chart'; + CLASS[_chartLine] = 'c3-chart-line'; + CLASS[_chartLines] = 'c3-chart-lines'; + CLASS[_chartBar] = 'c3-chart-bar'; + CLASS[_chartBars] = 'c3-chart-bars'; + CLASS[_chartText] = 'c3-chart-text'; + CLASS[_chartTexts] = 'c3-chart-texts'; + CLASS[_chartArc] = 'c3-chart-arc'; + CLASS[_chartArcs] = 'c3-chart-arcs'; + CLASS[_chartArcsTitle] = 'c3-chart-arcs-title'; + CLASS[_chartArcsBackground] = 'c3-chart-arcs-background'; + CLASS[_chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; + CLASS[_chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; + CLASS[_chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; + CLASS[_selectedCircle] = 'c3-selected-circle'; + CLASS[_selectedCircles] = 'c3-selected-circles'; + CLASS[_eventRect] = 'c3-event-rect'; + CLASS[_eventRects] = 'c3-event-rects'; + CLASS[_eventRectsSingle] = 'c3-event-rects-single'; + CLASS[_eventRectsMultiple] = 'c3-event-rects-multiple'; + CLASS[_zoomRect] = 'c3-zoom-rect'; + CLASS[_brush] = 'c3-brush'; + CLASS[_focused] = 'c3-focused'; + CLASS[_region] = 'c3-region'; + CLASS[_regions] = 'c3-regions'; + CLASS[_tooltip] = 'c3-tooltip'; + CLASS[_tooltipName] = 'c3-tooltip-name'; + CLASS[_shape] = 'c3-shape'; + CLASS[_shapes] = 'c3-shapes'; + CLASS[_line] = 'c3-line'; + CLASS[_lines] = 'c3-lines'; + CLASS[_bar] = 'c3-bar'; + CLASS[_bars] = 'c3-bars'; + CLASS[_circle] = 'c3-circle'; + CLASS[_circles] = 'c3-circles'; + CLASS[_arc] = 'c3-arc'; + CLASS[_arcs] = 'c3-arcs'; + CLASS[_area] = 'c3-area'; + CLASS[_areas] = 'c3-areas'; + CLASS[_empty] = 'c3-empty'; + CLASS[_text] = 'c3-text'; + CLASS[_texts] = 'c3-texts'; + CLASS[_gaugeValue] = 'c3-gauge-value'; + CLASS[_grid] = 'c3-grid'; + CLASS[_xgrid] = 'c3-xgrid'; + CLASS[_xgrids] = 'c3-xgrids'; + CLASS[_xgridLine] = 'c3-xgrid-line'; + CLASS[_xgridLines] = 'c3-xgrid-lines'; + CLASS[_xgridFocus] = 'c3-xgrid-focus'; + CLASS[_ygrid] = 'c3-ygrid'; + CLASS[_ygrids] = 'c3-ygrids'; + CLASS[_ygridLine] = 'c3-ygrid-line'; + CLASS[_ygridLines] = 'c3-ygrid-lines'; + CLASS[_axis] = 'c3-axis'; + CLASS[_axisX] = 'c3-axis-x'; + CLASS[_axisXLabel] = 'c3-axis-x-label'; + CLASS[_axisY] = 'c3-axis-y'; + CLASS[_axisYLabel] = 'c3-axis-y-label'; + CLASS[_axisY2] = 'c3-axis-y2'; + CLASS[_axisY2Label] = 'c3-axis-y2-label'; + CLASS[_legendBackground] = 'c3-legend-background'; + CLASS[_legendItem] = 'c3-legend-item'; + CLASS[_legendItemEvent] = 'c3-legend-item-event'; + CLASS[_legendItemTile] = 'c3-legend-item-tile'; + CLASS[_legendItemHidden] = 'c3-legend-item-hidden'; + CLASS[_legendItemFocused] = 'c3-legend-item-focused'; + CLASS[_dragarea] = 'c3-dragarea'; + CLASS[_EXPANDED] = '_expanded_'; + CLASS[_SELECTED] = '_selected_'; + CLASS[_INCLUDED] = '_included_'; c3_chart_internal_fn.generateClass = function (prefix, targetId) { return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); }; c3_chart_internal_fn.classText = function (d) { - return this.generateClass(CLASS[text], d.index); + return this.generateClass(CLASS[_text], d.index); }; c3_chart_internal_fn.classTexts = function (d) { - return this.generateClass(CLASS[texts], d.id); + return this.generateClass(CLASS[_texts], d.id); }; c3_chart_internal_fn.classShape = function (d) { - return this.generateClass(CLASS[shape], d.index); + return this.generateClass(CLASS[_shape], d.index); }; c3_chart_internal_fn.classShapes = function (d) { - return this.generateClass(CLASS[shapes], d.id); + return this.generateClass(CLASS[_shapes], d.id); }; c3_chart_internal_fn.classLine = function (d) { - return this.classShape(d) + this.generateClass(CLASS[line], d.id); + return this.classShape(d) + this.generateClass(CLASS[_line], d.id); }; c3_chart_internal_fn.classLines = function (d) { - return this.classShapes(d) + this.generateClass(CLASS[lines], d.id); + return this.classShapes(d) + this.generateClass(CLASS[_lines], d.id); }; c3_chart_internal_fn.classCircle = function (d) { - return this.classShape(d) + this.generateClass(CLASS[circle], d.index); + return this.classShape(d) + this.generateClass(CLASS[_circle], d.index); }; c3_chart_internal_fn.classCircles = function (d) { - return this.classShapes(d) + this.generateClass(CLASS[circles], d.id); + return this.classShapes(d) + this.generateClass(CLASS[_circles], d.id); }; c3_chart_internal_fn.classBar = function (d) { - return this.classShape(d) + this.generateClass(CLASS[bar], d.index); + return this.classShape(d) + this.generateClass(CLASS[_bar], d.index); }; c3_chart_internal_fn.classBars = function (d) { - return this.classShapes(d) + this.generateClass(CLASS[bars], d.id); + return this.classShapes(d) + this.generateClass(CLASS[_bars], d.id); }; c3_chart_internal_fn.classArc = function (d) { - return this.classShape(d.data) + this.generateClass(CLASS[arc], d.data.id); + return this.classShape(d.data) + this.generateClass(CLASS[_arc], d.data.id); }; c3_chart_internal_fn.classArcs = function (d) { - return this.classShapes(d.data) + this.generateClass(CLASS[arcs], d.data.id); + return this.classShapes(d.data) + this.generateClass(CLASS[_arcs], d.data.id); }; c3_chart_internal_fn.classArea = function (d) { - return this.classShape(d) + this.generateClass(CLASS[area], d.id); + return this.classShape(d) + this.generateClass(CLASS[_area], d.id); }; c3_chart_internal_fn.classAreas = function (d) { - return this.classShapes(d) + this.generateClass(CLASS[areas], d.id); + return this.classShapes(d) + this.generateClass(CLASS[_areas], d.id); }; c3_chart_internal_fn.classRegion = function (d, i) { - return this.generateClass(CLASS[region], i) + ' ' + ('class' in d ? d.class : ''); + return this.generateClass(CLASS[_region], i) + ' ' + ('class' in d ? d.class : ''); }; c3_chart_internal_fn.classEvent = function (d) { - return this.generateClass(CLASS[eventRect], d.index); + return this.generateClass(CLASS[_eventRect], d.index); }; c3_chart_internal_fn.classTarget = function (id) { var $$ = this; var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; if (additionalClassSuffix) { - additionalClass = ' ' + CLASS[target] + '-' + additionalClassSuffix; + additionalClass = ' ' + CLASS[_target] + '-' + additionalClassSuffix; } - return $$.generateClass(CLASS[target], id) + additionalClass; + return $$.generateClass(CLASS[_target], id) + additionalClass; }; c3_chart_internal_fn.classChartText = function (d) { - return CLASS[chartText] + this.classTarget(d.id); + return CLASS[_chartText] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartLine = function (d) { - return CLASS[chartLine] + this.classTarget(d.id); + return CLASS[_chartLine] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartBar = function (d) { - return CLASS[chartBar] + this.classTarget(d.id); + return CLASS[_chartBar] + this.classTarget(d.id); }; c3_chart_internal_fn.classChartArc = function (d) { - return CLASS[chartArc] + this.classTarget(d.data.id); + return CLASS[_chartArc] + this.classTarget(d.data.id); }; c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; }; c3_chart_internal_fn.selectorTarget = function (id) { - return '.' + CLASS[target] + this.getTargetSelectorSuffix(id); + return '.' + CLASS[_target] + this.getTargetSelectorSuffix(id); }; c3_chart_internal_fn.selectorTargets = function (ids) { var $$ = this; return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; }; c3_chart_internal_fn.selectorLegend = function (id) { - return '.' + CLASS[legendItem] + this.getTargetSelectorSuffix(id); + return '.' + CLASS[_legendItem] + this.getTargetSelectorSuffix(id); }; c3_chart_internal_fn.selectorLegends = function (ids) { var $$ = this; @@ -5391,26 +5391,26 @@ minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); - main.select('.' + CLASS[dragarea]) + main.select('.' + CLASS[_dragarea]) .attr('x', minX) .attr('y', minY) .attr('width', maxX - minX) .attr('height', maxY - minY); // TODO: binary search when multiple xs - main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]) + main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]) .filter(function (d) { return config[__data_selection_isselectable](d); }) .each(function (d, i) { var shape = d3.select(this), - isSelected = shape.classed(CLASS[SELECTED]), - isIncluded = shape.classed(CLASS[INCLUDED]), + isSelected = shape.classed(CLASS[_SELECTED]), + isIncluded = shape.classed(CLASS[_INCLUDED]), _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS[circle])) { + if (shape.classed(CLASS[_circle])) { _x = shape.attr("cx") * 1; _y = shape.attr("cy") * 1; toggle = $$.togglePoint; isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; } - else if (shape.classed(CLASS[bar])) { + else if (shape.classed(CLASS[_bar])) { box = getPathBox(this); _x = box.x; _y = box.y; @@ -5423,9 +5423,9 @@ return; } if (isWithin ^ isIncluded) { - shape.classed(CLASS[INCLUDED], !isIncluded); + shape.classed(CLASS[_INCLUDED], !isIncluded); // TODO: included/unincluded callback here - shape.classed(CLASS[SELECTED], !isSelected); + shape.classed(CLASS[_SELECTED], !isSelected); $$.toggle(!isSelected, shape, d, i); } }); @@ -5436,8 +5436,8 @@ if ($$.hasArcType()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable $$.dragStart = mouse; - $$.main.select('.' + CLASS[chart]).append('rect') - .attr('class', CLASS[dragarea]) + $$.main.select('.' + CLASS[_chart]).append('rect') + .attr('class', CLASS[_dragarea]) .style('opacity', 0.1); $$.dragging = true; $$.config[__data_ondragstart](); @@ -5447,12 +5447,12 @@ var $$ = this, config = $$.config; if ($$.hasArcType()) { return; } if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.main.select('.' + CLASS[dragarea]) + $$.main.select('.' + CLASS[_dragarea]) .transition().duration(100) .style('opacity', 0) .remove(); - $$.main.selectAll('.' + CLASS[shape]) - .classed(CLASS[INCLUDED], false); + $$.main.selectAll('.' + CLASS[_shape]) + .classed(CLASS[_INCLUDED], false); $$.dragging = false; $$.config[__data_ondragend](); }; @@ -5474,7 +5474,7 @@ } this.revert(); this.defocus(); - focus(candidatesForNoneArc.classed(CLASS[focused], true)); + focus(candidatesForNoneArc.classed(CLASS[_focused], true)); focus(candidatesForArc); if ($$.hasArcType()) { $$.expandArc(targetId, true); @@ -5491,7 +5491,7 @@ $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } this.revert(); - defocus(candidatesForNoneArc.classed(CLASS[focused], false)); + defocus(candidatesForNoneArc.classed(CLASS[_focused], false)); defocus(candidatesForArc); if ($$.hasArcType()) { $$.unexpandArc(targetId); @@ -5507,7 +5507,7 @@ function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } - revert(candidatesForNoneArc.classed(CLASS[focused], false)); + revert(candidatesForNoneArc.classed(CLASS[_focused], false)); revert(candidatesForArc); if ($$.hasArcType()) { $$.unexpandArc(targetId); @@ -5754,30 +5754,30 @@ c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( - $$.main.selectAll('.' + CLASS[shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[shape]) - .filter(function () { return d3.select(this).classed(CLASS[SELECTED]); }) + $$.main.selectAll('.' + CLASS[_shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[_shape]) + .filter(function () { return d3.select(this).classed(CLASS[_SELECTED]); }) .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) ); }; c3_chart_fn.select = function (ids, indices, resetOther) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[SELECTED]); + isSelected = shape.classed(CLASS[_SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d) && !isSelected) { - toggle(true, shape.classed(CLASS[SELECTED], true), d, i); + toggle(true, shape.classed(CLASS[_SELECTED], true), d, i); } } else if (isDefined(resetOther) && resetOther) { if (isSelected) { - toggle(false, shape.classed(CLASS[SELECTED], false), d, i); + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); } } }); @@ -5785,19 +5785,19 @@ c3_chart_fn.unselect = function (ids, indices) { var $$ = this.internal, d3 = $$.d3, config = $$.config; if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[shapes]).selectAll('.' + CLASS[shape]).each(function (d, i) { + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[SELECTED]); + isSelected = shape.classed(CLASS[_SELECTED]); // line/area selection not supported yet - if (shape.classed(CLASS[line]) || shape.classed(CLASS[area])) { + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { return; } if (isTargetId && isTargetIndex) { if (config[__data_selection_isselectable](d)) { if (isSelected) { - toggle(false, shape.classed(CLASS[SELECTED], false), d, i); + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); } } } @@ -5870,9 +5870,9 @@ options = options || {}; 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) .style('opacity', 0) .remove(); From 47e95ecf313fdc602882fd69f3712b649038c083 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 20:55:59 +0100 Subject: [PATCH 19/44] Refactor init of internal params --- c3.js | 282 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 154 insertions(+), 128 deletions(-) diff --git a/c3.js b/c3.js index 92e7eb8..c66eb4b 100644 --- a/c3.js +++ b/c3.js @@ -441,33 +441,11 @@ }; - - // should be define in c3.zoom.js - c3_chart_internal_fn.initZoom = function () { - var $$ = this, d3 = $$.d3, config = $$.config; - $$.zoom = d3.behavior.zoom() - .on("zoomstart", function () { - $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; - }) - .on("zoom", $$.redrawForZoom); - $$.zoom.scale = function (scale) { - return config[__axis_rotated] ? this.y(scale) : this.x(scale); - }; - $$.zoom.orgScaleExtent = function () { - var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; - return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; - }; - $$.zoom.updateScaleExtent = function () { - var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), - extent = $$.orgScaleExtent(); - $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); - return this; - }; - }; - - c3_chart_internal_fn.init = function () { var $$ = this, config = $$.config; + + $$.initParams(); + if (config[__data_url]) { $$.convertUrlToData(config[__data_url], config[__data_mimeType], config[__data_keys], $$.initWithData); } @@ -485,9 +463,8 @@ } }; - c3_chart_internal_fn.initWithData = function (data) { - var $$ = this, d3 = $$.d3, config = $$.config; - var main, legend, eventRect, i, binding = true; + c3_chart_internal_fn.initParams = function () { + var $$ = this, d3 = $$.d3; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId = "c3-" + (+new Date()) + '-clip', @@ -497,19 +474,14 @@ $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - $$.isTimeSeries = (config[__axis_x_type] === 'timeseries'); - $$.isCategorized = (config[__axis_x_type].indexOf('categor') >= 0); - $$.isCustomX = function () { return !$$.isTimeSeries && (config[__data_x] || notEmpty(config[__data_xs])); }; - $$.dragStart = null; $$.dragging = false; $$.cancelClick = false; $$.mouseover = false; $$.transiting = false; - $$.defaultColorPattern = d3.scale.category10().range(); - $$.color = $$.generateColor(config[__data_colors], notEmpty(config[__color_pattern]) ? config[__color_pattern] : $$.defaultColorPattern, config[__data_color]); - $$.levelColor = notEmpty(config[__color_threshold]) ? $$.generateLevelColor(config[__color_pattern], config[__color_threshold]) : null; + $$.color = $$.generateColor(); + $$.levelColor = $$.generateLevelColor(); $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.time.format.utc; @@ -532,17 +504,6 @@ $$.y2Orient = config[__axis_rotated] ? (config[__axis_y2_inner] ? "bottom" : "top") : (config[__axis_y2_inner] ? "left" : "right"); $$.subXOrient = config[__axis_rotated] ? "left" : "bottom"; - $$.translate = { - main : function () { return "translate(" + asHalfPixel($$.margin.left) + "," + asHalfPixel($$.margin.top) + ")"; }, - context : function () { return "translate(" + asHalfPixel($$.margin2.left) + "," + asHalfPixel($$.margin2.top) + ")"; }, - legend : function () { return "translate(" + $$.margin3.left + "," + $$.margin3.top + ")"; }, - x : function () { return "translate(0," + (config[__axis_rotated] ? 0 : $$.height) + ")"; }, - y : function () { return "translate(0," + (config[__axis_rotated] ? $$.height : 0) + ")"; }, - y2 : function () { return "translate(" + (config[__axis_rotated] ? 0 : $$.width) + "," + (config[__axis_rotated] ? 1 : 0) + ")"; }, - subx : function () { return "translate(0," + (config[__axis_rotated] ? 0 : $$.height2) + ")"; }, - arc: function () { return "translate(" + ($$.arcWidth / 2) + "," + ($$.arcHeight / 2) + ")"; } - }; - $$.isLegendRight = config[__legend_position] === 'right'; $$.isLegendInset = config[__legend_position] === 'inset'; $$.isLegendTop = config[__legend_inset_anchor] === 'top-left' || config[__legend_inset_anchor] === 'top-right'; @@ -560,15 +521,16 @@ $$.withoutFadeIn = {}; - if (isFunction($$.initPie)) { - $$.initPie(); - } - if (isFunction($$.initBrush)) { - $$.initBrush(); - } else { - $$.axes.subx = d3.selectAll([]); - } - if ($$.initZoom) { $$.initZoom(); } + $$.axes.subx = d3.selectAll([]); // needs when excluding subchart.js + }; + + c3_chart_internal_fn.initWithData = function (data) { + var $$ = this, d3 = $$.d3, config = $$.config; + var main, legend, eventRect, i, binding = true; + + if (isFunction($$.initPie)) { $$.initPie(); } + if (isFunction($$.initBrush)) { $$.initBrush(); } + if (isFunction($$.initZoom)) { $$.initZoom(); } $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { @@ -631,8 +593,8 @@ $$.updateSvgSize(); // Define regions - main = $$.main = $$.svg.append("g").attr("transform", $$.translate.main); - legend = $$.legend = $$.svg.append("g").attr("transform", $$.translate.legend); + main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); + legend = $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); if (isFunction($$.initSubchart)) { $$.initSubchart(); @@ -734,7 +696,7 @@ $$.axes.x = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisX]) .attr("clip-path", $$.clipPathForXAxis) - .attr("transform", $$.translate.x) + .attr("transform", $$.getTranslate('x')) .style("visibility", config[__axis_x_show] ? 'visible' : 'hidden'); $$.axes.x.append("text") .attr("class", CLASS[_axisXLabel]) @@ -744,7 +706,7 @@ $$.axes.y = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) .attr("clip-path", $$.clipPathForYAxis) - .attr("transform", $$.translate.y) + .attr("transform", $$.getTranslate('y')) .style("visibility", config[__axis_y_show] ? 'visible' : 'hidden'); $$.axes.y.append("text") .attr("class", CLASS[_axisYLabel]) @@ -754,7 +716,7 @@ $$.axes.y2 = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY2]) // clip-path? - .attr("transform", $$.translate.y2) + .attr("transform", $$.getTranslate('y2')) .style("visibility", config[__axis_y2_show] ? 'visible' : 'hidden'); $$.axes.y2.append("text") .attr("class", CLASS[_axisY2Label]) @@ -777,7 +739,7 @@ // Show tooltip if needed if (config[__tooltip_init_show]) { - if ($$.isTimeSeries && isString(config[__tooltip_init_x])) { + if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); for (i = 0; i < $$.data.targets[0].values.length; i++) { if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } @@ -1017,7 +979,7 @@ } // MEMO: needed for grids calculation - if ($$.isCategorized && targetsToShow.length === 0) { + if ($$.isCategorized() && targetsToShow.length === 0) { $$.x.domain([0, $$.axes.x.selectAll('.tick').size()]); } @@ -1117,7 +1079,7 @@ // this is used to flow flushXGrid = function (withoutUpdate) { xgridData = $$.generateGridData(config[__grid_x_type], $$.x); - tickOffset = $$.isCategorized ? $$.xAxis.tickOffset() : 0; + tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; xgrid = main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) .data(xgridData); xgrid.enter().append('line').attr("class", CLASS[_xgrid]); @@ -1319,7 +1281,7 @@ .selectAll('.' + CLASS[_eventRect]).remove(); } - if (($$.isCustomX() || $$.isTimeSeries) && !$$.isCategorized) { + if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { rectW = function (d) { var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; @@ -1440,7 +1402,7 @@ if ($$.data.targets[0].values.length !== 1) { translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); } else { - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); @@ -1451,7 +1413,7 @@ } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); } else { - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); } else { translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); @@ -1553,7 +1515,7 @@ zoom.scale(x).updateScaleExtent(); return; } - if ($$.isCategorized && x.orgDomain()[0] === orgXDomain[0]) { + if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) { x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); } $$.redraw({ @@ -1807,10 +1769,46 @@ - - - - + 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.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; }; @@ -1826,7 +1824,7 @@ }; c3_chart_internal_fn.xv = function (d) { var $$ = this; - return Math.ceil($$.x($$.isTimeSeries ? $$.parseDate(d.value) : d.value)); + return Math.ceil($$.x($$.isTimeSeries() ? $$.parseDate(d.value) : d.value)); }; c3_chart_internal_fn.yv = function (d) { var $$ = this, @@ -1860,15 +1858,15 @@ y2Axis = $$.main.select('.' + CLASS[_axisY2]); if (withTransition) { y2Axis = y2Axis.transition(); } } - (withTransition ? $$.main.transition() : $$.main).attr("transform", $$.translate.main); - xAxis.attr("transform", $$.translate.x); - yAxis.attr("transform", $$.translate.y); - y2Axis.attr("transform", $$.translate.y2); - $$.main.select('.' + CLASS[_chartArcs]).attr("transform", $$.translate.arc); + (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.transformLegend = function (withTransition) { var $$ = this; - (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.translate.legend); + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); }; c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; @@ -2058,7 +2056,7 @@ return $$.config[__axis_rotated] ? $$.height : $$.width; } maxDataCount = $$.getMaxDataCount(); - ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized ? 0.25 : 1)) / maxDataCount : 1); + ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized() ? 0.25 : 1)) / maxDataCount : 1); w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; return w < 1 ? 1 : w; }; @@ -2595,10 +2593,10 @@ }; c3_chart_internal_fn.generateTargetX = function (rawX, id, index) { var $$ = this, x; - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); } - else if ($$.isCustomX() && !$$.isCategorized) { + else if ($$.isCustomX() && !$$.isCategorized()) { x = isValue(rawX) ? +rawX : $$.getXValue(id, index); } else { @@ -2690,7 +2688,7 @@ c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { var $$ = this; var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); - return $$.isTimeSeries ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); + return $$.isTimeSeries() ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); }; c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); @@ -2873,7 +2871,7 @@ ids.forEach(function (id) { var xKey = $$.getXKey(id); - if ($$.isCustomX() || $$.isTimeSeries) { + if ($$.isCustomX() || $$.isTimeSeries()) { // if included in input data if (xs.indexOf(xKey) >= 0) { $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( @@ -2912,7 +2910,7 @@ values: data.map(function (d, i) { var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); // use x as categories if custom x and categorized - if ($$.isCustomX() && $$.isCategorized && index === 0 && rawX) { + if ($$.isCustomX() && $$.isCategorized() && index === 0 && rawX) { if (i === 0) { config[__axis_x_categories] = []; } config[__axis_x_categories].push(rawX); } @@ -3372,12 +3370,12 @@ if (isUndefined(_regions[i].start)) { regions[i].start = d[0].x; } else { - regions[i].start = $$.isTimeSeries ? $$.parseDate(_regions[i].start) : _regions[i].start; + regions[i].start = $$.isTimeSeries() ? $$.parseDate(_regions[i].start) : _regions[i].start; } if (isUndefined(_regions[i].end)) { regions[i].end = d[d.length - 1].x; } else { - regions[i].end = $$.isTimeSeries ? $$.parseDate(_regions[i].end) : _regions[i].end; + regions[i].end = $$.isTimeSeries() ? $$.parseDate(_regions[i].end) : _regions[i].end; } } } @@ -3387,7 +3385,7 @@ yValue = config[__axis_rotated] ? function (d) { return x(d.x); } : function (d) { return y(d.value); }; // Define svg generator function for region - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { sWithRegion = function (d0, d1, j, diff) { var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, xv0 = new Date(x0 + x_diff * j), @@ -3409,7 +3407,7 @@ } // Draw with region // TODO: Fix for horizotal charts else { - xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries); + xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries()); yp = $$.getScale(d[i - 1].value, d[i].value); dx = x(d[i].x) - x(d[i - 1].x); @@ -3635,8 +3633,12 @@ /** * c3.color.js */ - c3_chart_internal_fn.generateColor = function (colors, pattern, callback) { - var ids = []; + c3_chart_internal_fn.generateColor = function () { + var $$ = this, config = $$.config, d3 = $$.d3, + colors = config[__data_colors], + pattern = notEmpty(config[__color_pattern]) ? config[__color_pattern] : d3.scale.category10().range(), + callback = config[__data_color], + ids = []; return function (d) { var id = d.id || d, color; @@ -3658,11 +3660,14 @@ return callback instanceof Function ? callback(color, d) : color; }; }; - c3_chart_internal_fn.generateLevelColor = function (colors, threshold) { - var asValue = threshold.unit === 'value', + c3_chart_internal_fn.generateLevelColor = function () { + var $$ = this, config = $$.config, + colors = config[__color_pattern], + threshold = config[__color_threshold], + asValue = threshold.unit === 'value', values = threshold.values && threshold.values.length ? threshold.values : [], max = threshold.max || 100; - return function (value) { + return notEmpty(config[__color_threshold]) ? function (value) { var i, v, color = colors[colors.length - 1]; for (i = 0; i < values.length; i++) { v = asValue ? value : (value * 100 / max); @@ -3672,7 +3677,7 @@ } } return color; - }; + } : null; }; @@ -3684,10 +3689,10 @@ }; c3_chart_internal_fn.getX = function (min, max, domain, offset) { var $$ = this, - scale = $$.getScale(min, max, $$.isTimeSeries), + scale = $$.getScale(min, max, $$.isTimeSeries()), _scale = domain ? scale.domain(domain) : scale, key; // Define customized scale if categorized axis - if ($$.isCategorized) { + if ($$.isCategorized()) { offset = offset || function () { return 0; }; scale = function (d, raw) { var v = _scale(d) + offset(d); @@ -3707,7 +3712,7 @@ return _scale.domain(); }; // define custom domain() for categorized axis - if ($$.isCategorized) { + if ($$.isCategorized()) { scale.domain = function (domain) { if (!arguments.length) { domain = this.orgDomain(); @@ -3899,20 +3904,20 @@ c3_chart_internal_fn.getXDomainMin = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_min] ? - ($$.isTimeSeries ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; c3_chart_internal_fn.getXDomainMax = function (targets) { var $$ = this, config = $$.config; return config[__axis_x_max] ? - ($$.isTimeSeries ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; c3_chart_internal_fn.getXDomainPadding = function (targets) { var $$ = this, config = $$.config, edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], maxDataCount, padding, paddingLeft, paddingRight; - if ($$.isCategorized) { + if ($$.isCategorized()) { padding = 0; } else if ($$.hasType('bar', targets)) { maxDataCount = $$.getMaxDataCount(); @@ -3937,15 +3942,15 @@ padding = $$.getXDomainPadding(targets), min = 0, max = 0; // show center of x domain if min and max are the same - if ((firstX - lastX) === 0 && !$$.isCategorized) { - firstX = $$.isTimeSeries ? new Date(firstX.getTime() * 0.5) : -0.5; - lastX = $$.isTimeSeries ? new Date(lastX.getTime() * 1.5) : 0.5; + if ((firstX - lastX) === 0 && !$$.isCategorized()) { + firstX = $$.isTimeSeries() ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$.isTimeSeries() ? new Date(lastX.getTime() * 1.5) : 0.5; } if (firstX || firstX === 0) { - min = $$.isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + min = $$.isTimeSeries() ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; } if (lastX || lastX === 0) { - max = $$.isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + max = $$.isTimeSeries() ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; } return [min, max]; }; @@ -3970,11 +3975,11 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, - axis = c3_axis($$.d3, $$.isCategorized).scale(scale).orient(orient); + axis = c3_axis($$.d3, $$.isCategorized()).scale(scale).orient(orient); // Set tick axis.tickFormat(tickFormat).tickValues(tickValues); - if ($$.isCategorized) { + if ($$.isCategorized()) { axis.tickCentered(config[__axis_x_tick_centered]); if (isEmpty(config[__axis_x_tick_culling])) { config[__axis_x_tick_culling] = false; @@ -3999,11 +4004,11 @@ }; c3_chart_internal_fn.getXAxisTickFormat = function () { var $$ = this, config = $$.config, - format = $$.isTimeSeries ? $$.defaultAxisTimeFormat : $$.isCategorized ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; + 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) { + } else if ($$.isTimeSeries()) { format = function (date) { return date ? $$.axisTimeFormat(config[__axis_x_tick_format])(date) : ""; }; @@ -4243,12 +4248,12 @@ tickValues = [start]; for (i = 0; i < count; i++) { tickValue = +start + interval * (i + 1); - tickValues.push($$.isTimeSeries ? new Date(tickValue) : tickValue); + tickValues.push($$.isTimeSeries() ? new Date(tickValue) : tickValue); } tickValues.push(end); } } - if (!$$.isTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; @@ -4262,7 +4267,7 @@ if (d.axis === 'y' || d.axis === 'y2') { xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; } else { - xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0); + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0); } return xPos; }; @@ -4272,7 +4277,7 @@ if (d.axis === 'y' || d.axis === 'y2') { yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); } else { - yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.start) : d.start) : 0) : 0; + yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0) : 0; } return yPos; }; @@ -4282,7 +4287,7 @@ if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; } else { - end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.width); + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.width); } return end < start ? 0 : end - start; }; @@ -4292,7 +4297,7 @@ if (d.axis === 'y' || d.axis === 'y2') { end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); } else { - end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; + end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; } return end < start ? 0 : end - start; }; @@ -4521,7 +4526,7 @@ var $$ = this, arcs; arcs = $$.main.select('.' + CLASS[_chart]).append("g") .attr("class", CLASS[_chartArcs]) - .attr("transform", $$.translate.arc); + .attr("transform", $$.getTranslate('arc')); arcs.append('text') .attr('class', CLASS[_chartArcsTitle]) .style("text-anchor", "middle") @@ -4700,7 +4705,7 @@ }; c3_chart_internal_fn.initSubchart = function () { var $$ = this, config = $$.config, - context = $$.context = $$.svg.append("g").attr("transform", $$.translate.context); + context = $$.context = $$.svg.append("g").attr("transform", $$.getTranslate('context')); if (!config[__subchart_show]) { context.style('visibility', 'hidden'); @@ -4731,7 +4736,7 @@ // Add Axis $$.axes.subx = context.append("g") .attr("class", CLASS[_axisX]) - .attr("transform", $$.translate.subx) + .attr("transform", $$.getTranslate('subx')) .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); }; c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { @@ -4857,14 +4862,35 @@ subXAxis = $$.context.select('.' + CLASS[_axisX]); if (withTransition) { subXAxis = subXAxis.transition(); } } - $$.context.attr("transform", $$.translate.context); - subXAxis.attr("transform", $$.translate.subx); + $$.context.attr("transform", $$.getTranslate('context')); + subXAxis.attr("transform", $$.getTranslate('subx')); }; /** * c3.zoom.js */ + c3_chart_internal_fn.initZoom = function () { + var $$ = this, d3 = $$.d3, config = $$.config; + $$.zoom = d3.behavior.zoom() + .on("zoomstart", function () { + $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; + }) + .on("zoom", $$.redrawForZoom); + $$.zoom.scale = function (scale) { + return config[__axis_rotated] ? this.y(scale) : this.x(scale); + }; + $$.zoom.orgScaleExtent = function () { + var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; + return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; + }; + $$.zoom.updateScaleExtent = function () { + var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), + extent = $$.orgScaleExtent(); + $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + return this; + }; + }; c3_chart_internal_fn.updateZoom = function () { var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; $$.main.select('.' + $$.CLASS[_zoomRect]).call(z); @@ -5582,7 +5608,7 @@ }); } // update categories if exists - if ('categories' in args && $$.isCategorized) { + if ('categories' in args && $$.isCategorized()) { config[__axis_x_categories] = args.categories; } // use cache if exists @@ -5643,7 +5669,7 @@ for (j = 0; j < length; j++) { targets[i].values[j].index = tail + j; - if (!$$.isTimeSeries) { + if (!$$.isTimeSeries()) { targets[i].values[j].x = tail + j; } } @@ -5666,7 +5692,7 @@ t.values.push({ id: t.id, index: tail + j, - x: $$.isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j, + x: $$.isTimeSeries() ? $$.getOtherTargetX(tail + j) : tail + j, value: null }); } @@ -5682,13 +5708,13 @@ missing.push({ id: t.id, index: i, - x: $$.isTimeSeries ? $$.getOtherTargetX(i) : i, + x: $$.isTimeSeries() ? $$.getOtherTargetX(i) : i, value: null }); } t.values.forEach(function (v) { v.index += tail; - if (!$$.isTimeSeries) { + if (!$$.isTimeSeries()) { v.x += tail; } }); @@ -5705,7 +5731,7 @@ // Update length to flow if needed if (isDefined(args.to)) { length = 0; - to = $$.isTimeSeries ? $$.parseDate(args.to) : args.to; + to = $$.isTimeSeries() ? $$.parseDate(args.to) : args.to; baseTarget.values.forEach(function (v) { if (v.x < to) { length++; } }); @@ -5715,7 +5741,7 @@ // If only one data, update the domain to flow from left edge of the chart if (!orgDataCount) { - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { if (baseTarget.values.length > 1) { diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; } else { @@ -5727,7 +5753,7 @@ domain = [baseValue.x - diff, baseValue.x]; $$.updateXDomain(null, true, true, domain); } else if (orgDataCount === 1) { - if ($$.isTimeSeries) { + if ($$.isTimeSeries()) { diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; $$.updateXDomain(null, true, true, domain); From 6fd0279150147c3c58102e9de7a0ca2c9ecab07c Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Thu, 31 Jul 2014 21:07:36 +0100 Subject: [PATCH 20/44] Remove inner y axis --- c3.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/c3.js b/c3.js index c66eb4b..984a319 100644 --- a/c3.js +++ b/c3.js @@ -132,7 +132,6 @@ __axis_y_min = 'axis_y_min', __axis_y_center = 'axis_y_center', __axis_y_label = 'axis_y_label', - __axis_y_inner = 'axis_y_inner', __axis_y_tick_format = 'axis_y_tick_format', __axis_y_tick_outer = 'axis_y_tick_outer', __axis_y_padding = 'axis_y_padding', @@ -142,7 +141,6 @@ __axis_y2_min = 'axis_y2_min', __axis_y2_center = 'axis_y2_center', __axis_y2_label = 'axis_y2_label', - __axis_y2_inner = 'axis_y2_inner', __axis_y2_tick_format = 'axis_y2_tick_format', __axis_y2_tick_outer = 'axis_y2_tick_outer', __axis_y2_padding = 'axis_y2_padding', @@ -305,7 +303,6 @@ config[__axis_y_min] = undefined; config[__axis_y_center] = undefined; config[__axis_y_label] = {}; - config[__axis_y_inner] = false; config[__axis_y_tick_format] = undefined; config[__axis_y_tick_outer] = true; config[__axis_y_padding] = undefined; @@ -315,7 +312,6 @@ config[__axis_y2_min] = undefined; config[__axis_y2_center] = undefined; config[__axis_y2_label] = {}; - config[__axis_y2_inner] = false; config[__axis_y2_tick_format] = undefined; config[__axis_y2_tick_outer] = true; config[__axis_y2_padding] = undefined; @@ -500,8 +496,8 @@ $$.hiddenLegendIds = []; $$.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"); + $$.yOrient = config[__axis_rotated] ? "bottom" : "left"; + $$.y2Orient = config[__axis_rotated] ? "top" : "right"; $$.subXOrient = config[__axis_rotated] ? "left" : "bottom"; $$.isLegendRight = config[__legend_position] === 'right'; @@ -1983,7 +1979,7 @@ } else if (config[__axis_rotated]) { return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); } else { - return !config[__axis_y_show] || config[__axis_y_inner] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); + return !config[__axis_y_show] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); } }; c3_chart_internal_fn.getCurrentPaddingRight = function () { @@ -1994,7 +1990,7 @@ } else if (config[__axis_rotated]) { return defaultPadding + legendWidthOnRight; } else { - return (!config[__axis_y2_show] || config[__axis_y2_inner] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + return (!config[__axis_y2_show] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; } }; From 26638a330ed582fbe2f6446fb7e108875183e018 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 1 Aug 2014 16:24:07 +0100 Subject: [PATCH 21/44] Make plugable legend --- c3.js | 175 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 92 insertions(+), 83 deletions(-) diff --git a/c3.js b/c3.js index 984a319..af908d3 100644 --- a/c3.js +++ b/c3.js @@ -381,30 +381,8 @@ config[__tooltip_format_name] = undefined; config[__tooltip_format_value] = undefined; config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { - var $$ = this, config = $$.config, - titleFormat = config[__tooltip_format_title] || defaultTitleFormat, - nameFormat = config[__tooltip_format_name] || function (name) { return name; }, - valueFormat = config[__tooltip_format_value] || defaultValueFormat, - text, i, title, value, name, bgcolor; - for (i = 0; i < d.length; i++) { - if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } - - if (! text) { - title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "
" + title + "
" + name + "" + value + "
" + (title || title === 0 ? "" : ""); - } - - name = nameFormat(d[i].name); - value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - - text += ""; - text += ""; - text += ""; - text += ""; - } - return text + "
" + title + "
" + name + "" + value + "
"; - }; + return this.getTooltipContent ? this.getTooltipContent(d, defaultValueFormat, defaultValueFormat, color) : ''; + }, config[__tooltip_init_show] = false; config[__tooltip_init_x] = 0; config[__tooltip_init_position] = {top: '0px', left: '50px'}; @@ -522,7 +500,7 @@ c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; - var main, legend, eventRect, i, binding = true; + var main, eventRect, binding = true; if (isFunction($$.initPie)) { $$.initPie(); } if (isFunction($$.initBrush)) { $$.initBrush(); } @@ -590,29 +568,10 @@ // Define regions main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); - legend = $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); - - if (isFunction($$.initSubchart)) { - $$.initSubchart(); - } - - if (!config[__legend_show]) { - $$.legend.style('visibility', 'hidden'); - $$.hiddenLegendIds = $$.mapToIds($$.data.targets); - } - - // Define tooltip - $$.tooltip = $$.selectChart - .style("position", "relative") - .append("div") - .style("position", "absolute") - .style("pointer-events", "none") - .style("z-index", "10") - .style("display", "none"); - // MEMO: call here to update legend box and tranlate for all - // MEMO: translate will be upated by this, so transform not needed in updateLegend() - $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + if (isFunction($$.initSubchart)) { $$.initSubchart(); } + if (isFunction($$.initTooltip)) { $$.initTooltip(); } + if (isFunction($$.initLegend)) { $$.initLegend(); } /*-- Main Region --*/ @@ -733,23 +692,6 @@ }); } - // Show tooltip if needed - if (config[__tooltip_init_show]) { - if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { - config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); - for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } - } - config[__tooltip_init_x] = i; - } - $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { - return $$.addName(d.values[config[__tooltip_init_x]]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); - $$.tooltip.style("top", config[__tooltip_init_position].top) - .style("left", config[__tooltip_init_position].left) - .style("display", "block"); - } - // Bind resize event if (window.onresize == null) { window.onresize = $$.generateResize(); @@ -793,7 +735,8 @@ c3_chart_internal_fn.updateSizes = function () { var $$ = this, config = $$.config; - var legendHeight = $$.getLegendHeight(), legendWidth = $$.getLegendWidth(), + var legendHeight = $$.legend ? $$.getLegendHeight() : 0, + legendWidth = $$.legend ? $$.getLegendWidth() : 0, legendHeightForBottom = $$.isLegendRight || $$.isLegendInset ? 0 : legendHeight, hasArc = $$.hasArcType(), xAxisHeight = config[__axis_rotated] || hasArc ? 0 : $$.getHorizontalAxisHeight('x'), @@ -830,17 +773,9 @@ left: $$.margin.left }; } + // for legend - var insetLegendPosition = { - 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 - }; - $$.margin3 = { - top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, - right: NaN, - bottom: 0, - left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 - }; + if (isFunction($$.updateSizeForLegend)) { $$.updateSizeForLegend(legendHeight, legendWidth); } $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; @@ -1860,15 +1795,11 @@ y2Axis.attr("transform", $$.getTranslate('y2')); $$.main.select('.' + CLASS[_chartArcs]).attr("transform", $$.getTranslate('arc')); }; - c3_chart_internal_fn.transformLegend = function (withTransition) { - var $$ = this; - (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); - }; c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); if (config[__subchart_show]) { $$.transformContext(withTransition, transitions); } - $$.transformLegend(withTransition); + if ($$.legend) { $$.transformLegend(withTransition); } }; @@ -2061,6 +1992,57 @@ /** * c3.tooltip.js */ + c3_chart_internal_fn.initTooltip = function () { + var $$ = this, config = $$.config, i; + $$.tooltip = $$.selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + // Show tooltip if needed + if (config[__tooltip_init_show]) { + if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); + for (i = 0; i < $$.data.targets[0].values.length; i++) { + if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } + } + config[__tooltip_init_x] = i; + } + $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); + $$.tooltip.style("top", config[__tooltip_init_position].top) + .style("left", config[__tooltip_init_position].left) + .style("display", "block"); + } + }; + c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { + var $$ = this, config = $$.config, + titleFormat = config[__tooltip_format_title] || defaultTitleFormat, + nameFormat = config[__tooltip_format_name] || function (name) { return name; }, + valueFormat = config[__tooltip_format_value] || defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } + + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "" + (title || title === 0 ? "" : ""); + } + + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); + + text += ""; + text += ""; + text += ""; + text += ""; + } + return text + "
" + title + "
" + name + "" + value + "
"; + }; c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { var $$ = this, config = $$.config; var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; @@ -2187,6 +2169,33 @@ /** * c3.legend.js */ + c3_chart_internal_fn.initLegend = function () { + var $$ = this; + $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); + if (!config[__legend_show]) { + $$.legend.style('visibility', 'hidden'); + $$.hiddenLegendIds = $$.mapToIds($$.data.targets); + } + // MEMO: call here to update legend box and tranlate for all + // MEMO: translate will be upated by this, so transform not needed in updateLegend() + $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); + }; + c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { + var $$ = this, insetLegendPosition = { + 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 + }; + $$.margin3 = { + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + }; + }; + c3_chart_internal_fn.transformLegend = function (withTransition) { + var $$ = this; + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); + }; c3_chart_internal_fn.updateLegendStep = function (step) { this.legendStep = step; }; @@ -2456,8 +2465,6 @@ }; - - c3_chart_internal_fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; @@ -3035,7 +3042,9 @@ // Reset fadein for future load $$.withoutFadeIn[id] = false; // Remove target's elements - $$.legend.selectAll('.' + CLASS[_legendItem] + $$.getTargetSelectorSuffix(id)).remove(); + if ($$.legend) { + $$.legend.selectAll('.' + CLASS[_legendItem] + $$.getTargetSelectorSuffix(id)).remove(); + } // Remove target $$.data.targets = $$.data.targets.filter(function (t) { return t.id !== id; From 06f36e06708f38a3ef6e694847f3fff6f088e7f1 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 1 Aug 2014 17:32:27 +0100 Subject: [PATCH 22/44] Make plugble zoom --- c3.js | 430 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 219 insertions(+), 211 deletions(-) diff --git a/c3.js b/c3.js index af908d3..5d3f156 100644 --- a/c3.js +++ b/c3.js @@ -635,6 +635,7 @@ .attr("class", CLASS[_chartTexts]); // 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) @@ -1431,33 +1432,7 @@ $$.withoutFadeIn[id] = true; }); - $$.updateZoom(); - }; - c3_chart_internal_fn.redrawForZoom = function () { - var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; - if (!config[__zoom_enabled]) { - return; - } - if ($$.filterTargetsToShow($$.data.targets).length === 0) { - return; - } - if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { - x.domain(zoom.altDomain); - zoom.scale(x).updateScaleExtent(); - return; - } - if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) { - x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); - } - $$.redraw({ - withTransition: false, - withY: false, - withSubchart: false - }); - if (d3.event.sourceEvent.type === 'mousemove') { - $$.cancelClick = true; - } - config[__zoom_onzoom].call(c3, x.orgDomain()); + if (isFunction($$.updateZoom)) { $$.updateZoom(); } }; c3_chart_internal_fn.updateAndRedraw = function (options) { var $$ = this, config = $$.config, transitions; @@ -1594,12 +1569,14 @@ }) .on('click', function (d) { var index = d.index; - if ($$.hasArcType()) { return; } + if ($$.hasArcType() || !$$.toggleShape) { return; } if ($$.cancelClick) { $$.cancelClick = false; return; } - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { $$.toggleShape(this, d, index); }); + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + $$.toggleShape(this, d, index); + }); }) .call( d3.behavior.drag().origin(Object) @@ -1682,7 +1659,7 @@ if (! closest) { return; } // select if selection enabled - if ($$.dist(closest, mouse) < 100) { + if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { $$.toggleShape(this, closest, closest.index); }); @@ -1989,183 +1966,6 @@ }; - /** - * c3.tooltip.js - */ - c3_chart_internal_fn.initTooltip = function () { - var $$ = this, config = $$.config, i; - $$.tooltip = $$.selectChart - .style("position", "relative") - .append("div") - .style("position", "absolute") - .style("pointer-events", "none") - .style("z-index", "10") - .style("display", "none"); - // Show tooltip if needed - if (config[__tooltip_init_show]) { - if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { - config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); - for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } - } - config[__tooltip_init_x] = i; - } - $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { - return $$.addName(d.values[config[__tooltip_init_x]]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); - $$.tooltip.style("top", config[__tooltip_init_position].top) - .style("left", config[__tooltip_init_position].left) - .style("display", "block"); - } - }; - c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { - var $$ = this, config = $$.config, - titleFormat = config[__tooltip_format_title] || defaultTitleFormat, - nameFormat = config[__tooltip_format_name] || function (name) { return name; }, - valueFormat = config[__tooltip_format_value] || defaultValueFormat, - text, i, title, value, name, bgcolor; - for (i = 0; i < d.length; i++) { - if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } - - if (! text) { - title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); - } - - name = nameFormat(d[i].name); - value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - - text += ""; - text += ""; - text += ""; - text += ""; - } - return text + "
" + title + "
" + name + "" + value + "
"; - }; - c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { - var $$ = this, config = $$.config; - var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$.hasArcType(), - dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (dataToShow.length === 0 || !config[__tooltip_show]) { - return; - } - $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); - - // Get tooltip dimensions - tWidth = $$.tooltip.property('offsetWidth'); - tHeight = $$.tooltip.property('offsetHeight'); - // Determin tooltip position - if (forArc) { - tooltipLeft = ($$.width / 2) + mouse[0]; - tooltipTop = ($$.height / 2) + mouse[1] + 20; - } else { - if (config[__axis_rotated]) { - svgLeft = $$.getSvgLeft(); - tooltipLeft = svgLeft + mouse[0] + 100; - tooltipRight = tooltipLeft + tWidth; - chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); - tooltipTop = $$.x(dataToShow[0].x) + 20; - } else { - svgLeft = $$.getSvgLeft(); - tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; - tooltipRight = tooltipLeft + tWidth; - chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); - tooltipTop = mouse[1] + 15; - } - - if (tooltipRight > chartRight) { - tooltipLeft -= tooltipRight - chartRight; - } - if (tooltipTop + tHeight > $$.getCurrentHeight()) { - tooltipTop -= tHeight + 30; - } - } - // Set tooltip - $$.tooltip - .style("top", tooltipTop + "px") - .style("left", tooltipLeft + 'px'); - }; - c3_chart_internal_fn.hideTooltip = function () { - this.tooltip.style("display", "none"); - }; - - - /** - * c3.grid.js - */ - c3_chart_internal_fn.showXGridFocus = function (selectedData) { - var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (! config[__tooltip_show]) { return; } - // Hide when scatter plot exists - if ($$.hasType('scatter') || $$.hasArcType()) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); - focusEl - .style("visibility", "visible") - .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); - $$.smoothLines(focusEl, 'grid'); - }; - c3_chart_internal_fn.hideXGridFocus = function () { - this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); - }; - c3_chart_internal_fn.updateXgridFocus = function () { - var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS[_xgridFocus]) - .attr("x1", config[__axis_rotated] ? 0 : -10) - .attr("x2", config[__axis_rotated] ? $$.width : -10) - .attr("y1", config[__axis_rotated] ? -10 : 0) - .attr("y2", config[__axis_rotated] ? -10 : $$.height); - }; - c3_chart_internal_fn.generateGridData = function (type, scale) { - var $$ = this, - gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); - if (type === 'year') { - xDomain = $$.getXDomain(); - firstYear = xDomain[0].getFullYear(); - lastYear = xDomain[1].getFullYear(); - for (i = firstYear; i <= lastYear; i++) { - gridData.push(new Date(i + '-01-01 00:00:00')); - } - } else { - gridData = scale.ticks(10); - if (gridData.length > tickNum) { // use only int - gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); - } - } - return gridData; - }; - c3_chart_internal_fn.getGridFilterToRemove = function (params) { - return params ? function (line) { - var found = false; - [].concat(params).forEach(function (param) { - if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { - found = true; - } - }); - return found; - } : function () { return true; }; - }; - c3_chart_internal_fn.removeGridLines = function (params, forX) { - var $$ = this, config = $$.config, - toRemove = $$.getGridFilterToRemove(params), - toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], - classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; - $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) - .transition().duration(config[__transition_duration]) - .style('opacity', 0).remove(); - if (forX) { - config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); - } else { - config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); - } - }; - - /** * c3.legend.js */ @@ -2465,6 +2265,186 @@ }; + + /** + * c3.tooltip.js + */ + c3_chart_internal_fn.initTooltip = function () { + var $$ = this, config = $$.config, i; + $$.tooltip = $$.selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + // Show tooltip if needed + if (config[__tooltip_init_show]) { + if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); + for (i = 0; i < $$.data.targets[0].values.length; i++) { + if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } + } + config[__tooltip_init_x] = i; + } + $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); + $$.tooltip.style("top", config[__tooltip_init_position].top) + .style("left", config[__tooltip_init_position].left) + .style("display", "block"); + } + }; + c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { + var $$ = this, config = $$.config, + titleFormat = config[__tooltip_format_title] || defaultTitleFormat, + nameFormat = config[__tooltip_format_name] || function (name) { return name; }, + valueFormat = config[__tooltip_format_value] || defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } + + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "" + (title || title === 0 ? "" : ""); + } + + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); + + text += ""; + text += ""; + text += ""; + text += ""; + } + return text + "
" + title + "
" + name + "" + value + "
"; + }; + c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { + var $$ = this, config = $$.config; + var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; + var forArc = $$.hasArcType(), + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (dataToShow.length === 0 || !config[__tooltip_show]) { + return; + } + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + + // Get tooltip dimensions + tWidth = $$.tooltip.property('offsetWidth'); + tHeight = $$.tooltip.property('offsetHeight'); + // Determin tooltip position + if (forArc) { + tooltipLeft = ($$.width / 2) + mouse[0]; + tooltipTop = ($$.height / 2) + mouse[1] + 20; + } else { + if (config[__axis_rotated]) { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + mouse[0] + 100; + tooltipRight = tooltipLeft + tWidth; + chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = $$.x(dataToShow[0].x) + 20; + } else { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; + tooltipRight = tooltipLeft + tWidth; + chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = mouse[1] + 15; + } + + if (tooltipRight > chartRight) { + tooltipLeft -= tooltipRight - chartRight; + } + if (tooltipTop + tHeight > $$.getCurrentHeight()) { + tooltipTop -= tHeight + 30; + } + } + // Set tooltip + $$.tooltip + .style("top", tooltipTop + "px") + .style("left", tooltipLeft + 'px'); + }; + c3_chart_internal_fn.hideTooltip = function () { + this.tooltip.style("display", "none"); + }; + + + + /** + * c3.grid.js + */ + c3_chart_internal_fn.showXGridFocus = function (selectedData) { + var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (! config[__tooltip_show]) { return; } + // Hide when scatter plot exists + if ($$.hasType('scatter') || $$.hasArcType()) { return; } + var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); + focusEl + .style("visibility", "visible") + .data([dataToShow[0]]) + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + $$.smoothLines(focusEl, 'grid'); + }; + c3_chart_internal_fn.hideXGridFocus = function () { + this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); + }; + c3_chart_internal_fn.updateXgridFocus = function () { + var $$ = this, config = $$.config; + $$.main.select('line.' + CLASS[_xgridFocus]) + .attr("x1", config[__axis_rotated] ? 0 : -10) + .attr("x2", config[__axis_rotated] ? $$.width : -10) + .attr("y1", config[__axis_rotated] ? -10 : 0) + .attr("y2", config[__axis_rotated] ? -10 : $$.height); + }; + c3_chart_internal_fn.generateGridData = function (type, scale) { + var $$ = this, + gridData = [], xDomain, firstYear, lastYear, i, + tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); + if (type === 'year') { + xDomain = $$.getXDomain(); + firstYear = xDomain[0].getFullYear(); + lastYear = xDomain[1].getFullYear(); + for (i = firstYear; i <= lastYear; i++) { + gridData.push(new Date(i + '-01-01 00:00:00')); + } + } else { + gridData = scale.ticks(10); + if (gridData.length > tickNum) { // use only int + gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } + } + return gridData; + }; + c3_chart_internal_fn.getGridFilterToRemove = function (params) { + return params ? function (line) { + var found = false; + [].concat(params).forEach(function (param) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + found = true; + } + }); + return found; + } : function () { return true; }; + }; + c3_chart_internal_fn.removeGridLines = function (params, forX) { + var $$ = this, config = $$.config, + toRemove = $$.getGridFilterToRemove(params), + toShow = function (line) { return !toRemove(line); }, + classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], + classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; + $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) + .transition().duration(config[__transition_duration]) + .style('opacity', 0).remove(); + if (forX) { + config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); + } else { + config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); + } + }; + + + c3_chart_internal_fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; @@ -4586,8 +4566,12 @@ $$.config[__data_onmouseout](arcData, this); }) .on('click', function (d, i) { - var updated = $$.updateAngle(d), - arcData = $$.convertToArcData(updated); + var updated, arcData; + if (!$$.toggleShape) { + return; + } + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); $$.toggleShape(this, arcData, i); // onclick called in toogleShape() }); mainArc @@ -4901,8 +4885,32 @@ $$.main.select('.' + $$.CLASS[_zoomRect]).call(z); $$.main.selectAll('.' + $$.CLASS[_eventRect]).call(z); }; - - + c3_chart_internal_fn.redrawForZoom = function () { + var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; + if (!config[__zoom_enabled]) { + return; + } + if ($$.filterTargetsToShow($$.data.targets).length === 0) { + return; + } + if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { + x.domain(zoom.altDomain); + zoom.scale(x).updateScaleExtent(); + return; + } + if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) { + x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); + } + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false + }); + if (d3.event.sourceEvent.type === 'mousemove') { + $$.cancelClick = true; + } + config[__zoom_onzoom].call(c3, x.orgDomain()); + }; /** From fe5a71ab3e3e626e988ca8aa7a69396cc31d8f3a Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 1 Aug 2014 19:44:57 +0100 Subject: [PATCH 23/44] Separete src files --- Gruntfile.coffee | 43 +- c3.js | 3623 ++++++++++++++++++++----------------------- c3.min.js | 7 +- src/api.js | 573 +++++++ src/arc.js | 359 +++++ src/axis.js | 283 ++++ src/c3.axis.js | 184 +++ src/cache.js | 16 + src/category.js | 4 + src/class.js | 233 +++ src/clip.js | 52 + src/color.js | 46 + src/config.js | 353 +++++ src/core.js | 1542 ++++++++++++++++++ src/data.convert.js | 176 +++ src/data.js | 327 ++++ src/data.load.js | 89 ++ src/domain.js | 193 +++ src/drag.js | 84 + src/format.js | 38 + src/grid.js | 69 + src/head.js | 4 + src/legend.js | 294 ++++ src/region.js | 43 + src/scale.js | 87 ++ src/selection.js | 80 + src/shape.js | 386 +++++ src/size.js | 101 ++ src/subchart.js | 173 +++ src/tail.js | 9 + src/text.js | 11 + src/tooltip.js | 98 ++ src/type.js | 81 + src/util.js | 49 + src/zoom.js | 52 + 35 files changed, 7823 insertions(+), 1939 deletions(-) create mode 100644 src/api.js create mode 100644 src/arc.js create mode 100644 src/axis.js create mode 100644 src/c3.axis.js create mode 100644 src/cache.js create mode 100644 src/category.js create mode 100644 src/class.js create mode 100644 src/clip.js create mode 100644 src/color.js create mode 100644 src/config.js create mode 100644 src/core.js create mode 100644 src/data.convert.js create mode 100644 src/data.js create mode 100644 src/data.load.js create mode 100644 src/domain.js create mode 100644 src/drag.js create mode 100644 src/format.js create mode 100644 src/grid.js create mode 100644 src/head.js create mode 100644 src/legend.js create mode 100644 src/region.js create mode 100644 src/scale.js create mode 100644 src/selection.js create mode 100644 src/shape.js create mode 100644 src/size.js create mode 100644 src/subchart.js create mode 100644 src/tail.js create mode 100644 src/text.js create mode 100644 src/tooltip.js create mode 100644 src/type.js create mode 100644 src/util.js create mode 100644 src/zoom.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 074f379..4f22aed 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -9,15 +9,48 @@ module.exports = (grunt) -> concat: dist: + options: + process: (src, filepath) -> + if filepath != 'src/head.js' && filepath != 'src/tail.js' + lines = [] + src.split('\n').forEach (line) -> + lines.push( (if line.length > 0 then ' ' else '') + line) + src = lines.join('\n') + return src src: [ 'src/head.js', - 'src/c3.core.js', - 'src/c3.render.bar.js', - 'src/c3.draw.bar.js', + 'src/core.js', + 'src/config.js', + 'src/scale.js', + 'src/domain.js', + 'src/data.js', + 'src/data.convert.js', + 'src/data.load.js', + 'src/category.js', + 'src/size.js', + 'src/shape.js', + 'src/text.js', + 'src/type.js', + 'src/grid.js', + 'src/tooltip.js', + 'src/legend.js', + 'src/axis.js', + 'src/clip.js', + 'src/arc.js', + 'src/region.js', + 'src/drag.js', + 'src/subchart.js', + 'src/zoom.js', + 'src/color.js', + 'src/format.js', + 'src/cache.js', + 'src/class.js', + 'src/util.js', + 'src/api.js', 'src/c3.axis.js', 'src/tail.js' ] - dest: 'dist/c3.js' + dest: 'c3.js' jshint: c3: 'c3.js' @@ -36,4 +69,4 @@ module.exports = (grunt) -> files: 'c3.min.js': 'c3.js' - grunt.registerTask 'default', ['jshint', 'jasmine', 'uglify'] + grunt.registerTask 'default', ['concat', 'jshint', 'jasmine', 'uglify'] diff --git a/c3.js b/c3.js index 5d3f156..d950b3f 100644 --- a/c3.js +++ b/c3.js @@ -36,439 +36,60 @@ c3_chart_internal_fn = c3.chart.internal.fn; - /** - * c3.config.js - */ - var __bindto = 'bindto', - __size_width = 'size_width', - __size_height = 'size_height', - __padding_left = 'padding_left', - __padding_right = 'padding_right', - __padding_top = 'padding_top', - __padding_bottom = 'padding_bottom', - __zoom_enabled = 'zoom_enabled', - __zoom_extent = 'zoom_extent', - __zoom_privileged = 'zoom_privileged', - __zoom_onzoom = 'zoom_onzoom', - __interaction_enabled = 'interaction_enabled', - __onmouseover = 'onmouseover', - __onmouseout = 'onmouseout', - __onresize = 'onresize', - __onresized = 'onresized', - __transition_duration = 'transition_duration', - __data_x = 'data_x', - __data_xs = 'data_xs', - __data_x_format = 'data_x_format', - __data_x_localtime = 'data_x_localtime', - __data_id_converter = 'data_id_converter', - __data_names = 'data_names', - __data_classes = 'data_classes', - __data_groups = 'data_groups', - __data_axes = 'data_axes', - __data_type = 'data_type', - __data_types = 'data_types', - __data_labels = 'data_labels', - __data_order = 'data_order', - __data_regions = 'data_regions', - __data_color = 'data_color', - __data_colors = 'data_colors', - __data_hide = 'data_hide', - __data_filter = 'data_filter', - __data_selection_enabled = 'data_selection_enabled', - __data_selection_grouped = 'data_selection_grouped', - __data_selection_isselectable = 'data_selection_isselectable', - __data_selection_multiple = 'data_selection_multiple', - __data_onclick = 'data_onclick', - __data_onmouseover = 'data_onmouseover', - __data_onmouseout = 'data_onmouseout', - __data_onselected = 'data_onselected', - __data_onunselected = 'data_onunselected', - __data_ondragstart = 'data_ondragstart', - __data_ondragend = 'data_ondragend', - __data_url = 'data_url', - __data_json = 'data_json', - __data_rows = 'data_rows', - __data_columns = 'data_columns', - __data_mimeType = 'data_mimeType', - __data_keys = 'data_keys', - __data_empty_label_text = 'data_empty_label_text', - __subchart_show = 'subchart_show', - __subchart_size_height = 'subchart_size_height', - __subchart_onbrush = 'subchart_onbrush', - __color_pattern = 'color_pattern', - __color_threshold = 'color_threshold', - __legend_show = 'legend_show', - __legend_position = 'legend_position', - __legend_inset_anchor = 'legend_inset_anchor', - __legend_inset_x = 'legend_inset_x', - __legend_inset_y = 'legend_inset_y', - __legend_inset_step = 'legend_inset_step', - __legend_item_onclick = 'legend_item_onclick', - __legend_item_onmouseover = 'legend_item_onmouseover', - __legend_item_onmouseout = 'legend_item_onmouseout', - __legend_equally = 'legend_equally', - __axis_rotated = 'axis_rotated', - __axis_x_show = 'axis_x_show', - __axis_x_type = 'axis_x_type', - __axis_x_localtime = 'axis_x_localtime', - __axis_x_categories = 'axis_x_categories', - __axis_x_tick_centered = 'axis_x_tick_centered', - __axis_x_tick_format = 'axis_x_tick_format', - __axis_x_tick_culling = 'axis_x_tick_culling', - __axis_x_tick_culling_max = 'axis_x_tick_culling_max', - __axis_x_tick_count = 'axis_x_tick_count', - __axis_x_tick_fit = 'axis_x_tick_fit', - __axis_x_tick_values = 'axis_x_tick_values', - __axis_x_tick_rotate = 'axis_x_tick_rotate', - __axis_x_tick_outer = 'axis_x_tick_outer', - __axis_x_max = 'axis_x_max', - __axis_x_min = 'axis_x_min', - __axis_x_padding = 'axis_x_padding', - __axis_x_height = 'axis_x_height', - __axis_x_default = 'axis_x_default', - __axis_x_label = 'axis_x_label', - __axis_y_show = 'axis_y_show', - __axis_y_max = 'axis_y_max', - __axis_y_min = 'axis_y_min', - __axis_y_center = 'axis_y_center', - __axis_y_label = 'axis_y_label', - __axis_y_tick_format = 'axis_y_tick_format', - __axis_y_tick_outer = 'axis_y_tick_outer', - __axis_y_padding = 'axis_y_padding', - __axis_y_ticks = 'axis_y_ticks', - __axis_y2_show = 'axis_y2_show', - __axis_y2_max = 'axis_y2_max', - __axis_y2_min = 'axis_y2_min', - __axis_y2_center = 'axis_y2_center', - __axis_y2_label = 'axis_y2_label', - __axis_y2_tick_format = 'axis_y2_tick_format', - __axis_y2_tick_outer = 'axis_y2_tick_outer', - __axis_y2_padding = 'axis_y2_padding', - __axis_y2_ticks = 'axis_y2_ticks', - __grid_x_show = 'grid_x_show', - __grid_x_type = 'grid_x_type', - __grid_x_lines = 'grid_x_lines', - __grid_y_show = 'grid_y_show', - __grid_y_lines = 'grid_y_lines', - __grid_y_ticks = 'grid_y_ticks', - __grid_focus_show = 'grid_focus_show', - __point_show = 'point_show', - __point_r = 'point_r', - __point_focus_expand_enabled = 'point_focus_expand_enabled', - __point_focus_expand_r = 'point_focus_expand_r', - __point_select_r = 'point_select_r', - __line_connect_null = 'line_connect_null', - __bar_width = 'bar_width', - __bar_width_ratio = 'bar_width_ratio', - __bar_width_max = 'bar_width_max', - __bar_zerobased = 'bar_zerobased', - __area_zerobased = 'area_zerobased', - __pie_label_show = 'pie_label_show', - __pie_label_format = 'pie_label_format', - __pie_label_threshold = 'pie_label_threshold', - __pie_sort = 'pie_sort', - __pie_expand = 'pie_expand', - __gauge_label_show = 'gauge_label_show', - __gauge_label_format = 'gauge_label_format', - __gauge_expand = 'gauge_expand', - __gauge_min = 'gauge_min', - __gauge_max = 'gauge_max', - __gauge_units = 'gauge_units', - __gauge_width = 'gauge_width', - __donut_label_show = 'donut_label_show', - __donut_label_format = 'donut_label_format', - __donut_label_threshold = 'donut_label_threshold', - __donut_width = 'donut_width', - __donut_sort = 'donut_sort', - __donut_expand = 'donut_expand', - __donut_title = 'donut_title', - __regions = 'regions', - __tooltip_show = 'tooltip_show', - __tooltip_grouped = 'tooltip_grouped', - __tooltip_format_title = 'tooltip_format_title', - __tooltip_format_name = 'tooltip_format_name', - __tooltip_format_value = 'tooltip_format_value', - __tooltip_contents = 'tooltip_contents', - __tooltip_init_show = 'tooltip_init_show', - __tooltip_init_x = 'tooltip_init_x', - __tooltip_init_position = 'tooltip_init_position'; + c3_chart_internal_fn.init = function () { + var $$ = this, config = $$.config; - var config = c3_chart_internal_fn.config = {}; - config[__bindto] = '#chart'; - config[__size_width] = undefined; - config[__size_height] = undefined; + $$.initParams(); - config[__padding_left] = undefined; - config[__padding_right] = undefined; - config[__padding_top] = undefined; - config[__padding_bottom] = undefined; + if (config[__data_url]) { + $$.convertUrlToData(config[__data_url], config[__data_mimeType], 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.'); + } + }; - config[__zoom_enabled] = false; - config[__zoom_extent] = undefined; - config[__zoom_privileged] = false; - config[__zoom_onzoom] = function () {}; + c3_chart_internal_fn.initParams = function () { + var $$ = this, d3 = $$.d3; - config[__interaction_enabled] = true; + // MEMO: clipId needs to be unique because it conflicts when multiple charts exist + $$.clipId = "c3-" + (+new Date()) + '-clip', + $$.clipIdForXAxis = $$.clipId + '-xaxis', + $$.clipIdForYAxis = $$.clipId + '-yaxis', + $$.clipPath = $$.getClipPath($$.clipId), + $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), + $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - config[__onmouseover] = function () {}; - config[__onmouseout] = function () {}; - config[__onresize] = function () {}; - config[__onresized] = function () {}; + $$.dragStart = null; + $$.dragging = false; + $$.cancelClick = false; + $$.mouseover = false; + $$.transiting = false; - config[__transition_duration] = 350; + $$.color = $$.generateColor(); + $$.levelColor = $$.generateLevelColor(); - config[__data_x] = undefined; - config[__data_xs] = {}; - config[__data_x_format] = '%Y-%m-%d'; - config[__data_x_localtime] = true; - config[__data_id_converter] = function (id) { return id; }; - config[__data_names] = {}; - config[__data_classes] = {}; - config[__data_groups] = []; - config[__data_axes] = {}; - config[__data_type] = undefined; - config[__data_types] = {}; - config[__data_labels] = {}; - config[__data_order] = 'desc'; - config[__data_regions] = {}; - config[__data_color] = undefined; - config[__data_colors] = {}; - config[__data_hide] = false; - config[__data_filter] = undefined; - config[__data_selection_enabled] = false; - config[__data_selection_grouped] = false; - config[__data_selection_isselectable] = function () { return true; }; - config[__data_selection_multiple] = true; - config[__data_onclick] = function () {}; - config[__data_onmouseover] = function () {}; - config[__data_onmouseout] = function () {}; - config[__data_onselected] = function () {}; - config[__data_onunselected] = function () {}; - config[__data_ondragstart] = function () {}; - config[__data_ondragend] = function () {}; - config[__data_url] = undefined; - config[__data_json] = undefined; - config[__data_rows] = undefined; - config[__data_columns] = undefined; - config[__data_mimeType] = undefined; - config[__data_keys] = undefined; - - // configuration for no plot-able data supplied. - config[__data_empty_label_text] = ""; - - // subchart - config[__subchart_show] = false; - config[__subchart_size_height] = 60; - config[__subchart_onbrush] = function () {}; - - // color - config[__color_pattern] = []; - config[__color_threshold] = {}; - - // legend - config[__legend_show] = true; - config[__legend_position] = 'bottom'; - config[__legend_inset_anchor] = 'top-left'; - config[__legend_inset_x] = 10; - config[__legend_inset_y] = 0; - config[__legend_inset_step] = undefined; - config[__legend_item_onclick] = undefined; - config[__legend_item_onmouseover] = undefined; - config[__legend_item_onmouseout] = undefined; - config[__legend_equally] = false; - - // axis - config[__axis_rotated] = false; - config[__axis_x_show] = true; - config[__axis_x_type] = 'indexed'; - config[__axis_x_localtime] = true; - config[__axis_x_categories] = []; - config[__axis_x_tick_centered] = false; - config[__axis_x_tick_format] = undefined; - config[__axis_x_tick_culling] = {}; - config[__axis_x_tick_culling_max] = 10; - config[__axis_x_tick_count] = undefined; - config[__axis_x_tick_fit] = true; - config[__axis_x_tick_values] = null; - config[__axis_x_tick_rotate] = undefined; - config[__axis_x_tick_outer] = true; - config[__axis_x_max] = null; - config[__axis_x_min] = null; - config[__axis_x_padding] = {}; - config[__axis_x_height] = undefined; - config[__axis_x_default] = undefined; - config[__axis_x_label] = {}; - config[__axis_y_show] = true; - config[__axis_y_max] = undefined; - config[__axis_y_min] = undefined; - config[__axis_y_center] = undefined; - config[__axis_y_label] = {}; - config[__axis_y_tick_format] = undefined; - config[__axis_y_tick_outer] = true; - config[__axis_y_padding] = undefined; - config[__axis_y_ticks] = 10; - config[__axis_y2_show] = false; - config[__axis_y2_max] = undefined; - config[__axis_y2_min] = undefined; - config[__axis_y2_center] = undefined; - config[__axis_y2_label] = {}; - config[__axis_y2_tick_format] = undefined; - config[__axis_y2_tick_outer] = true; - config[__axis_y2_padding] = undefined; - config[__axis_y2_ticks] = 10; - - // grid - config[__grid_x_show] = false; - config[__grid_x_type] = 'tick'; - config[__grid_x_lines] = []; - config[__grid_y_show] = false; - // not used - // grid_y_type: {}, 'tick'), - config[__grid_y_lines] = []; - config[__grid_y_ticks] = 10; - config[__grid_focus_show] = true; - - // point - point of each data - config[__point_show] = true; - config[__point_r] = 2.5; - config[__point_focus_expand_enabled] = true; - config[__point_focus_expand_r] = undefined; - config[__point_select_r] = undefined; - - config[__line_connect_null] = false; - - // bar - config[__bar_width] = undefined; - config[__bar_width_ratio] = 0.6; - config[__bar_width_max] = undefined; - config[__bar_zerobased] = true; - - // area - config[__area_zerobased] = true; - - // pie - config[__pie_label_show] = true; - config[__pie_label_format] = undefined; - config[__pie_label_threshold] = 0.05; - config[__pie_sort] = true; - config[__pie_expand] = true; - - // gauge - config[__gauge_label_show] = true; - config[__gauge_label_format] = undefined; - config[__gauge_expand] = true; - config[__gauge_min] = 0; - config[__gauge_max] = 100; - config[__gauge_units] = undefined; - config[__gauge_width] = undefined; - - // donut - config[__donut_label_show] = true; - config[__donut_label_format] = undefined; - config[__donut_label_threshold] = 0.05; - config[__donut_width] = undefined; - config[__donut_sort] = true; - config[__donut_expand] = true; - config[__donut_title] = ""; - - // region - region to change style - config[__regions] = []; - - // tooltip - show when mouseover on each data - config[__tooltip_show] = true; - config[__tooltip_grouped] = true; - config[__tooltip_format_title] = undefined; - config[__tooltip_format_name] = undefined; - config[__tooltip_format_value] = undefined; - config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { - return this.getTooltipContent ? this.getTooltipContent(d, defaultValueFormat, defaultValueFormat, color) : ''; - }, - config[__tooltip_init_show] = false; - config[__tooltip_init_x] = 0; - config[__tooltip_init_position] = {top: '0px', left: '50px'}; - - c3_chart_internal_fn.loadConfig = function (config) { - var this_config = this.config, target, keys, read; - function find() { - var key = keys.shift(); -// console.log("key =>", key, ", target =>", target); - if (key && target && key in target) { - target = target[key]; - return find(); - } - else if (!key) { - return target; - } - else { - return undefined; - } - } - Object.keys(this_config).forEach(function (key) { - target = config; - keys = key.split('_'); - read = find(); -// console.log("CONFIG : ", key, read); - if (isDefined(read)) { - this_config[key] = read; - } - }); - }; - - - c3_chart_internal_fn.init = function () { - var $$ = this, config = $$.config; - - $$.initParams(); - - if (config[__data_url]) { - $$.convertUrlToData(config[__data_url], config[__data_mimeType], 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 = $$.d3; - - // MEMO: clipId needs to be unique because it conflicts when multiple charts exist - $$.clipId = "c3-" + (+new Date()) + '-clip', - $$.clipIdForXAxis = $$.clipId + '-xaxis', - $$.clipIdForYAxis = $$.clipId + '-yaxis', - $$.clipPath = $$.getClipPath($$.clipId), - $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), - $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); - - $$.dragStart = null; - $$.dragging = false; - $$.cancelClick = false; - $$.mouseover = false; - $$.transiting = false; - - $$.color = $$.generateColor(); - $$.levelColor = $$.generateLevelColor(); - - $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; - $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.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; }] - ]); + $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.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 = []; @@ -601,7 +222,7 @@ if (config[__grid_focus_show]) { $$.grid.append('g') .attr("class", CLASS[_xgridFocus]) - .append('line') + .append('line') .attr('class', CLASS[_xgridFocus]); } @@ -713,7 +334,6 @@ $$.api.element = $$.selectChart.node(); }; - c3_chart_internal_fn.smoothLines = function (el, type) { var $$ = this; if (type === 'grid') { @@ -1259,47 +879,47 @@ cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); transitions.push(mainBar.transition() - .attr('d', drawBar) - .style("fill", $$.color) - .style("opacity", 1)); + .attr('d', drawBar) + .style("fill", $$.color) + .style("opacity", 1)); transitions.push(mainLine.transition() - .attr("d", drawLine) - .style("stroke", $$.color) - .style("opacity", 1)); + .attr("d", drawLine) + .style("stroke", $$.color) + .style("opacity", 1)); transitions.push(mainArea.transition() - .attr("d", drawArea) - .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity)); + .attr("d", drawArea) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity)); transitions.push(mainCircle.transition() - .style('opacity', generateCall($$.opacityForCircle, $$)) - .style("fill", $$.color) - .attr("cx", cx) - .attr("cy", cy)); + .style('opacity', generateCall($$.opacityForCircle, $$)) + .style("fill", $$.color) + .attr("cx", cx) + .attr("cy", cy)); transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() - .attr("cx", cx) - .attr("cy", cy)); + .attr("cx", cx) + .attr("cy", cy)); transitions.push(mainText.transition() - .attr('x', xForText) - .attr('y', yForText) - .style("fill", $$.color) - .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); + .attr('x', xForText) + .attr('y', yForText) + .style("fill", $$.color) + .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); transitions.push(mainRegion.selectAll('rect').transition() - .attr("x", $$.regionX) - .attr("y", $$.regionY) - .attr("width", $$.regionWidth) - .attr("height", $$.regionHeight) - .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + .attr("x", $$.regionX) + .attr("y", $$.regionY) + .attr("width", $$.regionWidth) + .attr("height", $$.regionHeight) + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() - .attr("x1", config[__axis_rotated] ? 0 : xv_) - .attr("x2", config[__axis_rotated] ? $$.width : xv_) - .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) - .attr("y2", config[__axis_rotated] ? xv_ : $$.height) - .style("opacity", 1)); + .attr("x1", config[__axis_rotated] ? 0 : xv_) + .attr("x2", config[__axis_rotated] ? $$.width : xv_) + .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv_ : $$.height) + .style("opacity", 1)); transitions.push(xgridLines.select('text').transition() - .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv_) - .text(function (d) { return d.text; }) - .style("opacity", 1)); + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv_) + .text(function (d) { return d.text; }) + .style("opacity", 1)); // Wait for end of transitions if called from flow API if (options.flow) { waitForDraw = $$.generateWait(); @@ -1434,6 +1054,7 @@ if (isFunction($$.updateZoom)) { $$.updateZoom(); } }; + c3_chart_internal_fn.updateAndRedraw = function (options) { var $$ = this, config = $$.config, transitions; options = options || {}; @@ -1674,9 +1295,6 @@ .on("dblclick.zoom", null); }; - - - c3_chart_internal_fn.isTimeSeries = function () { return this.config[__axis_x_type] === 'timeseries'; }; @@ -1743,8 +1361,6 @@ return d ? this.subX(d.x) : null; }; - - c3_chart_internal_fn.transformMain = function (withTransition, transitions) { var $$ = this, xAxis, yAxis, y2Axis; @@ -1779,7 +1395,6 @@ if ($$.legend) { $$.transformLegend(withTransition); } }; - c3_chart_internal_fn.updateSvgSize = function () { var $$ = this; $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); @@ -1861,647 +1476,712 @@ return callResizeFunctions; }; + c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { + var $$ = this, + withTransitionForAxis = !$$.hasArcType(), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); + }; - - c3_chart_internal_fn.getCurrentWidth = function () { - var $$ = this, config = $$.config; - return config[__size_width] ? config[__size_width] : $$.getParentWidth(); + c3_chart_internal_fn.generateAxisTransitions = function (duration) { + var $$ = this, 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 + }; }; - c3_chart_internal_fn.getCurrentHeight = function () { - var $$ = this, config = $$.config, - h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); - return h > 0 ? h : 320; + c3_chart_internal_fn.endall = function (transition, callback) { + var n = 0; + transition + .each(function () { ++n; }) + .each("end", function () { + if (!--n) { callback.apply(this, arguments); } + }); }; - c3_chart_internal_fn.getCurrentPaddingTop = function () { - var config = this.config; - return isValue(config[__padding_top]) ? config[__padding_top] : 0; - }; - c3_chart_internal_fn.getCurrentPaddingBottom = function () { - var config = this.config; - return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; - }; - c3_chart_internal_fn.getCurrentPaddingLeft = function () { - var $$ = this, config = $$.config; - if (isValue(config[__padding_left])) { - return config[__padding_left]; - } else if (config[__axis_rotated]) { - return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); - } else { - return !config[__axis_y_show] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); - } + c3_chart_internal_fn.generateWait = function () { + var transitionsToWait = [], + f = function (transition, callback) { + var timer = setInterval(function () { + var done = 0; + transitionsToWait.forEach(function (t) { + if (t.empty()) { + done += 1; + return; + } + try { + t.transition(); + } catch (e) { + done += 1; + } + }); + if (done === transitionsToWait.length) { + clearInterval(timer); + if (callback) { callback(); } + } + }, 10); + }; + f.add = function (transition) { + transitionsToWait.push(transition); + }; + return f; }; - c3_chart_internal_fn.getCurrentPaddingRight = function () { - var $$ = this, config = $$.config, - defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; - if (isValue(config[__padding_right])) { - return config[__padding_right] + 1; // 1 is needed not to hide tick line - } else if (config[__axis_rotated]) { - return defaultPadding + legendWidthOnRight; + + c3_chart_internal_fn.parseDate = function (date) { + var $$ = this, parsedDate; + if (date instanceof Date) { + parsedDate = date; + } else if (typeof date === 'number') { + parsedDate = new Date(date); } else { - return (!config[__axis_y2_show] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); } - }; - - c3_chart_internal_fn.getParentRectValue = function (key) { - var parent = this.selectChart.node(), v; - while (parent && parent.tagName !== 'BODY') { - v = parent.getBoundingClientRect()[key]; - if (v) { - break; - } - parent = parent.parentNode; + if (!parsedDate || isNaN(+parsedDate)) { + window.console.error("Failed to parse x '" + date + "' to Date object"); } - return v; - }; - c3_chart_internal_fn.getParentWidth = function () { - return this.getParentRectValue('width'); - }; - c3_chart_internal_fn.getParentHeight = function () { - var h = this.selectChart.style('height'); - return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; - }; - - - c3_chart_internal_fn.getSvgLeft = function () { - var $$ = this, config = $$.config, - leftAxisClass = config[__axis_rotated] ? CLASS[_axisX] : CLASS[_axisY], - leftAxis = $$.main.select('.' + leftAxisClass).node(), - svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, - chartRect = $$.selectChart.node().getBoundingClientRect(), - hasArc = $$.hasArcType(), - svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); - return svgLeft > 0 ? svgLeft : 0; + return parsedDate; }; + var __bindto = 'bindto', + __size_width = 'size_width', + __size_height = 'size_height', + __padding_left = 'padding_left', + __padding_right = 'padding_right', + __padding_top = 'padding_top', + __padding_bottom = 'padding_bottom', + __zoom_enabled = 'zoom_enabled', + __zoom_extent = 'zoom_extent', + __zoom_privileged = 'zoom_privileged', + __zoom_onzoom = 'zoom_onzoom', + __interaction_enabled = 'interaction_enabled', + __onmouseover = 'onmouseover', + __onmouseout = 'onmouseout', + __onresize = 'onresize', + __onresized = 'onresized', + __transition_duration = 'transition_duration', + __data_x = 'data_x', + __data_xs = 'data_xs', + __data_x_format = 'data_x_format', + __data_x_localtime = 'data_x_localtime', + __data_id_converter = 'data_id_converter', + __data_names = 'data_names', + __data_classes = 'data_classes', + __data_groups = 'data_groups', + __data_axes = 'data_axes', + __data_type = 'data_type', + __data_types = 'data_types', + __data_labels = 'data_labels', + __data_order = 'data_order', + __data_regions = 'data_regions', + __data_color = 'data_color', + __data_colors = 'data_colors', + __data_hide = 'data_hide', + __data_filter = 'data_filter', + __data_selection_enabled = 'data_selection_enabled', + __data_selection_grouped = 'data_selection_grouped', + __data_selection_isselectable = 'data_selection_isselectable', + __data_selection_multiple = 'data_selection_multiple', + __data_onclick = 'data_onclick', + __data_onmouseover = 'data_onmouseover', + __data_onmouseout = 'data_onmouseout', + __data_onselected = 'data_onselected', + __data_onunselected = 'data_onunselected', + __data_ondragstart = 'data_ondragstart', + __data_ondragend = 'data_ondragend', + __data_url = 'data_url', + __data_json = 'data_json', + __data_rows = 'data_rows', + __data_columns = 'data_columns', + __data_mimeType = 'data_mimeType', + __data_keys = 'data_keys', + __data_empty_label_text = 'data_empty_label_text', + __subchart_show = 'subchart_show', + __subchart_size_height = 'subchart_size_height', + __subchart_onbrush = 'subchart_onbrush', + __color_pattern = 'color_pattern', + __color_threshold = 'color_threshold', + __legend_show = 'legend_show', + __legend_position = 'legend_position', + __legend_inset_anchor = 'legend_inset_anchor', + __legend_inset_x = 'legend_inset_x', + __legend_inset_y = 'legend_inset_y', + __legend_inset_step = 'legend_inset_step', + __legend_item_onclick = 'legend_item_onclick', + __legend_item_onmouseover = 'legend_item_onmouseover', + __legend_item_onmouseout = 'legend_item_onmouseout', + __legend_equally = 'legend_equally', + __axis_rotated = 'axis_rotated', + __axis_x_show = 'axis_x_show', + __axis_x_type = 'axis_x_type', + __axis_x_localtime = 'axis_x_localtime', + __axis_x_categories = 'axis_x_categories', + __axis_x_tick_centered = 'axis_x_tick_centered', + __axis_x_tick_format = 'axis_x_tick_format', + __axis_x_tick_culling = 'axis_x_tick_culling', + __axis_x_tick_culling_max = 'axis_x_tick_culling_max', + __axis_x_tick_count = 'axis_x_tick_count', + __axis_x_tick_fit = 'axis_x_tick_fit', + __axis_x_tick_values = 'axis_x_tick_values', + __axis_x_tick_rotate = 'axis_x_tick_rotate', + __axis_x_tick_outer = 'axis_x_tick_outer', + __axis_x_max = 'axis_x_max', + __axis_x_min = 'axis_x_min', + __axis_x_padding = 'axis_x_padding', + __axis_x_height = 'axis_x_height', + __axis_x_default = 'axis_x_default', + __axis_x_label = 'axis_x_label', + __axis_y_show = 'axis_y_show', + __axis_y_max = 'axis_y_max', + __axis_y_min = 'axis_y_min', + __axis_y_center = 'axis_y_center', + __axis_y_label = 'axis_y_label', + __axis_y_tick_format = 'axis_y_tick_format', + __axis_y_tick_outer = 'axis_y_tick_outer', + __axis_y_padding = 'axis_y_padding', + __axis_y_ticks = 'axis_y_ticks', + __axis_y2_show = 'axis_y2_show', + __axis_y2_max = 'axis_y2_max', + __axis_y2_min = 'axis_y2_min', + __axis_y2_center = 'axis_y2_center', + __axis_y2_label = 'axis_y2_label', + __axis_y2_tick_format = 'axis_y2_tick_format', + __axis_y2_tick_outer = 'axis_y2_tick_outer', + __axis_y2_padding = 'axis_y2_padding', + __axis_y2_ticks = 'axis_y2_ticks', + __grid_x_show = 'grid_x_show', + __grid_x_type = 'grid_x_type', + __grid_x_lines = 'grid_x_lines', + __grid_y_show = 'grid_y_show', + __grid_y_lines = 'grid_y_lines', + __grid_y_ticks = 'grid_y_ticks', + __grid_focus_show = 'grid_focus_show', + __point_show = 'point_show', + __point_r = 'point_r', + __point_focus_expand_enabled = 'point_focus_expand_enabled', + __point_focus_expand_r = 'point_focus_expand_r', + __point_select_r = 'point_select_r', + __line_connect_null = 'line_connect_null', + __bar_width = 'bar_width', + __bar_width_ratio = 'bar_width_ratio', + __bar_width_max = 'bar_width_max', + __bar_zerobased = 'bar_zerobased', + __area_zerobased = 'area_zerobased', + __pie_label_show = 'pie_label_show', + __pie_label_format = 'pie_label_format', + __pie_label_threshold = 'pie_label_threshold', + __pie_sort = 'pie_sort', + __pie_expand = 'pie_expand', + __gauge_label_show = 'gauge_label_show', + __gauge_label_format = 'gauge_label_format', + __gauge_expand = 'gauge_expand', + __gauge_min = 'gauge_min', + __gauge_max = 'gauge_max', + __gauge_units = 'gauge_units', + __gauge_width = 'gauge_width', + __donut_label_show = 'donut_label_show', + __donut_label_format = 'donut_label_format', + __donut_label_threshold = 'donut_label_threshold', + __donut_width = 'donut_width', + __donut_sort = 'donut_sort', + __donut_expand = 'donut_expand', + __donut_title = 'donut_title', + __regions = 'regions', + __tooltip_show = 'tooltip_show', + __tooltip_grouped = 'tooltip_grouped', + __tooltip_format_title = 'tooltip_format_title', + __tooltip_format_name = 'tooltip_format_name', + __tooltip_format_value = 'tooltip_format_value', + __tooltip_contents = 'tooltip_contents', + __tooltip_init_show = 'tooltip_init_show', + __tooltip_init_x = 'tooltip_init_x', + __tooltip_init_position = 'tooltip_init_position'; - c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { - var $$ = this, position = $$.getAxisLabelPositionById(id); - return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); - }; - c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { - var $$ = this, config = $$.config; - if (axisId === 'x' && !config[__axis_x_show]) { return 0; } - if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } - if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } - if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } - return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); - }; - - c3_chart_internal_fn.getEventRectWidth = function () { - var $$ = this; - var target = $$.getMaxDataCountTarget($$.data.targets), - firstData, lastData, base, maxDataCount, ratio, w; - if (!target) { - return 0; - } - firstData = target.values[0], lastData = target.values[target.values.length - 1]; - base = $$.x(lastData.x) - $$.x(firstData.x); - if (base === 0) { - return $$.config[__axis_rotated] ? $$.height : $$.width; - } - maxDataCount = $$.getMaxDataCount(); - ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized() ? 0.25 : 1)) / maxDataCount : 1); - w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; - return w < 1 ? 1 : w; - }; - - - /** - * c3.legend.js - */ - c3_chart_internal_fn.initLegend = function () { - var $$ = this; - $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); - if (!config[__legend_show]) { - $$.legend.style('visibility', 'hidden'); - $$.hiddenLegendIds = $$.mapToIds($$.data.targets); - } - // MEMO: call here to update legend box and tranlate for all - // MEMO: translate will be upated by this, so transform not needed in updateLegend() - $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); - }; - c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { - var $$ = this, insetLegendPosition = { - 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 - }; - $$.margin3 = { - top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, - right: NaN, - bottom: 0, - left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 - }; - }; - c3_chart_internal_fn.transformLegend = function (withTransition) { - var $$ = this; - (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); - }; - c3_chart_internal_fn.updateLegendStep = function (step) { - this.legendStep = step; - }; - c3_chart_internal_fn.updateLegendItemWidth = function (w) { - this.legendItemWidth = w; - }; - c3_chart_internal_fn.updateLegendItemHeight = function (h) { - this.legendItemHeight = h; - }; - c3_chart_internal_fn.getLegendWidth = function () { - var $$ = this; - return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; - }; - c3_chart_internal_fn.getLegendHeight = function () { - var $$ = this, config = $$.config, h = 0; - if (config[__legend_show]) { - if ($$.isLegendRight) { - h = $$.currentHeight; - } else if ($$.isLegendInset) { - h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; - } else { - h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); - } - } - return h; - }; - c3_chart_internal_fn.opacityForLegend = function (legendItem) { - var $$ = this; - return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 1; - }; - c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { - var $$ = this; - return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; - }; - c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { - var $$ = this; - $$.legend.selectAll('.' + CLASS[_legendItem]) - .transition().duration(100) - .style('opacity', function (_id) { - var This = $$.d3.select(this); - if (id && _id !== id) { - return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); - } else { - return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); - } - }); - }; - c3_chart_internal_fn.revertLegend = function () { - var $$ = this, d3 = $$.d3; - $$.legend.selectAll('.' + CLASS[_legendItem]) - .transition().duration(100) - .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); - }; - c3_chart_internal_fn.showLegend = function (targetIds) { - var $$ = this, config = $$.config; - if (!config[__legend_show]) { - config[__legend_show] = true; - $$.legend.style('visibility', 'visible'); - } - $$.removeHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) - .style('visibility', 'visible') - .transition() - .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); - }; - c3_chart_internal_fn.hideLegend = function (targetIds) { - var $$ = this, config = $$.config; - if (config[__legend_show] && isEmpty(targetIds)) { - config[__legend_show] = false; - $$.legend.style('visibility', 'hidden'); - } - $$.addHiddenLegendIds(targetIds); - $$.legend.selectAll($$.selectorLegends(targetIds)) - .style('opacity', 0) - .style('visibility', 'hidden'); - }; - c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { - var $$ = this, config = $$.config; - var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; - var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; - var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; - var withTransition, withTransitionForTransform; - var hasFocused = $$.legend.selectAll('.' + CLASS[_legendItemFocused]).size(); - var texts, rects, tiles; - - options = options || {}; - withTransition = getOption(options, "withTransition", true); - withTransitionForTransform = getOption(options, "withTransitionForTransform", true); - - function updatePositions(textElement, id, reset) { - var box = $$.getTextRect(textElement.textContent, CLASS[_legendItem]), - itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, - itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, - itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, - areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), - margin, maxLength; - - // MEMO: care about condifion of step, totalLength - function updateValues(id, withoutStep) { - if (!withoutStep) { - margin = (areaLength - totalLength - itemLength) / 2; - if (margin < posMin) { - margin = (areaLength - itemLength) / 2; - totalLength = 0; - step++; - } - } - steps[id] = step; - margins[step] = $$.isLegendInset ? 10 : margin; - offsets[id] = totalLength; - totalLength += itemLength; - } - - if (reset) { - totalLength = 0; - step = 0; - maxWidth = 0; - maxHeight = 0; - } - - if (config[__legend_show] && !$$.isLegendToShow(id)) { - widths[id] = heights[id] = steps[id] = offsets[id] = 0; - return; - } - - widths[id] = itemWidth; - heights[id] = itemHeight; - - if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } - if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } - maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; - - if (config[__legend_equally]) { - Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); - Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); - margin = (areaLength - maxLength * targetIds.length) / 2; - if (margin < posMin) { - totalLength = 0; - step = 0; - targetIds.forEach(function (id) { updateValues(id); }); - } - else { - updateValues(id, true); - } - } else { - updateValues(id); - } - } - - if ($$.isLegendRight) { - xForLegend = function (id) { return maxWidth * steps[id]; }; - yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else if ($$.isLegendInset) { - xForLegend = function (id) { return maxWidth * steps[id] + 10; }; - yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - } else { - xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; - yForLegend = function (id) { return maxHeight * steps[id]; }; - } - xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; - yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; - xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; - yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; - - // Define g for legend area - l = $$.legend.selectAll('.' + CLASS[_legendItem]) - .data(targetIds) - .enter().append('g') - .attr('class', function (id) { return $$.generateClass(CLASS[_legendItem], id); }) - .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) - .style('cursor', 'pointer') - .on('click', function (id) { - isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); - }) - .on('mouseover', function (id) { - $$.d3.select(this).classed(CLASS[_legendItemFocused], true); - if (!$$.transiting) { - $$.api.focus(id); - } - if (isFunction(config[__legend_item_onmouseover])) { - config[__legend_item_onmouseover].call($$, id); - } - }) - .on('mouseout', function (id) { - $$.d3.select(this).classed(CLASS[_legendItemFocused], false); - if (!$$.transiting) { - $$.api.revert(); - } - if (isFunction(config[__legend_item_onmouseout])) { - config[__legend_item_onmouseout].call($$, id); - } - }); - l.append('text') - .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) - .each(function (id, i) { updatePositions(this, id, i === 0); }) - .style("pointer-events", "none") - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); - l.append('rect') - .attr("class", CLASS[_legendItemEvent]) - .style('fill-opacity', 0) - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); - l.append('rect') - .attr("class", CLASS[_legendItemTile]) - .style("pointer-events", "none") - .style('fill', $$.color) - .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) - .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) - .attr('width', 10) - .attr('height', 10); - // Set background for inset legend - if ($$.isLegendInset && maxWidth !== 0) { - $$.legend.insert('g', '.' + CLASS[_legendItem]) - .attr("class", CLASS[_legendBackground]) - .append('rect') - .attr('height', $$.getLegendHeight() - 10) - .attr('width', maxWidth * (step + 1) + 10); - } - - texts = $$.legend.selectAll('text') - .data(targetIds) - .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) // MEMO: needed for update - .each(function (id, i) { updatePositions(this, id, i === 0); }); - (withTransition ? texts.transition() : texts) - .attr('x', xForLegendText) - .attr('y', yForLegendText); - - rects = $$.legend.selectAll('rect.' + CLASS[_legendItemEvent]) - .data(targetIds); - (withTransition ? rects.transition() : rects) - .attr('width', function (id) { return widths[id]; }) - .attr('height', function (id) { return heights[id]; }) - .attr('x', xForLegendRect) - .attr('y', yForLegendRect); - - tiles = $$.legend.selectAll('rect.' + CLASS[_legendItemTile]) - .data(targetIds); - (withTransition ? tiles.transition() : tiles) - .style('fill', $$.color) - .attr('x', xForLegend) - .attr('y', yForLegend); - - // toggle legend state - $$.legend.selectAll('.' + CLASS[_legendItem]) - .classed(CLASS[_legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) - .transition() - .style('opacity', function (id) { - var This = $$.d3.select(this); - if ($$.isTargetToShow(id)) { - return !hasFocused || This.classed(CLASS[_legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); - } else { - return $$.legendOpacityForHidden; - } - }); - - // Update all to reflect change of legend - $$.updateLegendItemWidth(maxWidth); - $$.updateLegendItemHeight(maxHeight); - $$.updateLegendStep(step); - // Update size and scale - $$.updateSizes(); - $$.updateScales(); - $$.updateSvgSize(); - // Update g positions - $$.transformAll(withTransitionForTransform, transitions); - }; - - - - /** - * c3.tooltip.js - */ - c3_chart_internal_fn.initTooltip = function () { - var $$ = this, config = $$.config, i; - $$.tooltip = $$.selectChart - .style("position", "relative") - .append("div") - .style("position", "absolute") - .style("pointer-events", "none") - .style("z-index", "10") - .style("display", "none"); - // Show tooltip if needed - if (config[__tooltip_init_show]) { - if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { - config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); - for (i = 0; i < $$.data.targets[0].values.length; i++) { - if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } - } - config[__tooltip_init_x] = i; - } - $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { - return $$.addName(d.values[config[__tooltip_init_x]]); - }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); - $$.tooltip.style("top", config[__tooltip_init_position].top) - .style("left", config[__tooltip_init_position].left) - .style("display", "block"); - } - }; - c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { - var $$ = this, config = $$.config, - titleFormat = config[__tooltip_format_title] || defaultTitleFormat, - nameFormat = config[__tooltip_format_name] || function (name) { return name; }, - valueFormat = config[__tooltip_format_value] || defaultValueFormat, - text, i, title, value, name, bgcolor; - for (i = 0; i < d.length; i++) { - if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } + var config = c3_chart_internal_fn.config = {}; + config[__bindto] = '#chart'; + config[__size_width] = undefined; + config[__size_height] = undefined; + config[__padding_left] = undefined; + config[__padding_right] = undefined; + config[__padding_top] = undefined; + config[__padding_bottom] = undefined; + config[__zoom_enabled] = false; + config[__zoom_extent] = undefined; + config[__zoom_privileged] = false; + config[__zoom_onzoom] = function () {}; + config[__interaction_enabled] = true; + config[__onmouseover] = function () {}; + config[__onmouseout] = function () {}; + config[__onresize] = function () {}; + config[__onresized] = function () {}; + config[__transition_duration] = 350; + config[__data_x] = undefined; + config[__data_xs] = {}; + config[__data_x_format] = '%Y-%m-%d'; + config[__data_x_localtime] = true; + config[__data_id_converter] = function (id) { return id; }; + config[__data_names] = {}; + config[__data_classes] = {}; + config[__data_groups] = []; + config[__data_axes] = {}; + config[__data_type] = undefined; + config[__data_types] = {}; + config[__data_labels] = {}; + config[__data_order] = 'desc'; + config[__data_regions] = {}; + config[__data_color] = undefined; + config[__data_colors] = {}; + config[__data_hide] = false; + config[__data_filter] = undefined; + config[__data_selection_enabled] = false; + config[__data_selection_grouped] = false; + config[__data_selection_isselectable] = function () { return true; }; + config[__data_selection_multiple] = true; + config[__data_onclick] = function () {}; + config[__data_onmouseover] = function () {}; + config[__data_onmouseout] = function () {}; + config[__data_onselected] = function () {}; + config[__data_onunselected] = function () {}; + config[__data_ondragstart] = function () {}; + config[__data_ondragend] = function () {}; + config[__data_url] = undefined; + config[__data_json] = undefined; + config[__data_rows] = undefined; + config[__data_columns] = undefined; + config[__data_mimeType] = undefined; + config[__data_keys] = undefined; + // configuration for no plot-able data supplied. + config[__data_empty_label_text] = ""; + // subchart + config[__subchart_show] = false; + config[__subchart_size_height] = 60; + config[__subchart_onbrush] = function () {}; + // color + config[__color_pattern] = []; + config[__color_threshold] = {}; + // legend + config[__legend_show] = true; + config[__legend_position] = 'bottom'; + config[__legend_inset_anchor] = 'top-left'; + config[__legend_inset_x] = 10; + config[__legend_inset_y] = 0; + config[__legend_inset_step] = undefined; + config[__legend_item_onclick] = undefined; + config[__legend_item_onmouseover] = undefined; + config[__legend_item_onmouseout] = undefined; + config[__legend_equally] = false; + // axis + config[__axis_rotated] = false; + config[__axis_x_show] = true; + config[__axis_x_type] = 'indexed'; + config[__axis_x_localtime] = true; + config[__axis_x_categories] = []; + config[__axis_x_tick_centered] = false; + config[__axis_x_tick_format] = undefined; + config[__axis_x_tick_culling] = {}; + config[__axis_x_tick_culling_max] = 10; + config[__axis_x_tick_count] = undefined; + config[__axis_x_tick_fit] = true; + config[__axis_x_tick_values] = null; + config[__axis_x_tick_rotate] = undefined; + config[__axis_x_tick_outer] = true; + config[__axis_x_max] = null; + config[__axis_x_min] = null; + config[__axis_x_padding] = {}; + config[__axis_x_height] = undefined; + config[__axis_x_default] = undefined; + config[__axis_x_label] = {}; + config[__axis_y_show] = true; + config[__axis_y_max] = undefined; + config[__axis_y_min] = undefined; + config[__axis_y_center] = undefined; + config[__axis_y_label] = {}; + config[__axis_y_tick_format] = undefined; + config[__axis_y_tick_outer] = true; + config[__axis_y_padding] = undefined; + config[__axis_y_ticks] = 10; + config[__axis_y2_show] = false; + config[__axis_y2_max] = undefined; + config[__axis_y2_min] = undefined; + config[__axis_y2_center] = undefined; + config[__axis_y2_label] = {}; + config[__axis_y2_tick_format] = undefined; + config[__axis_y2_tick_outer] = true; + config[__axis_y2_padding] = undefined; + config[__axis_y2_ticks] = 10; + // grid + config[__grid_x_show] = false; + config[__grid_x_type] = 'tick'; + config[__grid_x_lines] = []; + config[__grid_y_show] = false; + // not used + // grid_y_type: {}, 'tick'), + config[__grid_y_lines] = []; + config[__grid_y_ticks] = 10; + config[__grid_focus_show] = true; + // point - point of each data + config[__point_show] = true; + config[__point_r] = 2.5; + config[__point_focus_expand_enabled] = true; + config[__point_focus_expand_r] = undefined; + config[__point_select_r] = undefined; + config[__line_connect_null] = false; + // bar + config[__bar_width] = undefined; + config[__bar_width_ratio] = 0.6; + config[__bar_width_max] = undefined; + config[__bar_zerobased] = true; + // area + config[__area_zerobased] = true; + // pie + config[__pie_label_show] = true; + config[__pie_label_format] = undefined; + config[__pie_label_threshold] = 0.05; + config[__pie_sort] = true; + config[__pie_expand] = true; + // gauge + config[__gauge_label_show] = true; + config[__gauge_label_format] = undefined; + config[__gauge_expand] = true; + config[__gauge_min] = 0; + config[__gauge_max] = 100; + config[__gauge_units] = undefined; + config[__gauge_width] = undefined; + // donut + config[__donut_label_show] = true; + config[__donut_label_format] = undefined; + config[__donut_label_threshold] = 0.05; + config[__donut_width] = undefined; + config[__donut_sort] = true; + config[__donut_expand] = true; + config[__donut_title] = ""; + // region - region to change style + config[__regions] = []; + // tooltip - show when mouseover on each data + config[__tooltip_show] = true; + config[__tooltip_grouped] = true; + config[__tooltip_format_title] = undefined; + config[__tooltip_format_name] = undefined; + config[__tooltip_format_value] = undefined; + config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { + return this.getTooltipContent ? this.getTooltipContent(d, defaultValueFormat, defaultValueFormat, color) : ''; + }, + config[__tooltip_init_show] = false; + config[__tooltip_init_x] = 0; + config[__tooltip_init_position] = {top: '0px', left: '50px'}; - if (! text) { - title = titleFormat ? titleFormat(d[i].x) : d[i].x; - text = "" + (title || title === 0 ? "" : ""); + c3_chart_internal_fn.loadConfig = function (config) { + var this_config = this.config, target, keys, read; + function find() { + var key = keys.shift(); + // console.log("key =>", key, ", target =>", target); + if (key && target && key in target) { + target = target[key]; + return find(); + } + else if (!key) { + return target; + } + else { + return undefined; } - - name = nameFormat(d[i].name); - value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); - bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - - text += ""; - text += ""; - text += ""; - text += ""; } - return text + "
" + title + "
" + name + "" + value + "
"; + Object.keys(this_config).forEach(function (key) { + target = config; + keys = key.split('_'); + read = find(); + // console.log("CONFIG : ", key, read); + if (isDefined(read)) { + this_config[key] = read; + } + }); }; - c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { - var $$ = this, config = $$.config; - var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; - var forArc = $$.hasArcType(), - dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (dataToShow.length === 0 || !config[__tooltip_show]) { - return; - } - $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); - // Get tooltip dimensions - tWidth = $$.tooltip.property('offsetWidth'); - tHeight = $$.tooltip.property('offsetHeight'); - // Determin tooltip position - if (forArc) { - tooltipLeft = ($$.width / 2) + mouse[0]; - tooltipTop = ($$.height / 2) + mouse[1] + 20; + c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { + return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); + }; + c3_chart_internal_fn.getX = function (min, max, domain, offset) { + var $$ = this, + scale = $$.getScale(min, max, $$.isTimeSeries()), + _scale = domain ? scale.domain(domain) : scale, key; + // Define customized scale if categorized axis + if ($$.isCategorized()) { + offset = offset || function () { return 0; }; + scale = function (d, raw) { + var v = _scale(d) + offset(d); + return raw ? v : Math.ceil(v); + }; } else { - if (config[__axis_rotated]) { - svgLeft = $$.getSvgLeft(); - tooltipLeft = svgLeft + mouse[0] + 100; - tooltipRight = tooltipLeft + tWidth; - chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); - tooltipTop = $$.x(dataToShow[0].x) + 20; - } else { - svgLeft = $$.getSvgLeft(); - tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; - tooltipRight = tooltipLeft + tWidth; - chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); - tooltipTop = mouse[1] + 15; - } - - if (tooltipRight > chartRight) { - tooltipLeft -= tooltipRight - chartRight; - } - if (tooltipTop + tHeight > $$.getCurrentHeight()) { - tooltipTop -= tHeight + 30; - } + scale = function (d, raw) { + var v = _scale(d); + return raw ? v : Math.ceil(v); + }; } - // Set tooltip - $$.tooltip - .style("top", tooltipTop + "px") - .style("left", tooltipLeft + 'px'); + // define functions + for (key in _scale) { + scale[key] = _scale[key]; + } + scale.orgDomain = function () { + return _scale.domain(); + }; + // define custom domain() for categorized axis + if ($$.isCategorized()) { + scale.domain = function (domain) { + if (!arguments.length) { + domain = this.orgDomain(); + return [domain[0], domain[1] + 1]; + } + _scale.domain(domain); + return scale; + }; + } + return scale; }; - c3_chart_internal_fn.hideTooltip = function () { - this.tooltip.style("display", "none"); + c3_chart_internal_fn.getY = function (min, max, domain) { + var scale = this.getScale(min, max); + if (domain) { scale.domain(domain); } + return scale; }; - - - - /** - * c3.grid.js - */ - c3_chart_internal_fn.showXGridFocus = function (selectedData) { - var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); - if (! config[__tooltip_show]) { return; } - // Hide when scatter plot exists - if ($$.hasType('scatter') || $$.hasArcType()) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); - focusEl - .style("visibility", "visible") - .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); - $$.smoothLines(focusEl, 'grid'); + c3_chart_internal_fn.getYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.y2 : this.y; }; - c3_chart_internal_fn.hideXGridFocus = function () { - this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); + c3_chart_internal_fn.getSubYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; }; - c3_chart_internal_fn.updateXgridFocus = function () { - var $$ = this, config = $$.config; - $$.main.select('line.' + CLASS[_xgridFocus]) - .attr("x1", config[__axis_rotated] ? 0 : -10) - .attr("x2", config[__axis_rotated] ? $$.width : -10) - .attr("y1", config[__axis_rotated] ? -10 : 0) - .attr("y2", config[__axis_rotated] ? -10 : $$.height); + c3_chart_internal_fn.updateScales = function () { + var $$ = this, config = $$.config, + forInit = !$$.x; + // update edges + $$.xMin = config[__axis_rotated] ? 1 : 0; + $$.xMax = config[__axis_rotated] ? $$.height : $$.width; + $$.yMin = config[__axis_rotated] ? 0 : $$.height; + $$.yMax = config[__axis_rotated] ? $$.width : 1; + $$.subXMin = $$.xMin; + $$.subXMax = $$.xMax; + $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; + $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; + // update scales + $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); + $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); + $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); + $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); + $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); + $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); + // update axes + $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); + // Set initialized scales to brush and zoom + if (!forInit) { + if ($$.brush) { $$.brush.scale($$.subX); } + if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } + } + // update for arc + if (isFunction($$.updateArc)) { + $$.updateArc(); + } }; - c3_chart_internal_fn.generateGridData = function (type, scale) { - var $$ = this, - gridData = [], xDomain, firstYear, lastYear, i, - tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); - if (type === 'year') { - xDomain = $$.getXDomain(); - firstYear = xDomain[0].getFullYear(); - lastYear = xDomain[1].getFullYear(); - for (i = firstYear; i <= lastYear; i++) { - gridData.push(new Date(i + '-01-01 00:00:00')); + + c3_chart_internal_fn.getYDomainMin = function (targets) { + var $$ = this, config = $$.config, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasNegativeValue; + if (config[__data_groups].length > 0) { + hasNegativeValue = $$.hasNegativeValueInTargets(targets); + for (j = 0; j < config[__data_groups].length; j++) { + // Determine baseId + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider negative values + if (hasNegativeValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v < 0 ? v : 0; + }); + } + // Compute min + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + ys[baseId][i] += +v; + } + }); + } } - } else { - gridData = scale.ticks(10); - if (gridData.length > tickNum) { // use only int - gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } + return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); + }; + c3_chart_internal_fn.getYDomainMax = function (targets) { + var $$ = this, config = $$.config, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasPositiveValue; + if (config[__data_groups].length > 0) { + hasPositiveValue = $$.hasPositiveValueInTargets(targets); + for (j = 0; j < config[__data_groups].length; j++) { + // Determine baseId + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider positive values + if (hasPositiveValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v > 0 ? v : 0; + }); + } + // Compute max + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + ys[baseId][i] += +v; + } + }); + } } } - return gridData; - }; - c3_chart_internal_fn.getGridFilterToRemove = function (params) { - return params ? function (line) { - var found = false; - [].concat(params).forEach(function (param) { - if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { - found = true; - } - }); - return found; - } : function () { return true; }; + return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - c3_chart_internal_fn.removeGridLines = function (params, forX) { + c3_chart_internal_fn.getYDomain = function (targets, axisId) { var $$ = this, config = $$.config, - toRemove = $$.getGridFilterToRemove(params), - toShow = function (line) { return !toRemove(line); }, - classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], - classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; - $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) - .transition().duration(config[__transition_duration]) - .style('opacity', 0).remove(); - if (forX) { - config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); - } else { - config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); + yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), + yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], + yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], + yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), + yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), + domainLength, padding, padding_top, padding_bottom, + center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], + yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, + isZeroBased = ($$.hasType('bar', yTargets) && config[__bar_zerobased]) || ($$.hasType('area', yTargets) && config[__area_zerobased]), + showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], + showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; + if (yTargets.length === 0) { // use current domain if target of axisId is none + return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); } - }; + if (yDomainMin === yDomainMax) { + yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; + } + isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; + isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { yDomainMin = 0; } + if (isAllNegative) { yDomainMax = 0; } + } + domainLength = Math.abs(yDomainMax - yDomainMin); + padding = padding_top = padding_bottom = domainLength * 0.1; - c3_chart_internal_fn.getClipPath = function (id) { - var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; - return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; - }; - c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { - // axis line width + padding for left - return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); - }; - c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { - return forHorizontal ? -20 : -4; - }; - c3_chart_internal_fn.getXAxisClipX = function () { - var $$ = this; - return $$.getAxisClipX(!$$.config[__axis_rotated]); - }; - c3_chart_internal_fn.getXAxisClipY = function () { - var $$ = this; - return $$.getAxisClipY(!$$.config[__axis_rotated]); - }; - c3_chart_internal_fn.getYAxisClipX = function () { - var $$ = this; - return $$.getAxisClipX($$.config[__axis_rotated]); - }; - c3_chart_internal_fn.getYAxisClipY = function () { - var $$ = this; - return $$.getAxisClipY($$.config[__axis_rotated]); - }; - c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { - var $$ = this; - // width + axis line width + padding for left/right - return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; + if (center) { + yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); + yDomainMax = yDomainAbs - center; + yDomainMin = center - yDomainAbs; + } + // add padding for data label + if (showHorizontalDataLabel) { + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + diff = diffDomain($$.y.range()); + ratio = [lengths[0] / diff, lengths[1] / diff]; + padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); + padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); + } else if (showVerticalDataLabel) { + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + padding_top += lengths[1]; + padding_bottom += lengths[0]; + } + if (axisId === 'y' && config[__axis_y_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); + } + if (axisId === 'y2' && config[__axis_y2_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); + } + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { padding_bottom = yDomainMin; } + if (isAllNegative) { padding_top = -yDomainMax; } + } + return [yDomainMin - padding_bottom, yDomainMax + padding_top]; }; - c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { + c3_chart_internal_fn.getXDomainMin = function (targets) { var $$ = this, config = $$.config; - return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; + return config[__axis_x_min] ? + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : + $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); }; - c3_chart_internal_fn.getXAxisClipWidth = function () { - var $$ = this; - return $$.getAxisClipWidth(!$$.config[__axis_rotated]); + c3_chart_internal_fn.getXDomainMax = function (targets) { + var $$ = this, config = $$.config; + return config[__axis_x_max] ? + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : + $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); }; - c3_chart_internal_fn.getXAxisClipHeight = function () { - var $$ = this; - return $$.getAxisClipHeight(!$$.config[__axis_rotated]); + c3_chart_internal_fn.getXDomainPadding = function (targets) { + var $$ = this, config = $$.config, + edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], + maxDataCount, padding, paddingLeft, paddingRight; + if ($$.isCategorized()) { + padding = 0; + } else if ($$.hasType('bar', targets)) { + maxDataCount = $$.getMaxDataCount(); + padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; + } else { + padding = diff * 0.01; + } + if (typeof config[__axis_x_padding] === 'object' && notEmpty(config[__axis_x_padding])) { + paddingLeft = isValue(config[__axis_x_padding].left) ? config[__axis_x_padding].left : padding; + paddingRight = isValue(config[__axis_x_padding].right) ? config[__axis_x_padding].right : padding; + } else if (typeof config[__axis_x_padding] === 'number') { + paddingLeft = paddingRight = config[__axis_x_padding]; + } else { + paddingLeft = paddingRight = padding; + } + return {left: paddingLeft, right: paddingRight}; }; - c3_chart_internal_fn.getYAxisClipWidth = function () { - var $$ = this; - return $$.getAxisClipWidth($$.config[__axis_rotated]); + c3_chart_internal_fn.getXDomain = function (targets) { + var $$ = this, + xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], + firstX = xDomain[0], lastX = xDomain[1], + padding = $$.getXDomainPadding(targets), + min = 0, max = 0; + // show center of x domain if min and max are the same + if ((firstX - lastX) === 0 && !$$.isCategorized()) { + firstX = $$.isTimeSeries() ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$.isTimeSeries() ? new Date(lastX.getTime() * 1.5) : 0.5; + } + if (firstX || firstX === 0) { + min = $$.isTimeSeries() ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + } + if (lastX || lastX === 0) { + max = $$.isTimeSeries() ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + } + return [min, max]; }; - c3_chart_internal_fn.getYAxisClipHeight = function () { - var $$ = this; - return $$.getAxisClipHeight($$.config[__axis_rotated]); + c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + var $$ = this, config = $$.config; + if (withUpdateOrgXDomain) { + $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); + $$.orgXDomain = $$.x.domain(); + if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } + $$.subX.domain($$.x.domain()); + if ($$.brush) { $$.brush.scale($$.subX); } + } + if (withUpdateXDomain) { + $$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent()); + if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } + } + return $$.x.domain(); }; - - /** - * $$.data.js - */ c3_chart_internal_fn.isX = function (key) { var $$ = this, config = $$.config; return (config[__data_x] && key === config[__data_x]) || (notEmpty(config[__data_xs]) && hasValue(config[__data_xs], key)); @@ -2587,18 +2267,6 @@ } return x; }; - c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { - var $$ = this, type = mimeType ? mimeType : 'csv'; - $$.d3.xhr(url, function (error, data) { - var d; - if (type === 'json') { - d = $$.convertJsonToData(JSON.parse(data.response), keys); - } else { - d = $$.convertCsvToData(data.response); - } - done(d); - }); - }; c3_chart_internal_fn.cloneTarget = function (target) { return { id : target.id, @@ -2755,12 +2423,12 @@ lengths = [0, 0], paddingCoef = 1.3; $$.selectChart.select('svg').selectAll('.dummy') .data([min, max]) - .enter().append('text') + .enter().append('text') .text(function (d) { return $$.formatByAxisId(axisId)(d); }) .each(function (d, i) { lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; }) - .remove(); + .remove(); return lengths; }; c3_chart_internal_fn.isNoneArc = function (d) { @@ -2769,11 +2437,91 @@ c3_chart_internal_fn.isArc = function (d) { return 'data' in d && this.hasTarget(this.data.targets, d.data.id); }; + c3_chart_internal_fn.findSameXOfValues = function (values, index) { + var i, targetX = values[index].x, sames = []; + for (i = index - 1; i >= 0; i--) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + for (i = index; i < values.length; i++) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + return sames; + }; + + c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + var $$ = this, + min = _min ? _min : 0, + max = _max ? _max : values.length - 1, + med = Math.floor((max - min) / 2) + min, + value = values[med], + diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], + candidates; + + // Update range for search + diff > 0 ? max = med : min = med; + + // if candidates are two closest min and max, stop recursive call + if ((max - min) === 1 || (min === 0 && max === 0)) { + + // Get candidates that has same min and max index + candidates = []; + if (values[min].x || values[min].x === 0) { + candidates = candidates.concat($$.findSameXOfValues(values, min)); + } + if (values[max].x || values[max].x === 0) { + candidates = candidates.concat($$.findSameXOfValues(values, max)); + } + + // Determine the closest and return + return $$.findClosest(candidates, pos); + } + + return $$.findClosestOfValues(values, pos, min, max); + }; + c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { + var $$ = this, candidates; + // map to array of closest points of each target + candidates = targets.map(function (target) { + return $$.findClosestOfValues(target.values, pos); + }); - /** - * c3.data.convert.js - */ + // decide closest point and return + return $$.findClosest(candidates, pos); + }; + c3_chart_internal_fn.findClosest = function (values, pos) { + var $$ = this, minDist, closest; + values.forEach(function (v) { + var d = $$.dist(v, pos); + if (d < minDist || ! minDist) { + minDist = d; + closest = v; + } + }); + return closest; + }; + c3_chart_internal_fn.dist = function (data, pos) { + var $$ = this, config = $$.config, + yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, + xIndex = config[__axis_rotated] ? 1 : 0, + yIndex = config[__axis_rotated] ? 0 : 1; + return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + }; + + c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { + var $$ = this, type = mimeType ? mimeType : 'csv'; + $$.d3.xhr(url, function (error, data) { + var d; + if (type === 'json') { + d = $$.convertJsonToData(JSON.parse(data.response), keys); + } else { + d = $$.convertCsvToData(data.response); + } + done(d); + }); + }; c3_chart_internal_fn.convertCsvToData = function (csv) { var d3 = this.d3, rows = d3.csv.parseRows(csv), d; if (rows.length === 1) { @@ -2939,9 +2687,6 @@ return targets; }; - /** - * c3.data.load.js - */ c3_chart_internal_fn.load = function (targets, args) { var $$ = this; if (targets) { @@ -3014,7 +2759,7 @@ return; } $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) - .transition() + .transition() .style('opacity', 0) .remove() .call($$.endall, done); @@ -3032,19 +2777,113 @@ }); }; - - /** - * c3.data.category.js - */ c3_chart_internal_fn.categoryName = function (i) { var config = this.config; return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; }; + c3_chart_internal_fn.getCurrentWidth = function () { + var $$ = this, config = $$.config; + return config[__size_width] ? config[__size_width] : $$.getParentWidth(); + }; + c3_chart_internal_fn.getCurrentHeight = function () { + var $$ = this, config = $$.config, + h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); + return h > 0 ? h : 320; + }; + c3_chart_internal_fn.getCurrentPaddingTop = function () { + var config = this.config; + return isValue(config[__padding_top]) ? config[__padding_top] : 0; + }; + c3_chart_internal_fn.getCurrentPaddingBottom = function () { + var config = this.config; + return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; + }; + c3_chart_internal_fn.getCurrentPaddingLeft = function () { + var $$ = this, config = $$.config; + if (isValue(config[__padding_left])) { + return config[__padding_left]; + } else if (config[__axis_rotated]) { + return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); + } else { + return !config[__axis_y_show] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); + } + }; + c3_chart_internal_fn.getCurrentPaddingRight = function () { + var $$ = this, config = $$.config, + defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; + if (isValue(config[__padding_right])) { + return config[__padding_right] + 1; // 1 is needed not to hide tick line + } else if (config[__axis_rotated]) { + return defaultPadding + legendWidthOnRight; + } else { + return (!config[__axis_y2_show] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + } + }; + + c3_chart_internal_fn.getParentRectValue = function (key) { + var parent = this.selectChart.node(), v; + while (parent && parent.tagName !== 'BODY') { + v = parent.getBoundingClientRect()[key]; + if (v) { + break; + } + parent = parent.parentNode; + } + return v; + }; + c3_chart_internal_fn.getParentWidth = function () { + return this.getParentRectValue('width'); + }; + c3_chart_internal_fn.getParentHeight = function () { + var h = this.selectChart.style('height'); + return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; + }; + + + c3_chart_internal_fn.getSvgLeft = function () { + var $$ = this, config = $$.config, + leftAxisClass = config[__axis_rotated] ? CLASS[_axisX] : CLASS[_axisY], + leftAxis = $$.main.select('.' + leftAxisClass).node(), + svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, + chartRect = $$.selectChart.node().getBoundingClientRect(), + hasArc = $$.hasArcType(), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); + return svgLeft > 0 ? svgLeft : 0; + }; + + + c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { + var $$ = this, position = $$.getAxisLabelPositionById(id); + return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); + }; + c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { + var $$ = this, config = $$.config; + if (axisId === 'x' && !config[__axis_x_show]) { return 0; } + if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } + if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } + return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); + }; + + c3_chart_internal_fn.getEventRectWidth = function () { + var $$ = this; + var target = $$.getMaxDataCountTarget($$.data.targets), + firstData, lastData, base, maxDataCount, ratio, w; + if (!target) { + return 0; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + base = $$.x(lastData.x) - $$.x(firstData.x); + if (base === 0) { + return $$.config[__axis_rotated] ? $$.height : $$.width; + } + maxDataCount = $$.getMaxDataCount(); + ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized() ? 0.25 : 1)) / maxDataCount : 1); + w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; + return w < 1 ? 1 : w; + }; - /** - * c3.shape.js - */ c3_chart_internal_fn.getShapeIndices = function (typeFilter) { var $$ = this, config = $$.config, indices = {}, i = 0, j, k; @@ -3410,9 +3249,6 @@ return s; }; - - - c3_chart_internal_fn.isWithinCircle = function (_this, _r) { var d3 = this.d3, mouse = d3.mouse(_this), d3_this = d3.select(_this), @@ -3435,83 +3271,18 @@ return false; }; - - - - c3_chart_internal_fn.findSameXOfValues = function (values, index) { - var i, targetX = values[index].x, sames = []; - for (i = index - 1; i >= 0; i--) { - if (targetX !== values[i].x) { break; } - sames.push(values[i]); - } - for (i = index; i < values.length; i++) { - if (targetX !== values[i].x) { break; } - sames.push(values[i]); - } - return sames; - }; - - c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x - var $$ = this, - min = _min ? _min : 0, - max = _max ? _max : values.length - 1, - med = Math.floor((max - min) / 2) + min, - value = values[med], - diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], - candidates; - - // Update range for search - diff > 0 ? max = med : min = med; - - // if candidates are two closest min and max, stop recursive call - if ((max - min) === 1 || (min === 0 && max === 0)) { - - // Get candidates that has same min and max index - candidates = []; - if (values[min].x || values[min].x === 0) { - candidates = candidates.concat($$.findSameXOfValues(values, min)); - } - if (values[max].x || values[max].x === 0) { - candidates = candidates.concat($$.findSameXOfValues(values, max)); - } - - // Determine the closest and return - return $$.findClosest(candidates, pos); - } - - return $$.findClosestOfValues(values, pos, min, max); - }; - c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { - var $$ = this, candidates; - - // map to array of closest points of each target - candidates = targets.map(function (target) { - return $$.findClosestOfValues(target.values, pos); - }); - - // decide closest point and return - return $$.findClosest(candidates, pos); - }; - c3_chart_internal_fn.findClosest = function (values, pos) { - var $$ = this, minDist, closest; - values.forEach(function (v) { - var d = $$.dist(v, pos); - if (d < minDist || ! minDist) { - minDist = d; - closest = v; - } - }); - return closest; - }; - c3_chart_internal_fn.dist = function (data, pos) { - var $$ = this, config = $$.config, - yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, - xIndex = config[__axis_rotated] ? 1 : 0, - yIndex = config[__axis_rotated] ? 0 : 1; - return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); + c3_chart_internal_fn.getTextRect = function (text, cls) { + var rect; + this.d3.select('body').selectAll('.dummy') + .data([text]) + .enter().append('text') + .classed(cls ? cls : "", true) + .text(text) + .each(function () { rect = this.getBoundingClientRect(); }) + .remove(); + return rect; }; - c3_chart_internal_fn.setTargetType = function (targetIds, type) { var $$ = this, config = $$.config; $$.mapToTargetIds(targetIds).forEach(function (id) { @@ -3594,369 +3365,469 @@ return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; - - - /** - * c3.date.js - */ - c3_chart_internal_fn.parseDate = function (date) { - var $$ = this, parsedDate; - if (date instanceof Date) { - parsedDate = date; - } else if (typeof date === 'number') { - parsedDate = new Date(date); - } else { - parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); - } - if (!parsedDate || isNaN(+parsedDate)) { - window.console.error("Failed to parse x '" + date + "' to Date object"); - } - return parsedDate; - }; - - - /** - * c3.color.js - */ - c3_chart_internal_fn.generateColor = function () { - var $$ = this, config = $$.config, d3 = $$.d3, - colors = config[__data_colors], - pattern = notEmpty(config[__color_pattern]) ? config[__color_pattern] : d3.scale.category10().range(), - callback = config[__data_color], - ids = []; - - return function (d) { - var id = d.id || d, color; - - // if callback function is provided - if (colors[id] instanceof Function) { - color = colors[id](d); - } - // if specified, choose that color - else if (colors[id]) { - color = colors[id]; - } - // if not specified, choose from pattern - else { - if (ids.indexOf(id) < 0) { ids.push(id); } - color = pattern[ids.indexOf(id) % pattern.length]; - colors[id] = color; - } - return callback instanceof Function ? callback(color, d) : color; - }; + c3_chart_internal_fn.showXGridFocus = function (selectedData) { + var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (! config[__tooltip_show]) { return; } + // Hide when scatter plot exists + if ($$.hasType('scatter') || $$.hasArcType()) { return; } + var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); + focusEl + .style("visibility", "visible") + .data([dataToShow[0]]) + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + $$.smoothLines(focusEl, 'grid'); }; - c3_chart_internal_fn.generateLevelColor = function () { - var $$ = this, config = $$.config, - colors = config[__color_pattern], - threshold = config[__color_threshold], - asValue = threshold.unit === 'value', - values = threshold.values && threshold.values.length ? threshold.values : [], - max = threshold.max || 100; - return notEmpty(config[__color_threshold]) ? function (value) { - var i, v, color = colors[colors.length - 1]; - for (i = 0; i < values.length; i++) { - v = asValue ? value : (value * 100 / max); - if (v < values[i]) { - color = colors[i]; - break; - } - } - return color; - } : null; + c3_chart_internal_fn.hideXGridFocus = function () { + this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); }; - - - /** - * c3.scale.js - */ - c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { - return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); + c3_chart_internal_fn.updateXgridFocus = function () { + var $$ = this, config = $$.config; + $$.main.select('line.' + CLASS[_xgridFocus]) + .attr("x1", config[__axis_rotated] ? 0 : -10) + .attr("x2", config[__axis_rotated] ? $$.width : -10) + .attr("y1", config[__axis_rotated] ? -10 : 0) + .attr("y2", config[__axis_rotated] ? -10 : $$.height); }; - c3_chart_internal_fn.getX = function (min, max, domain, offset) { + c3_chart_internal_fn.generateGridData = function (type, scale) { var $$ = this, - scale = $$.getScale(min, max, $$.isTimeSeries()), - _scale = domain ? scale.domain(domain) : scale, key; - // Define customized scale if categorized axis - if ($$.isCategorized()) { - offset = offset || function () { return 0; }; - scale = function (d, raw) { - var v = _scale(d) + offset(d); - return raw ? v : Math.ceil(v); - }; + gridData = [], xDomain, firstYear, lastYear, i, + tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); + if (type === 'year') { + xDomain = $$.getXDomain(); + firstYear = xDomain[0].getFullYear(); + lastYear = xDomain[1].getFullYear(); + for (i = firstYear; i <= lastYear; i++) { + gridData.push(new Date(i + '-01-01 00:00:00')); + } } else { - scale = function (d, raw) { - var v = _scale(d); - return raw ? v : Math.ceil(v); - }; - } - // define functions - for (key in _scale) { - scale[key] = _scale[key]; - } - scale.orgDomain = function () { - return _scale.domain(); - }; - // define custom domain() for categorized axis - if ($$.isCategorized()) { - scale.domain = function (domain) { - if (!arguments.length) { - domain = this.orgDomain(); - return [domain[0], domain[1] + 1]; - } - _scale.domain(domain); - return scale; - }; + gridData = scale.ticks(10); + if (gridData.length > tickNum) { // use only int + gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } } - return scale; - }; - c3_chart_internal_fn.getY = function (min, max, domain) { - var scale = this.getScale(min, max); - if (domain) { scale.domain(domain); } - return scale; - }; - c3_chart_internal_fn.getYScale = function (id) { - return this.getAxisId(id) === 'y2' ? this.y2 : this.y; + return gridData; }; - c3_chart_internal_fn.getSubYScale = function (id) { - return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; + c3_chart_internal_fn.getGridFilterToRemove = function (params) { + return params ? function (line) { + var found = false; + [].concat(params).forEach(function (param) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + found = true; + } + }); + return found; + } : function () { return true; }; }; - c3_chart_internal_fn.updateScales = function () { + c3_chart_internal_fn.removeGridLines = function (params, forX) { var $$ = this, config = $$.config, - forInit = !$$.x; - // update edges - $$.xMin = config[__axis_rotated] ? 1 : 0; - $$.xMax = config[__axis_rotated] ? $$.height : $$.width; - $$.yMin = config[__axis_rotated] ? 0 : $$.height; - $$.yMax = config[__axis_rotated] ? $$.width : 1; - $$.subXMin = $$.xMin; - $$.subXMax = $$.xMax; - $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; - $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; - // update scales - $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); - $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); - $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); - $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); - $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); - $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); - // update axes - $$.xAxisTickFormat = $$.getXAxisTickFormat(); - $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); - $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); - $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); - $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); - // Set initialized scales to brush and zoom - if (!forInit) { - if ($$.brush) { $$.brush.scale($$.subX); } - if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } - } - // update for arc - if (isFunction($$.updateArc)) { - $$.updateArc(); + toRemove = $$.getGridFilterToRemove(params), + toShow = function (line) { return !toRemove(line); }, + classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], + classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; + $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) + .transition().duration(config[__transition_duration]) + .style('opacity', 0).remove(); + if (forX) { + config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); + } else { + config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); } }; - - /** - * c3.domain.js - */ - c3_chart_internal_fn.getYDomainMin = function (targets) { - var $$ = this, config = $$.config, - ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), - j, k, baseId, idsInGroup, id, hasNegativeValue; - if (config[__data_groups].length > 0) { - hasNegativeValue = $$.hasNegativeValueInTargets(targets); - for (j = 0; j < config[__data_groups].length; j++) { - // Determine baseId - idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); - if (idsInGroup.length === 0) { continue; } - baseId = idsInGroup[0]; - // Consider negative values - if (hasNegativeValue && ys[baseId]) { - ys[baseId].forEach(function (v, i) { - ys[baseId][i] = v < 0 ? v : 0; - }); - } - // Compute min - for (k = 1; k < idsInGroup.length; k++) { - id = idsInGroup[k]; - if (! ys[id]) { continue; } - ys[id].forEach(function (v, i) { - if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { - ys[baseId][i] += +v; - } - }); - } - } - } - return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); - }; - c3_chart_internal_fn.getYDomainMax = function (targets) { - var $$ = this, config = $$.config, - ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), - j, k, baseId, idsInGroup, id, hasPositiveValue; - if (config[__data_groups].length > 0) { - hasPositiveValue = $$.hasPositiveValueInTargets(targets); - for (j = 0; j < config[__data_groups].length; j++) { - // Determine baseId - idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); - if (idsInGroup.length === 0) { continue; } - baseId = idsInGroup[0]; - // Consider positive values - if (hasPositiveValue && ys[baseId]) { - ys[baseId].forEach(function (v, i) { - ys[baseId][i] = v > 0 ? v : 0; - }); - } - // Compute max - for (k = 1; k < idsInGroup.length; k++) { - id = idsInGroup[k]; - if (! ys[id]) { continue; } - ys[id].forEach(function (v, i) { - if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { - ys[baseId][i] += +v; - } - }); + c3_chart_internal_fn.initTooltip = function () { + var $$ = this, config = $$.config, i; + $$.tooltip = $$.selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + // Show tooltip if needed + if (config[__tooltip_init_show]) { + if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); + for (i = 0; i < $$.data.targets[0].values.length; i++) { + if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } } + config[__tooltip_init_x] = i; } + $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); + $$.tooltip.style("top", config[__tooltip_init_position].top) + .style("left", config[__tooltip_init_position].left) + .style("display", "block"); } - return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); }; - c3_chart_internal_fn.getYDomain = function (targets, axisId) { + c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { var $$ = this, config = $$.config, - yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), - yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], - yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], - yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), - yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), - domainLength, padding, padding_top, padding_bottom, - center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], - yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, - isZeroBased = ($$.hasType('bar', yTargets) && config[__bar_zerobased]) || ($$.hasType('area', yTargets) && config[__area_zerobased]), - showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], - showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; - if (yTargets.length === 0) { // use current domain if target of axisId is none - return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); - } - if (yDomainMin === yDomainMax) { - yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; - } - isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; - isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + titleFormat = config[__tooltip_format_title] || defaultTitleFormat, + nameFormat = config[__tooltip_format_name] || function (name) { return name; }, + valueFormat = config[__tooltip_format_value] || defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } - // Bar/Area chart should be 0-based if all positive|negative - if (isZeroBased) { - if (isAllPositive) { yDomainMin = 0; } - if (isAllNegative) { yDomainMax = 0; } - } + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "" + (title || title === 0 ? "" : ""); + } - domainLength = Math.abs(yDomainMax - yDomainMin); - padding = padding_top = padding_bottom = domainLength * 0.1; + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); - if (center) { - yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); - yDomainMax = yDomainAbs - center; - yDomainMin = center - yDomainAbs; - } - // add padding for data label - if (showHorizontalDataLabel) { - lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); - diff = diffDomain($$.y.range()); - ratio = [lengths[0] / diff, lengths[1] / diff]; - padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); - padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); - } else if (showVerticalDataLabel) { - lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); - padding_top += lengths[1]; - padding_bottom += lengths[0]; + text += ""; + text += ""; + text += ""; + text += ""; } - if (axisId === 'y' && config[__axis_y_padding]) { - padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); + return text + "
" + title + "
" + name + "" + value + "
"; + }; + c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { + var $$ = this, config = $$.config; + var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; + var forArc = $$.hasArcType(), + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (dataToShow.length === 0 || !config[__tooltip_show]) { + return; } - if (axisId === 'y2' && config[__axis_y2_padding]) { - padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); - padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + + // Get tooltip dimensions + tWidth = $$.tooltip.property('offsetWidth'); + tHeight = $$.tooltip.property('offsetHeight'); + // Determin tooltip position + if (forArc) { + tooltipLeft = ($$.width / 2) + mouse[0]; + tooltipTop = ($$.height / 2) + mouse[1] + 20; + } else { + if (config[__axis_rotated]) { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + mouse[0] + 100; + tooltipRight = tooltipLeft + tWidth; + chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = $$.x(dataToShow[0].x) + 20; + } else { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; + tooltipRight = tooltipLeft + tWidth; + chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = mouse[1] + 15; + } + + if (tooltipRight > chartRight) { + tooltipLeft -= tooltipRight - chartRight; + } + if (tooltipTop + tHeight > $$.getCurrentHeight()) { + tooltipTop -= tHeight + 30; + } } - // Bar/Area chart should be 0-based if all positive|negative - if (isZeroBased) { - if (isAllPositive) { padding_bottom = yDomainMin; } - if (isAllNegative) { padding_top = -yDomainMax; } + // Set tooltip + $$.tooltip + .style("top", tooltipTop + "px") + .style("left", tooltipLeft + 'px'); + }; + c3_chart_internal_fn.hideTooltip = function () { + this.tooltip.style("display", "none"); + }; + + c3_chart_internal_fn.initLegend = function () { + var $$ = this; + $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); + if (!config[__legend_show]) { + $$.legend.style('visibility', 'hidden'); + $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } - return [yDomainMin - padding_bottom, yDomainMax + padding_top]; + // MEMO: call here to update legend box and tranlate for all + // MEMO: translate will be upated by this, so transform not needed in updateLegend() + $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); }; - c3_chart_internal_fn.getXDomainMin = function (targets) { - var $$ = this, config = $$.config; - return config[__axis_x_min] ? - ($$.isTimeSeries() ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : - $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); + c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { + var $$ = this, insetLegendPosition = { + 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 + }; + $$.margin3 = { + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + }; }; - c3_chart_internal_fn.getXDomainMax = function (targets) { - var $$ = this, config = $$.config; - return config[__axis_x_max] ? - ($$.isTimeSeries() ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : - $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); + c3_chart_internal_fn.transformLegend = function (withTransition) { + var $$ = this; + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); }; - c3_chart_internal_fn.getXDomainPadding = function (targets) { - var $$ = this, config = $$.config, - edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], - maxDataCount, padding, paddingLeft, paddingRight; - if ($$.isCategorized()) { - padding = 0; - } else if ($$.hasType('bar', targets)) { - maxDataCount = $$.getMaxDataCount(); - padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; - } else { - padding = diff * 0.01; - } - if (typeof config[__axis_x_padding] === 'object' && notEmpty(config[__axis_x_padding])) { - paddingLeft = isValue(config[__axis_x_padding].left) ? config[__axis_x_padding].left : padding; - paddingRight = isValue(config[__axis_x_padding].right) ? config[__axis_x_padding].right : padding; - } else if (typeof config[__axis_x_padding] === 'number') { - paddingLeft = paddingRight = config[__axis_x_padding]; - } else { - paddingLeft = paddingRight = padding; - } - return {left: paddingLeft, right: paddingRight}; + c3_chart_internal_fn.updateLegendStep = function (step) { + this.legendStep = step; }; - c3_chart_internal_fn.getXDomain = function (targets) { - var $$ = this, - xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], - firstX = xDomain[0], lastX = xDomain[1], - padding = $$.getXDomainPadding(targets), - min = 0, max = 0; - // show center of x domain if min and max are the same - if ((firstX - lastX) === 0 && !$$.isCategorized()) { - firstX = $$.isTimeSeries() ? new Date(firstX.getTime() * 0.5) : -0.5; - lastX = $$.isTimeSeries() ? new Date(lastX.getTime() * 1.5) : 0.5; + c3_chart_internal_fn.updateLegendItemWidth = function (w) { + this.legendItemWidth = w; + }; + c3_chart_internal_fn.updateLegendItemHeight = function (h) { + this.legendItemHeight = h; + }; + c3_chart_internal_fn.getLegendWidth = function () { + var $$ = this; + return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; + }; + c3_chart_internal_fn.getLegendHeight = function () { + var $$ = this, config = $$.config, h = 0; + if (config[__legend_show]) { + if ($$.isLegendRight) { + h = $$.currentHeight; + } else if ($$.isLegendInset) { + h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; + } else { + h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); + } } - if (firstX || firstX === 0) { - min = $$.isTimeSeries() ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + return h; + }; + c3_chart_internal_fn.opacityForLegend = function (legendItem) { + var $$ = this; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 1; + }; + c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { + var $$ = this; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; + }; + c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { + var $$ = this; + $$.legend.selectAll('.' + CLASS[_legendItem]) + .transition().duration(100) + .style('opacity', function (_id) { + var This = $$.d3.select(this); + if (id && _id !== id) { + return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); + } else { + return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } + }); + }; + c3_chart_internal_fn.revertLegend = function () { + var $$ = this, d3 = $$.d3; + $$.legend.selectAll('.' + CLASS[_legendItem]) + .transition().duration(100) + .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); + }; + c3_chart_internal_fn.showLegend = function (targetIds) { + var $$ = this, config = $$.config; + if (!config[__legend_show]) { + config[__legend_show] = true; + $$.legend.style('visibility', 'visible'); } - if (lastX || lastX === 0) { - max = $$.isTimeSeries() ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + $$.removeHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('visibility', 'visible') + .transition() + .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); + }; + c3_chart_internal_fn.hideLegend = function (targetIds) { + var $$ = this, config = $$.config; + if (config[__legend_show] && isEmpty(targetIds)) { + config[__legend_show] = false; + $$.legend.style('visibility', 'hidden'); } - return [min, max]; + $$.addHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('opacity', 0) + .style('visibility', 'hidden'); }; - c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { var $$ = this, config = $$.config; - if (withUpdateOrgXDomain) { - $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); - $$.orgXDomain = $$.x.domain(); - if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } - $$.subX.domain($$.x.domain()); - if ($$.brush) { $$.brush.scale($$.subX); } + var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; + var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; + var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; + var withTransition, withTransitionForTransform; + var hasFocused = $$.legend.selectAll('.' + CLASS[_legendItemFocused]).size(); + var texts, rects, tiles; + + options = options || {}; + withTransition = getOption(options, "withTransition", true); + withTransitionForTransform = getOption(options, "withTransitionForTransform", true); + + function updatePositions(textElement, id, reset) { + var box = $$.getTextRect(textElement.textContent, CLASS[_legendItem]), + itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, + itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, + itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, + areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), + margin, maxLength; + + // MEMO: care about condifion of step, totalLength + function updateValues(id, withoutStep) { + if (!withoutStep) { + margin = (areaLength - totalLength - itemLength) / 2; + if (margin < posMin) { + margin = (areaLength - itemLength) / 2; + totalLength = 0; + step++; + } + } + steps[id] = step; + margins[step] = $$.isLegendInset ? 10 : margin; + offsets[id] = totalLength; + totalLength += itemLength; + } + + if (reset) { + totalLength = 0; + step = 0; + maxWidth = 0; + maxHeight = 0; + } + + if (config[__legend_show] && !$$.isLegendToShow(id)) { + widths[id] = heights[id] = steps[id] = offsets[id] = 0; + return; + } + + widths[id] = itemWidth; + heights[id] = itemHeight; + + if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } + if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } + maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; + + if (config[__legend_equally]) { + Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); + Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); + margin = (areaLength - maxLength * targetIds.length) / 2; + if (margin < posMin) { + totalLength = 0; + step = 0; + targetIds.forEach(function (id) { updateValues(id); }); + } + else { + updateValues(id, true); + } + } else { + updateValues(id); + } } - if (withUpdateXDomain) { - $$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent()); - if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } + + if ($$.isLegendRight) { + xForLegend = function (id) { return maxWidth * steps[id]; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else if ($$.isLegendInset) { + xForLegend = function (id) { return maxWidth * steps[id] + 10; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else { + xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + yForLegend = function (id) { return maxHeight * steps[id]; }; } - return $$.x.domain(); - }; + xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; + yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; + xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; + yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; + + // Define g for legend area + l = $$.legend.selectAll('.' + CLASS[_legendItem]) + .data(targetIds) + .enter().append('g') + .attr('class', function (id) { return $$.generateClass(CLASS[_legendItem], id); }) + .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) + .style('cursor', 'pointer') + .on('click', function (id) { + isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); + }) + .on('mouseover', function (id) { + $$.d3.select(this).classed(CLASS[_legendItemFocused], true); + if (!$$.transiting) { + $$.api.focus(id); + } + if (isFunction(config[__legend_item_onmouseover])) { + config[__legend_item_onmouseover].call($$, id); + } + }) + .on('mouseout', function (id) { + $$.d3.select(this).classed(CLASS[_legendItemFocused], false); + if (!$$.transiting) { + $$.api.revert(); + } + if (isFunction(config[__legend_item_onmouseout])) { + config[__legend_item_onmouseout].call($$, id); + } + }); + l.append('text') + .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) + .each(function (id, i) { updatePositions(this, id, i === 0); }) + .style("pointer-events", "none") + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); + l.append('rect') + .attr("class", CLASS[_legendItemEvent]) + .style('fill-opacity', 0) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); + l.append('rect') + .attr("class", CLASS[_legendItemTile]) + .style("pointer-events", "none") + .style('fill', $$.color) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) + .attr('width', 10) + .attr('height', 10); + // Set background for inset legend + if ($$.isLegendInset && maxWidth !== 0) { + $$.legend.insert('g', '.' + CLASS[_legendItem]) + .attr("class", CLASS[_legendBackground]) + .append('rect') + .attr('height', $$.getLegendHeight() - 10) + .attr('width', maxWidth * (step + 1) + 10); + } + + texts = $$.legend.selectAll('text') + .data(targetIds) + .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) // MEMO: needed for update + .each(function (id, i) { updatePositions(this, id, i === 0); }); + (withTransition ? texts.transition() : texts) + .attr('x', xForLegendText) + .attr('y', yForLegendText); + + rects = $$.legend.selectAll('rect.' + CLASS[_legendItemEvent]) + .data(targetIds); + (withTransition ? rects.transition() : rects) + .attr('width', function (id) { return widths[id]; }) + .attr('height', function (id) { return heights[id]; }) + .attr('x', xForLegendRect) + .attr('y', yForLegendRect); + tiles = $$.legend.selectAll('rect.' + CLASS[_legendItemTile]) + .data(targetIds); + (withTransition ? tiles.transition() : tiles) + .style('fill', $$.color) + .attr('x', xForLegend) + .attr('y', yForLegend); + // toggle legend state + $$.legend.selectAll('.' + CLASS[_legendItem]) + .classed(CLASS[_legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) + .transition() + .style('opacity', function (id) { + var This = $$.d3.select(this); + if ($$.isTargetToShow(id)) { + return !hasFocused || This.classed(CLASS[_legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } else { + return $$.legendOpacityForHidden; + } + }); + // Update all to reflect change of legend + $$.updateLegendItemWidth(maxWidth); + $$.updateLegendItemHeight(maxHeight); + $$.updateLegendStep(step); + // Update size and scale + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); + // Update g positions + $$.transformAll(withTransitionForTransform, transitions); + }; c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, @@ -4242,58 +4113,58 @@ return tickValues; }; - - /** - * c3.region.js - */ - c3_chart_internal_fn.regionX = function (d) { - var $$ = this, config = $$.config, - xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; - if (d.axis === 'y' || d.axis === 'y2') { - xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; - } else { - xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0); - } - return xPos; + c3_chart_internal_fn.getClipPath = function (id) { + var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; + return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; }; - c3_chart_internal_fn.regionY = function (d) { - var $$ = this, config = $$.config, - yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; - if (d.axis === 'y' || d.axis === 'y2') { - yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); - } else { - yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0) : 0; - } - return yPos; + c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { + // axis line width + padding for left + return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); + }; + c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { + return forHorizontal ? -20 : -4; + }; + c3_chart_internal_fn.getXAxisClipX = function () { + var $$ = this; + return $$.getAxisClipX(!$$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getXAxisClipY = function () { + var $$ = this; + return $$.getAxisClipY(!$$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getYAxisClipX = function () { + var $$ = this; + return $$.getAxisClipX($$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getYAxisClipY = function () { + var $$ = this; + return $$.getAxisClipY($$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { + var $$ = this; + // width + axis line width + padding for left/right + return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; }; - c3_chart_internal_fn.regionWidth = function (d) { - var $$ = this, config = $$.config, - start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; - if (d.axis === 'y' || d.axis === 'y2') { - end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; - } else { - end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.width); - } - return end < start ? 0 : end - start; + c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { + var $$ = this, config = $$.config; + return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; }; - c3_chart_internal_fn.regionHeight = function (d) { - var $$ = this, config = $$.config, - start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; - if (d.axis === 'y' || d.axis === 'y2') { - end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); - } else { - end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; - } - return end < start ? 0 : end - start; + c3_chart_internal_fn.getXAxisClipWidth = function () { + var $$ = this; + return $$.getAxisClipWidth(!$$.config[__axis_rotated]); }; - c3_chart_internal_fn.isRegionOnX = function (d) { - return !d.axis || d.axis === 'x'; + c3_chart_internal_fn.getXAxisClipHeight = function () { + var $$ = this; + return $$.getAxisClipHeight(!$$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getYAxisClipWidth = function () { + var $$ = this; + return $$.getAxisClipWidth($$.config[__axis_rotated]); + }; + c3_chart_internal_fn.getYAxisClipHeight = function () { + var $$ = this; + return $$.getAxisClipHeight($$.config[__axis_rotated]); }; - - - - - //-- c3.arc.js --// c3_chart_internal_fn.initPie = function () { var $$ = this, d3 = $$.d3, config = $$.config; @@ -4422,9 +4293,9 @@ if ($$.shouldExpand(id)) { target.selectAll('path') - .transition().duration(50) + .transition().duration(50) .attr("d", $$.svgArcExpanded) - .transition().duration(100) + .transition().duration(100) .attr("d", $$.svgArcExpandedSub) .each(function (d) { if ($$.isDonutType(d.data)) { @@ -4441,7 +4312,7 @@ var $$ = this, target = $$.svg.selectAll('.' + CLASS[_chartArc] + $$.selectorTarget(id)); target.selectAll('path.' + CLASS[_arc]) - .transition().duration(50) + .transition().duration(50) .attr("d", $$.svgArc); $$.svg.selectAll('.' + CLASS[_arc]) .style("opacity", 1); @@ -4578,18 +4449,18 @@ .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) .style("opacity", function (d) { return d === this._current ? 0 : 1; }) .each(function () { $$.transiting = true; }) - .transition().duration(duration) + .transition().duration(duration) .attrTween("d", function (d) { var updated = $$.updateAngle(d), interpolate; if (! updated) { return function () { return "M 0 0"; }; } -// if (this._current === d) { -// this._current = { -// startAngle: Math.PI*2, -// endAngle: Math.PI*2, -// }; -// } + // if (this._current === d) { + // this._current = { + // startAngle: Math.PI*2, + // endAngle: Math.PI*2, + // }; + // } if (isNaN(this._current.endAngle)) { this._current.endAngle = this._current.startAngle; } @@ -4613,15 +4484,12 @@ .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[_gaugeValue] : ''; }) .text(generateCall($$.textForArcLabel, $$)) .attr("transform", generateCall($$.transformForArcLabel, $$)) - .transition().duration(duration) + .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS[_chartArcsTitle]) .style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0); }; - - //-- gauge.js --// - c3_chart_internal_fn.initGauge = function () { var $$ = this, config = $$.config, arcs; if ($$.hasType('gauge')) { @@ -4658,28 +4526,134 @@ } }; - - /** - * c3.cache.js - */ - c3_chart_internal_fn.hasCaches = function (ids) { - for (var i = 0; i < ids.length; i++) { - if (! (ids[i] in this.cache)) { return false; } + c3_chart_internal_fn.regionX = function (d) { + var $$ = this, config = $$.config, + xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; + } else { + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0); } - return true; + return xPos; }; - c3_chart_internal_fn.addCache = function (id, target) { - this.cache[id] = this.cloneTarget(target); + c3_chart_internal_fn.regionY = function (d) { + var $$ = this, config = $$.config, + yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); + } else { + yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0) : 0; + } + return yPos; }; - c3_chart_internal_fn.getCaches = function (ids) { - var targets = [], i; - for (i = 0; i < ids.length; i++) { - if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } + c3_chart_internal_fn.regionWidth = function (d) { + var $$ = this, config = $$.config, + start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; + } else { + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.width); } - return targets; + return end < start ? 0 : end - start; + }; + c3_chart_internal_fn.regionHeight = function (d) { + var $$ = this, config = $$.config, + start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); + } else { + end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; + } + return end < start ? 0 : end - start; + }; + c3_chart_internal_fn.isRegionOnX = function (d) { + return !d.axis || d.axis === 'x'; + }; + + c3_chart_internal_fn.drag = function (mouse) { + var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; + var sx, sy, mx, my, minX, maxX, minY, maxY; + + if ($$.hasArcType()) { return; } + 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection + + sx = $$.dragStart[0]; + sy = $$.dragStart[1]; + mx = mouse[0]; + my = mouse[1]; + minX = Math.min(sx, mx); + maxX = Math.max(sx, mx); + minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); + maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); + + main.select('.' + CLASS[_dragarea]) + .attr('x', minX) + .attr('y', minY) + .attr('width', maxX - minX) + .attr('height', maxY - minY); + // TODO: binary search when multiple xs + main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]) + .filter(function (d) { return config[__data_selection_isselectable](d); }) + .each(function (d, i) { + var shape = d3.select(this), + isSelected = shape.classed(CLASS[_SELECTED]), + isIncluded = shape.classed(CLASS[_INCLUDED]), + _x, _y, _w, _h, toggle, isWithin = false, box; + if (shape.classed(CLASS[_circle])) { + _x = shape.attr("cx") * 1; + _y = shape.attr("cy") * 1; + toggle = $$.togglePoint; + isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; + } + else if (shape.classed(CLASS[_bar])) { + box = getPathBox(this); + _x = box.x; + _y = box.y; + _w = box.width; + _h = box.height; + toggle = $$.toggleBar; + isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); + } else { + // line/area selection not supported yet + return; + } + if (isWithin ^ isIncluded) { + shape.classed(CLASS[_INCLUDED], !isIncluded); + // TODO: included/unincluded callback here + shape.classed(CLASS[_SELECTED], !isSelected); + $$.toggle(!isSelected, shape, d, i); + } + }); + }; + + c3_chart_internal_fn.dragstart = function (mouse) { + var $$ = this, config = $$.config; + if ($$.hasArcType()) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable + $$.dragStart = mouse; + $$.main.select('.' + CLASS[_chart]).append('rect') + .attr('class', CLASS[_dragarea]) + .style('opacity', 0.1); + $$.dragging = true; + $$.config[__data_ondragstart](); + }; + + c3_chart_internal_fn.dragend = function () { + var $$ = this, config = $$.config; + if ($$.hasArcType()) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable + $$.main.select('.' + CLASS[_dragarea]) + .transition().duration(100) + .style('opacity', 0) + .remove(); + $$.main.selectAll('.' + CLASS[_shape]) + .classed(CLASS[_INCLUDED], false); + $$.dragging = false; + $$.config[__data_ondragend](); }; - //-- subchart.js --// c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; @@ -4718,7 +4692,7 @@ .attr("clip-path", $$.clipPath) .attr("class", CLASS[_brush]) .call($$.brush) - .selectAll("rect") + .selectAll("rect") .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); // ATTENTION: This must be called AFTER chart added @@ -4794,7 +4768,7 @@ .style("fill", $$.color); contextBar .style("opacity", generateCall($$.initialOpacity, $$)) - .transition().duration(duration) + .transition().duration(duration) .attr('d', drawBarOnSub) .style('opacity', 1); contextBar.exit().transition().duration(duration) @@ -4808,7 +4782,7 @@ .style('stroke', $$.color); contextLine .style("opacity", generateCall($$.initialOpacity, $$)) - .transition().duration(duration) + .transition().duration(duration) .attr("d", drawLineOnSub) .style('opacity', 1); contextLine.exit().transition().duration(duration) @@ -4823,7 +4797,7 @@ .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea .style("opacity", 0) - .transition().duration(duration) + .transition().duration(duration) .attr("d", drawAreaOnSub) .style("fill", $$.color) .style("opacity", $$.orgAreaOpacity); @@ -4855,10 +4829,6 @@ subXAxis.attr("transform", $$.getTranslate('subx')); }; - - /** - * c3.zoom.js - */ c3_chart_internal_fn.initZoom = function () { var $$ = this, d3 = $$.d3, config = $$.config; $$.zoom = d3.behavior.zoom() @@ -4912,223 +4882,109 @@ config[__zoom_onzoom].call(c3, x.orgDomain()); }; + c3_chart_internal_fn.generateColor = function () { + var $$ = this, config = $$.config, d3 = $$.d3, + colors = config[__data_colors], + pattern = notEmpty(config[__color_pattern]) ? config[__color_pattern] : d3.scale.category10().range(), + callback = config[__data_color], + ids = []; - /** - * c3.util.js - */ - var isValue = c3_chart_internal_fn.isValue = function (v) { - return v || v === 0; - }, - isFunction = c3_chart_internal_fn.isFunction = function (o) { - return typeof o === 'function'; - }, - isString = c3_chart_internal_fn.isString = function (o) { - return typeof o === 'string'; - }, - isUndefined = c3_chart_internal_fn.isUndefined = function (v) { - return typeof v === 'undefined'; - }, - isDefined = c3_chart_internal_fn.isDefined = function (v) { - return typeof v !== 'undefined'; - }, - ceil10 = c3_chart_internal_fn.ceil10 = function (v) { - return Math.ceil(v / 10) * 10; - }, - asHalfPixel = c3_chart_internal_fn.asHalfPixel = function (n) { - return Math.ceil(n) + 0.5; - }, - diffDomain = c3_chart_internal_fn.diffDomain = function (d) { - return d[1] - d[0]; - }, - isEmpty = c3_chart_internal_fn.isEmpty = function (o) { - return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); - }, - notEmpty = c3_chart_internal_fn.notEmpty = function (o) { - return Object.keys(o).length > 0; - }, - getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { - return isDefined(options[key]) ? options[key] : defaultValue; - }, - hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { - var found = false; - Object.keys(dict).forEach(function (key) { - if (dict[key] === value) { found = true; } - }); - return found; - }, - getPathBox = c3_chart_internal_fn.getPathBox = function (path) { - var box = path.getBoundingClientRect(), - items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], - minX = items[0].x, minY = Math.min(items[0].y, items[1].y); - return {x: minX, y: minY, width: box.width, height: box.height}; - }, - generateCall = c3_chart_internal_fn.generateCall = function (f, context) { - return function (d, i) { return f.call(context, d, i); }; - }; - - c3_chart_internal_fn.getTextRect = function (text, cls) { - var rect; - this.d3.select('body').selectAll('.dummy') - .data([text]) - .enter().append('text') - .classed(cls ? cls : "", true) - .text(text) - .each(function () { rect = this.getBoundingClientRect(); }) - .remove(); - return rect; - }, - + return function (d) { + var id = d.id || d, color; - /** - * c3.selection.js - */ - c3_chart_internal_fn.selectPoint = function (target, d, i) { - var $$ = this, config = $$.config; - config[__data_onselected](d, target.node()); - // add selected-circle on low layer g - $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) - .data([d]) - .enter().append('circle') - .attr("class", function () { return $$.generateClass(CLASS[_selectedCircle], i); }) - .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) - .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) - .attr("stroke", function () { return $$.color(d); }) - .attr("r", $$.pointSelectR(d) * 1.4) - .transition().duration(100) - .attr("r", $$.pointSelectR); - }; - c3_chart_internal_fn.unselectPoint = function (target, d, i) { - var $$ = this; - $$.config[__data_onunselected](d, target.node()); - // remove selected-circle from low layer g - $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) - .transition().duration(100).attr('r', 0) - .remove(); + // if callback function is provided + if (colors[id] instanceof Function) { + color = colors[id](d); + } + // if specified, choose that color + else if (colors[id]) { + color = colors[id]; + } + // if not specified, choose from pattern + else { + if (ids.indexOf(id) < 0) { ids.push(id); } + color = pattern[ids.indexOf(id) % pattern.length]; + colors[id] = color; + } + return callback instanceof Function ? callback(color, d) : color; + }; + }; + c3_chart_internal_fn.generateLevelColor = function () { + var $$ = this, config = $$.config, + colors = config[__color_pattern], + threshold = config[__color_threshold], + asValue = threshold.unit === 'value', + values = threshold.values && threshold.values.length ? threshold.values : [], + max = threshold.max || 100; + return notEmpty(config[__color_threshold]) ? function (value) { + var i, v, color = colors[colors.length - 1]; + for (i = 0; i < values.length; i++) { + v = asValue ? value : (value * 100 / max); + if (v < values[i]) { + color = colors[i]; + break; + } + } + return color; + } : null; }; - c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { - selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); + + c3_chart_internal_fn.getYFormat = function (forArc) { + var $$ = this, + formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.y2Format; + return function (v, ratio, id) { + var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; + return format.call($$, v, ratio); + }; }; - c3_chart_internal_fn.selectBar = function (target, d) { - var $$ = this; - $$.config[__data_onselected].call($$, d, target.node()); - target.transition().duration(100) - .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + c3_chart_internal_fn.yFormat = function (v) { + var $$ = this, config = $$.config, + format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; + return format(v); }; - c3_chart_internal_fn.unselectBar = function (target, d) { - var $$ = this; - $$.config[__data_onunselected].call($$, d, target.node()); - target.transition().duration(100) - .style("fill", function () { return $$.color(d); }); + c3_chart_internal_fn.y2Format = function (v) { + var $$ = this, config = $$.config, + format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; + return format(v); }; - c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { - selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); + c3_chart_internal_fn.defaultValueFormat = function (v) { + return isValue(v) ? +v : ""; }; - c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { - this.toggleBar(selected, target, d.data, i); + c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { + return (ratio * 100).toFixed(1) + '%'; }; - c3_chart_internal_fn.getToggle = function (that) { - var $$ = this; - // path selection not supported yet - return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[_bar]) ? $$.toggleBar : $$.toggleArc); - }; - c3_chart_internal_fn.toggleShape = function (that, d, i) { - var $$ = this, d3 = $$.d3, config = $$.config, - shape = d3.select(that), isSelected = shape.classed(CLASS[_SELECTED]), isWithin, toggle; - if (that.nodeName === 'circle') { - isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); - toggle = $$.togglePoint; - } - else if (that.nodeName === 'path') { - if (shape.classed(CLASS[_bar])) { - isWithin = $$.isWithinBar(that); - toggle = $$.toggleBar; - } else { // would be arc - isWithin = true; - toggle = $$.toggleArc; - } - } - if (config[__data_selection_grouped] || isWithin) { - if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { - if (!config[__data_selection_multiple]) { - $$.main.selectAll('.' + CLASS[_shapes] + (config[__data_selection_grouped] ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS[_shape]).each(function (d, i) { - var shape = d3.select(this); - if (shape.classed(CLASS[_SELECTED])) { toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); } - }); - } - shape.classed(CLASS[_SELECTED], !isSelected); - toggle(!isSelected, shape, d, i); + c3_chart_internal_fn.formatByAxisId = function (axisId) { + var $$ = this.internal, data_labels = $$.config[__data_labels], + format = function (v) { return isValue(v) ? +v : ""; }; + // find format according to axis id + if (isFunction(data_labels.format)) { + format = data_labels.format; + } else if (typeof data_labels.format === 'object') { + if (isFunction(data_labels.format[axisId])) { + format = data_labels.format[axisId]; } - $$.config[__data_onclick](d, that); } + return format; }; - - /** - * c3.transition.js - */ - c3_chart_internal_fn.generateAxisTransitions = function (duration) { - var $$ = this, 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 - }; - }; - c3_chart_internal_fn.endall = function (transition, callback) { - var n = 0; - transition - .each(function () { ++n; }) - .each("end", function () { - if (!--n) { callback.apply(this, arguments); } - }); + c3_chart_internal_fn.hasCaches = function (ids) { + for (var i = 0; i < ids.length; i++) { + if (! (ids[i] in this.cache)) { return false; } + } + return true; }; - c3_chart_internal_fn.generateWait = function () { - var transitionsToWait = [], - f = function (transition, callback) { - var timer = setInterval(function () { - var done = 0; - transitionsToWait.forEach(function (t) { - if (t.empty()) { - done += 1; - return; - } - try { - t.transition(); - } catch (e) { - done += 1; - } - }); - if (done === transitionsToWait.length) { - clearInterval(timer); - if (callback) { callback(); } - } - }, 10); - }; - f.add = function (transition) { - transitionsToWait.push(transition); - }; - return f; + c3_chart_internal_fn.addCache = function (id, target) { + this.cache[id] = this.cloneTarget(target); }; - - - /** - * c3.transform.js - */ - c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { - var $$ = this, - withTransitionForAxis = !$$.hasArcType(), - options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; - options.withTransitionForTransform = false; - $$.transiting = false; - $$.setTargetType(targetIds, type); - $$.updateAndRedraw(options); + c3_chart_internal_fn.getCaches = function (ids) { + var targets = [], i; + for (i = 0; i < ids.length; i++) { + if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } + } + return targets; }; - - /** - * c3.class.js - */ var _target = 'target', _chart = 'chart ', _chartLine = 'chartLine', @@ -5363,146 +5219,56 @@ return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; }; - - - /** - * c3.format.js - */ - c3_chart_internal_fn.getYFormat = function (forArc) { - var $$ = this, - formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat, - formatForY2 = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.y2Format; - return function (v, ratio, id) { - var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; - return format.call($$, v, ratio); - }; - }; - c3_chart_internal_fn.yFormat = function (v) { - var $$ = this, config = $$.config, - format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; - return format(v); - }; - c3_chart_internal_fn.y2Format = function (v) { - var $$ = this, config = $$.config, - format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; - return format(v); - }; - c3_chart_internal_fn.defaultValueFormat = function (v) { - return isValue(v) ? +v : ""; - }; - c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { - return (ratio * 100).toFixed(1) + '%'; - }; - c3_chart_internal_fn.formatByAxisId = function (axisId) { - var $$ = this.internal, data_labels = $$.config[__data_labels], - format = function (v) { return isValue(v) ? +v : ""; }; - // find format according to axis id - if (isFunction(data_labels.format)) { - format = data_labels.format; - } else if (typeof data_labels.format === 'object') { - if (isFunction(data_labels.format[axisId])) { - format = data_labels.format[axisId]; - } - } - return format; - }; - - - - /** - * c3.drag.js - */ - c3_chart_internal_fn.drag = function (mouse) { - var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; - var sx, sy, mx, my, minX, maxX, minY, maxY; - - if ($$.hasArcType()) { return; } - 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection - - sx = $$.dragStart[0]; - sy = $$.dragStart[1]; - mx = mouse[0]; - my = mouse[1]; - minX = Math.min(sx, mx); - maxX = Math.max(sx, mx); - minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); - maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); - - main.select('.' + CLASS[_dragarea]) - .attr('x', minX) - .attr('y', minY) - .attr('width', maxX - minX) - .attr('height', maxY - minY); - // TODO: binary search when multiple xs - main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]) - .filter(function (d) { return config[__data_selection_isselectable](d); }) - .each(function (d, i) { - var shape = d3.select(this), - isSelected = shape.classed(CLASS[_SELECTED]), - isIncluded = shape.classed(CLASS[_INCLUDED]), - _x, _y, _w, _h, toggle, isWithin = false, box; - if (shape.classed(CLASS[_circle])) { - _x = shape.attr("cx") * 1; - _y = shape.attr("cy") * 1; - toggle = $$.togglePoint; - isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; - } - else if (shape.classed(CLASS[_bar])) { - box = getPathBox(this); - _x = box.x; - _y = box.y; - _w = box.width; - _h = box.height; - toggle = $$.toggleBar; - isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); - } else { - // line/area selection not supported yet - return; - } - if (isWithin ^ isIncluded) { - shape.classed(CLASS[_INCLUDED], !isIncluded); - // TODO: included/unincluded callback here - shape.classed(CLASS[_SELECTED], !isSelected); - $$.toggle(!isSelected, shape, d, i); - } + var isValue = c3_chart_internal_fn.isValue = function (v) { + return v || v === 0; + }, + isFunction = c3_chart_internal_fn.isFunction = function (o) { + return typeof o === 'function'; + }, + isString = c3_chart_internal_fn.isString = function (o) { + return typeof o === 'string'; + }, + isUndefined = c3_chart_internal_fn.isUndefined = function (v) { + return typeof v === 'undefined'; + }, + isDefined = c3_chart_internal_fn.isDefined = function (v) { + return typeof v !== 'undefined'; + }, + ceil10 = c3_chart_internal_fn.ceil10 = function (v) { + return Math.ceil(v / 10) * 10; + }, + asHalfPixel = c3_chart_internal_fn.asHalfPixel = function (n) { + return Math.ceil(n) + 0.5; + }, + diffDomain = c3_chart_internal_fn.diffDomain = function (d) { + return d[1] - d[0]; + }, + isEmpty = c3_chart_internal_fn.isEmpty = function (o) { + return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); + }, + notEmpty = c3_chart_internal_fn.notEmpty = function (o) { + return Object.keys(o).length > 0; + }, + getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { + return isDefined(options[key]) ? options[key] : defaultValue; + }, + hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { + var found = false; + Object.keys(dict).forEach(function (key) { + if (dict[key] === value) { found = true; } }); - }; - - c3_chart_internal_fn.dragstart = function (mouse) { - var $$ = this, config = $$.config; - if ($$.hasArcType()) { return; } - if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.dragStart = mouse; - $$.main.select('.' + CLASS[_chart]).append('rect') - .attr('class', CLASS[_dragarea]) - .style('opacity', 0.1); - $$.dragging = true; - $$.config[__data_ondragstart](); - }; - - c3_chart_internal_fn.dragend = function () { - var $$ = this, config = $$.config; - if ($$.hasArcType()) { return; } - if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable - $$.main.select('.' + CLASS[_dragarea]) - .transition().duration(100) - .style('opacity', 0) - .remove(); - $$.main.selectAll('.' + CLASS[_shape]) - .classed(CLASS[_INCLUDED], false); - $$.dragging = false; - $$.config[__data_ondragend](); - }; - - - - + return found; + }, + getPathBox = c3_chart_internal_fn.getPathBox = function (path) { + var box = path.getBoundingClientRect(), + items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], + minX = items[0].x, minY = Math.min(items[0].y, items[1].y); + return {x: minX, y: minY, width: box.width, height: box.height}; + }, + generateCall = c3_chart_internal_fn.generateCall = function (f, context) { + return function (d, i) { return f.call(context, d, i); }; + }; - /** - * c3.api.js (or c3.api.focus.js, etc?) - */ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), @@ -5562,7 +5328,7 @@ $$.removeHiddenTargetIds(targetIds); $$.svg.selectAll($$.selectorTargets(targetIds)) - .transition() + .transition() .style('opacity', 1); if (options.withLegend) { @@ -5580,7 +5346,7 @@ $$.addHiddenTargetIds(targetIds); $$.svg.selectAll($$.selectorTargets(targetIds)) - .transition() + .transition() .style('opacity', 0); if (options.withLegend) { @@ -6077,11 +5843,6 @@ window.onresize = null; }; - - - /** - * c3.axis.js - */ // Features: // 1. category axis // 2. ceil values of translate/x/y to int for half pixel antialiasing diff --git a/c3.min.js b/c3.min.js index d2165d8..8aa3c63 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,3 +1,4 @@ -!function(a){"use strict";function b(a){return a||0===a}function c(a){return"undefined"==typeof a}function d(a){return"undefined"!=typeof a}function e(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"}function k(a){return Math.ceil(a)+.5}function l(a,b){var c,d,e;b&&b.axisX?c=b.axisX:(c=vk.select("."+g.axisX),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=vk.select("."+g.axisY),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=vk.select("."+g.axisY2),a&&(e=e.transition())),(a?vk.transition():vk).attr("transform",ek.main),c.attr("transform",ek.x),d.attr("transform",ek.y),e.attr("transform",ek.y2),vk.select("."+g.chartArcs).attr("transform",ek.arc)}function m(a,b){var c;b&&b.axisSubX?c=b.axisSubX:(c=wk.select("."+g.axisX),a&&(c=c.transition())),wk.attr("transform",ek.context),c.attr("transform",ek.subx)}function n(a){(a?xk.transition():xk).attr("transform",ek.legend)}function o(a,b){l(a,b),Qh&&m(a,b),n(a)}function p(){var a=V(),b=U(),c=fk||gk?0:a,d=ve(lg.data.targets),e=di||d?0:A("x"),f=Qh&&!d?Rh+e:0;Lg=t(),Mg=u(),di?(Eg={top:A("y2")+v(),right:d?0:y(),bottom:A("y")+c+w(),left:f+(d?0:x())},Fg={top:Eg.top,right:0/0,bottom:20+c,left:ok}):(Eg={top:4+v(),right:d?0:y(),bottom:e+f+c+w(),left:d?0:x()},Fg={top:Mg-f-c,right:0/0,bottom:e+c,left:Eg.left});var g={top:hk?v()+Zh+5.5:Mg-a-w()-Zh,left:ik?x()+Yh+.5:Lg-b-y()-Yh+.5};Gg={top:fk?0:gk?g.top:Mg-a,right:0/0,bottom:0,left:fk?Lg-b:gk?g.left:0},Hg=Lg-Eg.left-Eg.right,Jg=Mg-Eg.top-Eg.bottom,0>Hg&&(Hg=0),0>Jg&&(Jg=0),Ig=di?Eg.left-ok-pk:Hg,Kg=di?Jg:Mg-Fg.top-Fg.bottom,0>Ig&&(Ig=0),0>Kg&&(Kg=0),Qg=Hg-(fk?b+10:0),Rg=Jg-(fk?0:10),r(),fk&&d&&(Gg.left=Qg/2+1.1*Og)}function q(){vk.select("line."+g.xgridFocus).attr("x1",di?0:-10).attr("x2",di?Hg:-10).attr("y1",di?-10:0).attr("y2",di?-10:Jg)}function r(){var a;Og=Math.min(Qg,Rg)/2,Ng=.95*Og,a=oj?(Ng-oj)/Ng:.6,Pg=ue(lg.data.targets)||te(lg.data.targets)?Ng*a:0}function s(){var a=di?g.axisX:g.axisY,b=vk.select("."+a).node(),c=b?b.getBoundingClientRect():{right:0},d=zk.node().getBoundingClientRect(),e=ve(lg.data.targets),f=c.right-d.left-(e?0:x());return f>0?f:0}function t(){return og?og:C()}function u(){var a=pg?pg:D();return a>0?a:320}function v(){return b(sg)?sg:0}function w(){return b(tg)?tg:0}function x(){return b(qg)?qg:di?ei?Math.max(Ze(z("x")),40):1:!wi||Bi?1:Ze(z("y"))}function y(){var a=10,c=fk?U()+20:0;return b(rg)?rg+1:di?a+c:(!Fi||Ki?a:Ze(z("y2")))+c}function z(a){var b=pb(a);return b.isInner?20+Ib(a):40+Ib(a)}function A(a){return"x"!==a||ei?"x"===a&&ti?ti:"y"!==a||wi?"y2"!==a||Fi?(pb(a).isInner?30:40)+("y2"===a?-10:0):qk:!Vh||fk||gk?1:10:0}function B(a){for(var b,c=zk.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b}function C(){return B("width")}function D(){var a=zk.style("height");return a.indexOf("px")>0?+a.replace("px",""):0}function E(a){return a?-31:-(Eg.left-1)}function F(a){return a?-20:-4}function G(){return E(!di)}function H(){return F(!di)}function I(){return E(di)}function J(){return F(di)}function K(a){return a?Hg+2+30+30:Eg.left+20}function L(a){return a?(ti?ti:0)+80:Jg+8}function M(){return K(!di)}function N(){return L(!di)}function O(){return K(di)}function P(){return L(di)}function Q(){var a,b,c,d,e,f,g=Nc(lg.data.targets);return g?(a=g.values[0],b=g.values[g.values.length-1],c=ch(b.x)-ch(a.x),0===c?di?Jg:Hg:(d=Mc(),e=qe(lg.data.targets)?(d-(Mj?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0}function R(a){jk=a}function S(a){kk=a}function T(a){lk=a}function U(){return Vh?fk||gk?kk*(jk+1):Lg:0}function V(){var a=0;return Vh&&(a=fk?Mg:gk?$h?Math.max(20,lk)*($h+1):Jg:Math.max(20,lk)*(jk+1)),a}function W(){var a,b,c=!ch;Wg=di?1:0,Xg=di?Jg:Hg,Yg=di?0:Jg,Zg=di?Hg:1,$g=Wg,_g=Xg,ah=di?0:Kg,bh=di?Ig:1,ch=Z(Wg,Xg,c?void 0:ch.orgDomain(),function(){return ih.tickOffset()}),dh=$(Yg,Zg,c?void 0:dh.domain()),eh=$(Yg,Zg,c?void 0:eh.domain()),fh=Z(Wg,Xg,Ak,function(a){return a%1?0:lh.tickOffset()}),gh=$(ah,bh,c?void 0:gh.domain()),hh=$(ah,bh,c?void 0:hh.domain()),a=eb(),b=oi?oi:c?void 0:ih.tickValues(),ih=bb(ch,ak,a,b),lh=bb(fh,dk,a,b),jh=cb(dh,bk,Ci,Ei),kh=cb(eh,ck,Li,Ni),c||(rk.scale(fh),ug&&sk.scale(ch)),X()}function X(){Sg=Mb(),Tg=Nb(),Ug=Nb(.98)}function Y(a,b,c){return(c?kg.time.scale():kg.scale.linear()).range([a,b])}function Z(a,b,c,d){var e,f=Y(a,b,Lj),g=c?f.domain(c):f;Mj?(d=d||function(){return 0},f=function(a,b){var c=g(a)+d(a);return b?c:Math.ceil(c)}):f=function(a,b){var c=g(a);return b?c:Math.ceil(c)};for(e in g)f[e]=g[e];return f.orgDomain=function(){return g.domain()},Mj&&(f.domain=function(a){return arguments.length?(g.domain(a),f):(a=this.orgDomain(),[a[0],a[1]+1])}),f}function $(a,b,c){var d=Y(a,b);return c&&d.domain(c),d}function _(a){return"y2"===db(a)?eh:dh}function ab(a){return"y2"===db(a)?hh:gh}function bb(a,b,c,d){var f=e(kg,Mj).scale(a).orient(b);return f.tickFormat(c).tickValues(d),Mj?(f.tickCentered(ii),Se(ki)&&(ki=!1)):f.tickOffset=function(){var a=Oc(lg.data.targets),b=ch(a[1])-ch(a[0]),c=b?b:di?Jg:Hg;return c/Mc()/2},f}function cb(a,b,c,d){return e(kg).scale(a).orient(b).tickFormat(c).ticks(d)}function db(a){return a in uh?uh[a]:"y"}function eb(){var a=Lj?Yj:Mj?dd:function(a){return 0>a?a.toFixed(0):a};return ji&&("function"==typeof ji?a=ji:Lj&&(a=function(a){return a?Xj(ji)(a):""})),a}function fb(a){var b;return"y"===a?b=Ai:"y2"===a?b=Ji:"x"===a&&(b=vi),b}function gb(a){var b=fb(a);return"string"==typeof b?b:b?b.text:null}function hb(a,b){var c=fb(a);"string"==typeof c?"y"===a?Ai=b:"y2"===a?Ji=b:"x"===a&&(vi=b):c&&(c.text=b)}function ib(a){return 10*Math.sin(Math.PI*(a/180))}function jb(a){return 11.5-2.5*(a/15)}function kb(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",jb(c)).attr("x",ib(c)).attr("transform","rotate("+c+")")}function lb(a,b){var c=fb(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}}function mb(){return lb("x",di?"inner-top":"inner-right")}function nb(){return lb("y",di?"inner-right":"inner-top")}function ob(){return lb("y2",di?"inner-right":"inner-top")}function pb(a){return"y2"===a?ob():"y"===a?nb():mb()}function qb(){return gb("x")}function rb(){return gb("y")}function sb(){return gb("y2")}function tb(a,b){return a?b.isLeft?0:b.isCenter?Hg/2:Hg:b.isBottom?-Jg:b.isMiddle?-Jg/2:0}function ub(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"}function vb(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"}function wb(){return tb(!di,mb())}function xb(){return tb(di,nb())}function yb(){return tb(di,ob())}function zb(){return ub(!di,mb())}function Ab(){return ub(di,nb())}function Bb(){return ub(di,ob())}function Cb(){var a=mb();return di?a.isInner?"1.2em":-25-Ib("x"):a.isInner?"-0.5em":ti?ti-10:"3em"}function Db(){var a=nb();return di?a.isInner?"-0.5em":"3em":a.isInner?"1.2em":-20-Ib("y")}function Eb(){var a=ob();return di?a.isInner?"1.2em":"-2.2em":a.isInner?"-0.5em":30+Ib("y2")}function Fb(){return vb(!di,mb())}function Gb(){return vb(di,nb())}function Hb(){return vb(di,ob())}function Ib(a){var b,c,d,e=0;return tk&&(b=Uc(lg.data.targets),"y"===a?(c=dh.copy().domain(ac(b,"y")),d=cb(c,bk,Ci,Ei)):"y2"===a?(c=eh.copy().domain(ac(b,"y2")),d=cb(c,ck,Li,Ni)):(c=ch.copy().domain(ec(b)),d=bb(c,ak,eb(),oi?oi:ih.tickValues())),vk.append("g").call(d).each(function(){kg.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();e=e?nk:e}function Jb(a){var b=vk.select("."+g.axisX+" ."+g.axisXLabel),c=vk.select("."+g.axisY+" ."+g.axisYLabel),d=vk.select("."+g.axisY2+" ."+g.axisY2Label);(a?b.transition():b).attr("x",wb).attr("dx",zb).attr("dy",Cb).text(qb),(a?c.transition():c).attr("x",xb).attr("dx",Ab).attr("dy",Db).attr("dy",Db).text(rb),(a?d.transition():d).attr("x",yb).attr("dx",Bb).attr("dy",Eb).text(sb)}function Kb(a,b){return a.startAngle-b.startAngle}function Lb(a){var b=!1,c=0;if(Vg(Uc(lg.data.targets)).sort(Kb).forEach(function(d){b||d.data.id!==a.data.id||(b=!0,a=d,a.index=c),c++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),De(a.data)){var d=lj,e=mj,f=Math.abs(d)+e,g=Math.PI/f;a.startAngle=-1*(Math.PI/2)+g*Math.abs(d),a.endAngle=a.startAngle+g*(a.value>e?e:a.value)}return b?a:null}function Mb(){var a=kg.svg.arc().outerRadius(Ng).innerRadius(Pg),b=function(b,c){var d;return c?a(b):(d=Lb(b),d?a(d):"M 0 0")};return b.centroid=a.centroid,b}function Nb(a){var b=kg.svg.arc().outerRadius(Og*(a?a:1)).innerRadius(Pg);return function(a){var c=Lb(a);return c?b(c):"M 0 0"}}function Ob(a,b,c){return c||Fe(a.data)?Sg(a,b):"M 0 0"}function Pb(a){var b,c,d,e,f,g=Lb(a),h="";return g&&!te(lg.data.targets)&&(b=Sg.centroid(g),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=Ng&&e?(36/Ng>.375?1.175-36/Ng:.8)*Ng/e:0,h="translate("+c*f+","+d*f+")"),h}function Qb(a){var b=te(lg.data.targets)?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/b:null}function Rb(a){return yc({id:a.data.id,value:a.value,ratio:Qb(a),index:a.index})}function Sb(a){var b,c,d,e;return Vb()?(b=Lb(a),c=b?b.value:null,d=Qb(b),te(lg.data.targets)||Wb(d)?(e=Xb(),e?e(c,d):Od(c,d)):""):""}function Tb(a,b){var c=tk.selectAll("."+g.chartArc+Bd(a)),d=tk.selectAll("."+g.arc).filter(function(b){return b.data.id!==a});Le(a)&&c.selectAll("path").transition().duration(50).attr("d",Tg).transition().duration(100).attr("d",Ug).each(function(a){Ee(a.data)}),b||d.style("opacity",.3)}function Ub(a){var b=tk.selectAll("."+g.chartArc+Bd(a));b.selectAll("path."+g.arc).transition().duration(50).attr("d",Sg),tk.selectAll("."+g.arc).style("opacity",1)}function Vb(){var a=!0;return ue(lg.data.targets)?a=pj:se(lg.data.targets)&&(a=dj),a}function Wb(a){var b=ue(lg.data.targets)?rj:fj;return a>=b}function Xb(){var a=ej;return te(lg.data.targets)?a=jj:ue(lg.data.targets)&&(a=qj),a}function Yb(){return ue(lg.data.targets)?uj:""}function Zb(a,c,d,e){var f="ratio"===a.unit?e:1;return b(a[c])?a[c]*f:d}function $b(a){var b,c,d,e,f,g,h=Pc(a),i=_c(a);if(th.length>0)for(g=bd(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&i[d]&&i[d].forEach(function(a,b){i[d][b]=0>a?a:0}),c=1;c0||(i[d][b]+=+a)});return kg.min(Object.keys(i).map(function(a){return kg.min(i[a])}))}function _b(a){var b,c,d,e,f,g,h=Pc(a),i=_c(a);if(th.length>0)for(g=cd(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&i[d]&&i[d].forEach(function(a,b){i[d][b]=a>0?a:0}),c=1;c+a||(i[d][b]+=+a)});return kg.max(Object.keys(i).map(function(a){return kg.max(i[a])}))}function ac(a,c){var d,e,f,g,h,i,j,k,l,m,n=a.filter(function(a){return db(a.id)===c}),o="y2"===c?Hi:yi,p="y2"===c?Gi:xi,q=b(o)?o:$b(n),r=b(p)?p:_b(n),s="y2"===c?Ii:zi,t=qe(n)&&bj||pe(n)&&cj,u=Id()&&di,v=Id()&&!di;return 0===n.length?"y2"===c?eh.domain():dh.domain():(q===r&&(0>q?r=0:q=0),l=q>=0&&r>=0,m=0>=q&&0>=r,t&&(l&&(q=0),m&&(r=0)),d=Math.abs(r-q),e=f=g=.1*d,s&&(h=Math.max(Math.abs(q),Math.abs(r)),r=h-s,q=s-h),u?(i=Jd(q,r,c,"width"),j=gc(dh.range()),k=[i[0]/j,i[1]/j],f+=d*(k[1]/(1-k[0]-k[1])),g+=d*(k[0]/(1-k[0]-k[1]))):v&&(i=Jd(q,r,c,"height"),f+=i[1],g+=i[0]),"y"===c&&Di&&(f=Zb(Di,"top",e,d),g=Zb(Di,"bottom",e,d)),"y2"===c&&Mi&&(f=Zb(Mi,"top",e,d),g=Zb(Mi,"bottom",e,d)),t&&(l&&(g=q),m&&(f=-r)),[q-g,r+f])}function bc(a){return ri?Lj?Oe(ri):ri:kg.min(a,function(a){return kg.min(a.values,function(a){return a.x})})}function cc(a){return qi?Lj?Oe(qi):qi:kg.max(a,function(a){return kg.max(a.values,function(a){return a.x})})}function dc(a){var c,d,e,f,g=Oc(a),h=g[1]-g[0];return Mj?d=0:qe(a)?(c=Mc(),d=c>1?h/(c-1)/2:.5):d=.01*h,"object"==typeof si&&Te(si)?(e=b(si.left)?si.left:d,f=b(si.right)?si.right:d):e=f="number"==typeof si?si:d,{left:e,right:f}}function ec(a){var b=[bc(a),cc(a)],c=b[0],d=b[1],e=dc(a),f=0,g=0;return c-d!==0||Mj||(c=Lj?new Date(.5*c.getTime()):-.5,d=Lj?new Date(1.5*d.getTime()):.5),(c||0===c)&&(f=Lj?new Date(c.getTime()-e.left):c-e.left),(d||0===d)&&(g=Lj?new Date(d.getTime()+e.right):d+e.right),[f,g]}function fc(a,b,c,d){return c&&(ch.domain(d?d:kg.extent(ec(a))),Ak=ch.domain(),ug&&sk.scale(ch).updateScaleExtent(),fh.domain(ch.domain()),rk.scale(fh)),b&&(ch.domain(d?d:rk.empty()?Ak:rk.extent()),ug&&sk.scale(ch).updateScaleExtent()),ch.domain()}function gc(a){return a[1]-a[0]}function hc(a){for(var b=0;bb?0:b-c}function nc(a){var b,c=lc(a),d="y"===a.axis?dh:eh;return b="y"===a.axis||"y2"===a.axis?di?Jg:"start"in a?d(a.start):Jg:di?"end"in a?ch(Lj?Oe(a.end):a.end):Jg:Jg,c>b?0:b-c}function oc(a){return!a.axis||"x"===a.axis}function pc(a){return mh&&a===mh||Te(nh)&&Ue(nh,a)}function qc(a){return!pc(a)}function rc(a){return mh?mh:Te(nh)?nh[a]:null}function sc(a,b){var c,d=b&&Te(b)?Pc(b):[];return d.forEach(function(b){rc(b)===a&&(c=lg.data.xs[b])}),c}function tc(a,c){return a in lg.data.xs&&lg.data.xs[a]&&b(lg.data.xs[a][c])?lg.data.xs[a][c]:c}function uc(){var a=Object.keys(lg.data.xs);return a.length?lg.data.xs[a[0]]:null}function vc(a){var b=uc();return b&&a=0?lg.data.xs[d]=(c&&lg.data.xs[d]?lg.data.xs[d]:[]).concat(a.map(function(a){return a[e]}).filter(b).map(function(a,b){return Cc(a,d,b)})):mh?lg.data.xs[d]=uc():Te(nh)&&(lg.data.xs[d]=sc(e,lg.data.targets)):lg.data.xs[d]=a.map(function(a,b){return b})}),e.forEach(function(a){if(!lg.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),d=e.map(function(b,c){var d=qh(b);return{id:d,id_org:b,values:a.map(function(a,e){var f=rc(b),g=a[f],h=Cc(g,b,e);return Nj()&&Mj&&0===c&&g&&(0===e&&(hi=[]),hi.push(g)),("undefined"==typeof a[b]||lg.data.xs[b].length<=e)&&(h=void 0),{x:h,value:null===a[b]||isNaN(a[b])?null:+a[b],id:d}}).filter(function(a){return"undefined"!=typeof a.x})}}),d.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),lg.data.xs[a.id].sort(function(a,b){return a-b})}),vh&&ne(Pc(d).filter(function(a){return!(a in wh)}),vh),d.forEach(function(a){ic(a.id_org,a)}),d}function Jc(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}}function Kc(a){var b=zc(lg.data.targets[0].values,a-1);return b?b.x:null}function Lc(a){var b=zc(lg.data.targets[0].values,a+1);return b?b.x:null}function Mc(){return kg.max(lg.data.targets,function(a){return a.values.length})}function Nc(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b}function Oc(a){var b,c,d=Nc(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]}function Pc(a){return a.map(function(a){return a.id})}function Qc(a){return a?"string"==typeof a?[a]:a:Pc(lg.data.targets)}function Rc(a,b){var c,d=Pc(a);for(c=0;c2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),j=[d],h=0;f>h;h++)i=+d+g*(h+1),j.push(Lj?new Date(i):i);j.push(e)}return Lj||(j=j.sort(function(a,b){return a-b})),j}function Xc(a){Zj=Zj.concat(a)}function Yc(a){Zj=Zj.filter(function(b){return a.indexOf(b)<0})}function Zc(a){$j=$j.concat(a)}function $c(a){$j=$j.filter(function(b){return a.indexOf(b)<0})}function _c(a){var b={};return a.forEach(function(a){b[a.id]=[],a.values.forEach(function(c){b[a.id].push(c.value)})}),b}function ad(a,b){var c,d,e,f=Object.keys(a);for(c=0;ca})}function cd(a){return ad(a,function(a){return a>0})}function dd(a){return a=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?g=h:f=h,g-f===1||0===f&&0===g?(e=[],(a[f].x||0===a[f].x)&&(e=e.concat(Ud(a,f))),(a[g].x||0===a[g].x)&&(e=e.concat(Ud(a,g))),Xd(e,b)):Vd(a,b,f,g)}function Wd(a,b){var c;return c=a.map(function(a){return Vd(a.values,b)}),Xd(c,b)}function Xd(a,b){var c,d;return a.forEach(function(a){var e=Ve(a,b);(c>e||!c)&&(c=e,d=a)}),d}function Yd(a,b){return kg.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})}function Zd(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}}function $d(){return yh&&"desc"===yh.toLowerCase()}function _d(){return yh&&"asc"===yh.toLowerCase()}function ae(a){var b=_d(),c=$d();return b||c?a.sort(function(a,c){var d=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(d,0),f=c.values.reduce(d,0);return b?f-e:e-f}):"function"==typeof yh&&a.sort(yh),a}function be(a,c){var d,e,f,g,h,i,j,k=ve(lg.data.targets),l=a.filter(function(a){return a&&b(a.value)});0!==l.length&&wj&&(yk.html(Bj(a,eb(),Kd(k),Uj)).style("display","block"),d=yk.property("offsetWidth"),e=yk.property("offsetHeight"),k?(g=Hg/2+c[0],i=Jg/2+c[1]+20):(di?(f=s(),g=f+c[0]+100,h=g+d,j=t()-y(),i=ch(l[0].x)+20):(f=s(),g=f+x()+ch(l[0].x)+20,h=g+d,j=f+t()-y(),i=c[1]+15),h>j&&(g-=h-j),i+e>u()&&(i-=e+30)),yk.style("top",i+"px").style("left",g+"px"))}function ce(){yk.style("display","none")}function de(a){var c=a.filter(function(a){return a&&b(a.value)});if(wj&&!re(lg.data.targets)&&!ve(lg.data.targets)){var d=vk.selectAll("line."+g.xgridFocus);d.style("visibility","visible").data([c[0]]).attr(di?"y1":"x1",Qd).attr(di?"y2":"x2",Qd),Of(d,"grid")}}function ee(){vk.select("line."+g.xgridFocus).style("visibility","hidden")}function fe(a,b){var c,d,e,f,h=[],i=vk.select("."+g.axisX).selectAll(".tick").size();if("year"===a)for(c=ec(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h}function ge(a){var b,d,e={},f=0;return Uc(lg.data.targets.filter(a)).forEach(function(a){for(b=0;b=0&&(i+=g(c.values[f].value)-h)}),i}}function ke(a){return a.x||0===a.x?ch(a.x):null}function le(a,b){var c=ge(we),d=Cf(c);return th.length>0?d(a,b)[0][1]:_(a.id)(a.value)}function me(a,b){return"number"==typeof _i?_i:b?2*a.tickOffset()*aj/b:0}function ne(a,b){Qc(a).forEach(function(a){Ck[a]=b===wh[a],wh[a]=b}),a||(vh=b)}function oe(a,b){var c=!1;return a.forEach(function(a){wh[a.id]===b&&(c=!0),a.id in wh||"line"!==b||(c=!0)}),c}function pe(a){return oe(a,"area")||oe(a,"area-spline")||oe(a,"area-step")}function qe(a){return oe(a,"bar")}function re(a){return oe(a,"scatter")}function se(a){return"pie"===vh||oe(a,"pie")}function te(a){return oe(a,"gauge")}function ue(a){return"donut"===vh||oe(a,"donut")}function ve(a){return se(a)||ue(a)||te(a)}function we(a){var b="string"==typeof a?a:a.id;return!wh[b]||["line","spline","area","area-spline","step","area-step"].indexOf(wh[b])>=0}function xe(a){var b="string"==typeof a?a:a.id;return["step","area-step"].indexOf(wh[b])>=0}function ye(a){var b="string"==typeof a?a:a.id;return["spline","area-spline"].indexOf(wh[b])>=0}function ze(a){var b="string"==typeof a?a:a.id;return["area","area-spline","area-step"].indexOf(wh[b])>=0}function Ae(a){var b="string"==typeof a?a:a.id;return"bar"===wh[b]}function Be(a){var b="string"==typeof a?a:a.id;return"scatter"===wh[b]}function Ce(a){var b="string"==typeof a?a:a.id;return"pie"===wh[b]}function De(a){var b="string"==typeof a?a:a.id;return"gauge"===wh[b]}function Ee(a){var b="string"==typeof a?a:a.id;return"donut"===wh[b]}function Fe(a){return Ce(a)||Ee(a)||De(a)}function Ge(a){return we(a)?[a]:[]}function He(a){return Fe(a.data)?[a]:[]}function Ie(a){return Ae(a)?a.values:[]}function Je(a){return we(a)||Be(a)?a.values:[]}function Ke(a){return Ae(a)||we(a)?a.values:[]}function Le(a){return Ee(a)&&tj||De(a)&&kj||Ce(a)&&hj}function Me(a,b,c){var d=[];return function(e){var f,g=e.id||e;return a[g]instanceof Function?f=a[g](e):a[g]?f=a[g]:(d.indexOf(g)<0&&d.push(g),f=b[d.indexOf(g)%b.length],a[g]=f),c instanceof Function?c(f,e):f}}function Ne(a,b){var c="value"===b.unit,d=b.values&&b.values.length?b.values:[],e=b.max||100;return function(b){var f,g,h=a[a.length-1];for(f=0;f0}function Ue(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c}function Ve(a,b){var c="y"===db(a.id)?dh:eh,d=di?1:0,e=di?0:1;return Math.pow(ch(a.x)-b[d],2)+Math.pow(c(a.value)-b[e],2)}function We(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})}function Xe(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b}function Ye(a,b,c){return d(a[b])?a[b]:c}function Ze(a){return 10*Math.ceil(a/10)}function $e(a,b){var c;return kg.select("body").selectAll(".dummy").data([a]).enter().append("text").classed(b?b:"",!0).text(a).each(function(){c=this.getBoundingClientRect()}).remove(),c}function _e(a){return ye(a)?"cardinal":xe(a)?"step-after":"linear"}function af(){return kg.selectAll([])}function bf(a,b,c){Lh.call(lg,b,a.node()),vk.select("."+g.selectedCircles+Ad(b.id)).selectAll("."+g.selectedCircle+"-"+c).data([b]).enter().append("circle").attr("class",function(){return ed(g.selectedCircle,c)}).attr("cx",di?le:ke).attr("cy",di?ke:le).attr("stroke",function(){return Uj(b)}).attr("r",1.4*nf(b)).transition().duration(100).attr("r",nf)}function cf(a,b,c){Mh.call(lg,b,a.node()),vk.select("."+g.selectedCircles+Ad(b.id)).selectAll("."+g.selectedCircle+"-"+c).transition().duration(100).attr("r",0).remove()}function df(a,b,c,d){a?bf(b,c,d):cf(b,c,d)}function ef(a,b){Lh.call(lg,b,a.node()),a.transition().duration(100).style("fill",function(){return kg.rgb(Uj(b)).brighter(.75)})}function ff(a,b){Mh.call(lg,b,a.node()),a.transition().duration(100).style("fill",function(){return Uj(b)})}function gf(a,b,c,d){a?ef(b,c,d):ff(b,c,d)}function hf(a,b,c,d){gf(a,b,c.data,d)}function jf(a){return"circle"===a.nodeName?df:kg.select(a).classed(g.bar)?gf:hf}function kf(a){return a.filter(function(a){return b(a.value)})}function lf(a){return Vi&&!xe(a)?"function"==typeof Wi?Wi(a):Wi:0}function mf(a){return Xi?Yi?Yi:1.75*lf(a):lf(a)}function nf(a){return Zi?Zi:4*lf(a)}function of(a,c){return(c?vk.selectAll("."+g.circles+Ad(c)):vk).selectAll("."+g.circle+(b(a)?"-"+a:""))}function pf(a,b){of(a,b).classed(g.EXPANDED,!0).attr("r",mf)}function qf(a){of(a).filter(function(){return kg.select(this).classed(g.EXPANDED)}).classed(g.EXPANDED,!1).attr("r",lf)}function rf(a){return vk.selectAll("."+g.bar+(b(a)?"-"+a:""))}function sf(a){rf(a).classed(g.EXPANDED,!0)}function tf(a){rf(a).classed(g.EXPANDED,!1)}function uf(a,b){var c=kg.svg.area(),d=Af(a,b),e=b?ab:_,f=function(a,b){return th.length>0?d(a,b)[0][1]:e(a.id)(0)},g=function(a,b){return th.length>0?d(a,b)[1][1]:e(a.id)(a.value)};return c=di?c.x0(f).x1(g).y(Qd):c.x(Qd).y0(f).y1(g),function(a){var b,d=kf(a.values),e=0,f=0;return ze(a)?b=c.interpolate(_e(a))(d):(d[0]&&(e=ch(d[0].x),f=_(a.id)(d[0].value)),b=di?"M "+f+" "+e:"M "+e+" "+f),b?b:"M 0 0"}}function vf(a,b){var c=kg.svg.line(),d=Cf(a,b),e=b?ab:_,f=b?Td:Qd,g=function(a,b){return th.length>0?d(a,b)[0][1]:e(a.id)(a.value)};return c=di?c.x(g).y(f):c.x(f).y(g),$i||(c=c.defined(function(a){return null!=a.value})),function(a){var d,f=$i?kf(a.values):a.values,g=b?g:fh,h=e(a.id),i=0,j=0;return we(a)?d=zh[a.id]?Df(f,g,h,zh[a.id]):c.interpolate(_e(a))(f):(f[0]&&(i=g(f[0].x),j=h(f[0].value)),d=di?"M "+j+" "+i:"M "+i+" "+j),d?d:"M 0 0"}}function wf(a,b){var c=Bf(a,b);return function(a,b){var d=c(a,b),e=di?1:0,f=di?0:1,g="M "+d[0][e]+","+d[0][f]+" L"+d[1][e]+","+d[1][f]+" L"+d[2][e]+","+d[2][f]+" L"+d[3][e]+","+d[3][f]+" z";return g}}function xf(a,b){var c=Bf(a,!1),d=b?yf:zf;return function(a,b){return d(c(a,b),a,this)}}function yf(a,b,c){var d,e,f=c.getBoundingClientRect();return di?(e=Ae(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>Hg?Hg-f.width:d}function zf(a,b,c){var d,e=c.getBoundingClientRect();return d=di?(a[0][0]+a[2][0]+.6*e.height)/2:a[2][1]+(b.value<0?e.height:Ae(b)?-3:-6),dj||a.value<0&&j>c)&&(j=c),[[i,h],[i,j-(c-h)]]}}function Bf(a,b){var c=a.__max__+1,d=me(ih,c),e=he(d,c,a,!!b),f=ie(!!b),g=je(Ae,a,!!b),h=b?ab:_;return function(a,b){var c=h(a.id)(0),i=g(a,b)||c,j=e(a),k=f(a);return di&&(0k||a.value<0&&k>c)&&(k=c),[[j,i],[j,k-(c-i)],[j+d,k-(c-i)],[j+d,i]]}}function Cf(a,b){var c=a.__max__+1,d=he(0,c,a,!!b),e=ie(!!b),f=je(we,a,!!b),g=b?ab:_;return function(a,b){var c=g(a.id)(0),h=f(a,b)||c,i=d(a),j=e(a);return di&&(0j||a.value<0&&j>c)&&(j=c),[[i,j-(c-h)]]}}function Df(a,b,e,f){var g,h,i,j,k,l,m,n,o,p,q,r,s=-1,t="M",u=[];if(d(f))for(g=0;g=h;h+=p)t+=i(a[g-1],a[g],h,o);s=a[g].x}return t}function Ef(){var a=ug?sk:function(){};vk.select("."+g.zoomRect).call(a),vk.selectAll("."+g.eventRect).call(a)}function Ff(){di?(_j.x.call(ih),_j.subx.call(lh)):(_j.y.call(jh),_j.y2.call(kh)),p(),W(),Tf(),o(!1)}function Gf(b){var c=new MutationObserver(function(d){d.forEach(function(d){if("childList"===d.type&&d.previousSibling){c.disconnect();var e=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(e),Ff(),Pf({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});c.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})}function Hf(b){var c,d,e,f,h=!0;if(zk=kg.select(ng),zk.empty()&&(zk=kg.select(document.createElement("div")).style("opacity",0),Gf(zk),h=!1),zk.html("").classed("c3",!0),lg.data.xs={},lg.data.targets=Ic(b),Dh&&(lg.data.targets=lg.data.targets.filter(Dh)),Ch&&Xc(Ch===!0?Pc(lg.data.targets):Ch),te(lg.data.targets)&&(Vh=!1),p(),W(),ch.domain(kg.extent(ec(lg.data.targets))),dh.domain(ac(lg.data.targets,"y")),eh.domain(ac(lg.data.targets,"y2")),fh.domain(ch.domain()),gh.domain(dh.domain()),hh.domain(eh.domain()),Ak=ch.domain(),rk.scale(fh),ug&&sk.scale(ch),tk=zk.append("svg").style("overflow","hidden").on("mouseenter",function(){return zg.call(lg)}).on("mouseleave",function(){return Ag.call(lg)}),uk=tk.append("defs"),uk.append("clipPath").attr("id",Fj).append("rect"),uk.append("clipPath").attr("id",Gj).append("rect"),uk.append("clipPath").attr("id",Hj).append("rect"),Tf(),vk=tk.append("g").attr("transform",ek.main),wk=tk.append("g").attr("transform",ek.context),xk=tk.append("g").attr("transform",ek.legend),Qh||wk.style("visibility","hidden"),Vh||(xk.style("visibility","hidden"),$j=Pc(lg.data.targets)),yk=zk.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),eg(Pc(lg.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1}),vk.append("text").attr("class",g.text+" "+g.empty).attr("text-anchor","middle").attr("dominant-baseline","middle"),vk.append("g").attr("clip-path",Ij).attr("class",g.regions),e=vk.append("g").attr("clip-path",Ij).attr("class",g.grid),Oi&&e.append("g").attr("class",g.xgrids),Ri&&e.append("g").attr("class",g.ygrids),e.append("g").attr("class",g.xgridLines),e.append("g").attr("class",g.ygridLines),Ui&&e.append("g").attr("class",g.xgridFocus).append("line").attr("class",g.xgridFocus),vk.append("g").attr("clip-path",Ij).attr("class",g.chart),d=vk.select("."+g.chart).append("g").attr("class",g.eventRects).style("fill-opacity",0),vk.select("."+g.chart).append("g").attr("class",g.chartBars),vk.select("."+g.chart).append("g").attr("class",g.chartLines),c=vk.select("."+g.chart).append("g").attr("class",g.chartArcs).attr("transform",ek.arc),c.append("text").attr("class",g.chartArcsTitle).style("text-anchor","middle").text(Yb()),te(lg.data.targets)&&(c.append("path").attr("class",g.chartArcsBackground).attr("d",function(){var a={data:[{value:mj}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return Ob(a,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",g.chartArcsGaugeUnit).style("text-anchor","middle").style("pointer-events","none").text(ij?nj:""),c.append("text").attr("dx",-1*(Pg+(Ng-Pg)/2)+"px").attr("dy","1.2em").attr("class",g.chartArcsGaugeMin).style("text-anchor","middle").style("pointer-events","none").text(ij?lj:""),c.append("text").attr("dx",Pg+(Ng-Pg)/2+"px").attr("dy","1.2em").attr("class",g.chartArcsGaugeMax).style("text-anchor","middle").style("pointer-events","none").text(ij?mj:"")),vk.select("."+g.chart).append("g").attr("class",g.chartTexts),vk.insert("rect",wg?null:"g."+g.regions).attr("class",g.zoomRect).attr("width",Hg).attr("height",Jg).style("opacity",0).on("dblclick.zoom",null),ui&&rk.extent("function"!=typeof ui?ui:ui(ec())),_j.x=vk.append("g").attr("class",g.axis+" "+g.axisX).attr("clip-path",Jj).attr("transform",ek.x).style("visibility",ei?"visible":"hidden"),_j.x.append("text").attr("class",g.axisXLabel).attr("transform",di?"rotate(-90)":"").style("text-anchor",Fb),_j.y=vk.append("g").attr("class",g.axis+" "+g.axisY).attr("clip-path",Kj).attr("transform",ek.y).style("visibility",wi?"visible":"hidden"),_j.y.append("text").attr("class",g.axisYLabel).attr("transform",di?"":"rotate(-90)").style("text-anchor",Gb),_j.y2=vk.append("g").attr("class",g.axis+" "+g.axisY2).attr("transform",ek.y2).style("visibility",Fi?"visible":"hidden"),_j.y2.append("text").attr("class",g.axisY2Label).attr("transform",di?"":"rotate(-90)").style("text-anchor",Hb),wk.append("g").attr("clip-path",Ij).attr("class",g.chart),wk.select("."+g.chart).append("g").attr("class",g.chartBars),wk.select("."+g.chart).append("g").attr("class",g.chartLines),wk.append("g").attr("clip-path",Ij).attr("class",g.brush).call(rk).selectAll("rect").attr(di?"width":"height",di?Ig:Kg),_j.subx=wk.append("g").attr("class",g.axisX).attr("transform",ek.subx).attr("clip-path",di?"":Jj),Wf(lg.data.targets),h&&(Ff(),Pf({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransitionForAxis:!1})),Cj){if(Lj&&"string"==typeof Dj){for(Dj=Oe(Dj),f=0;ff&&h>c&&d>i&&j>d;else{if(!n.classed(g.bar))return;m=Zd(this),c=m.x,d=m.y,e=m.width,k=m.height,l=gf,q=!(c>h||f>c+e||d>j||i>d+k)}q^p&&(n.classed(g.INCLUDED,!p),n.classed(g.SELECTED,!o),l(!o,n,a,b))}))}function Mf(a){ve(lg.data.targets)||Eh&&(Oj=a,vk.select("."+g.chart).append("rect").attr("class",g.dragarea).style("opacity",.1),Pj=!0,Nh.call(lg))}function Nf(){ve(lg.data.targets)||Eh&&(vk.select("."+g.dragarea).transition().duration(100).style("opacity",0).remove(),vk.selectAll("."+g.shape).classed(g.INCLUDED,!1),Pj=!1,Oh.call(lg))}function Of(a,b){"grid"===b&&a.each(function(){var a=kg.select(this),b=a.attr("x1"),c=a.attr("x2"),d=a.attr("y1"),e=a.attr("y2");a.attr({x1:Math.ceil(b),x2:Math.ceil(c),y1:Math.ceil(d),y2:Math.ceil(e)})})}function Pf(a,c){var d,e,f,h,i,j,k,l,m,n,o,p,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,R,S,T,U,V,W,X,Y,Z,$,_,ab,bb=ge(ze),cb=ge(Ae),eb=ge(we),fb=ve(lg.data.targets),gb=Uc(lg.data.targets);if(d=h=p=u=af(),a=a||{},E=Ye(a,"withY",!0),F=Ye(a,"withSubchart",!0),G=Ye(a,"withTransition",!0),J=Ye(a,"withTransform",!1),K=Ye(a,"withUpdateXDomain",!1),L=Ye(a,"withUpdateOrgXDomain",!1),M=Ye(a,"withLegend",!1),H=Ye(a,"withTransitionForExit",G),I=Ye(a,"withTransitionForAxis",G),W=G?Dg:0,X=H?W:0,Y=I?W:0,c=c||Uf(Y),M&&Vh&&eg(Pc(lg.data.targets),a,c),Mj&&0===gb.length&&ch.domain([0,_j.x.selectAll(".tick").size()]),gb.length?(fc(gb,K,L),oi||!ni&&!mi||($=Wc(Vc(gb),mi),ih.tickValues($),lh.tickValues($))):(ih.tickValues([]),lh.tickValues([])),dh.domain(ac(gb,"y")),eh.domain(ac(gb,"y2")),_j.x.style("opacity",fb?0:1),_j.y.style("opacity",fb?0:1),_j.y2.style("opacity",fb?0:1),_j.subx.style("opacity",fb?0:1),c.axisX.call(ih),c.axisY.call(jh),c.axisY2.call(kh),c.axisSubX.call(lh),Jb(G),K&&gb.length)if(ki&&$){for(_=1;_<$.length;_++)if($.length/_=0&&kg.select(this).style("display",b%ab?"none":"block")})}else tk.selectAll("."+g.axisX+" .tick text").style("display","block");!di&&pi&&kb(_j.x,c.axisX,pi),N=uf(bb,!1),P=wf(cb),S=vf(eb,!1),U=xf(cb,!0),V=xf(cb,!1),gh.domain(dh.domain()),hh.domain(eh.domain()),yk.style("display","none"),q(),vk.select("text."+g.text+"."+g.empty).attr("x",Hg/2).attr("y",Jg/2).text(Ph).transition().style("opacity",gb.length?0:1),vk.select("line."+g.xgridFocus).style("visibility","hidden"),Oi&&(e=di?{x1:0,x2:Hg,y1:function(a){return ch(a)-B},y2:function(a){return ch(a)-B}}:{x1:function(a){return ch(a)+B},x2:function(a){return ch(a)+B},y1:0,y2:Jg},(m=function(a){f=fe(Pi,ch),B=Mj?ih.tickOffset():0,d=vk.select("."+g.xgrids).selectAll("."+g.xgrid).data(f),d.enter().append("line").attr("class",g.xgrid),a||d.attr(e).style("opacity",function(){return+kg.select(this).attr(di?"y1":"x1")===(di?Jg:0)?0:1}),d.exit().remove()})()),h=vk.select("."+g.xgridLines).selectAll("."+g.xgridLine).data(Qi),i=h.enter().append("g").attr("class",function(a){return g.xgridLine+(a.class?" "+a.class:"")}),i.append("line").style("opacity",0),i.append("text").attr("text-anchor","end").attr("transform",di?"":"rotate(-90)").attr("dx",di?0:-Eg.top).attr("dy",-5).style("opacity",0),h.exit().transition().duration(W).style("opacity",0).remove(),E&&Ri&&(j=vk.select("."+g.ygrids).selectAll("."+g.ygrid).data(dh.ticks(Ti)),j.enter().append("line").attr("class",g.ygrid),j.attr("x1",di?dh:0).attr("x2",di?dh:Hg).attr("y1",di?0:dh).attr("y2",di?Jg:dh),j.exit().remove(),Of(j,"grid")),E&&(k=vk.select("."+g.ygridLines).selectAll("."+g.ygridLine).data(Si),l=k.enter().append("g").attr("class",function(a){return g.ygridLine+(a.class?" "+a.class:"")}),l.append("line").style("opacity",0),l.append("text").attr("text-anchor","end").attr("transform",di?"rotate(-90)":"").attr("dx",di?0:-Eg.top).attr("dy",-5).style("opacity",0),k.select("line").transition().duration(W).attr("x1",di?Sd:0).attr("x2",di?Sd:Hg).attr("y1",di?0:Sd).attr("y2",di?Jg:Sd).style("opacity",1),k.select("text").transition().duration(W).attr("x",di?0:Hg).attr("y",Sd).text(function(a){return a.text}).style("opacity",1),k.exit().transition().duration(W).style("opacity",0).remove()),t=vk.select("."+g.regions).selectAll("."+g.region).data(vj),t.enter().append("g").attr("class",td).append("rect").style("fill-opacity",0),t.exit().transition().duration(W).style("opacity",0).remove(),r=vk.selectAll("."+g.bars).selectAll("."+g.bar).data(Ie),r.enter().append("path").attr("class",nd).style("stroke",function(a){return Uj(a.id)}).style("fill",function(a){return Uj(a.id)}),r.style("opacity",Fd),r.exit().transition().duration(X).style("opacity",0).remove(),n=vk.selectAll("."+g.lines).selectAll("."+g.line).data(Ge),n.enter().append("path").attr("class",jd).style("stroke",Uj),n.style("opacity",Fd).attr("transform",null),n.exit().transition().duration(X).style("opacity",0).remove(),o=vk.selectAll("."+g.areas).selectAll("."+g.area).data(Ge),o.enter().append("path").attr("class",rd).style("fill",Uj).style("opacity",function(){return Bk=+kg.select(this).style("opacity"),0}),o.style("opacity",Bk),o.exit().transition().duration(X).style("opacity",0).remove(),Vi&&(p=vk.selectAll("."+g.circles).selectAll("."+g.circle).data(Je),p.enter().append("circle").attr("class",ld).attr("r",lf).style("fill",Uj),p.style("opacity",Fd),p.exit().remove()),Id()&&(u=vk.selectAll("."+g.texts).selectAll("."+g.text).data(Ke),u.enter().append("text").attr("class",fd).attr("text-anchor",function(a){return di?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",Uj).style("fill-opacity",0),u.text(function(a){return Pd(db(a.id))(a.value,a.id)}),u.exit().transition().duration(X).style("fill-opacity",0).remove()),s=vk.selectAll("."+g.arcs).selectAll("."+g.arc).data(He),s.enter().append("path").attr("class",pd).style("fill",function(a){return Uj(a.data)}).style("cursor",function(a){return Gh(a)?"pointer":null}).style("opacity",0).each(function(a){De(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;Sj||(b=Lb(a),c=Rb(b),Tb(b.data.id),ag(b.data.id,!0),Jh.call(lg,c,this))}).on("mousemove",function(a){var b=Lb(a),c=Rb(b),d=[c];be(d,kg.mouse(this))}).on("mouseout",function(a){var b,c;Sj||(b=Lb(a),c=Rb(b),Ub(b.data.id),bg(),ce(),Kh.call(lg,c,this))}).on("click",function(a,b){var c=Lb(a),d=Rb(c);Kf(this,d,b)}),s.attr("transform",function(a){return!De(a.data)&&J?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){Sj=!0}).transition().duration(W).attrTween("d",function(a){var b,c=Lb(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=kg.interpolate(this._current,c),this._current=b(0),function(a){return Ob(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",J?"scale(1)":"").style("fill",function(a){return Vj?Vj(a.data.values[0].value):Uj(a.data.id)}).style("opacity",1).call(We,function(){Sj=!1}),s.exit().transition().duration(X).style("opacity",0).remove(),vk.selectAll("."+g.chartArc).select("text").style("opacity",0).attr("class",function(a){return De(a.data)?g.gaugeValue:""}).text(Sb).attr("transform",Pb).transition().duration(W).style("opacity",function(a){return Sc(a.data.id)&&Fe(a.data)?1:0}),vk.select("."+g.chartArcsTitle).style("opacity",ue(lg.data.targets)||te(lg.data.targets)?1:0),Qh&&(kg.event&&"zoom"===kg.event.type&&rk.extent(ch.orgDomain()).update(),F&&(!di&&pi&&kb(_j.subx,c.axisSubX,pi),rk.empty()||rk.extent(ch.orgDomain()).update(),O=uf(bb,!0),R=wf(cb,!0),T=vf(eb,!0),x=wk.selectAll("."+g.bars).selectAll("."+g.bar).data(Ie),x.enter().append("path").attr("class",nd).style("stroke","none").style("fill",Uj),x.style("opacity",Fd).transition().duration(W).attr("d",R).style("opacity",1),x.exit().transition().duration(W).style("opacity",0).remove(),v=wk.selectAll("."+g.lines).selectAll("."+g.line).data(Ge),v.enter().append("path").attr("class",jd).style("stroke",Uj),v.style("opacity",Fd).transition().duration(W).attr("d",T).style("opacity",1),v.exit().transition().duration(W).style("opacity",0).remove(),w=wk.selectAll("."+g.areas).selectAll("."+g.area).data(Ge),w.enter().append("path").attr("class",rd).style("fill",Uj).style("opacity",function(){return Bk=+kg.select(this).style("opacity"),0}),w.style("opacity",0).transition().duration(W).attr("d",O).style("fill",Uj).style("opacity",Bk),w.exit().transition().duration(X).style("opacity",0).remove())),vk.selectAll("."+g.selectedCircles).filter(function(a){return Ae(a)}).selectAll("circle").remove(),yg&&(y=vk.select("."+g.eventRects).style("cursor",ug?di?"ns-resize":"ew-resize":null),Te(nh)&&!xc(nh)?(y.classed(g.eventRectsMultiple)||y.classed(g.eventRectsMultiple,!0).classed(g.eventRectsSingle,!1).selectAll("."+g.eventRect).remove(),z=vk.select("."+g.eventRects).selectAll("."+g.eventRect).data([0]),Jf(z.enter()),z.attr("x",0).attr("y",0).attr("width",Hg).attr("height",Jg)):(y.classed(g.eventRectsSingle)||y.classed(g.eventRectsMultiple,!1).classed(g.eventRectsSingle,!0).selectAll("."+g.eventRect).remove(),!Nj()&&!Lj||Mj?(D=Q(),C=function(a){return ch(a.x)-D/2}):(D=function(a){var b=Kc(a.index),c=Lc(a.index),d=lg.data.xs[a.id][a.index],e=(ch(c?c:d)-ch(b?b:d))/2;return 0>e?0:e},C=function(a){var b=Kc(a.index),c=lg.data.xs[a.id][a.index];return(ch(c)+ch(b?b:c))/2}),A=Nc(lg.data.targets),vk.select("."+g.eventRects).datum(A?A.values:[]),z=vk.select("."+g.eventRects).selectAll("."+g.eventRect).data(function(a){return a}),If(z.enter()),z.attr("class",ud).attr("x",di?0:C).attr("y",di?C:0).attr("width",di?Hg:D).attr("height",di?D:Jg),z.exit().remove())),kg.transition().duration(W).each(function(){var c=[];c.push(r.transition().attr("d",P).style("fill",Uj).style("opacity",1)),c.push(n.transition().attr("d",S).style("stroke",Uj).style("opacity",1)),c.push(o.transition().attr("d",N).style("fill",Uj).style("opacity",Bk)),c.push(p.transition().style("opacity",Gd).style("fill",Uj).attr("cx",di?le:ke).attr("cy",di?ke:le)),c.push(vk.selectAll("."+g.selectedCircle).transition().attr("cx",di?le:ke).attr("cy",di?ke:le)),c.push(u.transition().attr("x",U).attr("y",V).style("fill",Uj).style("fill-opacity",a.flow?0:Hd)),c.push(t.selectAll("rect").transition().attr("x",kc).attr("y",lc).attr("width",mc).attr("height",nc).style("fill-opacity",function(a){return b(a.opacity)?a.opacity:.1})),c.push(h.select("line").transition().attr("x1",di?0:Rd).attr("x2",di?Hg:Rd).attr("y1",di?Rd:Eg.top).attr("y2",di?Rd:Jg).style("opacity",1)),c.push(h.select("text").transition().attr("x",di?Hg:0).attr("y",Rd).text(function(a){return a.text}).style("opacity",1)),a.flow&&(Z=Xe(),c.forEach(function(a){Z.add(a)}))}).call(Z?Z:function(){},function(){var b,c,f,i=1,j=a.flow.index,k=a.flow.length,l=zc(lg.data.targets[0].values,j),q=zc(lg.data.targets[0].values,j+k),s=ch.domain(),v=a.flow.duration||W,w=a.flow.done||function(){},x=Xe();lg.data.targets.forEach(function(a){a.values.splice(0,k)}),f=fc(gb,!0,!0),m&&m(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||l.x===q.x?ch(s[0])-ch(f[0]):Lj?ch(s[0])-ch(f[0]):ch(l.x)-ch(q.x):1!==lg.data.targets[0].values.length?b=ch(s[0])-ch(f[0]):Lj?(l=zc(lg.data.targets[0].values,0),q=zc(lg.data.targets[0].values,lg.data.targets[0].values.length-1),b=ch(l.x)-ch(q.x)):b=gc(f)/2,i=gc(s)/gc(f),c="translate("+b+",0) scale("+i+",1)",kg.transition().ease("linear").duration(v).each(function(){x.add(_j.x.transition().call(ih)),x.add(r.transition().attr("transform",c)),x.add(n.transition().attr("transform",c)),x.add(o.transition().attr("transform",c)),x.add(p.transition().attr("transform",c)),x.add(u.transition().attr("transform",c)),x.add(t.filter(oc).transition().attr("transform",c)),x.add(d.transition().attr("transform",c)),x.add(h.transition().attr("transform",c))}).call(x,function(){var a,b=[],c=[],f=[];if(k){for(a=0;k>a;a++)b.push("."+g.shape+"-"+(j+a)),c.push("."+g.text+"-"+(j+a)),f.push("."+g.eventRect+"-"+(j+a));tk.selectAll("."+g.shapes).selectAll(b).remove(),tk.selectAll("."+g.texts).selectAll(c).remove(),tk.selectAll("."+g.eventRects).selectAll(f).remove(),tk.select("."+g.xgrid).remove()}d.attr("transform",null).attr(e),h.attr("transform",null),h.select("line").attr("x1",di?0:Rd).attr("x2",di?Hg:Rd),h.select("text").attr("x",di?Hg:0).attr("y",Rd),r.attr("transform",null).attr("d",P),n.attr("transform",null).attr("d",S),o.attr("transform",null).attr("d",N),p.attr("transform",null).attr("cx",di?le:ke).attr("cy",di?ke:le),u.attr("transform",null).attr("x",U).attr("y",V).style("fill-opacity",Hd),t.attr("transform",null),t.select("rect").filter(oc).attr("x",kc).attr("width",mc),z.attr("x",di?0:C).attr("y",di?C:0).attr("width",di?Hg:D).attr("height",di?D:Jg),w()})}),Pc(lg.data.targets).forEach(function(a){Ck[a]=!0}),Ef()}function Qf(){Pf({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),Sh.call(lg,ch.orgDomain())}function Rf(){if(ug&&0!==Uc(lg.data.targets).length){if("mousemove"===kg.event.sourceEvent.type&&sk.altDomain)return ch.domain(sk.altDomain),void sk.scale(ch).updateScaleExtent();Mj&&ch.orgDomain()[0]===Ak[0]&&ch.domain([Ak[0]-1e-10,ch.orgDomain()[1]]),Pf({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===kg.event.sourceEvent.type&&(Qj=!0),xg.call(lg,ch.orgDomain())}}function Sf(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a}function Tf(){tk.attr("width",Lg).attr("height",Mg),tk.select("#"+Fj).select("rect").attr("width",Hg).attr("height",Jg),tk.select("#"+Gj).select("rect").attr("x",G).attr("y",H).attr("width",M).attr("height",N),tk.select("#"+Hj).select("rect").attr("x",I).attr("y",J).attr("width",O).attr("height",P),tk.select("."+g.zoomRect).attr("width",Hg).attr("height",Jg),zk.style("max-height",Mg+"px")}function Uf(a){return{axisX:a?_j.x.transition().duration(a):_j.x,axisY:a?_j.y.transition().duration(a):_j.y,axisY2:a?_j.y2.transition().duration(a):_j.y2,axisSubX:a?_j.subx.transition().duration(a):_j.subx}}function Vf(a){var b;a=a||{},a.withTransition=Ye(a,"withTransition",!0),a.withTransform=Ye(a,"withTransform",!1),a.withLegend=Ye(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ye(a,"withTransitionForTransform",a.withTransition),p(),a.withLegend&&Vh||(b=Uf(a.withTransitionForAxis?Dg:0),W(),Tf(),o(a.withTransitionForTransform,b)),Pf(a,b)}function Wf(a){var b,c,d,e,f,h,i,j,k,l,m,n;i=vk.select("."+g.chartTexts).selectAll("."+g.chartText).data(a).attr("class",wd),j=i.enter().append("g").attr("class",wd).style("opacity",0).style("pointer-events","none"),j.append("g").attr("class",gd),e=vk.select("."+g.chartBars).selectAll("."+g.chartBar).data(a).attr("class",yd),d=e.enter().append("g").attr("class",yd).style("opacity",0).style("pointer-events","none"),d.append("g").attr("class",od).style("cursor",function(a){return Gh(a)?"pointer":null}),c=vk.select("."+g.chartLines).selectAll("."+g.chartLine).data(a).attr("class",xd),b=c.enter().append("g").attr("class",xd).style("opacity",0).style("pointer-events","none"),b.append("g").attr("class",kd),b.append("g").attr("class",sd),b.append("g").attr("class",function(a){return ed(g.selectedCircles,a.id)}),b.append("g").attr("class",md).style("cursor",function(a){return Gh(a)?"pointer":null}),a.forEach(function(a){vk.selectAll("."+g.selectedCircles+Ad(a.id)).selectAll("."+g.selectedCircle).each(function(b){b.value=a.values[b.index].value})}),h=vk.select("."+g.chartArcs).selectAll("."+g.chartArc).data(Vg(a)).attr("class",zd),f=h.enter().append("g").attr("class",zd),f.append("g").attr("class",qd),f.append("text").attr("dy",te(lg.data.targets)?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none"),Qh&&(n=wk.select("."+g.chartBars).selectAll("."+g.chartBar).data(a).attr("class",yd),m=n.enter().append("g").style("opacity",0).attr("class",yd),m.append("g").attr("class",od),l=wk.select("."+g.chartLines).selectAll("."+g.chartLine).data(a).attr("class",xd),k=l.enter().append("g").style("opacity",0).attr("class",xd),k.append("g").attr("class",kd),k.append("g").attr("class",sd)),tk.selectAll("."+g.target).filter(function(a){return Sc(a.id)}).transition().duration(Dg).style("opacity",1)}function Xf(a,b){a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){b.types?ne(a.id,b.types[a.id]):ne(a.id,b.type)}),lg.data.targets.forEach(function(b){for(var c=0;cf&&(f=(m-l)/2,z=0,F++)),E[a]=F,D[F]=gk?10:f,A[a]=z,z+=l}var f,h,i=$e(b.textContent,g.legendItem),j=10*Math.ceil((i.width+v)/10),k=10*Math.ceil((i.height+u)/10),l=fk||gk?k:j,m=fk||gk?V():U();return d&&(z=0,F=0,w=0,x=0),Vh&&!Tc(c)?void(B[c]=C[c]=E[c]=A[c]=0):(B[c]=j,C[c]=k,(!w||j>=w)&&(w=j),(!x||k>=x)&&(x=k),h=fk||gk?x:w,void(ci?(Object.keys(B).forEach(function(a){B[a]=w}),Object.keys(C).forEach(function(a){C[a]=x}),f=(m-h*a.length)/2,y>f?(z=0,F=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var f,h,i,j,k,l,m,n,q,r,s,t,u=4,v=36,w=0,x=0,y=10,z=0,A={},B={},C={},D=[0],E={},F=0,G=xk.selectAll("."+g.legendItemFocused).size();b=b||{},n=Ye(b,"withTransition",!0),q=Ye(b,"withTransitionForTransform",!0),fk?(f=function(a){return w*E[a]},j=function(a){return D[E[a]]+A[a]}):gk?(f=function(a){return w*E[a]+10},j=function(a){return D[E[a]]+A[a]}):(f=function(a){return D[E[a]]+A[a]},j=function(a){return x*E[a]}),h=function(a,b){return f(a,b)+14},k=function(a,b){return j(a,b)+9},i=function(a,b){return f(a,b)-4},l=function(a,b){return j(a,b)-7},m=xk.selectAll("."+g.legendItem).data(a).enter().append("g").attr("class",function(a){return ed(g.legendItem,a)}).style("visibility",function(a){return Tc(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){"function"==typeof _h?_h.call(lg,a):lg.toggle(a)}).on("mouseover",function(a){kg.select(this).classed(g.legendItemFocused,!0),Sj||lg.focus(a),"function"==typeof ai&&ai.call(lg,a)}).on("mouseout",function(a){kg.select(this).classed(g.legendItemFocused,!1),Sj||lg.revert(),"function"==typeof bi&&bi.call(lg,a)}),m.append("text").text(function(a){return d(rh[a])?rh[a]:a}).each(function(a,b){e(this,a,0===b)}).style("pointer-events","none").attr("x",fk||gk?h:-200).attr("y",fk||gk?-200:k),m.append("rect").attr("class",g.legendItemEvent).style("fill-opacity",0).attr("x",fk||gk?i:-200).attr("y",fk||gk?-200:l),m.append("rect").attr("class",g.legendItemTile).style("pointer-events","none").style("fill",Uj).attr("x",fk||gk?h:-200).attr("y",fk||gk?-200:j).attr("width",10).attr("height",10),gk&&0!==w&&xk.insert("g","."+g.legendItem).attr("class",g.legendBackground).append("rect").attr("height",V()-10).attr("width",w*(F+1)+10),r=xk.selectAll("text").data(a).text(function(a){return d(rh[a])?rh[a]:a}).each(function(a,b){e(this,a,0===b)}),(n?r.transition():r).attr("x",h).attr("y",k),s=xk.selectAll("rect."+g.legendItemEvent).data(a),(n?s.transition():s).attr("width",function(a){return B[a]}).attr("height",function(a){return C[a]}).attr("x",i).attr("y",l),t=xk.selectAll("rect."+g.legendItemTile).data(a),(n?t.transition():t).style("fill",Uj).attr("x",f).attr("y",j),xk.selectAll("."+g.legendItem).classed(g.legendItemHidden,function(a){return!Sc(a)}).transition().style("opacity",function(a){var b=kg.select(this);return Sc(a)?!G||b.classed(g.legendItemFocused)?$f(b):_f(b):mk}),S(w),T(x),R(F),p(),W(),Tf(),o(q,c)}function fg(a){return Rc(lg.data.targets,a.id)}function gg(a){return"data"in a&&Rc(lg.data.targets,a.data.id)}function hg(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}}function ig(a,b){var c=hg(a),d=function(a){return!c(a)},e=b?g.xgridLines:g.ygridLines,f=b?g.xgridLine:g.ygridLine;vk.select("."+e).selectAll("."+f).filter(c).transition().duration(Dg).style("opacity",0).remove(),b?Qi=Qi.filter(d):Si=Si.filter(d)}function jg(a,b,c){var d=!ve(lg.data.targets),e=c||{withTransitionForAxis:d};e.withTransitionForTransform=!1,Sj=!1,ne(a,b),Vf(e)}var kg=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,lg={data:{},axis:{},legend:{}},mg={},ng=i(["bindto"],"#chart"),og=i(["size","width"]),pg=i(["size","height"]),qg=i(["padding","left"]),rg=i(["padding","right"]),sg=i(["padding","top"]),tg=i(["padding","bottom"]),ug=i(["zoom","enabled"],!1),vg=i(["zoom","extent"]),wg=i(["zoom","privileged"],!1),xg=i(["zoom","onzoom"],function(){}),yg=i(["interaction","enabled"],!0),zg=i(["onmouseover"],function(){}),Ag=i(["onmouseout"],function(){}),Bg=i(["onresize"],function(){}),Cg=i(["onresized"],function(){}),Dg=i(["transition","duration"],350);h("data","data is required in config");var Eg,Fg,Gg,Hg,Ig,Jg,Kg,Lg,Mg,Ng,Og,Pg,Qg,Rg,Sg,Tg,Ug,Vg,Wg,Xg,Yg,Zg,$g,_g,ah,bh,ch,dh,eh,fh,gh,hh,ih,jh,kh,lh,mh=i(["data","x"]),nh=i(["data","xs"],{}),oh=i(["data","x_format"],"%Y-%m-%d"),ph=i(["data","x_localtime"],!0),qh=i(["data","id_converter"],function(a){return a}),rh=i(["data","names"],{}),sh=i(["data","classes"],{}),th=i(["data","groups"],[]),uh=i(["data","axes"],{}),vh=i(["data","type"]),wh=i(["data","types"],{}),xh=i(["data","labels"],{}),yh=i(["data","order"]),zh=i(["data","regions"],{}),Ah=i(["data","color"]),Bh=i(["data","colors"],{}),Ch=i(["data","hide"],!1),Dh=i(["data","filter"]),Eh=i(["data","selection","enabled"],!1),Fh=i(["data","selection","grouped"],!1),Gh=i(["data","selection","isselectable"],function(){return!0}),Hh=i(["data","selection","multiple"],!0),Ih=i(["data","onclick"],function(){}),Jh=i(["data","onmouseover"],function(){}),Kh=i(["data","onmouseout"],function(){}),Lh=i(["data","onselected"],function(){}),Mh=i(["data","onunselected"],function(){}),Nh=i(["data","ondragstart"],function(){}),Oh=i(["data","ondragend"],function(){}),Ph=i(["data","empty","label","text"],""),Qh=i(["subchart","show"],!1),Rh=i(["subchart","size","height"],60),Sh=i(["subchart","onbrush"],function(){}),Th=i(["color","pattern"],[]),Uh=i(["color","threshold"],{}),Vh=i(["legend","show"],!0),Wh=i(["legend","position"],"bottom"),Xh=i(["legend","inset","anchor"],"top-left"),Yh=i(["legend","inset","x"],10),Zh=i(["legend","inset","y"],0),$h=i(["legend","inset","step"]),_h=i(["legend","item","onclick"]),ai=i(["legend","item","onmouseover"]),bi=i(["legend","item","onmouseout"]),ci=i(["legend","equally"],!1),di=i(["axis","rotated"],!1),ei=i(["axis","x","show"],!0),fi=i(["axis","x","type"],"indexed"),gi=i(["axis","x","localtime"],!0),hi=i(["axis","x","categories"],[]),ii=i(["axis","x","tick","centered"],!1),ji=i(["axis","x","tick","format"]),ki=i(["axis","x","tick","culling"],{}),li=i(["axis","x","tick","culling","max"],10),mi=i(["axis","x","tick","count"]),ni=i(["axis","x","tick","fit"],!0),oi=i(["axis","x","tick","values"],null),pi=i(["axis","x","tick","rotate"]),qi=i(["axis","x","max"],null),ri=i(["axis","x","min"],null),si=i(["axis","x","padding"],{}),ti=i(["axis","x","height"]),ui=i(["axis","x","default"]),vi=i(["axis","x","label"],{}),wi=i(["axis","y","show"],!0),xi=i(["axis","y","max"]),yi=i(["axis","y","min"]),zi=i(["axis","y","center"]),Ai=i(["axis","y","label"],{}),Bi=i(["axis","y","inner"],!1),Ci=i(["axis","y","tick","format"]),Di=i(["axis","y","padding"]),Ei=i(["axis","y","ticks"],10),Fi=i(["axis","y2","show"],!1),Gi=i(["axis","y2","max"]),Hi=i(["axis","y2","min"]),Ii=i(["axis","y2","center"]),Ji=i(["axis","y2","label"],{}),Ki=i(["axis","y2","inner"],!1),Li=i(["axis","y2","tick","format"]),Mi=i(["axis","y2","padding"]),Ni=i(["axis","y2","ticks"],10),Oi=i(["grid","x","show"],!1),Pi=i(["grid","x","type"],"tick"),Qi=i(["grid","x","lines"],[]),Ri=i(["grid","y","show"],!1),Si=i(["grid","y","lines"],[]),Ti=i(["grid","y","ticks"],10),Ui=i(["grid","focus","show"],!0),Vi=i(["point","show"],!0),Wi=i(["point","r"],2.5),Xi=i(["point","focus","expand","enabled"],!0),Yi=i(["point","focus","expand","r"]),Zi=i(["point","focus","select","r"]),$i=i(["line","connect_null"],!1),_i=i(["bar","width"]),aj=i(["bar","width","ratio"],.6),bj=i(["bar","zerobased"],!0),cj=i(["area","zerobased"],!0),dj=i(["pie","label","show"],!0),ej=i(["pie","label","format"]),fj=i(["pie","label","threshold"],.05),gj=i(["pie","sort"],!0),hj=i(["pie","expand"],!0),ij=i(["gauge","label","show"],!0),jj=i(["gauge","label","format"]),kj=i(["gauge","expand"],!0),lj=i(["gauge","min"],0),mj=i(["gauge","max"],100),nj=i(["gauge","units"]),oj=i(["gauge","width"]),pj=i(["donut","label","show"],!0),qj=i(["donut","label","format"]),rj=i(["donut","label","threshold"],.05),sj=i(["donut","sort"],!0),tj=i(["donut","expand"],!0),uj=i(["donut","title"],""),vj=i(["regions"],[]),wj=i(["tooltip","show"],!0),xj=i(["tooltip","grouped"],!0),yj=i(["tooltip","format","title"]),zj=i(["tooltip","format","name"]),Aj=i(["tooltip","format","value"]),Bj=i(["tooltip","contents"],function(a,b,c,d){var e,f,h,i,j,k,l=yj?yj:b,m=zj?zj:function(a){return a},n=Aj?Aj:c;for(f=0;f"+(h||0===h?""+h+"":"")),j=m(a[f].name),i=n(a[f].value,a[f].ratio,a[f].id,a[f].index),k=Vj?Vj(a[f].value):d(a[f].id),e+="",e+=""+j+"",e+=""+i+"",e+="");return e+""}),Cj=i(["tooltip","init","show"],!1),Dj=i(["tooltip","init","x"],0),Ej=i(["tooltip","init","position"],{top:"0px",left:"50px"}),Fj="c3-"+ +new Date+"-clip",Gj=Fj+"-xaxis",Hj=Fj+"-yaxis",Ij=j(Fj),Jj=j(Gj),Kj=j(Hj),Lj="timeseries"===fi,Mj=fi.indexOf("categor")>=0,Nj=function(){return!Lj&&(mh||Te(nh))},Oj=null,Pj=!1,Qj=!1,Rj=!1,Sj=!1,Tj=kg.scale.category10().range(),Uj=Me(Bh,Te(Th)?Th:Tj,Ah),Vj=Te(Uh)?Ne(Th,Uh):null,Wj=ph?kg.time.format:kg.time.format.utc,Xj=gi?kg.time.format:kg.time.format.utc,Yj=Xj.multi([[".%L",function(a){return a.getMilliseconds()}],[":%S",function(a){return a.getSeconds()}],["%I:%M",function(a){return a.getMinutes()}],["%I %p",function(a){return a.getHours()}],["%-m/%-d",function(a){return a.getDay()&&1!==a.getDate()}],["%-m/%-d",function(a){return 1!==a.getDate()}],["%-m/%-d",function(a){return a.getMonth()}],["%Y/%-m/%-d",function(){return!0}]]),Zj=[],$j=[],_j={},ak=di?"left":"bottom",bk=di?Bi?"top":"bottom":Bi?"right":"left",ck=di?Ki?"bottom":"top":Ki?"left":"right",dk=di?"left":"bottom",ek={main:function(){return"translate("+k(Eg.left)+","+k(Eg.top)+")"},context:function(){return"translate("+k(Fg.left)+","+k(Fg.top)+")"},legend:function(){return"translate("+Gg.left+","+Gg.top+")"},x:function(){return"translate(0,"+(di?0:Jg)+")"},y:function(){return"translate(0,"+(di?Jg:0)+")"},y2:function(){return"translate("+(di?0:Hg)+","+(di?1:0)+")"},subx:function(){return"translate(0,"+(di?0:Kg)+")"},arc:function(){return"translate("+Qg/2+","+Rg/2+")"}},fk="right"===Wh,gk="inset"===Wh,hk="top-left"===Xh||"top-right"===Xh,ik="top-left"===Xh||"bottom-left"===Xh,jk=0,kk=0,lk=0,mk=.15,nk=0,ok=30,pk=di&&!ei?0:30,qk=5;Vg=kg.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),gj&&sj||Vg.sort(null);var rk,sk=function(){};rk=kg.svg.brush().on("brush",Qf),rk.update=function(){return wk&&wk.select("."+g.brush).call(this),this},rk.scale=function(a){return di?this.y(a):this.x(a)},sk=kg.behavior.zoom().on("zoomstart",function(){sk.altDomain=kg.event.sourceEvent.altKey?ch.orgDomain():null}).on("zoom",Rf),sk.scale=function(a){return di?this.y(a):this.x(a)},sk.orgScaleExtent=function(){var a=vg?vg:[1,10];return[a[0],Math.max(Mc()/a[1],a[1])]},sk.updateScaleExtent=function(){var a=gc(ch.orgDomain())/gc(Ak),b=this.orgScaleExtent();return this.scaleExtent([b[0]*a,b[1]*a]),this};var tk,uk,vk,wk,xk,yk,zk,Ak,Bk,Ck={};if(lg.focus=function(a){function b(a){Uc(a).transition().duration(100).style("opacity",1)}var c=tk.selectAll(Bd(a)),d=c.filter(fg),e=c.filter(gg);lg.revert(),lg.defocus(),b(d.classed(g.focused,!0)),b(e),ve(lg.data.targets)&&Tb(a,!0),ag(a,!0)},lg.defocus=function(a){function b(a){Uc(a).transition().duration(100).style("opacity",.3)}var c=tk.selectAll(Bd(a)),d=c.filter(fg),e=c.filter(gg);lg.revert(),b(d.classed(g.focused,!1)),b(e),ve(lg.data.targets)&&Ub(a),ag(a,!1)},lg.revert=function(a){function b(a){Uc(a).transition().duration(100).style("opacity",1)}var c=tk.selectAll(Bd(a)),d=c.filter(fg),e=c.filter(gg);b(d.classed(g.focused,!1)),b(e),ve(lg.data.targets)&&Ub(a),bg()},lg.show=function(a,b){a=Qc(a),b=b||{},Yc(a),tk.selectAll(Cd(a)).transition().style("opacity",1),b.withLegend&&cg(a),Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},lg.hide=function(a,b){a=Qc(a),b=b||{},Xc(a),tk.selectAll(Cd(a)).transition().style("opacity",0),b.withLegend&&dg(a),Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},lg.toggle=function(a){Sc(a)?lg.hide(a):lg.show(a)},lg.unzoom=function(){rk.clear().update(),Pf({withUpdateXDomain:!0})},lg.zoom=function(){},lg.zoom.enable=function(a){ug=a,Vf()},lg.load=function(a){return a.xs&&wc(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){sh[b]=a.classes[b]}),"categories"in a&&Mj&&(hi=a.categories),"cacheIds"in a&&hc(a.cacheIds)?void Xf(jc(a.cacheIds),a.done):void("unload"in a?Zf(Qc("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){Yf(a)}):Yf(a))},lg.unload=function(a){a=a||{},Zf(Qc(a.ids),function(){Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),"function"==typeof a.done&&a.done()})},lg.flow=function(a){var c,e,f,g,h,i,j=Ic(Hc(a.columns),!0),k=[],l=Mc(),m=0,n=0;lg.data.targets.forEach(function(a){var b,c,d=!1;for(b=0;bc;c++)j[b].values[c].index=n+c,Lj||(j[b].values[c].x=n+c);a.values=a.values.concat(j[b].values),j.splice(b,1);break}d||k.push(a.id)}),lg.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:Lj?vc(n+c):n+c,value:null})}),lg.data.targets.length&&j.forEach(function(a){var b,c=[];for(b=lg.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:Lj?vc(b):b,value:null});a.values.forEach(function(a){a.index+=n,Lj||(a.x+=n)}),a.values=c.concat(a.values)}),lg.data.targets=lg.data.targets.concat(j),c=Mc(),f=lg.data.targets[0],g=f.values[0],d(a.to)?(m=0,i=Lj?Oe(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-ec(lg.data.targets)[0]:1,e=[g.x-h,g.x],fc(null,!0,!0,e)),Wf(lg.data.targets),Pf({flow:{index:g.index,length:m,duration:b(a.duration)?a.duration:Dg,done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},lg.selected=function(a){return kg.merge(vk.selectAll("."+g.shapes+Ad(a)).selectAll("."+g.shape).filter(function(){return kg.select(this).classed(g.SELECTED)}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},lg.select=function(a,b,c){Eh&&vk.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(e,f){var h=kg.select(this),i=e.data?e.data.id:e.id,j=jf(this),k=Fh||!a||a.indexOf(i)>=0,l=!b||b.indexOf(f)>=0,m=h.classed(g.SELECTED);h.classed(g.line)||h.classed(g.area)||(k&&l?Gh(e)&&!m&&j(!0,h.classed(g.SELECTED,!0),e,f):d(c)&&c&&m&&j(!1,h.classed(g.SELECTED,!1),e,f))})},lg.unselect=function(a,b){Eh&&vk.selectAll("."+g.shapes).selectAll("."+g.shape).each(function(c,d){var e=kg.select(this),f=c.data?c.data.id:c.id,h=jf(this),i=Fh||!a||a.indexOf(f)>=0,j=!b||b.indexOf(d)>=0,k=e.classed(g.SELECTED);e.classed(g.line)||e.classed(g.area)||i&&j&&Gh(c)&&k&&h(!1,e.classed(g.SELECTED,!1),c,d)})},lg.transform=function(a,b){var c=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;jg(b,a,c)},lg.groups=function(a){return c(a)?th:(th=a,Pf(),th)},lg.xgrids=function(a){return a?(Qi=a,Pf(),Qi):Qi},lg.xgrids.add=function(a){return a?lg.xgrids(Qi.concat(a)):void 0},lg.xgrids.remove=function(a){ig(a,!0)},lg.ygrids=function(a){return a?(Si=a,Pf(),Si):Si},lg.ygrids.add=function(a){return a?lg.ygrids(Si.concat(a)):void 0},lg.ygrids.remove=function(a){ig(a,!1)},lg.regions=function(a){return a?(vj=a,Pf(),vj):vj},lg.regions.add=function(a){return a?(vj=vj.concat(a),Pf(),vj):vj},lg.regions.remove=function(a){var b,c,d;return a=a||{},b=Ye(a,"duration",Dg),c=Ye(a,"classes",[g.region]),d=vk.select("."+g.regions).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),vj=vj.filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0})},lg.data.get=function(a){var b=lg.data.getAsTarget(a);return d(b)?b.values.map(function(a){return a.value}):void 0},lg.data.getAsTarget=function(a){var b=lg.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},lg.data.names=function(a){return arguments.length?(Object.keys(a).forEach(function(b){rh[b]=a[b]}),Pf({withLegend:!0}),rh):rh},lg.data.colors=function(a){return arguments.length?(Object.keys(a).forEach(function(b){Bh[b]=a[b]}),Pf({withLegend:!0}),Bh):Bh},lg.category=function(a,b){return arguments.length>1&&(hi[a]=b,Pf()),hi[a]},lg.categories=function(a){return arguments.length?(hi=a,Pf(),hi):hi},lg.color=Uj,lg.x=function(a){return arguments.length&&(Ac(lg.data.targets,a),Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),lg.data.xs},lg.xs=function(a){return arguments.length&&(Bc(lg.data.targets,a),Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),lg.data.xs},lg.axis.labels=function(a){arguments.length&&(Object.keys(a).forEach(function(b){hb(b,a[b])}),Jb())},lg.axis.max=function(a){arguments.length&&("object"==typeof a?(b(a.x)&&(qi=a.x),b(a.y)&&(xi=a.y),b(a.y2)&&(Gi=a.y2)):xi=Gi=a,Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},lg.axis.min=function(a){arguments.length&&("object"==typeof a?(b(a.x)&&(ri=a.x),b(a.y)&&(yi=a.y),b(a.y2)&&(Hi=a.y2)):yi=Hi=a,Pf({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},lg.axis.range=function(a){arguments.length&&("undefined"!=typeof a.max&&lg.axis.max(a.max),"undefined"!=typeof a.min&&lg.axis.min(a.min))},lg.legend.show=function(a){cg(Qc(a)),Vf({withLegend:!0})},lg.legend.hide=function(a){dg(Qc(a)),Vf({withLegend:!0})},lg.resize=function(a){og=a?a.width:null,pg=a?a.height:null,lg.flush()},lg.flush=function(){Vf({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},lg.destroy=function(){lg.data.targets=void 0,lg.data.xs={},zk.classed("c3",!1).html(""),a.onresize=null},f.data.url)Dc(f.data.url,f.data.mimeType,f.data.keys,Hf);else if(f.data.json)Hf(Fc(f.data.json,f.data.keys));else if(f.data.rows)Hf(Gc(f.data.rows));else{if(!f.data.columns)throw Error("url or json or rows or columns is required.");Hf(Hc(f.data.columns))}return lg},"function"==typeof define&&define.amd?define("c3",["d3"],f):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=f:a.c3=f}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(a,this);b.loadConfig(a),b.init()}function c(b,c){var d=this;d.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,d.api=c,d.data={},d.cache={},d.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&Y.select(this).style("display",b%V?"none":"block")})}else W.svg.selectAll("."+qe[ae]+" .tick text").style("display","block");if(!Z[vb]&&Z[Hb]&&W.rotateTickText(W.axes.x,b.axisX,Z[Hb]),K=W.generateDrawArea($,!1),L=W.generateDrawBar(_),M=W.generateDrawLine(ab,!1),N=W.generateXYForText(_,!0),O=W.generateXYForText(_,!1),W.subY.domain(W.y.domain()),W.subY2.domain(W.y2.domain()),W.tooltip.style("display","none"),W.updateXgridFocus(),X.select("text."+qe[Od]+"."+qe[Nd]).attr("x",W.width/2).attr("y",W.height/2).text(Z[fb]).transition().style("opacity",cb.length?0:1),X.select("line."+qe[Wd]).style("visibility","hidden"),Z[fc]&&(d=Z[vb]?{x1:0,x2:W.width,y1:function(a){return W.x(a)-w},y2:function(a){return W.x(a)-w}}:{x1:function(a){return W.x(a)+w},x2:function(a){return W.x(a)+w},y1:0,y2:W.height},(k=function(a){e=W.generateGridData(Z[gc],W.x),w=W.isCategorized()?W.xAxis.tickOffset():0,c=X.select("."+qe[Td]).selectAll("."+qe[Sd]).data(e),c.enter().append("line").attr("class",qe[Sd]),a||c.attr(d).style("opacity",function(){return+Y.select(this).attr(Z[vb]?"y1":"x1")===(Z[vb]?W.height:0)?0:1}),c.exit().remove()})()),f=X.select("."+qe[Vd]).selectAll("."+qe[Ud]).data(Z[hc]),g=f.enter().append("g").attr("class",function(a){return qe[Ud]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",Z[vb]?"":"rotate(-90)").attr("dx",Z[vb]?0:-W.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&Z[ic]&&(h=X.select("."+qe[Yd]).selectAll("."+qe[Xd]).data(W.y.ticks(Z[kc])),h.enter().append("line").attr("class",qe[Xd]),h.attr("x1",Z[vb]?W.y:0).attr("x2",Z[vb]?W.y:W.width).attr("y1",Z[vb]?0:W.y).attr("y2",Z[vb]?W.height:W.y),h.exit().remove(),W.smoothLines(h,"grid")),B){i=X.select("."+qe[$d]).selectAll("."+qe[Zd]).data(Z[jc]),j=i.enter().append("g").attr("class",function(a){return qe[Zd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",Z[vb]?"rotate(-90)":"").attr("dx",Z[vb]?0:-W.margin.top).attr("dy",-5).style("opacity",0);var db=Ee(W.yv,W);i.select("line").transition().duration(P).attr("x1",Z[vb]?db:0).attr("x2",Z[vb]?db:W.width).attr("y1",Z[vb]?0:db).attr("y2",Z[vb]?W.height:db).style("opacity",1),i.select("text").transition().duration(P).attr("x",Z[vb]?0:W.width).attr("y",db).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()}q=X.select("."+qe[yd]).selectAll("."+qe[xd]).data(Z[Qc]),q.enter().append("g").attr("class",Ee(W.classRegion,W)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=X.selectAll("."+qe[Gd]).selectAll("."+qe[Fd]).data(Ee(W.barData,W)),p.enter().append("path").attr("class",Ee(W.classBar,W)).style("stroke",function(a){return W.color(a.id)}).style("fill",function(a){return W.color(a.id)}),p.style("opacity",Ee(W.initialOpacity,W)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=X.selectAll("."+qe[Ed]).selectAll("."+qe[Dd]).data(Ee(W.lineData,W)),l.enter().append("path").attr("class",Ee(W.classLine,W)).style("stroke",W.color),l.style("opacity",Ee(W.initialOpacity,W)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=X.selectAll("."+qe[Md]).selectAll("."+qe[Ld]).data(Ee(W.lineData,W)),m.enter().append("path").attr("class",Ee(W.classArea,W)).style("fill",W.color).style("opacity",function(){return W.orgAreaOpacity=+Y.select(this).style("opacity"),0}),m.style("opacity",W.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),Z[mc]&&(n=X.selectAll("."+qe[Id]).selectAll("."+qe[Hd]).data(Ee(W.lineOrScatterData,W)),n.enter().append("circle").attr("class",Ee(W.classCircle,W)).attr("r",Ee(W.pointR,W)).style("fill",W.color),n.style("opacity",Ee(W.initialOpacity,W)),n.exit().remove()),W.hasDataLabel()&&(r=X.selectAll("."+qe[Pd]).selectAll("."+qe[Od]).data(Ee(W.barOrLineData,W)),r.enter().append("text").attr("class",Ee(W.classText,W)).attr("text-anchor",function(a){return Z[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return W.color(a)}).style("fill-opacity",0),r.text(function(a){return W.formatByAxisId(W.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),se(W.redrawArc)&&W.redrawArc(P,Q,G),se(W.redrawSubchart)&&W.redrawSubchart(C,b,P,Q,$,_,ab),X.selectAll("."+qe[pd]).filter(Ee(W.isBarType,W)).selectAll("circle").remove(),Z[s]&&(t=X.select("."+qe[rd]).style("cursor",Z[o]?Z[vb]?"ns-resize":"ew-resize":null),Ae(Z[z])&&!W.isSingleX(Z[z])?(t.classed(qe[td])||t.classed(qe[td],!0).classed(qe[sd],!1).selectAll("."+qe[qd]).remove(),u=X.select("."+qe[rd]).selectAll("."+qe[qd]).data([0]),W.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",W.width).attr("height",W.height)):(t.classed(qe[sd])||t.classed(qe[td],!1).classed(qe[sd],!0).selectAll("."+qe[qd]).remove(),!W.isCustomX()&&!W.isTimeSeries()||W.isCategorized()?(A=W.getEventRectWidth(),y=function(a){return W.x(a.x)-A/2}):(A=function(a){var b=W.getPrevX(a.index),c=W.getNextX(a.index),d=W.data.xs[a.id][a.index],e=(W.x(c?c:d)-W.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=W.getPrevX(a.index),c=W.data.xs[a.id][a.index];return(W.x(c)+W.x(b?b:c))/2}),v=W.getMaxDataCountTarget(W.data.targets),X.select("."+qe[rd]).datum(v?v.values:[]),u=X.select("."+qe[rd]).selectAll("."+qe[qd]).data(function(a){return a}),W.generateEventRectsForSingleX(u.enter()),u.attr("class",Ee(W.classEvent,W)).attr("x",Z[vb]?0:y).attr("y",Z[vb]?y:0).attr("width",Z[vb]?W.width:A).attr("height",Z[vb]?A:W.height),u.exit().remove()));var eb=Ee(W.xv,W);Y.transition().duration(P).each(function(){var b=[],c=Ee(W.config[vb]?W.circleY:W.circleX,W),d=Ee(W.config[vb]?W.circleX:W.circleY,W);b.push(p.transition().attr("d",L).style("fill",W.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",W.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",W.color).style("opacity",W.orgAreaOpacity)),b.push(n.transition().style("opacity",Ee(W.opacityForCircle,W)).style("fill",W.color).attr("cx",c).attr("cy",d)),b.push(X.selectAll("."+qe[od]).transition().attr("cx",c).attr("cy",d)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",W.color).style("fill-opacity",a.flow?0:Ee(W.opacityForText,W))),b.push(q.selectAll("rect").transition().attr("x",W.regionX).attr("y",W.regionY).attr("width",W.regionWidth).attr("height",W.regionHeight).style("fill-opacity",function(a){return re(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",Z[vb]?0:eb).attr("x2",Z[vb]?W.width:eb).attr("y1",Z[vb]?eb:W.margin.top).attr("y2",Z[vb]?eb:W.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",Z[vb]?W.width:0).attr("y",eb).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=W.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=W.getValueOnIndex(W.data.targets[0].values,i),s=W.getValueOnIndex(W.data.targets[0].values,i+j),t=W.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=W.generateWait();W.data.targets.forEach(function(a){a.values.splice(0,j)}),g=W.updateXDomain(cb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?W.x(t[0])-W.x(g[0]):W.isTimeSeries()?W.x(t[0])-W.x(g[0]):W.x(o.x)-W.x(s.x):1!==W.data.targets[0].values.length?b=W.x(t[0])-W.x(g[0]):W.isTimeSeries()?(o=W.getValueOnIndex(W.data.targets[0].values,0),s=W.getValueOnIndex(W.data.targets[0].values,W.data.targets[0].values.length-1),b=W.x(o.x)-W.x(s.x)):b=ye(g)/2,h=ye(t)/ye(g),e="translate("+b+",0) scale("+h+",1)",Y.transition().ease("linear").duration(v).each(function(){x.add(W.axes.x.transition().call(W.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter(W.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+qe[Bd]+"-"+(i+a)),e.push("."+qe[Od]+"-"+(i+a)),g.push("."+qe[qd]+"-"+(i+a));W.svg.selectAll("."+qe[Cd]).selectAll(b).remove(),W.svg.selectAll("."+qe[Pd]).selectAll(e).remove(),W.svg.selectAll("."+qe[rd]).selectAll(g).remove(),W.svg.select("."+qe[Sd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",Z[vb]?0:eb).attr("x2",Z[vb]?W.width:eb),f.select("text").attr("x",Z[vb]?W.width:0).attr("y",eb),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Z[vb]?W.circleY:W.circleX).attr("cy",Z[vb]?W.circleX:W.circleY),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",Ee(W.opacityForText,W)),q.attr("transform",null),q.select("rect").filter(W.isRegionOnX).attr("x",W.regionX).attr("width",W.regionWidth),u.attr("x",Z[vb]?0:y).attr("y",Z[vb]?y:0).attr("width",Z[vb]?W.width:A).attr("height",Z[vb]?A:W.height),w()})}),W.mapToIds(W.data.targets).forEach(function(a){W.withoutFadeIn[a]=!0}),se(W.updateZoom)&&W.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Be(a,"withTransition",!0),a.withTransform=Be(a,"withTransform",!1),a.withLegend=Be(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Be(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",Ee(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||Ae(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=xe(d.margin.left),c=xe(d.margin.top)):"context"===a?(b=xe(d.margin2.left),c=xe(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return re(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+qe[ae]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+qe[ce]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+qe[ee]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+qe[id]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),$c[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",Ee(a.getXAxisClipX,a)).attr("y",Ee(a.getXAxisClipY,a)).attr("width",Ee(a.getXAxisClipWidth,a)).attr("height",Ee(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",Ee(a.getYAxisClipX,a)).attr("y",Ee(a.getYAxisClipY,a)).attr("width",Ee(a.getYAxisClipWidth,a)).attr("height",Ee(a.getYAxisClipHeight,a)),a.svg.select("."+qe[ud]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat($c[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_x_format",B="data_x_localtime",C="data_id_converter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position",$c=f.config={}; +$c[h]="#chart",$c[i]=void 0,$c[j]=void 0,$c[k]=void 0,$c[l]=void 0,$c[m]=void 0,$c[n]=void 0,$c[o]=!1,$c[p]=void 0,$c[q]=!1,$c[r]=function(){},$c[s]=!0,$c[t]=function(){},$c[u]=function(){},$c[v]=function(){},$c[w]=function(){},$c[x]=350,$c[y]=void 0,$c[z]={},$c[A]="%Y-%m-%d",$c[B]=!0,$c[C]=function(a){return a},$c[D]={},$c[E]={},$c[F]=[],$c[G]={},$c[H]=void 0,$c[I]={},$c[J]={},$c[K]="desc",$c[L]={},$c[M]=void 0,$c[N]={},$c[O]=!1,$c[P]=void 0,$c[Q]=!1,$c[R]=!1,$c[S]=function(){return!0},$c[T]=!0,$c[U]=function(){},$c[V]=function(){},$c[W]=function(){},$c[X]=function(){},$c[Y]=function(){},$c[Z]=function(){},$c[$]=function(){},$c[_]=void 0,$c[ab]=void 0,$c[bb]=void 0,$c[cb]=void 0,$c[db]=void 0,$c[eb]=void 0,$c[fb]="",$c[gb]=!1,$c[hb]=60,$c[ib]=function(){},$c[jb]=[],$c[kb]={},$c[lb]=!0,$c[mb]="bottom",$c[nb]="top-left",$c[ob]=10,$c[pb]=0,$c[qb]=void 0,$c[rb]=void 0,$c[sb]=void 0,$c[tb]=void 0,$c[ub]=!1,$c[vb]=!1,$c[wb]=!0,$c[xb]="indexed",$c[yb]=!0,$c[zb]=[],$c[Ab]=!1,$c[Bb]=void 0,$c[Cb]={},$c[Db]=10,$c[Eb]=void 0,$c[Fb]=!0,$c[Gb]=null,$c[Hb]=void 0,$c[Ib]=!0,$c[Jb]=null,$c[Kb]=null,$c[Lb]={},$c[Mb]=void 0,$c[Nb]=void 0,$c[Ob]={},$c[Pb]=!0,$c[Qb]=void 0,$c[Rb]=void 0,$c[Sb]=void 0,$c[Tb]={},$c[Ub]=void 0,$c[Vb]=!0,$c[Wb]=void 0,$c[Xb]=10,$c[Yb]=!1,$c[Zb]=void 0,$c[$b]=void 0,$c[_b]=void 0,$c[ac]={},$c[bc]=void 0,$c[cc]=!0,$c[dc]=void 0,$c[ec]=10,$c[fc]=!1,$c[gc]="tick",$c[hc]=[],$c[ic]=!1,$c[jc]=[],$c[kc]=10,$c[lc]=!0,$c[mc]=!0,$c[nc]=2.5,$c[oc]=!0,$c[pc]=void 0,$c[qc]=void 0,$c[rc]=!1,$c[sc]=void 0,$c[tc]=.6,$c[uc]=void 0,$c[vc]=!0,$c[wc]=!0,$c[xc]=!0,$c[yc]=void 0,$c[zc]=.05,$c[Ac]=!0,$c[Bc]=!0,$c[Cc]=!0,$c[Dc]=void 0,$c[Ec]=!0,$c[Fc]=0,$c[Gc]=100,$c[Hc]=void 0,$c[Ic]=void 0,$c[Jc]=!0,$c[Kc]=void 0,$c[Lc]=.05,$c[Mc]=void 0,$c[Nc]=!0,$c[Oc]=!0,$c[Pc]="",$c[Qc]=[],$c[Rc]=!0,$c[Sc]=!0,$c[Tc]=void 0,$c[Uc]=void 0,$c[Vc]=void 0,$c[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,c,c,d):""},$c[Xc]=!1,$c[Yc]=0,$c[Zc]={top:"0px",left:"50px"},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ve(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),se(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=re(p)?p:m.getYDomainMin(o),s=re(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=ye(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&Ae(g[Lb])?(d=re(g[Lb].left)?g[Lb].left:c,e=re(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||Ae(c[z])&&Ce(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:Ae(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&Ae(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&re(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?te(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):se(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return re(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&Ae(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d(g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=ue(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(re).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():Ae(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(ue(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ve(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return re(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return re(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return re(b[k])?b[k]:b[vb]?b[wb]?Math.max(we(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?we(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return re(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?we(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?qe[ae]:qe[ce],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+qe[Id]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+qe[Hd]+(re(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(qe[ne],!0).attr("r",Ee(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(qe[ne])}).classed(qe[ne],!1).attr("r",Ee(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?se(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+qe[Fd]+(re(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(qe[ne],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(qe[ne],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),function(a){var b,f=c.filterRemoveNull(a.values),g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e(d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return $c[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=$c[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ve(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=te(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=te(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=te(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=te(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=te(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=te(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=te(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=te(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=te(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=a.filter(function(a){return a&&re(a.value)});if($c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var d=b.main.selectAll("line."+qe[Wd]);d.style("visibility","visible").data([c[0]]).attr($c[vb]?"y1":"x1",Ee(b.xx,b)).attr($c[vb]?"y2":"x2",Ee(b.xx,b)),b.smoothLines(d,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+qe[Wd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+qe[Wd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+qe[ae]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?qe[Vd]:qe[$d],h=b?qe[Ud]:qe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&te(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&re(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),$c[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1}) +},f.updateSizeForLegend=function(a,b){var c=this,d={top:c.isLegendTop?c.getCurrentPaddingTop()+$c[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-$c[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+$c[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-$c[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?d.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?d.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(qe[ke])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(qe[ke])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+qe[he]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+qe[he]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ze(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-y-k)/2,x>f&&(f=(l-k)/2,y=0,F++)),E[a]=F,C[F]=r.isLegendInset?10:f,z[a]=y,y+=k}var f,g,h=r.getTextRect(b.textContent,qe[he]),i=10*Math.ceil((h.width+u)/10),j=10*Math.ceil((h.height+t)/10),k=r.isLegendRight||r.isLegendInset?j:i,l=r.isLegendRight||r.isLegendInset?r.getLegendHeight():r.getLegendWidth();return d&&(y=0,F=0,v=0,w=0),s[lb]&&!r.isLegendToShow(c)?void(A[c]=B[c]=E[c]=z[c]=0):(A[c]=i,B[c]=j,(!v||i>=v)&&(v=i),(!w||j>=w)&&(w=j),g=r.isLegendRight||r.isLegendInset?w:v,void(s[ub]?(Object.keys(A).forEach(function(a){A[a]=v}),Object.keys(B).forEach(function(a){B[a]=w}),f=(l-g*a.length)/2,x>f?(y=0,F=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,h,i,j,k,l,m,n,o,p,q,r=this,s=r.config,t=4,u=36,v=0,w=0,x=10,y=0,z={},A={},B={},C=[0],E={},F=0,G=r.legend.selectAll("."+qe[le]).size();b=b||{},m=Be(b,"withTransition",!0),n=Be(b,"withTransitionForTransform",!0),r.isLegendRight?(e=function(a){return v*E[a]},i=function(a){return C[E[a]]+z[a]}):r.isLegendInset?(e=function(a){return v*E[a]+10},i=function(a){return C[E[a]]+z[a]}):(e=function(a){return C[E[a]]+z[a]},i=function(a){return w*E[a]}),f=function(a,b){return e(a,b)+14},j=function(a,b){return i(a,b)+9},h=function(a,b){return e(a,b)-4},k=function(a,b){return i(a,b)-7},l=r.legend.selectAll("."+qe[he]).data(a).enter().append("g").attr("class",function(a){return r.generateClass(qe[he],a)}).style("visibility",function(a){return r.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){se(s[rb])?s[rb].call(g,a):r.api.toggle(a)}).on("mouseover",function(a){r.d3.select(this).classed(qe[le],!0),r.transiting||r.api.focus(a),se(s[sb])&&s[sb].call(r,a)}).on("mouseout",function(a){r.d3.select(this).classed(qe[le],!1),r.transiting||r.api.revert(),se(s[tb])&&s[tb].call(r,a)}),l.append("text").text(function(a){return ve(s[D][a])?s[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",r.isLegendRight||r.isLegendInset?f:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:j),l.append("rect").attr("class",qe[ie]).style("fill-opacity",0).attr("x",r.isLegendRight||r.isLegendInset?h:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:k),l.append("rect").attr("class",qe[je]).style("pointer-events","none").style("fill",r.color).attr("x",r.isLegendRight||r.isLegendInset?f:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:i).attr("width",10).attr("height",10),r.isLegendInset&&0!==v&&r.legend.insert("g","."+qe[he]).attr("class",qe[ge]).append("rect").attr("height",r.getLegendHeight()-10).attr("width",v*(F+1)+10),o=r.legend.selectAll("text").data(a).text(function(a){return ve(s[D][a])?s[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(m?o.transition():o).attr("x",f).attr("y",j),p=r.legend.selectAll("rect."+qe[ie]).data(a),(m?p.transition():p).attr("width",function(a){return A[a]}).attr("height",function(a){return B[a]}).attr("x",h).attr("y",k),q=r.legend.selectAll("rect."+qe[je]).data(a),(m?q.transition():q).style("fill",r.color).attr("x",e).attr("y",i),r.legend.selectAll("."+qe[he]).classed(qe[ke],function(a){return!r.isTargetToShow(a)}).transition().style("opacity",function(a){var b=r.d3.select(this);return r.isTargetToShow(a)?!G||b.classed(qe[le])?r.opacityForLegend(b):r.opacityForUnfocusedLegend(b):r.legendOpacityForHidden}),r.updateLegendItemWidth(v),r.updateLegendItemHeight(w),r.updateLegendStep(F),r.updateSizes(),r.updateScales(),r.updateSvgSize(),r.transformAll(n,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ze(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(se(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return te(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);te(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+qe[ae]+" ."+qe[be]),d=b.main.select("."+qe[ce]+" ."+qe[de]),e=b.main.select("."+qe[ee]+" ."+qe[fe]);(a?c.transition():c).attr("x",Ee(b.xForXAxisLabel,b)).attr("dx",Ee(b.dxForXAxisLabel,b)).attr("dy",Ee(b.dyForXAxisLabel,b)).text(Ee(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",Ee(b.xForYAxisLabel,b)).attr("dx",Ee(b.dxForYAxisLabel,b)).attr("dy",Ee(b.dyForYAxisLabel,b)).text(Ee(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",Ee(b.xForY2AxisLabel,b)).attr("dx",Ee(b.dxForY2AxisLabel,b)).attr("dy",Ee(b.dyForY2AxisLabel,b)).text(Ee(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return re(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=se(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+qe[hd]+c.selectorTarget(a)),e=c.svg.selectAll("."+qe[Jd]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+qe[hd]+b.selectorTarget(a));c.selectAll("path."+qe[Jd]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+qe[Jd]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+qe[id]).selectAll("."+qe[hd]).data(d.pie(a)).attr("class",Ee(d.classChartArc,d)),c=b.enter().append("g").attr("class",Ee(d.classChartArc,d)),c.append("g").attr("class",Ee(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a,b=this;a=b.main.select("."+qe[ad]).append("g").attr("class",qe[id]).attr("transform",b.getTranslate("arc")),a.append("text").attr("class",qe[jd]).style("text-anchor","middle").text(b.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+qe[Kd]).selectAll("."+qe[Jd]).data(Ee(e.arcData,e)),d.enter().append("path").attr("class",Ee(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+qe[hd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?qe[Qd]:""}).text(Ee(e.textForArcLabel,e)).attr("transform",Ee(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+qe[jd]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a,b=this,c=b.config;b.hasType("gauge")&&(a.append("path").attr("class",qe[kd]).attr("d",function(){var a={data:[{value:c[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return b.getArc(a,!0,!0)}),a.append("text").attr("dy",".75em").attr("class",qe[ld]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Hc]:""),a.append("text").attr("dx",-1*(b.innerRadius+(b.radius-b.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",qe[nd]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Fc]:""),a.append("text").attr("dx",b.innerRadius+(b.radius-b.innerRadius)/2+"px").attr("dy","1.2em").attr("class",qe[md]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+qe[me]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(qe[oe]),q=o.classed(qe[pe]),r=!1;if(o.classed(qe[Hd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(qe[Fd]))return;n=De(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(qe[pe],!q),o.classed(qe[oe],!p),j.toggle(!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+qe[ad]).append("rect").attr("class",qe[me]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+qe[me]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+qe[Bd]).classed(qe[pe],!1),a.dragging=!1,a.config[$]())},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[vd]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",qe[ad]),c.select("."+qe[ad]).append("g").attr("class",qe[ed]),c.select("."+qe[ad]).append("g").attr("class",qe[cd]),c.append("g").attr("clip-path",a.clipPath).attr("class",qe[vd]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",qe[ae]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+qe[ed]).selectAll("."+qe[dd]).data(a).attr("class",Ee(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",Ee(f.classChartBar,f)),d.append("g").attr("class",Ee(f.classBars,f)),c=g.select("."+qe[cd]).selectAll("."+qe[bd]).data(a).attr("class",Ee(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",Ee(f.classChartLine,f)),b.append("g").attr("class",Ee(f.classLines,f)),b.append("g").attr("class",Ee(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+qe[Gd]).selectAll("."+qe[Fd]).data(Ee(n.barData,n)),j.enter().append("path").attr("class",Ee(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",Ee(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+qe[Ed]).selectAll("."+qe[Dd]).data(Ee(n.lineData,n)),h.enter().append("path").attr("class",Ee(n.classLine,n)).style("stroke",n.color),h.style("opacity",Ee(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+qe[Md]).selectAll("."+qe[Ld]).data(Ee(n.lineData,n)),i.enter().append("path").attr("class",Ee(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+qe[ae]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",a.redrawForZoom),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=ye(a.x.orgDomain())/ye(a.orgXDomain),c=a.orgScaleExtent();return a.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[ud]).call(b),a.main.selectAll("."+a.CLASS[qd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(g,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=Ae(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return Ae(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Be=f.getOption=function(a,b,c){return ve(a[b])?a[b]:c},Ce=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},De=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},Ee=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),this.defocus(),b(e.classed(qe[wd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),b(e.classed(qe[wd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));b(e.classed(qe[wd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),se(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ve(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:re(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+qe[Cd]+b.getTargetSelectorSuffix(a)).selectAll("."+qe[Bd]).filter(function(){return c.select(this).classed(qe[oe])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(qe[oe]);i.classed(qe[Dd])||i.classed(qe[Ld])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(qe[oe],!0),g,h):ve(c)&&c&&n&&k(!1,i.classed(qe[oe],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(qe[oe]);h.classed(qe[Dd])||h.classed(qe[Ld])||k&&l&&e[S](f)&&m&&j(!1,h.classed(qe[oe],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return ue(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return g.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[qe[xd]]),d=e.main.select("."+qe[yd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ve(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(re(a.x)&&(c[Jb]=a.x),re(a.y)&&(c[Qb]=a.y),re(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(re(a.x)&&(c[Kb]=a.x),re(a.y)&&(c[Rb]=a.y),re(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ve(a.max)&&this.axis.max(a.max),ve(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/api.js b/src/api.js new file mode 100644 index 0000000..f03e313 --- /dev/null +++ b/src/api.js @@ -0,0 +1,573 @@ +c3_chart_fn.focus = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + function focus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + this.revert(); + this.defocus(); + focus(candidatesForNoneArc.classed(CLASS[_focused], true)); + focus(candidatesForArc); + if ($$.hasArcType()) { + $$.expandArc(targetId, true); + } + $$.toggleFocusLegend(targetId, true); +}; + +c3_chart_fn.defocus = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + function defocus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); + } + this.revert(); + defocus(candidatesForNoneArc.classed(CLASS[_focused], false)); + defocus(candidatesForArc); + if ($$.hasArcType()) { + $$.unexpandArc(targetId); + } + $$.toggleFocusLegend(targetId, false); +}; + +c3_chart_fn.revert = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), + candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + function revert(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + revert(candidatesForNoneArc.classed(CLASS[_focused], false)); + revert(candidatesForArc); + if ($$.hasArcType()) { + $$.unexpandArc(targetId); + } + $$.revertLegend(); +}; + +c3_chart_fn.show = function (targetIds, options) { + var $$ = this.internal; + + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; + + $$.removeHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 1); + + if (options.withLegend) { + $$.showLegend(targetIds); + } + + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); +}; + +c3_chart_fn.hide = function (targetIds, options) { + var $$ = this.internal; + + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; + + $$.addHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 0); + + if (options.withLegend) { + $$.hideLegend(targetIds); + } + + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); +}; + +c3_chart_fn.toggle = function (targetId) { + var $$ = this.internal; + $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); +}; + +c3_chart_fn.zoom = function () { +}; +c3_chart_fn.zoom.enable = function (enabled) { + var $$ = this.internal; + $$.config[__zoom_enabled] = enabled; + $$.updateAndRedraw(); +}; +c3_chart_fn.unzoom = function () { + var $$ = this.internal; + $$.brush.clear().update(); + $$.redraw({withUpdateXDomain: true}); +}; + +c3_chart_fn.load = function (args) { + var $$ = this.internal, config = $$.config; + // update xs if specified + if (args.xs) { + $$.addXs(args.xs); + } + // update classes if exists + if ('classes' in args) { + Object.keys(args.classes).forEach(function (id) { + config[__data_classes][id] = args.classes[id]; + }); + } + // update categories if exists + if ('categories' in args && $$.isCategorized()) { + config[__axis_x_categories] = args.categories; + } + // use cache if exists + if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { + $$.load($$.getCaches(args.cacheIds), args.done); + return; + } + // unload if needed + if ('unload' in args) { + // TODO: do not unload if target will load (included in url/rows/columns) + $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + $$.loadFromArgs(args); + }); + } else { + $$.loadFromArgs(args); + } +}; + +c3_chart_fn.unload = function (args) { + var $$ = this.internal; + args = args || {}; + $$.unload($$.mapToTargetIds(args.ids), function () { + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + if (isFunction(args.done)) { args.done(); } + }); +}; + +c3_chart_fn.flow = function (args) { + var $$ = this.internal, + targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), + dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + + if (args.json) { + data = $$.convertJsonToData(args.json, args.keys); + } + else if (args.rows) { + data = $$.convertRowsToData(args.rows); + } + else if (args.columns) { + data = $$.convertColumnsToData(args.columns); + } + else { + return; + } + targets = $$.convertDataToTargets(data, true); + + // Update/Add data + $$.data.targets.forEach(function (t) { + var found = false, i, j; + for (i = 0; i < targets.length; i++) { + if (t.id === targets[i].id) { + found = true; + + if (t.values[t.values.length - 1]) { + tail = t.values[t.values.length - 1].index + 1; + } + length = targets[i].values.length; + + for (j = 0; j < length; j++) { + targets[i].values[j].index = tail + j; + if (!$$.isTimeSeries()) { + targets[i].values[j].x = tail + j; + } + } + t.values = t.values.concat(targets[i].values); + + targets.splice(i, 1); + break; + } + } + if (!found) { notfoundIds.push(t.id); } + }); + + // Append null for not found targets + $$.data.targets.forEach(function (t) { + var i, j; + for (i = 0; i < notfoundIds.length; i++) { + if (t.id === notfoundIds[i]) { + tail = t.values[t.values.length - 1].index + 1; + for (j = 0; j < length; j++) { + t.values.push({ + id: t.id, + index: tail + j, + x: $$.isTimeSeries() ? $$.getOtherTargetX(tail + j) : tail + j, + value: null + }); + } + } + } + }); + + // Generate null values for new target + if ($$.data.targets.length) { + targets.forEach(function (t) { + var i, missing = []; + for (i = $$.data.targets[0].values[0].index; i < tail; i++) { + missing.push({ + id: t.id, + index: i, + x: $$.isTimeSeries() ? $$.getOtherTargetX(i) : i, + value: null + }); + } + t.values.forEach(function (v) { + v.index += tail; + if (!$$.isTimeSeries()) { + v.x += tail; + } + }); + t.values = missing.concat(t.values); + }); + } + $$.data.targets = $$.data.targets.concat(targets); // add remained + + // check data count because behavior needs to change when it's only one + dataCount = $$.getMaxDataCount(); + baseTarget = $$.data.targets[0]; + baseValue = baseTarget.values[0]; + + // Update length to flow if needed + if (isDefined(args.to)) { + length = 0; + to = $$.isTimeSeries() ? $$.parseDate(args.to) : args.to; + baseTarget.values.forEach(function (v) { + if (v.x < to) { length++; } + }); + } else if (isDefined(args.length)) { + length = args.length; + } + + // If only one data, update the domain to flow from left edge of the chart + if (!orgDataCount) { + if ($$.isTimeSeries()) { + if (baseTarget.values.length > 1) { + diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; + } else { + diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; + } + } else { + diff = 1; + } + domain = [baseValue.x - diff, baseValue.x]; + $$.updateXDomain(null, true, true, domain); + } else if (orgDataCount === 1) { + if ($$.isTimeSeries()) { + diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; + domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; + $$.updateXDomain(null, true, true, domain); + } + } + + // Set targets + $$.updateTargets($$.data.targets); + + // Redraw with new targets + $$.redraw({ + flow: { + index: baseValue.index, + length: length, + duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], + done: args.done, + orgDataCount: orgDataCount, + }, + withLegend: true, + withTransition: orgDataCount > 1, + }); +}; + +c3_chart_fn.selected = function (targetId) { + var $$ = this.internal, d3 = $$.d3; + return d3.merge( + $$.main.selectAll('.' + CLASS[_shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[_shape]) + .filter(function () { return d3.select(this).classed(CLASS[_SELECTED]); }) + .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) + ); +}; +c3_chart_fn.select = function (ids, indices, resetOther) { + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS[_SELECTED]); + // line/area selection not supported yet + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { + return; + } + if (isTargetId && isTargetIndex) { + if (config[__data_selection_isselectable](d) && !isSelected) { + toggle(true, shape.classed(CLASS[_SELECTED], true), d, i); + } + } else if (isDefined(resetOther) && resetOther) { + if (isSelected) { + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); + } + } + }); +}; +c3_chart_fn.unselect = function (ids, indices) { + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS[_SELECTED]); + // line/area selection not supported yet + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { + return; + } + if (isTargetId && isTargetIndex) { + if (config[__data_selection_isselectable](d)) { + if (isSelected) { + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); + } + } + } + }); +}; + +c3_chart_fn.transform = function (type, targetIds) { + var $$ = this.internal, + options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; + $$.transformTo(targetIds, type, options); +}; + +c3_chart_fn.groups = function (groups) { + var $$ = this.internal, config = $$.config; + if (isUndefined(groups)) { return config[__data_groups]; } + config[__data_groups] = groups; + $$.redraw(); + return config[__data_groups]; +}; + +c3_chart_fn.xgrids = function (grids) { + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_x_lines]; } + config[__grid_x_lines] = grids; + $$.redraw(); + return config[__grid_x_lines]; +}; +c3_chart_fn.xgrids.add = function (grids) { + var $$ = this.internal; + return this.xgrids($$.config[__grid_x_lines].concat(grids ? grids : [])); +}; +c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; + $$.removeGridLines(params, true); +}; + +c3_chart_fn.ygrids = function (grids) { + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_y_lines]; } + config[__grid_y_lines] = grids; + $$.redraw(); + return config[__grid_y_lines]; +}; +c3_chart_fn.ygrids.add = function (grids) { + var $$ = this.internal; + return c3.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); +}; +c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; + $$.removeGridLines(params, false); +}; + +c3_chart_fn.regions = function (regions) { + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = regions; + $$.redraw(); + return config[__regions]; +}; +c3_chart_fn.regions.add = function (regions) { + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = config[__regions].concat(regions); + $$.redraw(); + return config[__regions]; +}; +c3_chart_fn.regions.remove = function (options) { + var $$ = this.internal, config = $$.config, + duration, classes, regions; + + options = options || {}; + duration = $$.getOption(options, "duration", config[__transition_duration]); + classes = $$.getOption(options, "classes", [CLASS[_region]]); + + regions = $$.main.select('.' + CLASS[_regions]).selectAll(classes.map(function (c) { return '.' + c; })); + (duration ? regions.transition().duration(duration) : regions) + .style('opacity', 0) + .remove(); + + config[__regions] = config[__regions].filter(function (region) { + var found = false; + if (!region.class) { + return true; + } + region.class.split(' ').forEach(function (c) { + if (classes.indexOf(c) >= 0) { found = true; } + }); + return !found; + }); + + return config[__regions]; +}; + +c3_chart_fn.data = function () { +}; +c3_chart_fn.data.get = function (targetId) { + var target = this.data.getAsTarget(targetId); + return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; +}; +c3_chart_fn.data.getAsTarget = function (targetId) { + var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); + return targets.length > 0 ? targets[0] : undefined; +}; +c3_chart_fn.data.names = function (names) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_names]; } + Object.keys(names).forEach(function (id) { + config[__data_names][id] = names[id]; + }); + $$.redraw({withLegend: true}); + return config[__data_names]; +}; +c3_chart_fn.data.colors = function (colors) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_colors]; } + Object.keys(colors).forEach(function (id) { + config[__data_colors][id] = colors[id]; + }); + $$.redraw({withLegend: true}); + return config[__data_colors]; +}; +c3_chart_fn.category = function (i, category) { + var $$ = this.internal, config = $$.config; + if (arguments.length > 1) { + config[__axis_x_categories][i] = category; + $$.redraw(); + } + return config[__axis_x_categories][i]; +}; +c3_chart_fn.categories = function (categories) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__axis_x_categories]; } + config[__axis_x_categories] = categories; + $$.redraw(); + return config[__axis_x_categories]; +}; + +// TODO: fix +c3_chart_fn.color = function (id) { + var $$ = this.internal; + return $$.color(id); // more patterns +}; + +c3_chart_fn.x = function (x) { + var $$ = this.internal; + if (arguments.length) { + $$.updateTargetX($$.data.targets, x); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; +}; +c3_chart_fn.xs = function (xs) { + var $$ = this.internal; + if (arguments.length) { + $$.updateTargetXs($$.data.targets, xs); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; +}; + + +c3_chart_fn.axis = function () { +}; +c3_chart_fn.axis.labels = function (labels) { + var $$ = this.internal; + if (arguments.length) { + Object.keys(labels).forEach(function (axisId) { + $$.setAxisLabelText(axisId, labels[axisId]); + }); + $$.updateAxisLabels(); + } + // TODO: return some values? +}; +c3_chart_fn.axis.max = function (max) { + var $$ = this.internal, config = $$.config; + if (arguments.length) { + if (typeof max === 'object') { + if (isValue(max.x)) { config[__axis_x_max] = max.x; } + if (isValue(max.y)) { config[__axis_y_max] = max.y; } + if (isValue(max.y2)) { config[__axis_y2_max] = max.y2; } + } else { + config[__axis_y_max] = config[__axis_y2_max] = max; + } + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } +}; +c3_chart_fn.axis.min = function (min) { + var $$ = this.internal, config = $$.config; + if (arguments.length) { + if (typeof min === 'object') { + if (isValue(min.x)) { config[__axis_x_min] = min.x; } + if (isValue(min.y)) { config[__axis_y_min] = min.y; } + if (isValue(min.y2)) { config[__axis_y2_min] = min.y2; } + } else { + config[__axis_y_min] = config[__axis_y2_min] = min; + } + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } +}; +c3_chart_fn.axis.range = function (range) { + if (arguments.length) { + if (isDefined(range.max)) { this.axis.max(range.max); } + if (isDefined(range.min)) { this.axis.min(range.min); } + } +}; + + +c3_chart_fn.legend = function () { +}; +c3_chart_fn.legend.show = function (targetIds) { + var $$ = this.internal; + $$.showLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); +}; +c3_chart_fn.legend.hide = function (targetIds) { + var $$ = this.internal; + $$.hideLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); +}; + +c3_chart_fn.resize = function (size) { + var $$ = this.internal, config = $$.config; + config[__size_width] = size ? size.width : null; + config[__size_height] = size ? size.height : null; + this.flush(); +}; + +c3_chart_fn.flush = function () { + var $$ = this.internal; + $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); +}; + +c3_chart_fn.destroy = function () { + var $$ = this.internal; + $$.data.targets = undefined; + $$.data.xs = {}; + $$.selectChart.classed('c3', false).html(""); + window.onresize = null; +}; diff --git a/src/arc.js b/src/arc.js new file mode 100644 index 0000000..f729a73 --- /dev/null +++ b/src/arc.js @@ -0,0 +1,359 @@ +c3_chart_internal_fn.initPie = function () { + var $$ = this, d3 = $$.d3, config = $$.config; + $$.pie = d3.layout.pie().value(function (d) { + return d.values.reduce(function (a, b) { return a + b.value; }, 0); + }); + if (!config[__data_order] || !config[__pie_sort] || !config[__donut_sort]) { + $$.pie.sort(null); + } +}; + +c3_chart_internal_fn.updateRadius = function () { + var $$ = this, config = $$.config, + w = config[__gauge_width] || config[__donut_width]; + $$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; + $$.radius = $$.radiusExpanded * 0.95; + $$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; + $$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0; +}; + +c3_chart_internal_fn.updateArc = function () { + var $$ = this; + $$.svgArc = $$.getSvgArc(); + $$.svgArcExpanded = $$.getSvgArcExpanded(); + $$.svgArcExpandedSub = $$.getSvgArcExpanded(0.98); +}; + +c3_chart_internal_fn.updateAngle = function (d) { + var $$ = this, config = $$.config, + found = false, index = 0; + $$.pie($$.filterTargetsToShow($$.data.targets)).sort($$.descByStartAngle).forEach(function (t) { + if (! found && t.data.id === d.data.id) { + found = true; + d = t; + d.index = index; + } + index++; + }); + if (isNaN(d.endAngle)) { + d.endAngle = d.startAngle; + } + if ($$.isGaugeType(d.data)) { + var gMin = config[__gauge_min], gMax = config[__gauge_max], + gF = Math.abs(gMin) + gMax, + aTic = (Math.PI) / gF; + d.startAngle = (-1 * (Math.PI / 2)) + (aTic * Math.abs(gMin)); + d.endAngle = d.startAngle + (aTic * ((d.value > gMax) ? gMax : d.value)); + } + return found ? d : null; +}; + +c3_chart_internal_fn.getSvgArc = function () { + var $$ = this, + arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), + newArc = function (d, withoutUpdate) { + var updated; + if (withoutUpdate) { return arc(d); } // for interpolate + updated = $$.updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; + // TODO: extends all function + newArc.centroid = arc.centroid; + return newArc; +}; + +c3_chart_internal_fn.getSvgArcExpanded = function (rate) { + var $$ = this, + arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); + return function (d) { + var updated = $$.updateAngle(d); + return updated ? arc(updated) : "M 0 0"; + }; +}; + +c3_chart_internal_fn.getArc = function (d, withoutUpdate, force) { + return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0"; +}; + + +c3_chart_internal_fn.transformForArcLabel = function (d) { + var $$ = this, + updated = $$.updateAngle(d), c, x, y, h, ratio, translate = ""; + if (updated && !$$.hasType('gauge')) { + c = this.svgArc.centroid(updated); + x = isNaN(c[0]) ? 0 : c[0]; + y = isNaN(c[1]) ? 0 : c[1]; + h = Math.sqrt(x * x + y * y); + // TODO: ratio should be an option? + ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0; + translate = "translate(" + (x * ratio) + ',' + (y * ratio) + ")"; + } + return translate; +}; + +c3_chart_internal_fn.getArcRatio = function (d) { + var $$ = this, + whole = $$.hasType('gauge') ? Math.PI : (Math.PI * 2); + return d ? (d.endAngle - d.startAngle) / whole : null; +}; + +c3_chart_internal_fn.convertToArcData = function (d) { + return this.addName({ + id: d.data.id, + value: d.value, + ratio: this.getArcRatio(d), + index: d.index + }); +}; + +c3_chart_internal_fn.textForArcLabel = function (d) { + var $$ = this, + updated, value, ratio, format; + if (! $$.shouldShowArcLabel()) { return ""; } + updated = $$.updateAngle(d); + value = updated ? updated.value : null; + ratio = $$.getArcRatio(updated); + if (! $$.hasType('gauge') && ! $$.meetsArcLabelThreshold(ratio)) { return ""; } + format = $$.getArcLabelFormat(); + return format ? format(value, ratio) : $$.defaultArcValueFormat(value, ratio); +}; + +c3_chart_internal_fn.expandArc = function (id, withoutFadeOut) { + var $$ = this, + target = $$.svg.selectAll('.' + CLASS[_chartArc] + $$.selectorTarget(id)), + noneTargets = $$.svg.selectAll('.' + CLASS[_arc]).filter(function (data) { return data.data.id !== id; }); + + if ($$.shouldExpand(id)) { + target.selectAll('path') + .transition().duration(50) + .attr("d", $$.svgArcExpanded) + .transition().duration(100) + .attr("d", $$.svgArcExpandedSub) + .each(function (d) { + if ($$.isDonutType(d.data)) { + // callback here + } + }); + } + if (!withoutFadeOut) { + noneTargets.style("opacity", 0.3); + } +}; + +c3_chart_internal_fn.unexpandArc = function (id) { + var $$ = this, + target = $$.svg.selectAll('.' + CLASS[_chartArc] + $$.selectorTarget(id)); + target.selectAll('path.' + CLASS[_arc]) + .transition().duration(50) + .attr("d", $$.svgArc); + $$.svg.selectAll('.' + CLASS[_arc]) + .style("opacity", 1); +}; + +c3_chart_internal_fn.shouldExpand = function (id) { + var $$ = this, config = $$.config; + return ($$.isDonutType(id) && config[__donut_expand]) || ($$.isGaugeType(id) && config[__gauge_expand]) || ($$.isPieType(id) && config[__pie_expand]); +}; + +c3_chart_internal_fn.shouldShowArcLabel = function () { + var $$ = this, config = $$.config, shouldShow = true; + if ($$.hasType('donut')) { + shouldShow = config[__donut_label_show]; + } else if ($$.hasType('pie')) { + shouldShow = config[__pie_label_show]; + } + // when gauge, always true + return shouldShow; +}; + +c3_chart_internal_fn.meetsArcLabelThreshold = function (ratio) { + var $$ = this, config = $$.config, + threshold = $$.hasType('donut') ? config[__donut_label_threshold] : config[__pie_label_threshold]; + return ratio >= threshold; +}; + +c3_chart_internal_fn.getArcLabelFormat = function () { + var $$ = this, config = $$.config, + format = config[__pie_label_format]; + if ($$.hasType('gauge')) { + format = config[__gauge_label_format]; + } else if ($$.hasType('donut')) { + format = config[__donut_label_format]; + } + return format; +}; + +c3_chart_internal_fn.getArcTitle = function () { + var $$ = this; + return $$.hasType('donut') ? $$.config[__donut_title] : ""; +}; + +c3_chart_internal_fn.descByStartAngle = function (a, b) { + return a.startAngle - b.startAngle; +}; + +c3_chart_internal_fn.updateTargetsForArc = function (targets) { + var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; + mainPieUpdate = main.select('.' + CLASS[_chartArcs]).selectAll('.' + CLASS[_chartArc]) + .data($$.pie(targets)) + .attr("class", generateCall($$.classChartArc, $$)); + mainPieEnter = mainPieUpdate.enter().append("g") + .attr("class", generateCall($$.classChartArc, $$)); + mainPieEnter.append('g') + .attr('class', generateCall($$.classArcs, $$)); + mainPieEnter.append("text") + .attr("dy", $$.hasType('gauge') ? "-0.35em" : ".35em") + .style("opacity", 0) + .style("text-anchor", "middle") + .style("pointer-events", "none"); + // MEMO: can not keep same color..., but not bad to update color in redraw + //mainPieUpdate.exit().remove(); +}; + +c3_chart_internal_fn.initArc = function () { + var $$ = this, arcs; + arcs = $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartArcs]) + .attr("transform", $$.getTranslate('arc')); + arcs.append('text') + .attr('class', CLASS[_chartArcsTitle]) + .style("text-anchor", "middle") + .text($$.getArcTitle()); +}; + +c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransform) { + var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, + mainArc; + mainArc = main.selectAll('.' + CLASS[_arcs]).selectAll('.' + CLASS[_arc]) + .data(generateCall($$.arcData, $$)); + mainArc.enter().append('path') + .attr("class", generateCall($$.classArc, $$)) + .style("fill", function (d) { return $$.color(d.data); }) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) + .style("opacity", 0) + .each(function (d) { + if ($$.isGaugeType(d.data)) { + d.startAngle = d.endAngle = -1 * (Math.PI / 2); + } + this._current = d; + }) + .on('mouseover', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; + } + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); + // transitions + $$.expandArc(updated.data.id); + $$.toggleFocusLegend(updated.data.id, true); + $$.config[__data_onmouseover](arcData, this); + }) + .on('mousemove', function (d) { + var updated = $$.updateAngle(d), + arcData = $$.convertToArcData(updated), + selectedData = [arcData]; + $$.showTooltip(selectedData, d3.mouse(this)); + }) + .on('mouseout', function (d) { + var updated, arcData; + if ($$.transiting) { // skip while transiting + return; + } + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); + // transitions + $$.unexpandArc(updated.data.id); + $$.revertLegend(); + $$.hideTooltip(); + $$.config[__data_onmouseout](arcData, this); + }) + .on('click', function (d, i) { + var updated, arcData; + if (!$$.toggleShape) { + return; + } + updated = $$.updateAngle(d); + arcData = $$.convertToArcData(updated); + $$.toggleShape(this, arcData, i); // onclick called in toogleShape() + }); + mainArc + .attr("transform", function (d) { return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; }) + .style("opacity", function (d) { return d === this._current ? 0 : 1; }) + .each(function () { $$.transiting = true; }) + .transition().duration(duration) + .attrTween("d", function (d) { + var updated = $$.updateAngle(d), interpolate; + if (! updated) { + return function () { return "M 0 0"; }; + } + // if (this._current === d) { + // this._current = { + // startAngle: Math.PI*2, + // endAngle: Math.PI*2, + // }; + // } + if (isNaN(this._current.endAngle)) { + this._current.endAngle = this._current.startAngle; + } + interpolate = d3.interpolate(this._current, updated); + this._current = interpolate(0); + return function (t) { return $$.getArc(interpolate(t), true); }; + }) + .attr("transform", withTransform ? "scale(1)" : "") + .style("fill", function (d) { + return $$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data.id); + }) // Where gauge reading color would receive customization. + .style("opacity", 1) + .call($$.endall, function () { + $$.transiting = false; + }); + mainArc.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + main.selectAll('.' + CLASS[_chartArc]).select('text') + .style("opacity", 0) + .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[_gaugeValue] : ''; }) + .text(generateCall($$.textForArcLabel, $$)) + .attr("transform", generateCall($$.transformForArcLabel, $$)) + .transition().duration(duration) + .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); + main.select('.' + CLASS[_chartArcsTitle]) + .style("opacity", $$.hasType('donut') || $$.hasType('gauge') ? 1 : 0); + +}; +c3_chart_internal_fn.initGauge = function () { + var $$ = this, config = $$.config, arcs; + if ($$.hasType('gauge')) { + arcs.append('path') + .attr("class", CLASS[_chartArcsBackground]) + .attr("d", function () { + var d = { + data: [{value: config[__gauge_max]}], + startAngle: -1 * (Math.PI / 2), + endAngle: Math.PI / 2 + }; + return $$.getArc(d, true, true); + }); + arcs.append("text") + .attr("dy", ".75em") + .attr("class", CLASS[_chartArcsGaugeUnit]) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(config[__gauge_label_show] ? config[__gauge_units] : ''); + arcs.append("text") + .attr("dx", -1 * ($$.innerRadius + (($$.radius - $$.innerRadius) / 2)) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS[_chartArcsGaugeMin]) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(config[__gauge_label_show] ? config[__gauge_min] : ''); + arcs.append("text") + .attr("dx", $$.innerRadius + (($$.radius - $$.innerRadius) / 2) + "px") + .attr("dy", "1.2em") + .attr("class", CLASS[_chartArcsGaugeMax]) + .style("text-anchor", "middle") + .style("pointer-events", "none") + .text(config[__gauge_label_show] ? config[__gauge_max] : ''); + } +}; diff --git a/src/axis.js b/src/axis.js new file mode 100644 index 0000000..63b3cd2 --- /dev/null +++ b/src/axis.js @@ -0,0 +1,283 @@ +c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { + var $$ = this, config = $$.config, + axis = c3_axis($$.d3, $$.isCategorized()).scale(scale).orient(orient); + + // 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; + } + } else { + // TODO: move this to c3_axis + axis.tickOffset = function () { + var edgeX = $$.getEdgeX($$.data.targets), diff = $$.x(edgeX[1]) - $$.x(edgeX[0]), + base = diff ? diff : (config[__axis_rotated] ? $$.height : $$.width); + return (base / $$.getMaxDataCount()) / 2; + }; + } + + return axis; +}; +c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks) { + return c3_axis(this.d3).scale(scale).orient(orient).tickFormat(tickFormat).ticks(ticks); +}; +c3_chart_internal_fn.getAxisId = function (id) { + var config = this.config; + return id in config[__data_axes] ? config[__data_axes][id] : 'y'; +}; +c3_chart_internal_fn.getXAxisTickFormat = function () { + var $$ = this, 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 (date) { + return date ? $$.axisTimeFormat(config[__axis_x_tick_format])(date) : ""; + }; + } + } + return function (v) { return format.call($$, v); }; +}; +c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { + var $$ = this, 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; +}; +c3_chart_internal_fn.getAxisLabelText = function (axisId) { + var option = this.getAxisLabelOptionByAxisId(axisId); + return isString(option) ? option : option ? option.text : null; +}; +c3_chart_internal_fn.setAxisLabelText = function (axisId, text) { + var $$ = this, config = $$.config, + option = $$.getAxisLabelOptionByAxisId(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; + } +}; +c3_chart_internal_fn.getAxisLabelPosition = function (axisId, defaultPosition) { + var option = this.getAxisLabelOptionByAxisId(axisId), + position = (option && 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 + }; +}; +c3_chart_internal_fn.getXAxisLabelPosition = function () { + return this.getAxisLabelPosition('x', this.config[__axis_rotated] ? 'inner-top' : 'inner-right'); +}; +c3_chart_internal_fn.getYAxisLabelPosition = function () { + return this.getAxisLabelPosition('y', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); +}; +c3_chart_internal_fn.getY2AxisLabelPosition = function () { + return this.getAxisLabelPosition('y2', this.config[__axis_rotated] ? 'inner-right' : 'inner-top'); +}; +c3_chart_internal_fn.getAxisLabelPositionById = function (id) { + return id === 'y2' ? this.getY2AxisLabelPosition() : id === 'y' ? this.getYAxisLabelPosition() : this.getXAxisLabelPosition(); +}; +c3_chart_internal_fn.textForXAxisLabel = function () { + return this.getAxisLabelText('x'); +}; +c3_chart_internal_fn.textForYAxisLabel = function () { + return this.getAxisLabelText('y'); +}; +c3_chart_internal_fn.textForY2AxisLabel = function () { + return this.getAxisLabelText('y2'); +}; +c3_chart_internal_fn.xForAxisLabel = function (forHorizontal, position) { + var $$ = this; + if (forHorizontal) { + return position.isLeft ? 0 : position.isCenter ? $$.width / 2 : $$.width; + } else { + return position.isBottom ? -$$.height : position.isMiddle ? -$$.height / 2 : 0; + } +}; +c3_chart_internal_fn.dxForAxisLabel = function (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"; + } +}; +c3_chart_internal_fn.textAnchorForAxisLabel = function (forHorizontal, position) { + if (forHorizontal) { + return position.isLeft ? 'start' : position.isCenter ? 'middle' : 'end'; + } else { + return position.isBottom ? 'start' : position.isMiddle ? 'middle' : 'end'; + } +}; +c3_chart_internal_fn.xForXAxisLabel = function () { + return this.xForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); +}; +c3_chart_internal_fn.xForYAxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); +}; +c3_chart_internal_fn.xForY2AxisLabel = function () { + return this.xForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); +}; +c3_chart_internal_fn.dxForXAxisLabel = function () { + return this.dxForAxisLabel(!this.config[__axis_rotated], this.getXAxisLabelPosition()); +}; +c3_chart_internal_fn.dxForYAxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getYAxisLabelPosition()); +}; +c3_chart_internal_fn.dxForY2AxisLabel = function () { + return this.dxForAxisLabel(this.config[__axis_rotated], this.getY2AxisLabelPosition()); +}; +c3_chart_internal_fn.dyForXAxisLabel = function () { + var $$ = this, config = $$.config, + position = $$.getXAxisLabelPosition(); + if (config[__axis_rotated]) { + return position.isInner ? "1.2em" : -25 - $$.getMaxTickWidth('x'); + } else { + return position.isInner ? "-0.5em" : config[__axis_x_height] ? config[__axis_x_height] - 10 : "3em"; + } +}; +c3_chart_internal_fn.dyForYAxisLabel = function () { + var $$ = this, + position = $$.getYAxisLabelPosition(); + if ($$.config[__axis_rotated]) { + return position.isInner ? "-0.5em" : "3em"; + } else { + return position.isInner ? "1.2em" : -20 - $$.getMaxTickWidth('y'); + } +}; +c3_chart_internal_fn.dyForY2AxisLabel = function () { + var $$ = this, + position = $$.getY2AxisLabelPosition(); + if ($$.config[__axis_rotated]) { + return position.isInner ? "1.2em" : "-2.2em"; + } else { + return position.isInner ? "-0.5em" : 30 + this.getMaxTickWidth('y2'); + } +}; +c3_chart_internal_fn.textAnchorForXAxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel(!$$.config[__axis_rotated], $$.getXAxisLabelPosition()); +}; +c3_chart_internal_fn.textAnchorForYAxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getYAxisLabelPosition()); +}; +c3_chart_internal_fn.textAnchorForY2AxisLabel = function () { + var $$ = this; + return $$.textAnchorForAxisLabel($$.config[__axis_rotated], $$.getY2AxisLabelPosition()); +}; + +c3_chart_internal_fn.xForRotatedTickText = function (r) { + return 10 * Math.sin(Math.PI * (r / 180)); +}; +c3_chart_internal_fn.yForRotatedTickText = function (r) { + return 11.5 - 2.5 * (r / 15); +}; +c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) { + axis.selectAll('.tick text') + .style("text-anchor", "start"); + transition.selectAll('.tick text') + .attr("y", this.yForRotatedTickText(rotate)) + .attr("x", this.xForRotatedTickText(rotate)) + .attr("transform", "rotate(" + rotate + ")"); +}; + +c3_chart_internal_fn.getMaxTickWidth = function (id) { + var $$ = this, config = $$.config, + maxWidth = 0, targetsToShow, scale, axis; + if ($$.svg) { + targetsToShow = $$.filterTargetsToShow($$.data.targets); + if (id === 'y') { + scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); + axis = $$.getYAxis(scale, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + } else if (id === 'y2') { + scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); + axis = $$.getYAxis(scale, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); + } else { + scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); + axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config[__axis_x_tick_values] ? config[__axis_x_tick_values] : $$.xAxis.tickValues()); + } + $$.main.append("g").call(axis).each(function () { + $$.d3.select(this).selectAll('text').each(function () { + var box = this.getBoundingClientRect(); + if (maxWidth < box.width) { maxWidth = box.width; } + }); + }).remove(); + } + $$.currentMaxTickWidth = maxWidth <= 0 ? $$.currentMaxTickWidth : maxWidth; + return $$.currentMaxTickWidth; +}; + +c3_chart_internal_fn.updateAxisLabels = function (withTransition) { + var $$ = this; + 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", generateCall($$.xForXAxisLabel, $$)) + .attr("dx", generateCall($$.dxForXAxisLabel, $$)) + .attr("dy", generateCall($$.dyForXAxisLabel, $$)) + .text(generateCall($$.textForXAxisLabel, $$)); + (withTransition ? axisYLabel.transition() : axisYLabel) + .attr("x", generateCall($$.xForYAxisLabel, $$)) + .attr("dx", generateCall($$.dxForYAxisLabel, $$)) + .attr("dy", generateCall($$.dyForYAxisLabel, $$)) + .text(generateCall($$.textForYAxisLabel, $$)); + (withTransition ? axisY2Label.transition() : axisY2Label) + .attr("x", generateCall($$.xForY2AxisLabel, $$)) + .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) + .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) + .text(generateCall($$.textForY2AxisLabel, $$)); +}; + +c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { + var ratio = padding.unit === 'ratio' ? all : 1; + return isValue(padding[key]) ? padding[key] * ratio : defaultValue; +}; + +c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { + var $$ = this; + var tickValues = xs, targetCount, start, end, count, interval, i, tickValue; + if (tickCount) { + targetCount = isFunction(tickCount) ? tickCount() : tickCount; + // compute ticks according to $$.config.axis_x_tick_count + if (targetCount === 1) { + tickValues = [xs[0]]; + } else if (targetCount === 2) { + tickValues = [xs[0], xs[xs.length - 1]]; + } else if (targetCount > 2) { + count = targetCount - 2; + start = xs[0]; + end = xs[xs.length - 1]; + interval = (end - start) / (count + 1); + // re-construct uniqueXs + tickValues = [start]; + for (i = 0; i < count; i++) { + tickValue = +start + interval * (i + 1); + tickValues.push($$.isTimeSeries() ? new Date(tickValue) : tickValue); + } + tickValues.push(end); + } + } + if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } + return tickValues; +}; diff --git a/src/c3.axis.js b/src/c3.axis.js new file mode 100644 index 0000000..02a514f --- /dev/null +++ b/src/c3.axis.js @@ -0,0 +1,184 @@ +// Features: +// 1. category axis +// 2. ceil values of translate/x/y to int for half pixel antialiasing +function c3_axis(d3, isCategory) { + var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickValues = null, tickFormat, tickArguments; + + var tickOffset = 0, tickCulling = true, tickCentered; + + 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 (isCategory) { + domain = scale.domain(); + newScale.domain([domain[0], domain[1] - 1]); + } + return newScale; + } + function textFormatted(v) { + return tickFormat ? tickFormat(v) : v; + } + function axis(g) { + g.each(function () { + var g = d3.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 = d3.transition(tick).style("opacity", 1), + tickTransform, tickX; + + var range = scale.rangeExtent ? scale.rangeExtent() : scaleExtent(scale.range()), + path = g.selectAll(".domain").data([ 0 ]), + pathUpdate = (path.enter().append("path").attr("class", "domain"), d3.transition(path)); + tickEnter.append("line"); + tickEnter.append("text"); + + var lineEnter = tickEnter.select("line"), + lineUpdate = tickUpdate.select("line"), + text = tick.select("text").text(textFormatted), + textEnter = tickEnter.select("text"), + textUpdate = tickUpdate.select("text"); + + if (isCategory) { + tickOffset = Math.ceil((scale1(1) - scale1(0)) / 2); + tickX = tickCentered ? 0 : tickOffset; + } else { + tickOffset = tickX = 0; + } + + function tickSize(d) { + var tickPosition = scale(d) + tickOffset; + return range[0] < tickPosition && tickPosition < range[1] ? innerTickSize : 0; + } + + switch (orient) { + case "bottom": + { + tickTransform = axisX; + lineEnter.attr("y2", innerTickSize); + textEnter.attr("y", Math.max(innerTickSize, 0) + tickPadding); + lineUpdate.attr("x1", tickX).attr("x2", tickX).attr("y2", tickSize); + textUpdate.attr("x", 0).attr("y", Math.max(innerTickSize, 0) + tickPadding); + text.attr("dy", ".71em").style("text-anchor", "middle"); + pathUpdate.attr("d", "M" + range[0] + "," + outerTickSize + "V0H" + range[1] + "V" + outerTickSize); + break; + } + case "top": + { + tickTransform = axisX; + lineEnter.attr("y2", -innerTickSize); + textEnter.attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); + lineUpdate.attr("x2", 0).attr("y2", -innerTickSize); + textUpdate.attr("x", 0).attr("y", -(Math.max(innerTickSize, 0) + tickPadding)); + text.attr("dy", "0em").style("text-anchor", "middle"); + pathUpdate.attr("d", "M" + range[0] + "," + -outerTickSize + "V0H" + range[1] + "V" + -outerTickSize); + break; + } + case "left": + { + tickTransform = axisY; + lineEnter.attr("x2", -innerTickSize); + textEnter.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)); + lineUpdate.attr("x2", -innerTickSize).attr("y2", 0); + textUpdate.attr("x", -(Math.max(innerTickSize, 0) + tickPadding)).attr("y", tickOffset); + text.attr("dy", ".32em").style("text-anchor", "end"); + pathUpdate.attr("d", "M" + -outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + -outerTickSize); + break; + } + case "right": + { + tickTransform = axisY; + lineEnter.attr("x2", innerTickSize); + textEnter.attr("x", Math.max(innerTickSize, 0) + tickPadding); + lineUpdate.attr("x2", innerTickSize).attr("y2", 0); + textUpdate.attr("x", Math.max(innerTickSize, 0) + tickPadding).attr("y", 0); + text.attr("dy", ".32em").style("text-anchor", "start"); + 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 (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 () { // This will be overwritten when normal x axis + return tickOffset; + }; + 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 (!arguments.length) { return tickValues; } + tickValues = x; + return axis; + }; + return axis; +} diff --git a/src/cache.js b/src/cache.js new file mode 100644 index 0000000..6566616 --- /dev/null +++ b/src/cache.js @@ -0,0 +1,16 @@ +c3_chart_internal_fn.hasCaches = function (ids) { + for (var i = 0; i < ids.length; i++) { + if (! (ids[i] in this.cache)) { return false; } + } + return true; +}; +c3_chart_internal_fn.addCache = function (id, target) { + this.cache[id] = this.cloneTarget(target); +}; +c3_chart_internal_fn.getCaches = function (ids) { + var targets = [], i; + for (i = 0; i < ids.length; i++) { + if (ids[i] in this.cache) { targets.push(this.cloneTarget(this.cache[ids[i]])); } + } + return targets; +}; diff --git a/src/category.js b/src/category.js new file mode 100644 index 0000000..5abe0ba --- /dev/null +++ b/src/category.js @@ -0,0 +1,4 @@ +c3_chart_internal_fn.categoryName = function (i) { + var config = this.config; + return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; +}; diff --git a/src/class.js b/src/class.js new file mode 100644 index 0000000..4fc3b5c --- /dev/null +++ b/src/class.js @@ -0,0 +1,233 @@ +var _target = 'target', + _chart = 'chart ', + _chartLine = 'chartLine', + _chartLines = 'chartLines', + _chartBar = 'chartBar', + _chartBars = 'chartBars', + _chartText = 'chartText', + _chartTexts = 'chartTexts', + _chartArc = 'chartArc', + _chartArcs = 'chartArcs', + _chartArcsTitle = 'chartArcsTitle', + _chartArcsBackground = 'chartArcsBackground', + _chartArcsGaugeUnit = 'chartArcsGaugeUnit', + _chartArcsGaugeMax = 'chartArcsGaugeMax', + _chartArcsGaugeMin = 'chartArcsGaugeMin', + _selectedCircle = 'selectedCircle', + _selectedCircles = 'selectedCircles', + _eventRect = 'eventRect', + _eventRects = 'eventRects', + _eventRectsSingle = 'eventRectsSingle', + _eventRectsMultiple = 'eventRectsMultiple', + _zoomRect = 'zoomRect', + _brush = 'brush', + _focused = 'focused', + _region = 'region', + _regions = 'regions', + _tooltip = 'tooltip', + _tooltipName = 'tooltipName', + _shape = 'shape', + _shapes = 'shapes', + _line = 'line', + _lines = 'lines', + _bar = 'bar', + _bars = 'bars', + _circle = 'circle', + _circles = 'circles', + _arc = 'arc', + _arcs = 'arcs', + _area = 'area', + _areas = 'areas', + _empty = 'empty', + _text = 'text', + _texts = 'texts', + _gaugeValue = 'gaugeValue', + _grid = 'grid', + _xgrid = 'xgrid', + _xgrids = 'xgrids', + _xgridLine = 'xgridLine', + _xgridLines = 'xgridLines', + _xgridFocus = 'xgridFocus', + _ygrid = 'ygrid', + _ygrids = 'ygrids', + _ygridLine = 'ygridLine', + _ygridLines = 'ygridLines', + _axis = 'axis', + _axisX = 'axisX', + _axisXLabel = 'axisXLabel', + _axisY = 'axisY', + _axisYLabel = 'axisYLabel', + _axisY2 = 'axisY2', + _axisY2Label = 'axisY2Label', + _legendBackground = 'legendBackground', + _legendItem = 'legendItem', + _legendItemEvent = 'legendItemEvent', + _legendItemTile = 'legendItemTile', + _legendItemHidden = 'legendItemHidden', + _legendItemFocused = 'legendItemFocused', + _dragarea = 'dragarea', + _EXPANDED = 'EXPANDED', + _SELECTED = 'SELECTED', + _INCLUDED = 'INCLUDED'; + +var CLASS = c3_chart_internal_fn.CLASS = {}; +CLASS[_target] = 'c3-target'; +CLASS[_chart] = 'c3-chart'; +CLASS[_chartLine] = 'c3-chart-line'; +CLASS[_chartLines] = 'c3-chart-lines'; +CLASS[_chartBar] = 'c3-chart-bar'; +CLASS[_chartBars] = 'c3-chart-bars'; +CLASS[_chartText] = 'c3-chart-text'; +CLASS[_chartTexts] = 'c3-chart-texts'; +CLASS[_chartArc] = 'c3-chart-arc'; +CLASS[_chartArcs] = 'c3-chart-arcs'; +CLASS[_chartArcsTitle] = 'c3-chart-arcs-title'; +CLASS[_chartArcsBackground] = 'c3-chart-arcs-background'; +CLASS[_chartArcsGaugeUnit] = 'c3-chart-arcs-gauge-unit'; +CLASS[_chartArcsGaugeMax] = 'c3-chart-arcs-gauge-max'; +CLASS[_chartArcsGaugeMin] = 'c3-chart-arcs-gauge-min'; +CLASS[_selectedCircle] = 'c3-selected-circle'; +CLASS[_selectedCircles] = 'c3-selected-circles'; +CLASS[_eventRect] = 'c3-event-rect'; +CLASS[_eventRects] = 'c3-event-rects'; +CLASS[_eventRectsSingle] = 'c3-event-rects-single'; +CLASS[_eventRectsMultiple] = 'c3-event-rects-multiple'; +CLASS[_zoomRect] = 'c3-zoom-rect'; +CLASS[_brush] = 'c3-brush'; +CLASS[_focused] = 'c3-focused'; +CLASS[_region] = 'c3-region'; +CLASS[_regions] = 'c3-regions'; +CLASS[_tooltip] = 'c3-tooltip'; +CLASS[_tooltipName] = 'c3-tooltip-name'; +CLASS[_shape] = 'c3-shape'; +CLASS[_shapes] = 'c3-shapes'; +CLASS[_line] = 'c3-line'; +CLASS[_lines] = 'c3-lines'; +CLASS[_bar] = 'c3-bar'; +CLASS[_bars] = 'c3-bars'; +CLASS[_circle] = 'c3-circle'; +CLASS[_circles] = 'c3-circles'; +CLASS[_arc] = 'c3-arc'; +CLASS[_arcs] = 'c3-arcs'; +CLASS[_area] = 'c3-area'; +CLASS[_areas] = 'c3-areas'; +CLASS[_empty] = 'c3-empty'; +CLASS[_text] = 'c3-text'; +CLASS[_texts] = 'c3-texts'; +CLASS[_gaugeValue] = 'c3-gauge-value'; +CLASS[_grid] = 'c3-grid'; +CLASS[_xgrid] = 'c3-xgrid'; +CLASS[_xgrids] = 'c3-xgrids'; +CLASS[_xgridLine] = 'c3-xgrid-line'; +CLASS[_xgridLines] = 'c3-xgrid-lines'; +CLASS[_xgridFocus] = 'c3-xgrid-focus'; +CLASS[_ygrid] = 'c3-ygrid'; +CLASS[_ygrids] = 'c3-ygrids'; +CLASS[_ygridLine] = 'c3-ygrid-line'; +CLASS[_ygridLines] = 'c3-ygrid-lines'; +CLASS[_axis] = 'c3-axis'; +CLASS[_axisX] = 'c3-axis-x'; +CLASS[_axisXLabel] = 'c3-axis-x-label'; +CLASS[_axisY] = 'c3-axis-y'; +CLASS[_axisYLabel] = 'c3-axis-y-label'; +CLASS[_axisY2] = 'c3-axis-y2'; +CLASS[_axisY2Label] = 'c3-axis-y2-label'; +CLASS[_legendBackground] = 'c3-legend-background'; +CLASS[_legendItem] = 'c3-legend-item'; +CLASS[_legendItemEvent] = 'c3-legend-item-event'; +CLASS[_legendItemTile] = 'c3-legend-item-tile'; +CLASS[_legendItemHidden] = 'c3-legend-item-hidden'; +CLASS[_legendItemFocused] = 'c3-legend-item-focused'; +CLASS[_dragarea] = 'c3-dragarea'; +CLASS[_EXPANDED] = '_expanded_'; +CLASS[_SELECTED] = '_selected_'; +CLASS[_INCLUDED] = '_included_'; + +c3_chart_internal_fn.generateClass = function (prefix, targetId) { + return " " + prefix + " " + prefix + this.getTargetSelectorSuffix(targetId); +}; +c3_chart_internal_fn.classText = function (d) { + return this.generateClass(CLASS[_text], d.index); +}; +c3_chart_internal_fn.classTexts = function (d) { + return this.generateClass(CLASS[_texts], d.id); +}; +c3_chart_internal_fn.classShape = function (d) { + return this.generateClass(CLASS[_shape], d.index); +}; +c3_chart_internal_fn.classShapes = function (d) { + return this.generateClass(CLASS[_shapes], d.id); +}; +c3_chart_internal_fn.classLine = function (d) { + return this.classShape(d) + this.generateClass(CLASS[_line], d.id); +}; +c3_chart_internal_fn.classLines = function (d) { + return this.classShapes(d) + this.generateClass(CLASS[_lines], d.id); +}; +c3_chart_internal_fn.classCircle = function (d) { + return this.classShape(d) + this.generateClass(CLASS[_circle], d.index); +}; +c3_chart_internal_fn.classCircles = function (d) { + return this.classShapes(d) + this.generateClass(CLASS[_circles], d.id); +}; +c3_chart_internal_fn.classBar = function (d) { + return this.classShape(d) + this.generateClass(CLASS[_bar], d.index); +}; +c3_chart_internal_fn.classBars = function (d) { + return this.classShapes(d) + this.generateClass(CLASS[_bars], d.id); +}; +c3_chart_internal_fn.classArc = function (d) { + return this.classShape(d.data) + this.generateClass(CLASS[_arc], d.data.id); +}; +c3_chart_internal_fn.classArcs = function (d) { + return this.classShapes(d.data) + this.generateClass(CLASS[_arcs], d.data.id); +}; +c3_chart_internal_fn.classArea = function (d) { + return this.classShape(d) + this.generateClass(CLASS[_area], d.id); +}; +c3_chart_internal_fn.classAreas = function (d) { + return this.classShapes(d) + this.generateClass(CLASS[_areas], d.id); +}; +c3_chart_internal_fn.classRegion = function (d, i) { + return this.generateClass(CLASS[_region], i) + ' ' + ('class' in d ? d.class : ''); +}; +c3_chart_internal_fn.classEvent = function (d) { + return this.generateClass(CLASS[_eventRect], d.index); +}; +c3_chart_internal_fn.classTarget = function (id) { + var $$ = this; + var additionalClassSuffix = $$.config[__data_classes][id], additionalClass = ''; + if (additionalClassSuffix) { + additionalClass = ' ' + CLASS[_target] + '-' + additionalClassSuffix; + } + return $$.generateClass(CLASS[_target], id) + additionalClass; +}; +c3_chart_internal_fn.classChartText = function (d) { + return CLASS[_chartText] + this.classTarget(d.id); +}; +c3_chart_internal_fn.classChartLine = function (d) { + return CLASS[_chartLine] + this.classTarget(d.id); +}; +c3_chart_internal_fn.classChartBar = function (d) { + return CLASS[_chartBar] + this.classTarget(d.id); +}; +c3_chart_internal_fn.classChartArc = function (d) { + return CLASS[_chartArc] + this.classTarget(d.data.id); +}; +c3_chart_internal_fn.getTargetSelectorSuffix = function (targetId) { + return targetId || targetId === 0 ? '-' + (targetId.replace ? targetId.replace(/([^a-zA-Z0-9-_])/g, '-') : targetId) : ''; +}; +c3_chart_internal_fn.selectorTarget = function (id) { + return '.' + CLASS[_target] + this.getTargetSelectorSuffix(id); +}; +c3_chart_internal_fn.selectorTargets = function (ids) { + var $$ = this; + return ids.length ? ids.map(function (id) { return $$.selectorTarget(id); }) : null; +}; +c3_chart_internal_fn.selectorLegend = function (id) { + return '.' + CLASS[_legendItem] + this.getTargetSelectorSuffix(id); +}; +c3_chart_internal_fn.selectorLegends = function (ids) { + var $$ = this; + return ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null; +}; diff --git a/src/clip.js b/src/clip.js new file mode 100644 index 0000000..668c4a1 --- /dev/null +++ b/src/clip.js @@ -0,0 +1,52 @@ +c3_chart_internal_fn.getClipPath = function (id) { + var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; + return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; +}; +c3_chart_internal_fn.getAxisClipX = function (forHorizontal) { + // axis line width + padding for left + return forHorizontal ? -(1 + 30) : -(this.margin.left - 1); +}; +c3_chart_internal_fn.getAxisClipY = function (forHorizontal) { + return forHorizontal ? -20 : -4; +}; +c3_chart_internal_fn.getXAxisClipX = function () { + var $$ = this; + return $$.getAxisClipX(!$$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getXAxisClipY = function () { + var $$ = this; + return $$.getAxisClipY(!$$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getYAxisClipX = function () { + var $$ = this; + return $$.getAxisClipX($$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getYAxisClipY = function () { + var $$ = this; + return $$.getAxisClipY($$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getAxisClipWidth = function (forHorizontal) { + var $$ = this; + // width + axis line width + padding for left/right + return forHorizontal ? $$.width + 2 + 30 + 30 : $$.margin.left + 20; +}; +c3_chart_internal_fn.getAxisClipHeight = function (forHorizontal) { + var $$ = this, config = $$.config; + return forHorizontal ? (config[__axis_x_height] ? config[__axis_x_height] : 0) + 80 : $$.height + 8; +}; +c3_chart_internal_fn.getXAxisClipWidth = function () { + var $$ = this; + return $$.getAxisClipWidth(!$$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getXAxisClipHeight = function () { + var $$ = this; + return $$.getAxisClipHeight(!$$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getYAxisClipWidth = function () { + var $$ = this; + return $$.getAxisClipWidth($$.config[__axis_rotated]); +}; +c3_chart_internal_fn.getYAxisClipHeight = function () { + var $$ = this; + return $$.getAxisClipHeight($$.config[__axis_rotated]); +}; diff --git a/src/color.js b/src/color.js new file mode 100644 index 0000000..85a9109 --- /dev/null +++ b/src/color.js @@ -0,0 +1,46 @@ +c3_chart_internal_fn.generateColor = function () { + var $$ = this, config = $$.config, d3 = $$.d3, + colors = config[__data_colors], + pattern = notEmpty(config[__color_pattern]) ? config[__color_pattern] : d3.scale.category10().range(), + callback = config[__data_color], + ids = []; + + return function (d) { + var id = d.id || d, color; + + // if callback function is provided + if (colors[id] instanceof Function) { + color = colors[id](d); + } + // if specified, choose that color + else if (colors[id]) { + color = colors[id]; + } + // if not specified, choose from pattern + else { + if (ids.indexOf(id) < 0) { ids.push(id); } + color = pattern[ids.indexOf(id) % pattern.length]; + colors[id] = color; + } + return callback instanceof Function ? callback(color, d) : color; + }; +}; +c3_chart_internal_fn.generateLevelColor = function () { + var $$ = this, config = $$.config, + colors = config[__color_pattern], + threshold = config[__color_threshold], + asValue = threshold.unit === 'value', + values = threshold.values && threshold.values.length ? threshold.values : [], + max = threshold.max || 100; + return notEmpty(config[__color_threshold]) ? function (value) { + var i, v, color = colors[colors.length - 1]; + for (i = 0; i < values.length; i++) { + v = asValue ? value : (value * 100 / max); + if (v < values[i]) { + color = colors[i]; + break; + } + } + return color; + } : null; +}; diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..5ce9a14 --- /dev/null +++ b/src/config.js @@ -0,0 +1,353 @@ +var __bindto = 'bindto', + __size_width = 'size_width', + __size_height = 'size_height', + __padding_left = 'padding_left', + __padding_right = 'padding_right', + __padding_top = 'padding_top', + __padding_bottom = 'padding_bottom', + __zoom_enabled = 'zoom_enabled', + __zoom_extent = 'zoom_extent', + __zoom_privileged = 'zoom_privileged', + __zoom_onzoom = 'zoom_onzoom', + __interaction_enabled = 'interaction_enabled', + __onmouseover = 'onmouseover', + __onmouseout = 'onmouseout', + __onresize = 'onresize', + __onresized = 'onresized', + __transition_duration = 'transition_duration', + __data_x = 'data_x', + __data_xs = 'data_xs', + __data_x_format = 'data_x_format', + __data_x_localtime = 'data_x_localtime', + __data_id_converter = 'data_id_converter', + __data_names = 'data_names', + __data_classes = 'data_classes', + __data_groups = 'data_groups', + __data_axes = 'data_axes', + __data_type = 'data_type', + __data_types = 'data_types', + __data_labels = 'data_labels', + __data_order = 'data_order', + __data_regions = 'data_regions', + __data_color = 'data_color', + __data_colors = 'data_colors', + __data_hide = 'data_hide', + __data_filter = 'data_filter', + __data_selection_enabled = 'data_selection_enabled', + __data_selection_grouped = 'data_selection_grouped', + __data_selection_isselectable = 'data_selection_isselectable', + __data_selection_multiple = 'data_selection_multiple', + __data_onclick = 'data_onclick', + __data_onmouseover = 'data_onmouseover', + __data_onmouseout = 'data_onmouseout', + __data_onselected = 'data_onselected', + __data_onunselected = 'data_onunselected', + __data_ondragstart = 'data_ondragstart', + __data_ondragend = 'data_ondragend', + __data_url = 'data_url', + __data_json = 'data_json', + __data_rows = 'data_rows', + __data_columns = 'data_columns', + __data_mimeType = 'data_mimeType', + __data_keys = 'data_keys', + __data_empty_label_text = 'data_empty_label_text', + __subchart_show = 'subchart_show', + __subchart_size_height = 'subchart_size_height', + __subchart_onbrush = 'subchart_onbrush', + __color_pattern = 'color_pattern', + __color_threshold = 'color_threshold', + __legend_show = 'legend_show', + __legend_position = 'legend_position', + __legend_inset_anchor = 'legend_inset_anchor', + __legend_inset_x = 'legend_inset_x', + __legend_inset_y = 'legend_inset_y', + __legend_inset_step = 'legend_inset_step', + __legend_item_onclick = 'legend_item_onclick', + __legend_item_onmouseover = 'legend_item_onmouseover', + __legend_item_onmouseout = 'legend_item_onmouseout', + __legend_equally = 'legend_equally', + __axis_rotated = 'axis_rotated', + __axis_x_show = 'axis_x_show', + __axis_x_type = 'axis_x_type', + __axis_x_localtime = 'axis_x_localtime', + __axis_x_categories = 'axis_x_categories', + __axis_x_tick_centered = 'axis_x_tick_centered', + __axis_x_tick_format = 'axis_x_tick_format', + __axis_x_tick_culling = 'axis_x_tick_culling', + __axis_x_tick_culling_max = 'axis_x_tick_culling_max', + __axis_x_tick_count = 'axis_x_tick_count', + __axis_x_tick_fit = 'axis_x_tick_fit', + __axis_x_tick_values = 'axis_x_tick_values', + __axis_x_tick_rotate = 'axis_x_tick_rotate', + __axis_x_tick_outer = 'axis_x_tick_outer', + __axis_x_max = 'axis_x_max', + __axis_x_min = 'axis_x_min', + __axis_x_padding = 'axis_x_padding', + __axis_x_height = 'axis_x_height', + __axis_x_default = 'axis_x_default', + __axis_x_label = 'axis_x_label', + __axis_y_show = 'axis_y_show', + __axis_y_max = 'axis_y_max', + __axis_y_min = 'axis_y_min', + __axis_y_center = 'axis_y_center', + __axis_y_label = 'axis_y_label', + __axis_y_tick_format = 'axis_y_tick_format', + __axis_y_tick_outer = 'axis_y_tick_outer', + __axis_y_padding = 'axis_y_padding', + __axis_y_ticks = 'axis_y_ticks', + __axis_y2_show = 'axis_y2_show', + __axis_y2_max = 'axis_y2_max', + __axis_y2_min = 'axis_y2_min', + __axis_y2_center = 'axis_y2_center', + __axis_y2_label = 'axis_y2_label', + __axis_y2_tick_format = 'axis_y2_tick_format', + __axis_y2_tick_outer = 'axis_y2_tick_outer', + __axis_y2_padding = 'axis_y2_padding', + __axis_y2_ticks = 'axis_y2_ticks', + __grid_x_show = 'grid_x_show', + __grid_x_type = 'grid_x_type', + __grid_x_lines = 'grid_x_lines', + __grid_y_show = 'grid_y_show', + __grid_y_lines = 'grid_y_lines', + __grid_y_ticks = 'grid_y_ticks', + __grid_focus_show = 'grid_focus_show', + __point_show = 'point_show', + __point_r = 'point_r', + __point_focus_expand_enabled = 'point_focus_expand_enabled', + __point_focus_expand_r = 'point_focus_expand_r', + __point_select_r = 'point_select_r', + __line_connect_null = 'line_connect_null', + __bar_width = 'bar_width', + __bar_width_ratio = 'bar_width_ratio', + __bar_width_max = 'bar_width_max', + __bar_zerobased = 'bar_zerobased', + __area_zerobased = 'area_zerobased', + __pie_label_show = 'pie_label_show', + __pie_label_format = 'pie_label_format', + __pie_label_threshold = 'pie_label_threshold', + __pie_sort = 'pie_sort', + __pie_expand = 'pie_expand', + __gauge_label_show = 'gauge_label_show', + __gauge_label_format = 'gauge_label_format', + __gauge_expand = 'gauge_expand', + __gauge_min = 'gauge_min', + __gauge_max = 'gauge_max', + __gauge_units = 'gauge_units', + __gauge_width = 'gauge_width', + __donut_label_show = 'donut_label_show', + __donut_label_format = 'donut_label_format', + __donut_label_threshold = 'donut_label_threshold', + __donut_width = 'donut_width', + __donut_sort = 'donut_sort', + __donut_expand = 'donut_expand', + __donut_title = 'donut_title', + __regions = 'regions', + __tooltip_show = 'tooltip_show', + __tooltip_grouped = 'tooltip_grouped', + __tooltip_format_title = 'tooltip_format_title', + __tooltip_format_name = 'tooltip_format_name', + __tooltip_format_value = 'tooltip_format_value', + __tooltip_contents = 'tooltip_contents', + __tooltip_init_show = 'tooltip_init_show', + __tooltip_init_x = 'tooltip_init_x', + __tooltip_init_position = 'tooltip_init_position'; + +var config = c3_chart_internal_fn.config = {}; +config[__bindto] = '#chart'; +config[__size_width] = undefined; +config[__size_height] = undefined; +config[__padding_left] = undefined; +config[__padding_right] = undefined; +config[__padding_top] = undefined; +config[__padding_bottom] = undefined; +config[__zoom_enabled] = false; +config[__zoom_extent] = undefined; +config[__zoom_privileged] = false; +config[__zoom_onzoom] = function () {}; +config[__interaction_enabled] = true; +config[__onmouseover] = function () {}; +config[__onmouseout] = function () {}; +config[__onresize] = function () {}; +config[__onresized] = function () {}; +config[__transition_duration] = 350; +config[__data_x] = undefined; +config[__data_xs] = {}; +config[__data_x_format] = '%Y-%m-%d'; +config[__data_x_localtime] = true; +config[__data_id_converter] = function (id) { return id; }; +config[__data_names] = {}; +config[__data_classes] = {}; +config[__data_groups] = []; +config[__data_axes] = {}; +config[__data_type] = undefined; +config[__data_types] = {}; +config[__data_labels] = {}; +config[__data_order] = 'desc'; +config[__data_regions] = {}; +config[__data_color] = undefined; +config[__data_colors] = {}; +config[__data_hide] = false; +config[__data_filter] = undefined; +config[__data_selection_enabled] = false; +config[__data_selection_grouped] = false; +config[__data_selection_isselectable] = function () { return true; }; +config[__data_selection_multiple] = true; +config[__data_onclick] = function () {}; +config[__data_onmouseover] = function () {}; +config[__data_onmouseout] = function () {}; +config[__data_onselected] = function () {}; +config[__data_onunselected] = function () {}; +config[__data_ondragstart] = function () {}; +config[__data_ondragend] = function () {}; +config[__data_url] = undefined; +config[__data_json] = undefined; +config[__data_rows] = undefined; +config[__data_columns] = undefined; +config[__data_mimeType] = undefined; +config[__data_keys] = undefined; +// configuration for no plot-able data supplied. +config[__data_empty_label_text] = ""; +// subchart +config[__subchart_show] = false; +config[__subchart_size_height] = 60; +config[__subchart_onbrush] = function () {}; +// color +config[__color_pattern] = []; +config[__color_threshold] = {}; +// legend +config[__legend_show] = true; +config[__legend_position] = 'bottom'; +config[__legend_inset_anchor] = 'top-left'; +config[__legend_inset_x] = 10; +config[__legend_inset_y] = 0; +config[__legend_inset_step] = undefined; +config[__legend_item_onclick] = undefined; +config[__legend_item_onmouseover] = undefined; +config[__legend_item_onmouseout] = undefined; +config[__legend_equally] = false; +// axis +config[__axis_rotated] = false; +config[__axis_x_show] = true; +config[__axis_x_type] = 'indexed'; +config[__axis_x_localtime] = true; +config[__axis_x_categories] = []; +config[__axis_x_tick_centered] = false; +config[__axis_x_tick_format] = undefined; +config[__axis_x_tick_culling] = {}; +config[__axis_x_tick_culling_max] = 10; +config[__axis_x_tick_count] = undefined; +config[__axis_x_tick_fit] = true; +config[__axis_x_tick_values] = null; +config[__axis_x_tick_rotate] = undefined; +config[__axis_x_tick_outer] = true; +config[__axis_x_max] = null; +config[__axis_x_min] = null; +config[__axis_x_padding] = {}; +config[__axis_x_height] = undefined; +config[__axis_x_default] = undefined; +config[__axis_x_label] = {}; +config[__axis_y_show] = true; +config[__axis_y_max] = undefined; +config[__axis_y_min] = undefined; +config[__axis_y_center] = undefined; +config[__axis_y_label] = {}; +config[__axis_y_tick_format] = undefined; +config[__axis_y_tick_outer] = true; +config[__axis_y_padding] = undefined; +config[__axis_y_ticks] = 10; +config[__axis_y2_show] = false; +config[__axis_y2_max] = undefined; +config[__axis_y2_min] = undefined; +config[__axis_y2_center] = undefined; +config[__axis_y2_label] = {}; +config[__axis_y2_tick_format] = undefined; +config[__axis_y2_tick_outer] = true; +config[__axis_y2_padding] = undefined; +config[__axis_y2_ticks] = 10; +// grid +config[__grid_x_show] = false; +config[__grid_x_type] = 'tick'; +config[__grid_x_lines] = []; +config[__grid_y_show] = false; +// not used +// grid_y_type: {}, 'tick'), +config[__grid_y_lines] = []; +config[__grid_y_ticks] = 10; +config[__grid_focus_show] = true; +// point - point of each data +config[__point_show] = true; +config[__point_r] = 2.5; +config[__point_focus_expand_enabled] = true; +config[__point_focus_expand_r] = undefined; +config[__point_select_r] = undefined; +config[__line_connect_null] = false; +// bar +config[__bar_width] = undefined; +config[__bar_width_ratio] = 0.6; +config[__bar_width_max] = undefined; +config[__bar_zerobased] = true; +// area +config[__area_zerobased] = true; +// pie +config[__pie_label_show] = true; +config[__pie_label_format] = undefined; +config[__pie_label_threshold] = 0.05; +config[__pie_sort] = true; +config[__pie_expand] = true; +// gauge +config[__gauge_label_show] = true; +config[__gauge_label_format] = undefined; +config[__gauge_expand] = true; +config[__gauge_min] = 0; +config[__gauge_max] = 100; +config[__gauge_units] = undefined; +config[__gauge_width] = undefined; +// donut +config[__donut_label_show] = true; +config[__donut_label_format] = undefined; +config[__donut_label_threshold] = 0.05; +config[__donut_width] = undefined; +config[__donut_sort] = true; +config[__donut_expand] = true; +config[__donut_title] = ""; +// region - region to change style +config[__regions] = []; +// tooltip - show when mouseover on each data +config[__tooltip_show] = true; +config[__tooltip_grouped] = true; +config[__tooltip_format_title] = undefined; +config[__tooltip_format_name] = undefined; +config[__tooltip_format_value] = undefined; +config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { + return this.getTooltipContent ? this.getTooltipContent(d, defaultValueFormat, defaultValueFormat, color) : ''; +}, +config[__tooltip_init_show] = false; +config[__tooltip_init_x] = 0; +config[__tooltip_init_position] = {top: '0px', left: '50px'}; + +c3_chart_internal_fn.loadConfig = function (config) { + var this_config = this.config, target, keys, read; + function find() { + var key = keys.shift(); +// console.log("key =>", key, ", target =>", target); + if (key && target && key in target) { + target = target[key]; + return find(); + } + else if (!key) { + return target; + } + else { + return undefined; + } + } + Object.keys(this_config).forEach(function (key) { + target = config; + keys = key.split('_'); + read = find(); +// console.log("CONFIG : ", key, read); + if (isDefined(read)) { + this_config[key] = read; + } + }); +}; diff --git a/src/core.js b/src/core.js new file mode 100644 index 0000000..abbf009 --- /dev/null +++ b/src/core.js @@ -0,0 +1,1542 @@ +var c3 = { version: "0.3.0" }; + +var c3_chart_fn, c3_chart_internal_fn; + +function Chart(config) { + var $$ = this.internal = new ChartInternal(config, this); + $$.loadConfig(config); + $$.init(); +} + +function ChartInternal(config, api) { + var $$ = this; + $$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined; + $$.api = api; + $$.data = {}; + $$.cache = {}; + $$.axes = {}; +} + +c3.generate = function (config) { + return new Chart(config); +}; + +c3.chart = { + fn: Chart.prototype, + internal: { + fn: ChartInternal.prototype + } +}; +c3_chart_fn = c3.chart.fn; +c3_chart_internal_fn = c3.chart.internal.fn; + + +c3_chart_internal_fn.init = function () { + var $$ = this, config = $$.config; + + $$.initParams(); + + if (config[__data_url]) { + $$.convertUrlToData(config[__data_url], config[__data_mimeType], 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 = $$.d3; + + // MEMO: clipId needs to be unique because it conflicts when multiple charts exist + $$.clipId = "c3-" + (+new Date()) + '-clip', + $$.clipIdForXAxis = $$.clipId + '-xaxis', + $$.clipIdForYAxis = $$.clipId + '-yaxis', + $$.clipPath = $$.getClipPath($$.clipId), + $$.clipPathForXAxis = $$.getClipPath($$.clipIdForXAxis), + $$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis); + + $$.dragStart = null; + $$.dragging = false; + $$.cancelClick = false; + $$.mouseover = false; + $$.transiting = false; + + $$.color = $$.generateColor(); + $$.levelColor = $$.generateLevelColor(); + + $$.dataTimeFormat = config[__data_x_localtime] ? d3.time.format : d3.time.format.utc; + $$.axisTimeFormat = config[__axis_x_localtime] ? d3.time.format : d3.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 = []; + + $$.xOrient = config[__axis_rotated] ? "left" : "bottom"; + $$.yOrient = config[__axis_rotated] ? "bottom" : "left"; + $$.y2Orient = config[__axis_rotated] ? "top" : "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; + $$.legendOpacityForHidden = 0.15; + + $$.currentMaxTickWidth = 0; + + $$.rotated_padding_left = 30; + $$.rotated_padding_right = config[__axis_rotated] && !config[__axis_x_show] ? 0 : 30; + $$.rotated_padding_top = 5; + + $$.withoutFadeIn = {}; + + $$.axes.subx = d3.selectAll([]); // needs when excluding subchart.js +}; + +c3_chart_internal_fn.initWithData = function (data) { + var $$ = this, d3 = $$.d3, config = $$.config; + var main, eventRect, binding = true; + + if (isFunction($$.initPie)) { $$.initPie(); } + if (isFunction($$.initBrush)) { $$.initBrush(); } + if (isFunction($$.initZoom)) { $$.initZoom(); } + + $$.selectChart = d3.select(config[__bindto]); + if ($$.selectChart.empty()) { + $$.selectChart = d3.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]); + } + + // 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.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($$); }); + + // Define defs + $$.defs = $$.svg.append("defs"); + $$.defs.append("clipPath").attr("id", $$.clipId).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForXAxis).append("rect"); + $$.defs.append("clipPath").attr("id", $$.clipIdForYAxis).append("rect"); + $$.updateSvgSize(); + + // Define regions + main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); + + if (isFunction($$.initSubchart)) { $$.initSubchart(); } + if (isFunction($$.initTooltip)) { $$.initTooltip(); } + if (isFunction($$.initLegend)) { $$.initLegend(); } + + /*-- 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 + main.append('g') + .attr("clip-path", $$.clipPath) + .attr("class", CLASS[_regions]); + + // Grids + $$.grid = main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS[_grid]); + if (config[__grid_x_show]) { + $$.grid.append("g").attr("class", CLASS[_xgrids]); + } + if (config[__grid_y_show]) { + $$.grid.append('g').attr('class', CLASS[_ygrids]); + } + $$.grid.append('g').attr("class", CLASS[_xgridLines]); + $$.grid.append('g').attr('class', CLASS[_ygridLines]); + if (config[__grid_focus_show]) { + $$.grid.append('g') + .attr("class", CLASS[_xgridFocus]) + .append('line') + .attr('class', CLASS[_xgridFocus]); + } + + // Define g for chart area + main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS[_chart]); + + // Cover whole with rects for events + eventRect = main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_eventRects]) + .style('fill-opacity', 0); + + // Define g for bar chart area + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); + + // Define g for line chart area + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); + + // Define g for arc chart area + if (isFunction($$.initArc)) { + $$.initArc(); + } + if (isFunction($$.initGauge)) { + $$.initGauge(); + } + + main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartTexts]); + + // 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_default]) { + $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); + } + + // Add Axis + $$.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", generateCall($$.textAnchorForXAxisLabel, $$)); + + $$.axes.y = main.append("g") + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) + .attr("clip-path", $$.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", generateCall($$.textAnchorForYAxisLabel, $$)); + + $$.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", generateCall($$.textAnchorForY2AxisLabel, $$)); + + // Set targets + $$.updateTargets($$.data.targets); + + // Draw with targets + if (binding) { + $$.updateDimension(); + $$.redraw({ + withTransform: true, + withUpdateXDomain: true, + withUpdateOrgXDomain: true, + withTransitionForAxis: false + }); + } + + // Bind resize event + if (window.onresize == null) { + window.onresize = $$.generateResize(); + } + if (window.onresize.add) { + window.onresize.add(function () { + config[__onresize].call($$); + }); + window.onresize.add(function () { + $$.api.flush(); + }); + window.onresize.add(function () { + config[__onresized].call($$); + }); + } + + // 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, context + if (config[__axis_rotated]) { + $$.margin = { + top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) + }; + $$.margin2 = { + top: $$.margin.top, + right: NaN, + bottom: 20 + legendHeightForBottom, + left: $$.rotated_padding_left + }; + } else { + $$.margin = { + top: 4 + $$.getCurrentPaddingTop(), // for top tick text + right: hasArc ? 0 : $$.getCurrentPaddingRight(), + bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), + left: hasArc ? 0 : $$.getCurrentPaddingLeft() + }; + $$.margin2 = { + top: $$.currentHeight - subchartHeight - legendHeightForBottom, + right: NaN, + bottom: xAxisHeight + legendHeightForBottom, + left: $$.margin.left + }; + } + + // for legend + if (isFunction($$.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 (isFunction($$.updateRadius)) { + $$.updateRadius(); + } + + if ($$.isLegendRight && hasArc) { + $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; + } +}; + +c3_chart_internal_fn.updateTargets = function (targets) { + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; + var $$ = this, config = $$.config, main = $$.main; + + /*-- Main --*/ + + //-- Text --// + mainTextUpdate = main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) + .data(targets) + .attr('class', generateCall($$.classChartText, $$)); + mainTextEnter = mainTextUpdate.enter().append('g') + .attr('class', generateCall($$.classChartText, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); + mainTextEnter.append('g') + .attr('class', generateCall($$.classTexts, $$)); + + //-- Bar --// + mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) + .data(targets) + .attr('class', generateCall($$.classChartBar, $$)); + mainBarEnter = mainBarUpdate.enter().append('g') + .attr('class', generateCall($$.classChartBar, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); + // Bars for each data + mainBarEnter.append('g') + .attr("class", generateCall($$.classBars, $$)) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + + //-- Line --// + mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) + .data(targets) + .attr('class', generateCall($$.classChartLine, $$)); + mainLineEnter = mainLineUpdate.enter().append('g') + .attr('class', generateCall($$.classChartLine, $$)) + .style('opacity', 0) + .style("pointer-events", "none"); + // Lines for each data + mainLineEnter.append('g') + .attr("class", generateCall($$.classLines, $$)); + // Areas + mainLineEnter.append('g') + .attr('class', generateCall($$.classAreas, $$)); + // Circles for each data point on lines + mainLineEnter.append('g') + .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); + mainLineEnter.append('g') + .attr("class", generateCall($$.classCircles, $$)) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + // Update date for selected circles + targets.forEach(function (t) { + main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { + d.value = t.values[d.index].value; + }); + }); + // MEMO: can not keep same color... + //mainLineUpdate.exit().remove(); + + if (isFunction($$.updateTargetsForArc)) { + $$.updateTargetsForArc(targets); + } + if (isFunction($$.updateTargetsForSubchart)) { + $$.updateTargetsForSubchart(targets); + } + + /*-- Show --*/ + + // Fade-in each chart + $$.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 = $$.d3, config = $$.config; + var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; + var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var rectX, rectW; + var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; + var hideAxis = $$.hasArcType(); + var drawArea, drawBar, drawLine, xForText, yForText; + var duration, durationForExit, durationForAxis, waitForDraw; + var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; + + xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); + + 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); + withLegend = getOption(options, "withLegend", false); + 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 || $$.generateAxisTransitions(durationForAxis); + + // update legend and transform each g + if (withLegend && config[__legend_show]) { + $$.updateLegend($$.mapToIds($$.data.targets), options, transitions); + } + + // 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); + // update axis tick values according to options + if (!config[__axis_x_tick_values] && (config[__axis_x_tick_fit] || config[__axis_x_tick_count])) { + tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config[__axis_x_tick_count]); + $$.xAxis.tickValues(tickValues); + $$.subXAxis.tickValues(tickValues); + } + } else { + $$.xAxis.tickValues([]); + $$.subXAxis.tickValues([]); + } + + $$.y.domain($$.getYDomain(targetsToShow, 'y')); + $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); + + // axes + $$.axes.x.style("opacity", hideAxis ? 0 : 1); + $$.axes.y.style("opacity", hideAxis ? 0 : 1); + $$.axes.y2.style("opacity", hideAxis ? 0 : 1); + $$.axes.subx.style("opacity", hideAxis ? 0 : 1); + transitions.axisX.call($$.xAxis); + transitions.axisY.call($$.yAxis); + transitions.axisY2.call($$.y2Axis); + transitions.axisSubX.call($$.subXAxis); + + // Update axis label + $$.updateAxisLabels(withTransition); + + // show/hide if manual culling needed + if (withUpdateXDomain && targetsToShow.length) { + if (config[__axis_x_tick_culling] && tickValues) { + for (i = 1; i < tickValues.length; i++) { + if (tickValues.length / i < config[__axis_x_tick_culling_max]) { + intervalForCulling = i; + break; + } + } + $$.svg.selectAll('.' + CLASS[_axisX] + ' .tick text').each(function (e) { + var index = tickValues.indexOf(e); + if (index >= 0) { + d3.select(this).style('display', index % intervalForCulling ? 'none' : 'block'); + } + }); + } else { + $$.svg.selectAll('.' + CLASS[_axisX] + ' .tick text').style('display', 'block'); + } + } + + // rotate tick text if needed + if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { + $$.rotateTickText($$.axes.x, transitions.axisX, config[__axis_x_tick_rotate]); + } + + // setup drawer - MEMO: these must be called after axis updated + drawArea = $$.generateDrawArea(areaIndices, false); + drawBar = $$.generateDrawBar(barIndices); + drawLine = $$.generateDrawLine(lineIndices, false); + xForText = $$.generateXYForText(barIndices, true); + yForText = $$.generateXYForText(barIndices, false); + + // Update sub domain + $$.subY.domain($$.y.domain()); + $$.subY2.domain($$.y2.domain()); + + // tooltip + $$.tooltip.style("display", "none"); + + // 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 + main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); + if (config[__grid_x_show]) { + xgridAttr = config[__axis_rotated] ? { + 'x1': 0, + 'x2': $$.width, + 'y1': function (d) { return $$.x(d) - tickOffset; }, + 'y2': function (d) { return $$.x(d) - tickOffset; } + } : { + 'x1': function (d) { return $$.x(d) + tickOffset; }, + 'x2': function (d) { return $$.x(d) + tickOffset; }, + 'y1': 0, + 'y2': $$.height + }; + // this is used to flow + flushXGrid = function (withoutUpdate) { + xgridData = $$.generateGridData(config[__grid_x_type], $$.x); + tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; + xgrid = main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) + .data(xgridData); + xgrid.enter().append('line').attr("class", CLASS[_xgrid]); + if (!withoutUpdate) { + xgrid.attr(xgridAttr) + .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); + } + xgrid.exit().remove(); + }; + flushXGrid(); + } + xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) + .data(config[__grid_x_lines]); + // enter + xgridLine = xgridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); + xgridLine.append('line') + .style("opacity", 0); + xgridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // udpate + // done in d3.transition() of the end of this function + // exit + xgridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + // Y-Grid + if (withY && config[__grid_y_show]) { + ygrid = main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) + .data($$.y.ticks(config[__grid_y_ticks])); + ygrid.enter().append('line') + .attr('class', CLASS[_ygrid]); + ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) + .attr("x2", config[__axis_rotated] ? $$.y : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : $$.y) + .attr("y2", config[__axis_rotated] ? $$.height : $$.y); + ygrid.exit().remove(); + $$.smoothLines(ygrid, 'grid'); + } + if (withY) { + ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) + .data(config[__grid_y_lines]); + // enter + ygridLine = ygridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); + ygridLine.append('line') + .style("opacity", 0); + ygridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // update + var yv_ = generateCall($$.yv, $$); + ygridLines.select('line') + .transition().duration(duration) + .attr("x1", config[__axis_rotated] ? yv_ : 0) + .attr("x2", config[__axis_rotated] ? yv_ : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv_) + .attr("y2", config[__axis_rotated] ? $$.height : yv_) + .style("opacity", 1); + ygridLines.select('text') + .transition().duration(duration) + .attr("x", config[__axis_rotated] ? 0 : $$.width) + .attr("y", yv_) + .text(function (d) { return d.text; }) + .style("opacity", 1); + // exit + ygridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + } + + // rect for regions + mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) + .data(config[__regions]); + mainRegion.enter().append('g') + .attr('class', generateCall($$.classRegion, $$)) + .append('rect') + .style("fill-opacity", 0); + mainRegion.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + + // bars + mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) + .data(generateCall($$.barData, $$)); + mainBar.enter().append('path') + .attr("class", generateCall($$.classBar, $$)) + .style("stroke", function (d) { return $$.color(d.id); }) + .style("fill", function (d) { return $$.color(d.id); }); + mainBar + .style("opacity", generateCall($$.initialOpacity, $$)); + mainBar.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + // lines, areas and cricles + mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) + .data(generateCall($$.lineData, $$)); + mainLine.enter().append('path') + .attr('class', generateCall($$.classLine, $$)) + .style("stroke", $$.color); + mainLine + .style("opacity", generateCall($$.initialOpacity, $$)) + .attr('transform', null); + mainLine.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + mainArea = main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) + .data(generateCall($$.lineData, $$)); + mainArea.enter().append('path') + .attr("class", generateCall($$.classArea, $$)) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + mainArea + .style("opacity", $$.orgAreaOpacity); + mainArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + + if (config[__point_show]) { + mainCircle = main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) + .data(generateCall($$.lineOrScatterData, $$)); + mainCircle.enter().append("circle") + .attr("class", generateCall($$.classCircle, $$)) + .attr("r", generateCall($$.pointR, $$)) + .style("fill", $$.color); + mainCircle + .style("opacity", generateCall($$.initialOpacity, $$)); + mainCircle.exit().remove(); + } + + if ($$.hasDataLabel()) { + mainText = main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) + .data(generateCall($$.barOrLineData, $$)); + mainText.enter().append('text') + .attr("class", generateCall($$.classText, $$)) + .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .style("stroke", 'none') + .style("fill", function (d) { return $$.color(d); }) + .style("fill-opacity", 0); + mainText + .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); + mainText.exit() + .transition().duration(durationForExit) + .style('fill-opacity', 0) + .remove(); + } + + // arc + if (isFunction($$.redrawArc)) { + $$.redrawArc(duration, durationForExit, withTransform); + } + + // subchart + if (isFunction($$.redrawSubchart)) { + $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); + } + + // circles for select + main.selectAll('.' + CLASS[_selectedCircles]) + .filter(generateCall($$.isBarType, $$)) + .selectAll('circle') + .remove(); + + if (config[__interaction_enabled]) { + // rect for mouseover + eventRect = main.select('.' + CLASS[_eventRects]) + .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); + if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { + + if (!eventRect.classed(CLASS[_eventRectsMultiple])) { + eventRect.classed(CLASS[_eventRectsMultiple], true).classed(CLASS[_eventRectsSingle], false) + .selectAll('.' + CLASS[_eventRect]).remove(); + } + + eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) + .data([0]); + // enter : only one rect will be added + $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height); + // exit : not needed because always only one rect exists + } else { + + if (!eventRect.classed(CLASS[_eventRectsSingle])) { + eventRect.classed(CLASS[_eventRectsMultiple], false).classed(CLASS[_eventRectsSingle], true) + .selectAll('.' + CLASS[_eventRect]).remove(); + } + + if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { + rectW = function (d) { + var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], + w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; + return w < 0 ? 0 : w; + }; + rectX = function (d) { + var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; + return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; + }; + } else { + rectW = $$.getEventRectWidth(); + rectX = function (d) { + return $$.x(d.x) - (rectW / 2); + }; + } + // Set data + maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); + main.select('.' + CLASS[_eventRects]) + .datum(maxDataCountTarget ? maxDataCountTarget.values : []); + // Update rects + eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) + .data(function (d) { return d; }); + // enter + $$.generateEventRectsForSingleX(eventRectUpdate.enter()); + // update + eventRectUpdate + .attr('class', generateCall($$.classEvent, $$)) + .attr("x", config[__axis_rotated] ? 0 : rectX) + .attr("y", config[__axis_rotated] ? rectX : 0) + .attr("width", config[__axis_rotated] ? $$.width : rectW) + .attr("height", config[__axis_rotated] ? rectW : $$.height); + // exit + eventRectUpdate.exit().remove(); + } + } + + var xv_ = generateCall($$.xv, $$); + + // transition should be derived from one transition + d3.transition().duration(duration).each(function () { + var transitions = [], + cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), + cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); + + transitions.push(mainBar.transition() + .attr('d', drawBar) + .style("fill", $$.color) + .style("opacity", 1)); + transitions.push(mainLine.transition() + .attr("d", drawLine) + .style("stroke", $$.color) + .style("opacity", 1)); + transitions.push(mainArea.transition() + .attr("d", drawArea) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity)); + transitions.push(mainCircle.transition() + .style('opacity', generateCall($$.opacityForCircle, $$)) + .style("fill", $$.color) + .attr("cx", cx) + .attr("cy", cy)); + transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() + .attr("cx", cx) + .attr("cy", cy)); + transitions.push(mainText.transition() + .attr('x', xForText) + .attr('y', yForText) + .style("fill", $$.color) + .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); + transitions.push(mainRegion.selectAll('rect').transition() + .attr("x", $$.regionX) + .attr("y", $$.regionY) + .attr("width", $$.regionWidth) + .attr("height", $$.regionHeight) + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + transitions.push(xgridLines.select('line').transition() + .attr("x1", config[__axis_rotated] ? 0 : xv_) + .attr("x2", config[__axis_rotated] ? $$.width : xv_) + .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv_ : $$.height) + .style("opacity", 1)); + transitions.push(xgridLines.select('text').transition() + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv_) + .text(function (d) { return d.text; }) + .style("opacity", 1)); + // Wait for end of transitions if called from flow API + if (options.flow) { + waitForDraw = $$.generateWait(); + transitions.forEach(function (t) { + waitForDraw.add(t); + }); + } + }) + .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow + var translateX, scaleX = 1, transform, + flowIndex = options.flow.index, + flowLength = options.flow.length, + flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), + orgDomain = $$.x.domain(), domain, + durationForFlow = options.flow.duration || duration, + done = options.flow.done || function () {}, + wait = $$.generateWait(); + + // remove head data after rendered + $$.data.targets.forEach(function (d) { + d.values.splice(0, flowLength); + }); + + // update x domain to generate axis elements for flow + domain = $$.updateXDomain(targetsToShow, true, true); + // update elements related to x scale + if (flushXGrid) { flushXGrid(true); } + + // generate transform to flow + if (!options.flow.orgDataCount) { // if empty + if ($$.data.targets[0].values.length !== 1) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); + } else { + translateX = diffDomain(domain) / 2; + } + } + } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); + } else { + translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); + } + } + scaleX = (diffDomain(orgDomain) / diffDomain(domain)); + transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; + + d3.transition().ease('linear').duration(durationForFlow).each(function () { + wait.add($$.axes.x.transition().call($$.xAxis)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); + }) + .call(wait, function () { + var i, shapes = [], texts = [], eventRects = []; + + // remove flowed elements + if (flowLength) { + for (i = 0; i < flowLength; i++) { + shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); + } + $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[_xgrid]).remove(); + } + + // draw again for removing flowed elements and reverting attr + xgrid + .attr('transform', null) + .attr(xgridAttr); + xgridLines + .attr('transform', null); + xgridLines.select('line') + .attr("x1", config[__axis_rotated] ? 0 : xv_) + .attr("x2", config[__axis_rotated] ? $$.width : xv_); + xgridLines.select('text') + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv_); + mainBar + .attr('transform', null) + .attr("d", drawBar); + mainLine + .attr('transform', null) + .attr("d", drawLine); + mainArea + .attr('transform', null) + .attr("d", drawArea); + mainCircle + .attr('transform', null) + .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) + .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY); + mainText + .attr('transform', null) + .attr('x', xForText) + .attr('y', yForText) + .style('fill-opacity', generateCall($$.opacityForText, $$)); + mainRegion + .attr('transform', null); + mainRegion.select('rect').filter($$.isRegionOnX) + .attr("x", $$.regionX) + .attr("width", $$.regionWidth); + eventRectUpdate + .attr("x", config[__axis_rotated] ? 0 : rectX) + .attr("y", config[__axis_rotated] ? rectX : 0) + .attr("width", config[__axis_rotated] ? $$.width : rectW) + .attr("height", config[__axis_rotated] ? rectW : $$.height); + + // callback for end of flow + done(); + }); + }); + + // update fadein condition + $$.mapToIds($$.data.targets).forEach(function (id) { + $$.withoutFadeIn[id] = true; + }); + + if (isFunction($$.updateZoom)) { $$.updateZoom(); } +}; + +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 = $$.generateAxisTransitions(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.generateEventRectsForSingleX = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append("rect") + .attr("class", generateCall($$.classEvent, $$)) + .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) + .on('mouseover', function (d) { + var index = d.index, selectedData, newData; + + if ($$.dragging) { return; } // do nothing if dragging + if ($$.hasArcType()) { return; } + + selectedData = $$.data.targets.map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + // Sort selectedData as names order + newData = []; + Object.keys(config[__data_names]).forEach(function (id) { + for (var j = 0; j < selectedData.length; j++) { + if (selectedData[j] && selectedData[j].id === id) { + newData.push(selectedData[j]); + selectedData.shift(j); + break; + } + } + }); + selectedData = newData.concat(selectedData); // Add remained + + // Expand shapes for selection + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } + $$.expandBars(index); + + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseover].call(c3, d); + }); + }) + .on('mouseout', function (d) { + var index = d.index; + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + // Undo expanded shapes + $$.unexpandCircles(index); + $$.unexpandBars(); + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseout].call($$, d); + }); + }) + .on('mousemove', function (d) { + var selectedData, index = d.index, + eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType()) { return; } + + // Show tooltip + selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + if (config[__tooltip_grouped]) { + $$.showTooltip(selectedData, d3.mouse(this)); + $$.showXGridFocus(selectedData); + } + + if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { + return; + } + + $$.main.selectAll('.' + CLASS[_shape] + '-' + index) + .each(function () { + d3.select(this).classed(CLASS[_EXPANDED], true); + if (config[__data_selection_enabled]) { + eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); + } + if (!config[__tooltip_grouped]) { + $$.hideXGridFocus(); + $$.hideTooltip(); + if (!config[__data_selection_grouped]) { + $$.unexpandCircles(index); + $$.unexpandBars(); + } + } + }) + .filter(function (d) { + if (this.nodeName === 'circle') { + return $$.isWithinCircle(this, $$.pointSelectR(d)); + } + else if (this.nodeName === 'path') { + return $$.isWithinBar(this); + } + }) + .each(function (d) { + if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { + eventRect.style('cursor', 'pointer'); + } + if (!config[__tooltip_grouped]) { + $$.showTooltip([d], d3.mouse(this)); + $$.showXGridFocus([d]); + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } + $$.expandBars(index, d.id); + } + }); + }) + .on('click', function (d) { + var index = d.index; + if ($$.hasArcType() || !$$.toggleShape) { return; } + if ($$.cancelClick) { + $$.cancelClick = false; + return; + } + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + $$.toggleShape(this, d, index); + }); + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); +}; + +c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height) + .attr('class', CLASS[_eventRect]) + .on('mouseout', function () { + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + $$.unexpandCircles(); + }) + .on('mousemove', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest, sameXData, selectedData; + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + if ($$.isScatterType(closest)) { + sameXData = [closest]; + } else { + sameXData = $$.filterSameX(targetsToShow, closest.x); + } + + // show tooltip when cursor is close to some point + selectedData = sameXData.map(function (d) { + return $$.addName(d); + }); + $$.showTooltip(selectedData, mouse); + + // expand points + if (config[__point_focus_expand_enabled]) { + $$.unexpandCircles(); + $$.expandCircles(closest.index, closest.id); + } + + // Show xgrid focus line + $$.showXGridFocus(selectedData); + + // Show cursor as pointer if point is close to mouse position + if ($$.dist(closest, mouse) < 100) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); + if (!$$.mouseover) { + config[__data_onmouseover].call($$, closest); + $$.mouseover = true; + } + } else if ($$.mouseover) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); + config[__data_onmouseout].call($$, closest); + $$.mouseover = false; + } + }) + .on('click', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest; + + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + // select if selection enabled + if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { + $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { + $$.toggleShape(this, closest, closest.index); + }); + } + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); +}; + +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.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.opacityForCircle = function (d) { + var $$ = this; + return isValue(d.value) ? $$.isScatterType(d) ? 0.5 : 1 : 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; + return Math.ceil($$.x($$.isTimeSeries() ? $$.parseDate(d.value) : d.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; + $$.svg.attr('width', $$.currentWidth).attr('height', $$.currentHeight); + $$.svg.select('#' + $$.clipId).select('rect') + .attr('width', $$.width) + .attr('height', $$.height); + $$.svg.select('#' + $$.clipIdForXAxis).select('rect') + .attr('x', generateCall($$.getXAxisClipX, $$)) + .attr('y', generateCall($$.getXAxisClipY, $$)) + .attr('width', generateCall($$.getXAxisClipWidth, $$)) + .attr('height', generateCall($$.getXAxisClipHeight, $$)); + $$.svg.select('#' + $$.clipIdForYAxis).select('rect') + .attr('x', generateCall($$.getYAxisClipX, $$)) + .attr('y', generateCall($$.getYAxisClipY, $$)) + .attr('width', generateCall($$.getYAxisClipWidth, $$)) + .attr('height', generateCall($$.getYAxisClipHeight, $$)); + $$.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 () { + var $$ = this; + 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 = 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 + var interval = window.setInterval(function () { + // parentNode will NOT be null when completed + if (selection.node().parentNode) { + window.clearInterval(interval); + $$.updateDimension(); + $$.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.generateResize = function () { + var resizeFunctions = []; + function callResizeFunctions() { + resizeFunctions.forEach(function (f) { + f(); + }); + } + callResizeFunctions.add = function (f) { + resizeFunctions.push(f); + }; + return callResizeFunctions; +}; + +c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { + var $$ = this, + withTransitionForAxis = !$$.hasArcType(), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); +}; + +c3_chart_internal_fn.generateAxisTransitions = function (duration) { + var $$ = this, 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 + }; +}; +c3_chart_internal_fn.endall = function (transition, callback) { + var n = 0; + transition + .each(function () { ++n; }) + .each("end", function () { + if (!--n) { callback.apply(this, arguments); } + }); +}; +c3_chart_internal_fn.generateWait = function () { + var transitionsToWait = [], + f = function (transition, callback) { + var timer = setInterval(function () { + var done = 0; + transitionsToWait.forEach(function (t) { + if (t.empty()) { + done += 1; + return; + } + try { + t.transition(); + } catch (e) { + done += 1; + } + }); + if (done === transitionsToWait.length) { + clearInterval(timer); + if (callback) { callback(); } + } + }, 10); + }; + f.add = function (transition) { + transitionsToWait.push(transition); + }; + return f; +}; + +c3_chart_internal_fn.parseDate = function (date) { + var $$ = this, parsedDate; + if (date instanceof Date) { + parsedDate = date; + } else if (typeof date === 'number') { + parsedDate = new Date(date); + } else { + parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); + } + if (!parsedDate || isNaN(+parsedDate)) { + window.console.error("Failed to parse x '" + date + "' to Date object"); + } + return parsedDate; +}; diff --git a/src/data.convert.js b/src/data.convert.js new file mode 100644 index 0000000..852168e --- /dev/null +++ b/src/data.convert.js @@ -0,0 +1,176 @@ +c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) { + var $$ = this, type = mimeType ? mimeType : 'csv'; + $$.d3.xhr(url, function (error, data) { + var d; + if (type === 'json') { + d = $$.convertJsonToData(JSON.parse(data.response), keys); + } else { + d = $$.convertCsvToData(data.response); + } + done(d); + }); +}; +c3_chart_internal_fn.convertCsvToData = function (csv) { + var d3 = this.d3, rows = d3.csv.parseRows(csv), d; + if (rows.length === 1) { + d = [{}]; + rows[0].forEach(function (id) { + d[0][id] = null; + }); + } else { + d = d3.csv.parse(csv); + } + return d; +}; +c3_chart_internal_fn.convertJsonToData = function (json, keys) { + var $$ = this, + new_rows = [], targetKeys, data; + if (keys) { // when keys specified, json would be an array that includes objects + targetKeys = keys.value; + if (keys.x) { + targetKeys.push(keys.x); + $$.config[__data_x] = keys.x; + } + new_rows.push(targetKeys); + json.forEach(function (o) { + var new_row = []; + targetKeys.forEach(function (key) { + // convert undefined to null because undefined data will be removed in convertDataToTargets() + var v = isUndefined(o[key]) ? null : o[key]; + new_row.push(v); + }); + new_rows.push(new_row); + }); + data = $$.convertRowsToData(new_rows); + } else { + Object.keys(json).forEach(function (key) { + new_rows.push([key].concat(json[key])); + }); + data = $$.convertColumnsToData(new_rows); + } + return data; +}; +c3_chart_internal_fn.convertRowsToData = function (rows) { + var keys = rows[0], new_row = {}, new_rows = [], i, j; + for (i = 1; i < rows.length; i++) { + new_row = {}; + for (j = 0; j < rows[i].length; j++) { + if (isUndefined(rows[i][j])) { + throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); + } + new_row[keys[j]] = rows[i][j]; + } + new_rows.push(new_row); + } + return new_rows; +}; +c3_chart_internal_fn.convertColumnsToData = function (columns) { + var new_rows = [], i, j, key; + for (i = 0; i < columns.length; i++) { + key = columns[i][0]; + for (j = 1; j < columns[i].length; j++) { + if (isUndefined(new_rows[j - 1])) { + new_rows[j - 1] = {}; + } + if (isUndefined(columns[i][j])) { + throw new Error("Source data is missing a component at (" + i + "," + j + ")!"); + } + new_rows[j - 1][key] = columns[i][j]; + } + } + return new_rows; +}; +c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) { + var $$ = this, config = $$.config, + ids = $$.d3.keys(data[0]).filter($$.isNotX, $$), + xs = $$.d3.keys(data[0]).filter($$.isX, $$), + targets; + + // save x for update data by load when custom x and c3.x API + ids.forEach(function (id) { + var xKey = $$.getXKey(id); + + if ($$.isCustomX() || $$.isTimeSeries()) { + // if included in input data + if (xs.indexOf(xKey) >= 0) { + $$.data.xs[id] = (appendXs && $$.data.xs[id] ? $$.data.xs[id] : []).concat( + data.map(function (d) { return d[xKey]; }) + .filter(isValue) + .map(function (rawX, i) { return $$.generateTargetX(rawX, id, i); }) + ); + } + // if not included in input data, find from preloaded data of other id's x + else if (config[__data_x]) { + $$.data.xs[id] = $$.getOtherTargetXs(); + } + // if not included in input data, find from preloaded data + else if (notEmpty(config[__data_xs])) { + $$.data.xs[id] = $$.getXValuesOfXKey(xKey, $$.data.targets); + } + // MEMO: if no x included, use same x of current will be used + } else { + $$.data.xs[id] = data.map(function (d, i) { return i; }); + } + }); + + // check x is defined + ids.forEach(function (id) { + if (!$$.data.xs[id]) { + throw new Error('x is not defined for id = "' + id + '".'); + } + }); + + // convert to target + targets = ids.map(function (id, index) { + var convertedId = config[__data_id_converter](id); + return { + id: convertedId, + id_org: id, + values: data.map(function (d, i) { + var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i); + // use x as categories if custom x and categorized + if ($$.isCustomX() && $$.isCategorized() && index === 0 && rawX) { + if (i === 0) { config[__axis_x_categories] = []; } + config[__axis_x_categories].push(rawX); + } + // mark as x = undefined if value is undefined and filter to remove after mapped + if (isUndefined(d[id]) || $$.data.xs[id].length <= i) { + x = undefined; + } + return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId}; + }).filter(function (v) { return isDefined(v.x); }) + }; + }); + + // finish targets + targets.forEach(function (t) { + var i; + // sort values by its x + t.values = t.values.sort(function (v1, v2) { + var x1 = v1.x || v1.x === 0 ? v1.x : Infinity, + x2 = v2.x || v2.x === 0 ? v2.x : Infinity; + return x1 - x2; + }); + // indexing each value + i = 0; + t.values.forEach(function (v) { + v.index = i++; + }); + // this needs to be sorted because its index and value.index is identical + $$.data.xs[t.id].sort(function (v1, v2) { + return v1 - v2; + }); + }); + + // set target types + if (config[__data_type]) { + $$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config[__data_types]); }), config[__data_type]); + } + + // cache as original id keyed + targets.forEach(function (d) { + $$.addCache(d.id_org, d); + }); + + return targets; +}; diff --git a/src/data.js b/src/data.js new file mode 100644 index 0000000..483ecf7 --- /dev/null +++ b/src/data.js @@ -0,0 +1,327 @@ +c3_chart_internal_fn.isX = function (key) { + var $$ = this, config = $$.config; + return (config[__data_x] && key === config[__data_x]) || (notEmpty(config[__data_xs]) && hasValue(config[__data_xs], key)); +}; +c3_chart_internal_fn.isNotX = function (key) { + return !this.isX(key); +}; +c3_chart_internal_fn.getXKey = function (id) { + var $$ = this, config = $$.config; + return config[__data_x] ? config[__data_x] : notEmpty(config[__data_xs]) ? config[__data_xs][id] : null; +}; +c3_chart_internal_fn.getXValuesOfXKey = function (key, targets) { + var $$ = this, + xValues, ids = targets && notEmpty(targets) ? $$.mapToIds(targets) : []; + ids.forEach(function (id) { + if ($$.getXKey(id) === key) { + xValues = $$.data.xs[id]; + } + }); + return xValues; +}; +c3_chart_internal_fn.getXValue = function (id, i) { + var $$ = this; + return id in $$.data.xs && $$.data.xs[id] && isValue($$.data.xs[id][i]) ? $$.data.xs[id][i] : i; +}; +c3_chart_internal_fn.getOtherTargetXs = function () { + var $$ = this, + idsForX = Object.keys($$.data.xs); + return idsForX.length ? $$.data.xs[idsForX[0]] : null; +}; +c3_chart_internal_fn.getOtherTargetX = function (index) { + var xs = this.getOtherTargetXs(); + return xs && index < xs.length ? xs[index] : null; +}; +c3_chart_internal_fn.addXs = function (xs) { + var $$ = this; + Object.keys(xs).forEach(function (id) { + $$.config[__data_xs][id] = xs[id]; + }); +}; +c3_chart_internal_fn.isSingleX = function (xs) { + return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; +}; +c3_chart_internal_fn.addName = function (data) { + var $$ = this, name; + if (data) { + name = $$.config[__data_names][data.id]; + data.name = name ? name : data.id; + } + return data; +}; +c3_chart_internal_fn.getValueOnIndex = function (values, index) { + var valueOnIndex = values.filter(function (v) { return v.index === index; }); + return valueOnIndex.length ? valueOnIndex[0] : null; +}; +c3_chart_internal_fn.updateTargetX = function (targets, x) { + var $$ = this; + targets.forEach(function (t) { + t.values.forEach(function (v, i) { + v.x = $$.generateTargetX(x[i], t.id, i); + }); + $$.data.xs[t.id] = x; + }); +}; +c3_chart_internal_fn.updateTargetXs = function (targets, xs) { + var $$ = this; + targets.forEach(function (t) { + if (xs[t.id]) { + $$.updateTargetX([t], xs[t.id]); + } + }); +}; +c3_chart_internal_fn.generateTargetX = function (rawX, id, index) { + var $$ = this, x; + if ($$.isTimeSeries()) { + x = rawX ? $$.parseDate(rawX) : $$.parseDate($$.getXValue(id, index)); + } + else if ($$.isCustomX() && !$$.isCategorized()) { + x = isValue(rawX) ? +rawX : $$.getXValue(id, index); + } + else { + x = index; + } + return x; +}; +c3_chart_internal_fn.cloneTarget = function (target) { + return { + id : target.id, + id_org : target.id_org, + values : target.values.map(function (d) { + return {x: d.x, value: d.value, id: d.id}; + }) + }; +}; +c3_chart_internal_fn.getPrevX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i - 1); + return value ? value.x : null; +}; +c3_chart_internal_fn.getNextX = function (i) { + var $$ = this, value = $$.getValueOnIndex($$.data.targets[0].values, i + 1); + return value ? value.x : null; +}; +c3_chart_internal_fn.getMaxDataCount = function () { + var $$ = this; + return $$.d3.max($$.data.targets, function (t) { return t.values.length; }); +}; +c3_chart_internal_fn.getMaxDataCountTarget = function (targets) { + var length = targets.length, max = 0, maxTarget; + if (length > 1) { + targets.forEach(function (t) { + if (t.values.length > max) { + maxTarget = t; + max = t.values.length; + } + }); + } else { + maxTarget = length ? targets[0] : null; + } + return maxTarget; +}; +c3_chart_internal_fn.getEdgeX = function (targets) { + var target = this.getMaxDataCountTarget(targets), firstData, lastData; + if (!target) { + return [0, 0]; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + return [firstData.x, lastData.x]; +}; +c3_chart_internal_fn.mapToIds = function (targets) { + return targets.map(function (d) { return d.id; }); +}; +c3_chart_internal_fn.mapToTargetIds = function (ids) { + var $$ = this; + return ids ? (isString(ids) ? [ids] : ids) : $$.mapToIds($$.data.targets); +}; +c3_chart_internal_fn.hasTarget = function (targets, id) { + var ids = this.mapToIds(targets), i; + for (i = 0; i < ids.length; i++) { + if (ids[i] === id) { + return true; + } + } + return false; +}; +c3_chart_internal_fn.isTargetToShow = function (targetId) { + return this.hiddenTargetIds.indexOf(targetId) < 0; +}; +c3_chart_internal_fn.isLegendToShow = function (targetId) { + return this.hiddenLegendIds.indexOf(targetId) < 0; +}; +c3_chart_internal_fn.filterTargetsToShow = function (targets) { + var $$ = this; + return targets.filter(function (t) { return $$.isTargetToShow(t.id); }); +}; +c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { + var $$ = this; + var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return v.x; }); }))).values(); + return $$.isTimeSeries() ? xs.map(function (x) { return new Date(x); }) : xs.map(function (x) { return +x; }); +}; +c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); +}; +c3_chart_internal_fn.removeHiddenTargetIds = function (targetIds) { + this.hiddenTargetIds = this.hiddenTargetIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); +}; +c3_chart_internal_fn.addHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.concat(targetIds); +}; +c3_chart_internal_fn.removeHiddenLegendIds = function (targetIds) { + this.hiddenLegendIds = this.hiddenLegendIds.filter(function (id) { return targetIds.indexOf(id) < 0; }); +}; +c3_chart_internal_fn.getValuesAsIdKeyed = function (targets) { + var ys = {}; + targets.forEach(function (t) { + ys[t.id] = []; + t.values.forEach(function (v) { + ys[t.id].push(v.value); + }); + }); + return ys; +}; +c3_chart_internal_fn.checkValueInTargets = function (targets, checker) { + var ids = Object.keys(targets), i, j, values; + for (i = 0; i < ids.length; i++) { + values = targets[ids[i]].values; + for (j = 0; j < values.length; j++) { + if (checker(values[j].value)) { + return true; + } + } + } + return false; +}; +c3_chart_internal_fn.hasNegativeValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v < 0; }); +}; +c3_chart_internal_fn.hasPositiveValueInTargets = function (targets) { + return this.checkValueInTargets(targets, function (v) { return v > 0; }); +}; +c3_chart_internal_fn.isOrderDesc = function () { + var config = this.config; + return config[__data_order] && config[__data_order].toLowerCase() === 'desc'; +}; +c3_chart_internal_fn.isOrderAsc = function () { + var config = this.config; + return config[__data_order] && config[__data_order].toLowerCase() === 'asc'; +}; +c3_chart_internal_fn.orderTargets = function (targets) { + var $$ = this, config = $$.config, orderAsc = $$.isOrderAsc(), orderDesc = $$.isOrderDesc(); + if (orderAsc || orderDesc) { + targets.sort(function (t1, t2) { + var reducer = function (p, c) { return p + Math.abs(c.value); }; + var t1Sum = t1.values.reduce(reducer, 0), + t2Sum = t2.values.reduce(reducer, 0); + return orderAsc ? t2Sum - t1Sum : t1Sum - t2Sum; + }); + } else if (isFunction(config[__data_order])) { + targets.sort(config[__data_order]); + } // TODO: accept name array for order + return targets; +}; +c3_chart_internal_fn.filterSameX = function (targets, x) { + return this.d3.merge(targets.map(function (t) { return t.values; })).filter(function (v) { return v.x - x === 0; }); +}; +c3_chart_internal_fn.filterRemoveNull = function (data) { + return data.filter(function (d) { return isValue(d.value); }); +}; +c3_chart_internal_fn.hasDataLabel = function () { + var config = this.config; + if (typeof config[__data_labels] === 'boolean' && config[__data_labels]) { + return true; + } else if (typeof config[__data_labels] === 'object' && notEmpty(config[__data_labels])) { + return true; + } + return false; +}; +c3_chart_internal_fn.getDataLabelLength = function (min, max, axisId, key) { + var $$ = this, + lengths = [0, 0], paddingCoef = 1.3; + $$.selectChart.select('svg').selectAll('.dummy') + .data([min, max]) + .enter().append('text') + .text(function (d) { return $$.formatByAxisId(axisId)(d); }) + .each(function (d, i) { + lengths[i] = this.getBoundingClientRect()[key] * paddingCoef; + }) + .remove(); + return lengths; +}; +c3_chart_internal_fn.isNoneArc = function (d) { + return this.hasTarget(this.data.targets, d.id); +}, +c3_chart_internal_fn.isArc = function (d) { + return 'data' in d && this.hasTarget(this.data.targets, d.data.id); +}; +c3_chart_internal_fn.findSameXOfValues = function (values, index) { + var i, targetX = values[index].x, sames = []; + for (i = index - 1; i >= 0; i--) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + for (i = index; i < values.length; i++) { + if (targetX !== values[i].x) { break; } + sames.push(values[i]); + } + return sames; +}; + +c3_chart_internal_fn.findClosestOfValues = function (values, pos, _min, _max) { // MEMO: values must be sorted by x + var $$ = this, + min = _min ? _min : 0, + max = _max ? _max : values.length - 1, + med = Math.floor((max - min) / 2) + min, + value = values[med], + diff = $$.x(value.x) - pos[$$.config[__axis_rotated] ? 1 : 0], + candidates; + + // Update range for search + diff > 0 ? max = med : min = med; + + // if candidates are two closest min and max, stop recursive call + if ((max - min) === 1 || (min === 0 && max === 0)) { + + // Get candidates that has same min and max index + candidates = []; + if (values[min].x || values[min].x === 0) { + candidates = candidates.concat($$.findSameXOfValues(values, min)); + } + if (values[max].x || values[max].x === 0) { + candidates = candidates.concat($$.findSameXOfValues(values, max)); + } + + // Determine the closest and return + return $$.findClosest(candidates, pos); + } + + return $$.findClosestOfValues(values, pos, min, max); +}; +c3_chart_internal_fn.findClosestFromTargets = function (targets, pos) { + var $$ = this, candidates; + + // map to array of closest points of each target + candidates = targets.map(function (target) { + return $$.findClosestOfValues(target.values, pos); + }); + + // decide closest point and return + return $$.findClosest(candidates, pos); +}; +c3_chart_internal_fn.findClosest = function (values, pos) { + var $$ = this, minDist, closest; + values.forEach(function (v) { + var d = $$.dist(v, pos); + if (d < minDist || ! minDist) { + minDist = d; + closest = v; + } + }); + return closest; +}; +c3_chart_internal_fn.dist = function (data, pos) { + var $$ = this, config = $$.config, + yScale = $$.getAxisId(data.id) === 'y' ? $$.y : $$.y2, + xIndex = config[__axis_rotated] ? 1 : 0, + yIndex = config[__axis_rotated] ? 0 : 1; + return Math.pow($$.x(data.x) - pos[xIndex], 2) + Math.pow(yScale(data.value) - pos[yIndex], 2); +}; diff --git a/src/data.load.js b/src/data.load.js new file mode 100644 index 0000000..e161303 --- /dev/null +++ b/src/data.load.js @@ -0,0 +1,89 @@ +c3_chart_internal_fn.load = function (targets, args) { + var $$ = this; + if (targets) { + // filter loading targets if needed + if (args.filter) { + targets = targets.filter(args.filter); + } + // set type if args.types || args.type specified + if (args.type || args.types) { + targets.forEach(function (t) { + $$.setTargetType(t.id, args.types ? args.types[t.id] : args.type); + }); + } + // Update/Add data + $$.data.targets.forEach(function (d) { + for (var i = 0; i < targets.length; i++) { + if (d.id === targets[i].id) { + d.values = targets[i].values; + targets.splice(i, 1); + break; + } + } + }); + $$.data.targets = $$.data.targets.concat(targets); // add remained + } + + // Set targets + $$.updateTargets($$.data.targets); + + // Redraw with new targets + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + + if (isFunction(args.done)) { + args.done(); + } +}; +c3_chart_internal_fn.loadFromArgs = function (args) { + var $$ = this; + if (args.data) { + $$.load($$.convertDataToTargets(args.data), args); + } + else if (args.url) { + $$.convertUrlToData(args.url, args.mimeType, args.keys, function (data) { + $$.load($$.convertDataToTargets(data), args); + }); + } + else if (args.json) { + $$.load($$.convertDataToTargets($$.convertJsonToData(args.json, args.keys)), args); + } + else if (args.rows) { + $$.load($$.convertDataToTargets($$.convertRowsToData(args.rows)), args); + } + else if (args.columns) { + $$.load($$.convertDataToTargets($$.convertColumnsToData(args.columns)), args); + } + else { + $$.load(null, args); + } +}; +c3_chart_internal_fn.unload = function (targetIds, done) { + var $$ = this; + if (!isFunction(done)) { + done = function () {}; + } + // filter existing target + targetIds = targetIds.filter(function (id) { return $$.hasTarget($$.data.targets, id); }); + // If no target, call done and return + if (!targetIds || targetIds.length === 0) { + done(); + return; + } + $$.svg.selectAll(targetIds.map(function (id) { return $$.selectorTarget(id); })) + .transition() + .style('opacity', 0) + .remove() + .call($$.endall, done); + targetIds.forEach(function (id) { + // Reset fadein for future load + $$.withoutFadeIn[id] = false; + // Remove target's elements + if ($$.legend) { + $$.legend.selectAll('.' + CLASS[_legendItem] + $$.getTargetSelectorSuffix(id)).remove(); + } + // Remove target + $$.data.targets = $$.data.targets.filter(function (t) { + return t.id !== id; + }); + }); +}; diff --git a/src/domain.js b/src/domain.js new file mode 100644 index 0000000..8fdf2bd --- /dev/null +++ b/src/domain.js @@ -0,0 +1,193 @@ +c3_chart_internal_fn.getYDomainMin = function (targets) { + var $$ = this, config = $$.config, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasNegativeValue; + if (config[__data_groups].length > 0) { + hasNegativeValue = $$.hasNegativeValueInTargets(targets); + for (j = 0; j < config[__data_groups].length; j++) { + // Determine baseId + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider negative values + if (hasNegativeValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v < 0 ? v : 0; + }); + } + // Compute min + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasNegativeValue && +v > 0)) { + ys[baseId][i] += +v; + } + }); + } + } + } + return $$.d3.min(Object.keys(ys).map(function (key) { return $$.d3.min(ys[key]); })); +}; +c3_chart_internal_fn.getYDomainMax = function (targets) { + var $$ = this, config = $$.config, + ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), + j, k, baseId, idsInGroup, id, hasPositiveValue; + if (config[__data_groups].length > 0) { + hasPositiveValue = $$.hasPositiveValueInTargets(targets); + for (j = 0; j < config[__data_groups].length; j++) { + // Determine baseId + idsInGroup = config[__data_groups][j].filter(function (id) { return ids.indexOf(id) >= 0; }); + if (idsInGroup.length === 0) { continue; } + baseId = idsInGroup[0]; + // Consider positive values + if (hasPositiveValue && ys[baseId]) { + ys[baseId].forEach(function (v, i) { + ys[baseId][i] = v > 0 ? v : 0; + }); + } + // Compute max + for (k = 1; k < idsInGroup.length; k++) { + id = idsInGroup[k]; + if (! ys[id]) { continue; } + ys[id].forEach(function (v, i) { + if ($$.getAxisId(id) === $$.getAxisId(baseId) && ys[baseId] && !(hasPositiveValue && +v < 0)) { + ys[baseId][i] += +v; + } + }); + } + } + } + return $$.d3.max(Object.keys(ys).map(function (key) { return $$.d3.max(ys[key]); })); +}; +c3_chart_internal_fn.getYDomain = function (targets, axisId) { + var $$ = this, config = $$.config, + yTargets = targets.filter(function (d) { return $$.getAxisId(d.id) === axisId; }), + yMin = axisId === 'y2' ? config[__axis_y2_min] : config[__axis_y_min], + yMax = axisId === 'y2' ? config[__axis_y2_max] : config[__axis_y_max], + yDomainMin = isValue(yMin) ? yMin : $$.getYDomainMin(yTargets), + yDomainMax = isValue(yMax) ? yMax : $$.getYDomainMax(yTargets), + domainLength, padding, padding_top, padding_bottom, + center = axisId === 'y2' ? config[__axis_y2_center] : config[__axis_y_center], + yDomainAbs, lengths, diff, ratio, isAllPositive, isAllNegative, + isZeroBased = ($$.hasType('bar', yTargets) && config[__bar_zerobased]) || ($$.hasType('area', yTargets) && config[__area_zerobased]), + showHorizontalDataLabel = $$.hasDataLabel() && config[__axis_rotated], + showVerticalDataLabel = $$.hasDataLabel() && !config[__axis_rotated]; + if (yTargets.length === 0) { // use current domain if target of axisId is none + return axisId === 'y2' ? $$.y2.domain() : $$.y.domain(); + } + if (yDomainMin === yDomainMax) { + yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0; + } + isAllPositive = yDomainMin >= 0 && yDomainMax >= 0; + isAllNegative = yDomainMin <= 0 && yDomainMax <= 0; + + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { yDomainMin = 0; } + if (isAllNegative) { yDomainMax = 0; } + } + + domainLength = Math.abs(yDomainMax - yDomainMin); + padding = padding_top = padding_bottom = domainLength * 0.1; + + if (center) { + yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax)); + yDomainMax = yDomainAbs - center; + yDomainMin = center - yDomainAbs; + } + // add padding for data label + if (showHorizontalDataLabel) { + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'width'); + diff = diffDomain($$.y.range()); + ratio = [lengths[0] / diff, lengths[1] / diff]; + padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); + padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); + } else if (showVerticalDataLabel) { + lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); + padding_top += lengths[1]; + padding_bottom += lengths[0]; + } + if (axisId === 'y' && config[__axis_y_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y_padding], 'bottom', padding, domainLength); + } + if (axisId === 'y2' && config[__axis_y2_padding]) { + padding_top = $$.getAxisPadding(config[__axis_y2_padding], 'top', padding, domainLength); + padding_bottom = $$.getAxisPadding(config[__axis_y2_padding], 'bottom', padding, domainLength); + } + // Bar/Area chart should be 0-based if all positive|negative + if (isZeroBased) { + if (isAllPositive) { padding_bottom = yDomainMin; } + if (isAllNegative) { padding_top = -yDomainMax; } + } + return [yDomainMin - padding_bottom, yDomainMax + padding_top]; +}; +c3_chart_internal_fn.getXDomainMin = function (targets) { + var $$ = this, config = $$.config; + return config[__axis_x_min] ? + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_min]) : config[__axis_x_min]) : + $$.d3.min(targets, function (t) { return $$.d3.min(t.values, function (v) { return v.x; }); }); +}; +c3_chart_internal_fn.getXDomainMax = function (targets) { + var $$ = this, config = $$.config; + return config[__axis_x_max] ? + ($$.isTimeSeries() ? this.parseDate(config[__axis_x_max]) : config[__axis_x_max]) : + $$.d3.max(targets, function (t) { return $$.d3.max(t.values, function (v) { return v.x; }); }); +}; +c3_chart_internal_fn.getXDomainPadding = function (targets) { + var $$ = this, config = $$.config, + edgeX = this.getEdgeX(targets), diff = edgeX[1] - edgeX[0], + maxDataCount, padding, paddingLeft, paddingRight; + if ($$.isCategorized()) { + padding = 0; + } else if ($$.hasType('bar', targets)) { + maxDataCount = $$.getMaxDataCount(); + padding = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5; + } else { + padding = diff * 0.01; + } + if (typeof config[__axis_x_padding] === 'object' && notEmpty(config[__axis_x_padding])) { + paddingLeft = isValue(config[__axis_x_padding].left) ? config[__axis_x_padding].left : padding; + paddingRight = isValue(config[__axis_x_padding].right) ? config[__axis_x_padding].right : padding; + } else if (typeof config[__axis_x_padding] === 'number') { + paddingLeft = paddingRight = config[__axis_x_padding]; + } else { + paddingLeft = paddingRight = padding; + } + return {left: paddingLeft, right: paddingRight}; +}; +c3_chart_internal_fn.getXDomain = function (targets) { + var $$ = this, + xDomain = [$$.getXDomainMin(targets), $$.getXDomainMax(targets)], + firstX = xDomain[0], lastX = xDomain[1], + padding = $$.getXDomainPadding(targets), + min = 0, max = 0; + // show center of x domain if min and max are the same + if ((firstX - lastX) === 0 && !$$.isCategorized()) { + firstX = $$.isTimeSeries() ? new Date(firstX.getTime() * 0.5) : -0.5; + lastX = $$.isTimeSeries() ? new Date(lastX.getTime() * 1.5) : 0.5; + } + if (firstX || firstX === 0) { + min = $$.isTimeSeries() ? new Date(firstX.getTime() - padding.left) : firstX - padding.left; + } + if (lastX || lastX === 0) { + max = $$.isTimeSeries() ? new Date(lastX.getTime() + padding.right) : lastX + padding.right; + } + return [min, max]; +}; +c3_chart_internal_fn.updateXDomain = function (targets, withUpdateXDomain, withUpdateOrgXDomain, domain) { + var $$ = this, config = $$.config; + if (withUpdateOrgXDomain) { + $$.x.domain(domain ? domain : $$.d3.extent($$.getXDomain(targets))); + $$.orgXDomain = $$.x.domain(); + if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } + $$.subX.domain($$.x.domain()); + if ($$.brush) { $$.brush.scale($$.subX); } + } + if (withUpdateXDomain) { + $$.x.domain(domain ? domain : (!$$.brush || $$.brush.empty()) ? $$.orgXDomain : $$.brush.extent()); + if (config[__zoom_enabled]) { $$.zoom.scale($$.x).updateScaleExtent(); } + } + return $$.x.domain(); +}; diff --git a/src/drag.js b/src/drag.js new file mode 100644 index 0000000..fede416 --- /dev/null +++ b/src/drag.js @@ -0,0 +1,84 @@ +c3_chart_internal_fn.drag = function (mouse) { + var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; + var sx, sy, mx, my, minX, maxX, minY, maxY; + + if ($$.hasArcType()) { return; } + 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[__data_selection_multiple]) { return; } // skip when single selection because drag is used for multiple selection + + sx = $$.dragStart[0]; + sy = $$.dragStart[1]; + mx = mouse[0]; + my = mouse[1]; + minX = Math.min(sx, mx); + maxX = Math.max(sx, mx); + minY = (config[__data_selection_grouped]) ? $$.margin.top : Math.min(sy, my); + maxY = (config[__data_selection_grouped]) ? $$.height : Math.max(sy, my); + + main.select('.' + CLASS[_dragarea]) + .attr('x', minX) + .attr('y', minY) + .attr('width', maxX - minX) + .attr('height', maxY - minY); + // TODO: binary search when multiple xs + main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]) + .filter(function (d) { return config[__data_selection_isselectable](d); }) + .each(function (d, i) { + var shape = d3.select(this), + isSelected = shape.classed(CLASS[_SELECTED]), + isIncluded = shape.classed(CLASS[_INCLUDED]), + _x, _y, _w, _h, toggle, isWithin = false, box; + if (shape.classed(CLASS[_circle])) { + _x = shape.attr("cx") * 1; + _y = shape.attr("cy") * 1; + toggle = $$.togglePoint; + isWithin = minX < _x && _x < maxX && minY < _y && _y < maxY; + } + else if (shape.classed(CLASS[_bar])) { + box = getPathBox(this); + _x = box.x; + _y = box.y; + _w = box.width; + _h = box.height; + toggle = $$.toggleBar; + isWithin = !(maxX < _x || _x + _w < minX) && !(maxY < _y || _y + _h < minY); + } else { + // line/area selection not supported yet + return; + } + if (isWithin ^ isIncluded) { + shape.classed(CLASS[_INCLUDED], !isIncluded); + // TODO: included/unincluded callback here + shape.classed(CLASS[_SELECTED], !isSelected); + $$.toggle(!isSelected, shape, d, i); + } + }); +}; + +c3_chart_internal_fn.dragstart = function (mouse) { + var $$ = this, config = $$.config; + if ($$.hasArcType()) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable + $$.dragStart = mouse; + $$.main.select('.' + CLASS[_chart]).append('rect') + .attr('class', CLASS[_dragarea]) + .style('opacity', 0.1); + $$.dragging = true; + $$.config[__data_ondragstart](); +}; + +c3_chart_internal_fn.dragend = function () { + var $$ = this, config = $$.config; + if ($$.hasArcType()) { return; } + if (! config[__data_selection_enabled]) { return; } // do nothing if not selectable + $$.main.select('.' + CLASS[_dragarea]) + .transition().duration(100) + .style('opacity', 0) + .remove(); + $$.main.selectAll('.' + CLASS[_shape]) + .classed(CLASS[_INCLUDED], false); + $$.dragging = false; + $$.config[__data_ondragend](); +}; + diff --git a/src/format.js b/src/format.js new file mode 100644 index 0000000..23ceb57 --- /dev/null +++ b/src/format.js @@ -0,0 +1,38 @@ +c3_chart_internal_fn.getYFormat = function (forArc) { + var $$ = this, + formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat, + formatForY2 = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.y2Format; + return function (v, ratio, id) { + var format = $$.getAxisId(id) === 'y2' ? formatForY2 : formatForY; + return format.call($$, v, ratio); + }; +}; +c3_chart_internal_fn.yFormat = function (v) { + var $$ = this, config = $$.config, + format = config[__axis_y_tick_format] ? config[__axis_y_tick_format] : $$.defaultValueFormat; + return format(v); +}; +c3_chart_internal_fn.y2Format = function (v) { + var $$ = this, config = $$.config, + format = config[__axis_y2_tick_format] ? config[__axis_y2_tick_format] : $$.defaultValueFormat; + return format(v); +}; +c3_chart_internal_fn.defaultValueFormat = function (v) { + return isValue(v) ? +v : ""; +}; +c3_chart_internal_fn.defaultArcValueFormat = function (v, ratio) { + return (ratio * 100).toFixed(1) + '%'; +}; +c3_chart_internal_fn.formatByAxisId = function (axisId) { + var $$ = this.internal, data_labels = $$.config[__data_labels], + format = function (v) { return isValue(v) ? +v : ""; }; + // find format according to axis id + if (isFunction(data_labels.format)) { + format = data_labels.format; + } else if (typeof data_labels.format === 'object') { + if (isFunction(data_labels.format[axisId])) { + format = data_labels.format[axisId]; + } + } + return format; +}; diff --git a/src/grid.js b/src/grid.js new file mode 100644 index 0000000..1c775bb --- /dev/null +++ b/src/grid.js @@ -0,0 +1,69 @@ +c3_chart_internal_fn.showXGridFocus = function (selectedData) { + var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (! config[__tooltip_show]) { return; } + // Hide when scatter plot exists + if ($$.hasType('scatter') || $$.hasArcType()) { return; } + var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); + focusEl + .style("visibility", "visible") + .data([dataToShow[0]]) + .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) + .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + $$.smoothLines(focusEl, 'grid'); +}; +c3_chart_internal_fn.hideXGridFocus = function () { + this.main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); +}; +c3_chart_internal_fn.updateXgridFocus = function () { + var $$ = this, config = $$.config; + $$.main.select('line.' + CLASS[_xgridFocus]) + .attr("x1", config[__axis_rotated] ? 0 : -10) + .attr("x2", config[__axis_rotated] ? $$.width : -10) + .attr("y1", config[__axis_rotated] ? -10 : 0) + .attr("y2", config[__axis_rotated] ? -10 : $$.height); +}; +c3_chart_internal_fn.generateGridData = function (type, scale) { + var $$ = this, + gridData = [], xDomain, firstYear, lastYear, i, + tickNum = $$.main.select("." + CLASS[_axisX]).selectAll('.tick').size(); + if (type === 'year') { + xDomain = $$.getXDomain(); + firstYear = xDomain[0].getFullYear(); + lastYear = xDomain[1].getFullYear(); + for (i = firstYear; i <= lastYear; i++) { + gridData.push(new Date(i + '-01-01 00:00:00')); + } + } else { + gridData = scale.ticks(10); + if (gridData.length > tickNum) { // use only int + gridData = gridData.filter(function (d) { return ("" + d).indexOf('.') < 0; }); + } + } + return gridData; +}; +c3_chart_internal_fn.getGridFilterToRemove = function (params) { + return params ? function (line) { + var found = false; + [].concat(params).forEach(function (param) { + if ((('value' in param && line.value === params.value) || ('class' in param && line.class === params.class))) { + found = true; + } + }); + return found; + } : function () { return true; }; +}; +c3_chart_internal_fn.removeGridLines = function (params, forX) { + var $$ = this, config = $$.config, + toRemove = $$.getGridFilterToRemove(params), + toShow = function (line) { return !toRemove(line); }, + classLines = forX ? CLASS[_xgridLines] : CLASS[_ygridLines], + classLine = forX ? CLASS[_xgridLine] : CLASS.ygridLine; + $$.main.select('.' + classLines).selectAll('.' + classLine).filter(toRemove) + .transition().duration(config[__transition_duration]) + .style('opacity', 0).remove(); + if (forX) { + config[__grid_x_lines] = config[__grid_x_lines].filter(toShow); + } else { + config[__grid_y_lines] = config[__grid_y_lines].filter(toShow); + } +}; diff --git a/src/head.js b/src/head.js new file mode 100644 index 0000000..d77cbd0 --- /dev/null +++ b/src/head.js @@ -0,0 +1,4 @@ +(function (window) { + 'use strict'; + + /*global define, module, exports, require */ diff --git a/src/legend.js b/src/legend.js new file mode 100644 index 0000000..c3199c2 --- /dev/null +++ b/src/legend.js @@ -0,0 +1,294 @@ +c3_chart_internal_fn.initLegend = function () { + var $$ = this; + $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); + if (!config[__legend_show]) { + $$.legend.style('visibility', 'hidden'); + $$.hiddenLegendIds = $$.mapToIds($$.data.targets); + } + // MEMO: call here to update legend box and tranlate for all + // MEMO: translate will be upated by this, so transform not needed in updateLegend() + $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); +}; +c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { + var $$ = this, insetLegendPosition = { + 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 + }; + $$.margin3 = { + top: $$.isLegendRight ? 0 : $$.isLegendInset ? insetLegendPosition.top : $$.currentHeight - legendHeight, + right: NaN, + bottom: 0, + left: $$.isLegendRight ? $$.currentWidth - legendWidth : $$.isLegendInset ? insetLegendPosition.left : 0 + }; +}; +c3_chart_internal_fn.transformLegend = function (withTransition) { + var $$ = this; + (withTransition ? $$.legend.transition() : $$.legend).attr("transform", $$.getTranslate('legend')); +}; +c3_chart_internal_fn.updateLegendStep = function (step) { + this.legendStep = step; +}; +c3_chart_internal_fn.updateLegendItemWidth = function (w) { + this.legendItemWidth = w; +}; +c3_chart_internal_fn.updateLegendItemHeight = function (h) { + this.legendItemHeight = h; +}; +c3_chart_internal_fn.getLegendWidth = function () { + var $$ = this; + return $$.config[__legend_show] ? $$.isLegendRight || $$.isLegendInset ? $$.legendItemWidth * ($$.legendStep + 1) : $$.currentWidth : 0; +}; +c3_chart_internal_fn.getLegendHeight = function () { + var $$ = this, config = $$.config, h = 0; + if (config[__legend_show]) { + if ($$.isLegendRight) { + h = $$.currentHeight; + } else if ($$.isLegendInset) { + h = config[__legend_inset_step] ? Math.max(20, $$.legendItemHeight) * (config[__legend_inset_step] + 1) : $$.height; + } else { + h = Math.max(20, $$.legendItemHeight) * ($$.legendStep + 1); + } + } + return h; +}; +c3_chart_internal_fn.opacityForLegend = function (legendItem) { + var $$ = this; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 1; +}; +c3_chart_internal_fn.opacityForUnfocusedLegend = function (legendItem) { + var $$ = this; + return legendItem.classed(CLASS[_legendItemHidden]) ? $$.legendOpacityForHidden : 0.3; +}; +c3_chart_internal_fn.toggleFocusLegend = function (id, focus) { + var $$ = this; + $$.legend.selectAll('.' + CLASS[_legendItem]) + .transition().duration(100) + .style('opacity', function (_id) { + var This = $$.d3.select(this); + if (id && _id !== id) { + return focus ? $$.opacityForUnfocusedLegend(This) : $$.opacityForLegend(This); + } else { + return focus ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } + }); +}; +c3_chart_internal_fn.revertLegend = function () { + var $$ = this, d3 = $$.d3; + $$.legend.selectAll('.' + CLASS[_legendItem]) + .transition().duration(100) + .style('opacity', function () { return $$.opacityForLegend(d3.select(this)); }); +}; +c3_chart_internal_fn.showLegend = function (targetIds) { + var $$ = this, config = $$.config; + if (!config[__legend_show]) { + config[__legend_show] = true; + $$.legend.style('visibility', 'visible'); + } + $$.removeHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('visibility', 'visible') + .transition() + .style('opacity', function () { return $$.opacityForLegend($$.d3.select(this)); }); +}; +c3_chart_internal_fn.hideLegend = function (targetIds) { + var $$ = this, config = $$.config; + if (config[__legend_show] && isEmpty(targetIds)) { + config[__legend_show] = false; + $$.legend.style('visibility', 'hidden'); + } + $$.addHiddenLegendIds(targetIds); + $$.legend.selectAll($$.selectorLegends(targetIds)) + .style('opacity', 0) + .style('visibility', 'hidden'); +}; +c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { + var $$ = this, config = $$.config; + var xForLegend, xForLegendText, xForLegendRect, yForLegend, yForLegendText, yForLegendRect; + var paddingTop = 4, paddingRight = 36, maxWidth = 0, maxHeight = 0, posMin = 10; + var l, totalLength = 0, offsets = {}, widths = {}, heights = {}, margins = [0], steps = {}, step = 0; + var withTransition, withTransitionForTransform; + var hasFocused = $$.legend.selectAll('.' + CLASS[_legendItemFocused]).size(); + var texts, rects, tiles; + + options = options || {}; + withTransition = getOption(options, "withTransition", true); + withTransitionForTransform = getOption(options, "withTransitionForTransform", true); + + function updatePositions(textElement, id, reset) { + var box = $$.getTextRect(textElement.textContent, CLASS[_legendItem]), + itemWidth = Math.ceil((box.width + paddingRight) / 10) * 10, + itemHeight = Math.ceil((box.height + paddingTop) / 10) * 10, + itemLength = $$.isLegendRight || $$.isLegendInset ? itemHeight : itemWidth, + areaLength = $$.isLegendRight || $$.isLegendInset ? $$.getLegendHeight() : $$.getLegendWidth(), + margin, maxLength; + + // MEMO: care about condifion of step, totalLength + function updateValues(id, withoutStep) { + if (!withoutStep) { + margin = (areaLength - totalLength - itemLength) / 2; + if (margin < posMin) { + margin = (areaLength - itemLength) / 2; + totalLength = 0; + step++; + } + } + steps[id] = step; + margins[step] = $$.isLegendInset ? 10 : margin; + offsets[id] = totalLength; + totalLength += itemLength; + } + + if (reset) { + totalLength = 0; + step = 0; + maxWidth = 0; + maxHeight = 0; + } + + if (config[__legend_show] && !$$.isLegendToShow(id)) { + widths[id] = heights[id] = steps[id] = offsets[id] = 0; + return; + } + + widths[id] = itemWidth; + heights[id] = itemHeight; + + if (!maxWidth || itemWidth >= maxWidth) { maxWidth = itemWidth; } + if (!maxHeight || itemHeight >= maxHeight) { maxHeight = itemHeight; } + maxLength = $$.isLegendRight || $$.isLegendInset ? maxHeight : maxWidth; + + if (config[__legend_equally]) { + Object.keys(widths).forEach(function (id) { widths[id] = maxWidth; }); + Object.keys(heights).forEach(function (id) { heights[id] = maxHeight; }); + margin = (areaLength - maxLength * targetIds.length) / 2; + if (margin < posMin) { + totalLength = 0; + step = 0; + targetIds.forEach(function (id) { updateValues(id); }); + } + else { + updateValues(id, true); + } + } else { + updateValues(id); + } + } + + if ($$.isLegendRight) { + xForLegend = function (id) { return maxWidth * steps[id]; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else if ($$.isLegendInset) { + xForLegend = function (id) { return maxWidth * steps[id] + 10; }; + yForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + } else { + xForLegend = function (id) { return margins[steps[id]] + offsets[id]; }; + yForLegend = function (id) { return maxHeight * steps[id]; }; + } + xForLegendText = function (id, i) { return xForLegend(id, i) + 14; }; + yForLegendText = function (id, i) { return yForLegend(id, i) + 9; }; + xForLegendRect = function (id, i) { return xForLegend(id, i) - 4; }; + yForLegendRect = function (id, i) { return yForLegend(id, i) - 7; }; + + // Define g for legend area + l = $$.legend.selectAll('.' + CLASS[_legendItem]) + .data(targetIds) + .enter().append('g') + .attr('class', function (id) { return $$.generateClass(CLASS[_legendItem], id); }) + .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) + .style('cursor', 'pointer') + .on('click', function (id) { + isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); + }) + .on('mouseover', function (id) { + $$.d3.select(this).classed(CLASS[_legendItemFocused], true); + if (!$$.transiting) { + $$.api.focus(id); + } + if (isFunction(config[__legend_item_onmouseover])) { + config[__legend_item_onmouseover].call($$, id); + } + }) + .on('mouseout', function (id) { + $$.d3.select(this).classed(CLASS[_legendItemFocused], false); + if (!$$.transiting) { + $$.api.revert(); + } + if (isFunction(config[__legend_item_onmouseout])) { + config[__legend_item_onmouseout].call($$, id); + } + }); + l.append('text') + .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) + .each(function (id, i) { updatePositions(this, id, i === 0); }) + .style("pointer-events", "none") + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendText); + l.append('rect') + .attr("class", CLASS[_legendItemEvent]) + .style('fill-opacity', 0) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendRect : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegendRect); + l.append('rect') + .attr("class", CLASS[_legendItemTile]) + .style("pointer-events", "none") + .style('fill', $$.color) + .attr('x', $$.isLegendRight || $$.isLegendInset ? xForLegendText : -200) + .attr('y', $$.isLegendRight || $$.isLegendInset ? -200 : yForLegend) + .attr('width', 10) + .attr('height', 10); + // Set background for inset legend + if ($$.isLegendInset && maxWidth !== 0) { + $$.legend.insert('g', '.' + CLASS[_legendItem]) + .attr("class", CLASS[_legendBackground]) + .append('rect') + .attr('height', $$.getLegendHeight() - 10) + .attr('width', maxWidth * (step + 1) + 10); + } + + texts = $$.legend.selectAll('text') + .data(targetIds) + .text(function (id) { return isDefined(config[__data_names][id]) ? config[__data_names][id] : id; }) // MEMO: needed for update + .each(function (id, i) { updatePositions(this, id, i === 0); }); + (withTransition ? texts.transition() : texts) + .attr('x', xForLegendText) + .attr('y', yForLegendText); + + rects = $$.legend.selectAll('rect.' + CLASS[_legendItemEvent]) + .data(targetIds); + (withTransition ? rects.transition() : rects) + .attr('width', function (id) { return widths[id]; }) + .attr('height', function (id) { return heights[id]; }) + .attr('x', xForLegendRect) + .attr('y', yForLegendRect); + + tiles = $$.legend.selectAll('rect.' + CLASS[_legendItemTile]) + .data(targetIds); + (withTransition ? tiles.transition() : tiles) + .style('fill', $$.color) + .attr('x', xForLegend) + .attr('y', yForLegend); + + // toggle legend state + $$.legend.selectAll('.' + CLASS[_legendItem]) + .classed(CLASS[_legendItemHidden], function (id) { return !$$.isTargetToShow(id); }) + .transition() + .style('opacity', function (id) { + var This = $$.d3.select(this); + if ($$.isTargetToShow(id)) { + return !hasFocused || This.classed(CLASS[_legendItemFocused]) ? $$.opacityForLegend(This) : $$.opacityForUnfocusedLegend(This); + } else { + return $$.legendOpacityForHidden; + } + }); + + // Update all to reflect change of legend + $$.updateLegendItemWidth(maxWidth); + $$.updateLegendItemHeight(maxHeight); + $$.updateLegendStep(step); + // Update size and scale + $$.updateSizes(); + $$.updateScales(); + $$.updateSvgSize(); + // Update g positions + $$.transformAll(withTransitionForTransform, transitions); +}; diff --git a/src/region.js b/src/region.js new file mode 100644 index 0000000..1587fa3 --- /dev/null +++ b/src/region.js @@ -0,0 +1,43 @@ +c3_chart_internal_fn.regionX = function (d) { + var $$ = this, config = $$.config, + xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + xPos = config[__axis_rotated] ? ('start' in d ? yScale(d.start) : 0) : 0; + } else { + xPos = config[__axis_rotated] ? 0 : ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0); + } + return xPos; +}; +c3_chart_internal_fn.regionY = function (d) { + var $$ = this, config = $$.config, + yPos, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + yPos = config[__axis_rotated] ? 0 : ('end' in d ? yScale(d.end) : 0); + } else { + yPos = config[__axis_rotated] ? ('start' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.start) : d.start) : 0) : 0; + } + return yPos; +}; +c3_chart_internal_fn.regionWidth = function (d) { + var $$ = this, config = $$.config, + start = $$.regionX(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = config[__axis_rotated] ? ('end' in d ? yScale(d.end) : $$.width) : $$.width; + } else { + end = config[__axis_rotated] ? $$.width : ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.width); + } + return end < start ? 0 : end - start; +}; +c3_chart_internal_fn.regionHeight = function (d) { + var $$ = this, config = $$.config, + start = this.regionY(d), end, yScale = d.axis === 'y' ? $$.y : $$.y2; + if (d.axis === 'y' || d.axis === 'y2') { + end = config[__axis_rotated] ? $$.height : ('start' in d ? yScale(d.start) : $$.height); + } else { + end = config[__axis_rotated] ? ('end' in d ? $$.x($$.isTimeSeries() ? $$.parseDate(d.end) : d.end) : $$.height) : $$.height; + } + return end < start ? 0 : end - start; +}; +c3_chart_internal_fn.isRegionOnX = function (d) { + return !d.axis || d.axis === 'x'; +}; diff --git a/src/scale.js b/src/scale.js new file mode 100644 index 0000000..3f2c35d --- /dev/null +++ b/src/scale.js @@ -0,0 +1,87 @@ +c3_chart_internal_fn.getScale = function (min, max, forTimeseries) { + return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]); +}; +c3_chart_internal_fn.getX = function (min, max, domain, offset) { + var $$ = this, + scale = $$.getScale(min, max, $$.isTimeSeries()), + _scale = domain ? scale.domain(domain) : scale, key; + // Define customized scale if categorized axis + if ($$.isCategorized()) { + offset = offset || function () { return 0; }; + scale = function (d, raw) { + var v = _scale(d) + offset(d); + return raw ? v : Math.ceil(v); + }; + } else { + scale = function (d, raw) { + var v = _scale(d); + return raw ? v : Math.ceil(v); + }; + } + // define functions + for (key in _scale) { + scale[key] = _scale[key]; + } + scale.orgDomain = function () { + return _scale.domain(); + }; + // define custom domain() for categorized axis + if ($$.isCategorized()) { + scale.domain = function (domain) { + if (!arguments.length) { + domain = this.orgDomain(); + return [domain[0], domain[1] + 1]; + } + _scale.domain(domain); + return scale; + }; + } + return scale; +}; +c3_chart_internal_fn.getY = function (min, max, domain) { + var scale = this.getScale(min, max); + if (domain) { scale.domain(domain); } + return scale; +}; +c3_chart_internal_fn.getYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.y2 : this.y; +}; +c3_chart_internal_fn.getSubYScale = function (id) { + return this.getAxisId(id) === 'y2' ? this.subY2 : this.subY; +}; +c3_chart_internal_fn.updateScales = function () { + var $$ = this, config = $$.config, + forInit = !$$.x; + // update edges + $$.xMin = config[__axis_rotated] ? 1 : 0; + $$.xMax = config[__axis_rotated] ? $$.height : $$.width; + $$.yMin = config[__axis_rotated] ? 0 : $$.height; + $$.yMax = config[__axis_rotated] ? $$.width : 1; + $$.subXMin = $$.xMin; + $$.subXMax = $$.xMax; + $$.subYMin = config[__axis_rotated] ? 0 : $$.height2; + $$.subYMax = config[__axis_rotated] ? $$.width2 : 1; + // update scales + $$.x = $$.getX($$.xMin, $$.xMax, forInit ? undefined : $$.x.orgDomain(), function () { return $$.xAxis.tickOffset(); }); + $$.y = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y.domain()); + $$.y2 = $$.getY($$.yMin, $$.yMax, forInit ? undefined : $$.y2.domain()); + $$.subX = $$.getX($$.xMin, $$.xMax, $$.orgXDomain, function (d) { return d % 1 ? 0 : $$.subXAxis.tickOffset(); }); + $$.subY = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY.domain()); + $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? undefined : $$.subY2.domain()); + // update axes + $$.xAxisTickFormat = $$.getXAxisTickFormat(); + $$.xAxisTickValues = config[__axis_x_tick_values] ? config[__axis_x_tick_values] : (forInit ? undefined : $$.xAxis.tickValues()); + $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues); + $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config[__axis_y_tick_format], config[__axis_y_ticks]); + $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config[__axis_y2_tick_format], config[__axis_y2_ticks]); + // Set initialized scales to brush and zoom + if (!forInit) { + if ($$.brush) { $$.brush.scale($$.subX); } + if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } + } + // update for arc + if (isFunction($$.updateArc)) { + $$.updateArc(); + } +}; diff --git a/src/selection.js b/src/selection.js new file mode 100644 index 0000000..6dbe75f --- /dev/null +++ b/src/selection.js @@ -0,0 +1,80 @@ + c3_chart_internal_fn.selectPoint = function (target, d, i) { + var $$ = this, config = $$.config; + config[__data_onselected](d, target.node()); + // add selected-circle on low layer g + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) + .data([d]) + .enter().append('circle') + .attr("class", function () { return $$.generateClass(CLASS[_selectedCircle], i); }) + .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) + .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY) + .attr("stroke", function () { return $$.color(d); }) + .attr("r", $$.pointSelectR(d) * 1.4) + .transition().duration(100) + .attr("r", $$.pointSelectR); + }; + c3_chart_internal_fn.unselectPoint = function (target, d, i) { + var $$ = this; + $$.config[__data_onunselected](d, target.node()); + // remove selected-circle from low layer g + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) + .transition().duration(100).attr('r', 0) + .remove(); + }; + c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { + selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); + }; + c3_chart_internal_fn.selectBar = function (target, d) { + var $$ = this; + $$.config[__data_onselected].call($$, d, target.node()); + target.transition().duration(100) + .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + }; + c3_chart_internal_fn.unselectBar = function (target, d) { + var $$ = this; + $$.config[__data_onunselected].call($$, d, target.node()); + target.transition().duration(100) + .style("fill", function () { return $$.color(d); }); + }; + c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { + selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); + }; + c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { + this.toggleBar(selected, target, d.data, i); + }; + c3_chart_internal_fn.getToggle = function (that) { + var $$ = this; + // path selection not supported yet + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[_bar]) ? $$.toggleBar : $$.toggleArc); + }; + c3_chart_internal_fn.toggleShape = function (that, d, i) { + var $$ = this, d3 = $$.d3, config = $$.config, + shape = d3.select(that), isSelected = shape.classed(CLASS[_SELECTED]), isWithin, toggle; + if (that.nodeName === 'circle') { + isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); + toggle = $$.togglePoint; + } + else if (that.nodeName === 'path') { + if (shape.classed(CLASS[_bar])) { + isWithin = $$.isWithinBar(that); + toggle = $$.toggleBar; + } else { // would be arc + isWithin = true; + toggle = $$.toggleArc; + } + } + if (config[__data_selection_grouped] || isWithin) { + if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { + if (!config[__data_selection_multiple]) { + $$.main.selectAll('.' + CLASS[_shapes] + (config[__data_selection_grouped] ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this); + if (shape.classed(CLASS[_SELECTED])) { toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); } + }); + } + shape.classed(CLASS[_SELECTED], !isSelected); + toggle(!isSelected, shape, d, i); + } + $$.config[__data_onclick](d, that); + } + }; + diff --git a/src/shape.js b/src/shape.js new file mode 100644 index 0000000..5dde72a --- /dev/null +++ b/src/shape.js @@ -0,0 +1,386 @@ +c3_chart_internal_fn.getShapeIndices = function (typeFilter) { + var $$ = this, config = $$.config, + indices = {}, i = 0, j, k; + $$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach(function (d) { + for (j = 0; j < config[__data_groups].length; j++) { + if (config[__data_groups][j].indexOf(d.id) < 0) { continue; } + for (k = 0; k < config[__data_groups][j].length; k++) { + if (config[__data_groups][j][k] in indices) { + indices[d.id] = indices[config[__data_groups][j][k]]; + break; + } + } + } + if (isUndefined(indices[d.id])) { indices[d.id] = i++; } + }); + indices.__max__ = i - 1; + return indices; +}; +c3_chart_internal_fn.getShapeX = function (offset, targetsNum, indices, isSub) { + var $$ = this, scale = isSub ? $$.subX : $$.x; + return function (d) { + var index = d.id in indices ? indices[d.id] : 0; + return d.x || d.x === 0 ? scale(d.x) - offset * (targetsNum / 2 - index) : 0; + }; +}; +c3_chart_internal_fn.getShapeY = function (isSub) { + var $$ = this; + return function (d) { + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id); + return scale(d.value); + }; +}; +c3_chart_internal_fn.getShapeOffset = function (typeFilter, indices, isSub) { + var $$ = this, + targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$))), + targetIds = targets.map(function (t) { return t.id; }); + return function (d, i) { + var scale = isSub ? $$.getSubYScale(d.id) : $$.getYScale(d.id), + y0 = scale(0), offset = y0; + targets.forEach(function (t) { + if (t.id === d.id || indices[t.id] !== indices[d.id]) { return; } + if (targetIds.indexOf(t.id) < targetIds.indexOf(d.id) && t.values[i].value * d.value >= 0) { + offset += scale(t.values[i].value) - y0; + } + }); + return offset; + }; +}; + +c3_chart_internal_fn.getInterpolate = function (d) { + var $$ = this; + return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; +}; + + +c3_chart_internal_fn.circleX = function (d) { + return d.x || d.x === 0 ? this.x(d.x) : null; +}; +c3_chart_internal_fn.circleY = function (d, i) { + var $$ = this, + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); +}; +c3_chart_internal_fn.getCircles = function (i, id) { + var $$ = this; + return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); +}; +c3_chart_internal_fn.expandCircles = function (i, id) { + var $$ = this; + $$.getCircles(i, id) + .classed(CLASS[_EXPANDED], true) + .attr('r', generateCall($$.pointExpandedR, $$)); +}; +c3_chart_internal_fn.unexpandCircles = function (i) { + var $$ = this; + $$.getCircles(i) + .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) + .classed(CLASS[_EXPANDED], false) + .attr('r', generateCall($$.pointR, $$)); +}; +c3_chart_internal_fn.pointR = function (d) { + var $$ = this, config = $$.config; + return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; +}; +c3_chart_internal_fn.pointExpandedR = function (d) { + var $$ = this, config = $$.config; + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); +}; +c3_chart_internal_fn.pointSelectR = function (d) { + var $$ = this, config = $$.config; + return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; +}; + + + +c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { + var $$ = this, config = $$.config, + w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; + return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; +}; +c3_chart_internal_fn.getBars = function (i) { + var $$ = this; + return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); +}; +c3_chart_internal_fn.expandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], true); +}; +c3_chart_internal_fn.unexpandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], false); +}; +c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { + var $$ = this, config = $$.config, + getPoints = $$.generateGetBarPoints(barIndices, isSub); + return function (d, i) { + // 4 points that make a bar + var points = getPoints(d, i); + + // switch points if axis is rotated, not applicable for sub chart + var indexX = config[__axis_rotated] ? 1 : 0; + var indexY = config[__axis_rotated] ? 0 : 1; + + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + + 'z'; + + return path; + }; +}; +c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { + var $$ = this, + barTargetsNum = barIndices.__max__ + 1, + barW = $$.getBarW($$.xAxis, barTargetsNum), + barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = $$.getShapeY(!!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = barOffset(d, i) || y0, // offset is for stacked bar chart + posX = barX(d), posY = barY(d); + // fix posY not to overflow opposite quadrant + if ($$.config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 4 points that make a bar + return [ + [posX, offset], + [posX, posY - (y0 - offset)], + [posX + barW, posY - (y0 - offset)], + [posX + barW, offset] + ]; + }; +}; + +c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { + var $$ = this, config = $$.config, area = $$.d3.svg.area(), + getPoint = $$.generateGetAreaPoint(areaIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + value0 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + }, + value1 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(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); + + return function (d) { + var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + if ($$.isAreaType(d)) { + path = area.interpolate($$.getInterpolate(d))(data); + } else { + if (data[0]) { + x0 = $$.x(data[0].x); + y0 = $$.getYScale(d.id)(data[0].value); + } + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; +}; + +c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { + var $$ = this, config = $$.config, + line = $$.d3.svg.line(), + getPoint = $$.generateGetLinePoint(lineIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + yValue = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); + }; + + line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } + return function (d) { + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, + x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; + if ($$.isLineType(d)) { + if (config[__data_regions][d.id]) { + path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); + } else { + path = line.interpolate($$.getInterpolate(d))(data); + } + } else { + if (data[0]) { + x0 = x(data[0].x); + y0 = y(data[0].value); + } + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; +}; + +c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { + var $$ = this, + getPoints = $$.generateGetBarPoints(barIndices, false), + getter = forX ? $$.getXForText : $$.getYForText; + return function (d, i) { + return getter(getPoints(d, i), d, this); + }; +}; +c3_chart_internal_fn.getXForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), xPos, padding; + if (config[__axis_rotated]) { + padding = $$.isBarType(d) ? 4 : 6; + xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); + } else { + xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + } + return xPos > $$.width ? $$.width - box.width : xPos; +}; +c3_chart_internal_fn.getYForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), yPos; + if (config[__axis_rotated]) { + yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; + } else { + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); + } + return yPos < box.height ? box.height : yPos; +}; + +c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, config = $$.config, + areaTargetsNum = areaIndices.__max__ + 1, + x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = $$.getShapeY(!!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = areaOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the area position + return [ + [posX, offset], + [posX, posY - (y0 - offset)] + ]; + }; +}; + +c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, config = $$.config, + lineTargetsNum = lineIndices.__max__ + 1, + x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), + y = $$.getShapeY(!!isSub), + lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = lineOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the line position + return [ + [posX, posY - (y0 - offset)] + ]; + }; +}; + + +c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { + var $$ = this, config = $$.config, + prev = -1, i, j, + s = "M", sWithRegion, + xp, yp, dx, dy, dd, diff, diffx2, + xValue, yValue, + regions = []; + + // Check start/end of regions + if (isDefined(_regions)) { + for (i = 0; i < _regions.length; i++) { + regions[i] = {}; + if (isUndefined(_regions[i].start)) { + regions[i].start = d[0].x; + } else { + regions[i].start = $$.isTimeSeries() ? $$.parseDate(_regions[i].start) : _regions[i].start; + } + if (isUndefined(_regions[i].end)) { + regions[i].end = d[d.length - 1].x; + } else { + regions[i].end = $$.isTimeSeries() ? $$.parseDate(_regions[i].end) : _regions[i].end; + } + } + } + + // Set scales + 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); }; + + // Define svg generator function for region + if ($$.isTimeSeries()) { + sWithRegion = function (d0, d1, j, diff) { + var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, + xv0 = new Date(x0 + x_diff * j), + xv1 = new Date(x0 + x_diff * (j + diff)); + return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); + }; + } else { + sWithRegion = function (d0, d1, j, diff) { + return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); + }; + } + + // Generate + for (i = 0; i < d.length; i++) { + + // Draw as normal + if (isUndefined(regions) || ! $$.isWithinRegions(d[i].x, regions)) { + s += " " + xValue(d[i]) + " " + yValue(d[i]); + } + // Draw with region // TODO: Fix for horizotal charts + else { + xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries()); + yp = $$.getScale(d[i - 1].value, d[i].value); + + dx = x(d[i].x) - x(d[i - 1].x); + dy = y(d[i].value) - y(d[i - 1].value); + dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + diff = 2 / dd; + diffx2 = diff * 2; + + for (j = diff; j <= 1; j += diffx2) { + s += sWithRegion(d[i - 1], d[i], j, diff); + } + } + prev = d[i].x; + } + + return s; +}; +c3_chart_internal_fn.isWithinCircle = function (_this, _r) { + var d3 = this.d3, + mouse = d3.mouse(_this), d3_this = d3.select(_this), + cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; + return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; +}; +c3_chart_internal_fn.isWithinBar = function (_this) { + var d3 = this.d3, + mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), + seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), + x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, + sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; + return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; +}; +c3_chart_internal_fn.isWithinRegions = function (x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; +}; diff --git a/src/size.js b/src/size.js new file mode 100644 index 0000000..ad3b2cb --- /dev/null +++ b/src/size.js @@ -0,0 +1,101 @@ +c3_chart_internal_fn.getCurrentWidth = function () { + var $$ = this, config = $$.config; + return config[__size_width] ? config[__size_width] : $$.getParentWidth(); +}; +c3_chart_internal_fn.getCurrentHeight = function () { + var $$ = this, config = $$.config, + h = config[__size_height] ? config[__size_height] : $$.getParentHeight(); + return h > 0 ? h : 320; +}; +c3_chart_internal_fn.getCurrentPaddingTop = function () { + var config = this.config; + return isValue(config[__padding_top]) ? config[__padding_top] : 0; +}; +c3_chart_internal_fn.getCurrentPaddingBottom = function () { + var config = this.config; + return isValue(config[__padding_bottom]) ? config[__padding_bottom] : 0; +}; +c3_chart_internal_fn.getCurrentPaddingLeft = function () { + var $$ = this, config = $$.config; + if (isValue(config[__padding_left])) { + return config[__padding_left]; + } else if (config[__axis_rotated]) { + return !config[__axis_x_show] ? 1 : Math.max(ceil10($$.getAxisWidthByAxisId('x')), 40); + } else { + return !config[__axis_y_show] ? 1 : ceil10($$.getAxisWidthByAxisId('y')); + } +}; +c3_chart_internal_fn.getCurrentPaddingRight = function () { + var $$ = this, config = $$.config, + defaultPadding = 10, legendWidthOnRight = $$.isLegendRight ? $$.getLegendWidth() + 20 : 0; + if (isValue(config[__padding_right])) { + return config[__padding_right] + 1; // 1 is needed not to hide tick line + } else if (config[__axis_rotated]) { + return defaultPadding + legendWidthOnRight; + } else { + return (!config[__axis_y2_show] ? defaultPadding : ceil10($$.getAxisWidthByAxisId('y2'))) + legendWidthOnRight; + } +}; + +c3_chart_internal_fn.getParentRectValue = function (key) { + var parent = this.selectChart.node(), v; + while (parent && parent.tagName !== 'BODY') { + v = parent.getBoundingClientRect()[key]; + if (v) { + break; + } + parent = parent.parentNode; + } + return v; +}; +c3_chart_internal_fn.getParentWidth = function () { + return this.getParentRectValue('width'); +}; +c3_chart_internal_fn.getParentHeight = function () { + var h = this.selectChart.style('height'); + return h.indexOf('px') > 0 ? +h.replace('px', '') : 0; +}; + + +c3_chart_internal_fn.getSvgLeft = function () { + var $$ = this, config = $$.config, + leftAxisClass = config[__axis_rotated] ? CLASS[_axisX] : CLASS[_axisY], + leftAxis = $$.main.select('.' + leftAxisClass).node(), + svgRect = leftAxis ? leftAxis.getBoundingClientRect() : {right: 0}, + chartRect = $$.selectChart.node().getBoundingClientRect(), + hasArc = $$.hasArcType(), + svgLeft = svgRect.right - chartRect.left - (hasArc ? 0 : $$.getCurrentPaddingLeft()); + return svgLeft > 0 ? svgLeft : 0; +}; + + +c3_chart_internal_fn.getAxisWidthByAxisId = function (id) { + var $$ = this, position = $$.getAxisLabelPositionById(id); + return position.isInner ? 20 + $$.getMaxTickWidth(id) : 40 + $$.getMaxTickWidth(id); +}; +c3_chart_internal_fn.getHorizontalAxisHeight = function (axisId) { + var $$ = this, config = $$.config; + if (axisId === 'x' && !config[__axis_x_show]) { return 0; } + if (axisId === 'x' && config[__axis_x_height]) { return config[__axis_x_height]; } + if (axisId === 'y' && !config[__axis_y_show]) { return config[__legend_show] && !$$.isLegendRight && !$$.isLegendInset ? 10 : 1; } + if (axisId === 'y2' && !config[__axis_y2_show]) { return $$.rotated_padding_top; } + return ($$.getAxisLabelPositionById(axisId).isInner ? 30 : 40) + (axisId === 'y2' ? -10 : 0); +}; + +c3_chart_internal_fn.getEventRectWidth = function () { + var $$ = this; + var target = $$.getMaxDataCountTarget($$.data.targets), + firstData, lastData, base, maxDataCount, ratio, w; + if (!target) { + return 0; + } + firstData = target.values[0], lastData = target.values[target.values.length - 1]; + base = $$.x(lastData.x) - $$.x(firstData.x); + if (base === 0) { + return $$.config[__axis_rotated] ? $$.height : $$.width; + } + maxDataCount = $$.getMaxDataCount(); + ratio = ($$.hasType('bar') ? (maxDataCount - ($$.isCategorized() ? 0.25 : 1)) / maxDataCount : 1); + w = maxDataCount > 1 ? (base * ratio) / (maxDataCount - 1) : base; + return w < 1 ? 1 : w; +}; diff --git a/src/subchart.js b/src/subchart.js new file mode 100644 index 0000000..c9d2cbb --- /dev/null +++ b/src/subchart.js @@ -0,0 +1,173 @@ +c3_chart_internal_fn.initBrush = function () { + var $$ = this, d3 = $$.d3; + $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); + $$.brush.update = function () { + if ($$.context) { $$.context.select('.' + $$.CLASS[_brush]).call(this); } + return this; + }; + $$.brush.scale = function (scale) { + return $$.config[__axis_rotated] ? this.y(scale) : this.x(scale); + }; +}; +c3_chart_internal_fn.initSubchart = function () { + var $$ = this, config = $$.config, + context = $$.context = $$.svg.append("g").attr("transform", $$.getTranslate('context')); + + if (!config[__subchart_show]) { + context.style('visibility', 'hidden'); + } + + // Define g for chart area + context.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS[_chart]); + + // Define g for bar chart area + context.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); + + // Define g for line chart area + context.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); + + // Add extent rect for Brush + context.append("g") + .attr("clip-path", $$.clipPath) + .attr("class", CLASS[_brush]) + .call($$.brush) + .selectAll("rect") + .attr(config[__axis_rotated] ? "width" : "height", config[__axis_rotated] ? $$.width2 : $$.height2); + + // ATTENTION: This must be called AFTER chart added + // Add Axis + $$.axes.subx = context.append("g") + .attr("class", CLASS[_axisX]) + .attr("transform", $$.getTranslate('subx')) + .attr("clip-path", config[__axis_rotated] ? "" : $$.clipPathForXAxis); +}; +c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { + var $$ = this, context = $$.context, config = $$.config, + contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + + if (config[__subchart_show]) { + + contextBarUpdate = context.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) + .data(targets) + .attr('class', generateCall($$.classChartBar, $$)); + contextBarEnter = contextBarUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', generateCall($$.classChartBar, $$)); + // Bars for each data + contextBarEnter.append('g') + .attr("class", generateCall($$.classBars, $$)); + + //-- Line --// + contextLineUpdate = context.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) + .data(targets) + .attr('class', generateCall($$.classChartLine, $$)); + contextLineEnter = contextLineUpdate.enter().append('g') + .style('opacity', 0) + .attr('class', generateCall($$.classChartLine, $$)); + // Lines for each data + contextLineEnter.append("g") + .attr("class", generateCall($$.classLines, $$)); + // Area + contextLineEnter.append("g") + .attr("class", generateCall($$.classAreas, $$)); + } +}; +c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { + var $$ = this, d3 = $$.d3, context = $$.context, config = $$.config, + contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; + + // subchart + if (config[__subchart_show]) { + // reflect main chart to extent on subchart if zoomed + if (d3.event && d3.event.type === 'zoom') { + $$.brush.extent($$.x.orgDomain()).update(); + } + // update subchart elements if needed + if (withSubchart) { + + // rotate tick text if needed + if (!config[__axis_rotated] && config[__axis_x_tick_rotate]) { + $$.rotateTickText($$.axes.subx, transitions.axisSubX, config[__axis_x_tick_rotate]); + } + + // extent rect + if (!$$.brush.empty()) { + $$.brush.extent($$.x.orgDomain()).update(); + } + // setup drawer - MEMO: this must be called after axis updated + drawAreaOnSub = $$.generateDrawArea(areaIndices, true); + drawBarOnSub = $$.generateDrawBar(barIndices, true); + drawLineOnSub = $$.generateDrawLine(lineIndices, true); + // bars + contextBar = context.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) + .data(generateCall($$.barData, $$)); + contextBar.enter().append('path') + .attr("class", generateCall($$.classBar, $$)) + .style("stroke", 'none') + .style("fill", $$.color); + contextBar + .style("opacity", generateCall($$.initialOpacity, $$)) + .transition().duration(duration) + .attr('d', drawBarOnSub) + .style('opacity', 1); + contextBar.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // lines + contextLine = context.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) + .data(generateCall($$.lineData, $$)); + contextLine.enter().append('path') + .attr('class', generateCall($$.classLine, $$)) + .style('stroke', $$.color); + contextLine + .style("opacity", generateCall($$.initialOpacity, $$)) + .transition().duration(duration) + .attr("d", drawLineOnSub) + .style('opacity', 1); + contextLine.exit().transition().duration(duration) + .style('opacity', 0) + .remove(); + // area + contextArea = context.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) + .data(generateCall($$.lineData, $$)); + contextArea.enter().append('path') + .attr("class", generateCall($$.classArea, $$)) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + contextArea + .style("opacity", 0) + .transition().duration(duration) + .attr("d", drawAreaOnSub) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity); + contextArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + } + } +}; +c3_chart_internal_fn.redrawForBrush = function () { + var $$ = this, x = $$.x; + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false, + withUpdateXDomain: true + }); + $$.config[__subchart_onbrush].call($$, x.orgDomain()); +}; +c3_chart_internal_fn.transformContext = function (withTransition, transitions) { + var $$ = this, subXAxis; + if (transitions && transitions.axisSubX) { + subXAxis = transitions.axisSubX; + } else { + subXAxis = $$.context.select('.' + CLASS[_axisX]); + if (withTransition) { subXAxis = subXAxis.transition(); } + } + $$.context.attr("transform", $$.getTranslate('context')); + subXAxis.attr("transform", $$.getTranslate('subx')); +}; diff --git a/src/tail.js b/src/tail.js new file mode 100644 index 0000000..7e78a25 --- /dev/null +++ b/src/tail.js @@ -0,0 +1,9 @@ + if (typeof define === 'function' && define.amd) { + define("c3", ["d3"], c3); + } else if ('undefined' !== typeof exports && 'undefined' !== typeof module) { + module.exports = c3; + } else { + window.c3 = c3; + } + +})(window); diff --git a/src/text.js b/src/text.js new file mode 100644 index 0000000..0aa6e62 --- /dev/null +++ b/src/text.js @@ -0,0 +1,11 @@ +c3_chart_internal_fn.getTextRect = function (text, cls) { + var rect; + this.d3.select('body').selectAll('.dummy') + .data([text]) + .enter().append('text') + .classed(cls ? cls : "", true) + .text(text) + .each(function () { rect = this.getBoundingClientRect(); }) + .remove(); + return rect; +}; diff --git a/src/tooltip.js b/src/tooltip.js new file mode 100644 index 0000000..2b005d2 --- /dev/null +++ b/src/tooltip.js @@ -0,0 +1,98 @@ +c3_chart_internal_fn.initTooltip = function () { + var $$ = this, config = $$.config, i; + $$.tooltip = $$.selectChart + .style("position", "relative") + .append("div") + .style("position", "absolute") + .style("pointer-events", "none") + .style("z-index", "10") + .style("display", "none"); + // Show tooltip if needed + if (config[__tooltip_init_show]) { + if ($$.isTimeSeries() && isString(config[__tooltip_init_x])) { + config[__tooltip_init_x] = $$.parseDate(config[__tooltip_init_x]); + for (i = 0; i < $$.data.targets[0].values.length; i++) { + if (($$.data.targets[0].values[i].x - config[__tooltip_init_x]) === 0) { break; } + } + config[__tooltip_init_x] = i; + } + $$.tooltip.html(config[__tooltip_contents].call($$, $$.data.targets.map(function (d) { + return $$.addName(d.values[config[__tooltip_init_x]]); + }), $$.getXAxisTickFormat(), $$.getYFormat($$.hasArcType()), $$.color)); + $$.tooltip.style("top", config[__tooltip_init_position].top) + .style("left", config[__tooltip_init_position].left) + .style("display", "block"); + } +}; +c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaultValueFormat, color) { + var $$ = this, config = $$.config, + titleFormat = config[__tooltip_format_title] || defaultTitleFormat, + nameFormat = config[__tooltip_format_name] || function (name) { return name; }, + valueFormat = config[__tooltip_format_value] || defaultValueFormat, + text, i, title, value, name, bgcolor; + for (i = 0; i < d.length; i++) { + if (! (d[i] && (d[i].value || d[i].value === 0))) { continue; } + + if (! text) { + title = titleFormat ? titleFormat(d[i].x) : d[i].x; + text = "" + (title || title === 0 ? "" : ""); + } + + name = nameFormat(d[i].name); + value = valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index); + bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id); + + text += ""; + text += ""; + text += ""; + text += ""; + } + return text + "
" + title + "
" + name + "" + value + "
"; +}; +c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { + var $$ = this, config = $$.config; + var tWidth, tHeight, svgLeft, tooltipLeft, tooltipRight, tooltipTop, chartRight; + var forArc = $$.hasArcType(), + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + if (dataToShow.length === 0 || !config[__tooltip_show]) { + return; + } + $$.tooltip.html(config[__tooltip_contents].call($$, selectedData, $$.getXAxisTickFormat(), $$.getYFormat(forArc), $$.color)).style("display", "block"); + + // Get tooltip dimensions + tWidth = $$.tooltip.property('offsetWidth'); + tHeight = $$.tooltip.property('offsetHeight'); + // Determin tooltip position + if (forArc) { + tooltipLeft = ($$.width / 2) + mouse[0]; + tooltipTop = ($$.height / 2) + mouse[1] + 20; + } else { + if (config[__axis_rotated]) { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + mouse[0] + 100; + tooltipRight = tooltipLeft + tWidth; + chartRight = $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = $$.x(dataToShow[0].x) + 20; + } else { + svgLeft = $$.getSvgLeft(); + tooltipLeft = svgLeft + $$.getCurrentPaddingLeft() + $$.x(dataToShow[0].x) + 20; + tooltipRight = tooltipLeft + tWidth; + chartRight = svgLeft + $$.getCurrentWidth() - $$.getCurrentPaddingRight(); + tooltipTop = mouse[1] + 15; + } + + if (tooltipRight > chartRight) { + tooltipLeft -= tooltipRight - chartRight; + } + if (tooltipTop + tHeight > $$.getCurrentHeight()) { + tooltipTop -= tHeight + 30; + } + } + // Set tooltip + $$.tooltip + .style("top", tooltipTop + "px") + .style("left", tooltipLeft + 'px'); +}; +c3_chart_internal_fn.hideTooltip = function () { + this.tooltip.style("display", "none"); +}; diff --git a/src/type.js b/src/type.js new file mode 100644 index 0000000..bd7217a --- /dev/null +++ b/src/type.js @@ -0,0 +1,81 @@ +c3_chart_internal_fn.setTargetType = function (targetIds, type) { + var $$ = this, config = $$.config; + $$.mapToTargetIds(targetIds).forEach(function (id) { + $$.withoutFadeIn[id] = (type === config[__data_types][id]); + config[__data_types][id] = type; + }); + if (!targetIds) { + config[__data_type] = type; + } +}; +c3_chart_internal_fn.hasType = function (type, targets) { + var $$ = this, types = $$.config[__data_types], has = false; + (targets || $$.data.targets).forEach(function (t) { + if ((types[t.id] && types[t.id].indexOf(type) >= 0) || (!(t.id in types) && type === 'line')) { + has = true; + } + }); + return has; +}; +c3_chart_internal_fn.hasArcType = function (targets) { + return this.hasType('pie', targets) || this.hasType('donut', targets) || this.hasType('gauge', targets); +}; +c3_chart_internal_fn.isLineType = function (d) { + var config = this.config, id = isString(d) ? d : d.id; + return !config[__data_types][id] || ['line', 'spline', 'area', 'area-spline', 'step', 'area-step'].indexOf(config[__data_types][id]) >= 0; +}; +c3_chart_internal_fn.isStepType = function (d) { + var id = isString(d) ? d : d.id; + return ['step', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; +}; +c3_chart_internal_fn.isSplineType = function (d) { + var id = isString(d) ? d : d.id; + return ['spline', 'area-spline'].indexOf(this.config[__data_types][id]) >= 0; +}; +c3_chart_internal_fn.isAreaType = function (d) { + var id = isString(d) ? d : d.id; + return ['area', 'area-spline', 'area-step'].indexOf(this.config[__data_types][id]) >= 0; +}; +c3_chart_internal_fn.isBarType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'bar'; +}; +c3_chart_internal_fn.isScatterType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'scatter'; +}; +c3_chart_internal_fn.isPieType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'pie'; +}; +c3_chart_internal_fn.isGaugeType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'gauge'; +}; +c3_chart_internal_fn.isDonutType = function (d) { + var id = isString(d) ? d : d.id; + return this.config[__data_types][id] === 'donut'; +}; +c3_chart_internal_fn.isArcType = function (d) { + return this.isPieType(d) || this.isDonutType(d) || this.isGaugeType(d); +}; +c3_chart_internal_fn.lineData = function (d) { + return this.isLineType(d) ? [d] : []; +}; +c3_chart_internal_fn.arcData = function (d) { + return this.isArcType(d.data) ? [d] : []; +}; +/* not used + function scatterData(d) { + return isScatterType(d) ? d.values : []; + } + */ +c3_chart_internal_fn.barData = function (d) { + return this.isBarType(d) ? d.values : []; +}; +c3_chart_internal_fn.lineOrScatterData = function (d) { + return this.isLineType(d) || this.isScatterType(d) ? d.values : []; +}; +c3_chart_internal_fn.barOrLineData = function (d) { + return this.isBarType(d) || this.isLineType(d) ? d.values : []; +}; diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..f94982d --- /dev/null +++ b/src/util.js @@ -0,0 +1,49 @@ +var isValue = c3_chart_internal_fn.isValue = function (v) { + return v || v === 0; +}, + isFunction = c3_chart_internal_fn.isFunction = function (o) { + return typeof o === 'function'; + }, + isString = c3_chart_internal_fn.isString = function (o) { + return typeof o === 'string'; + }, + isUndefined = c3_chart_internal_fn.isUndefined = function (v) { + return typeof v === 'undefined'; + }, + isDefined = c3_chart_internal_fn.isDefined = function (v) { + return typeof v !== 'undefined'; + }, + ceil10 = c3_chart_internal_fn.ceil10 = function (v) { + return Math.ceil(v / 10) * 10; + }, + asHalfPixel = c3_chart_internal_fn.asHalfPixel = function (n) { + return Math.ceil(n) + 0.5; + }, + diffDomain = c3_chart_internal_fn.diffDomain = function (d) { + return d[1] - d[0]; + }, + isEmpty = c3_chart_internal_fn.isEmpty = function (o) { + return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); + }, + notEmpty = c3_chart_internal_fn.notEmpty = function (o) { + return Object.keys(o).length > 0; + }, + getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { + return isDefined(options[key]) ? options[key] : defaultValue; + }, + hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { + var found = false; + Object.keys(dict).forEach(function (key) { + if (dict[key] === value) { found = true; } + }); + return found; + }, + getPathBox = c3_chart_internal_fn.getPathBox = function (path) { + var box = path.getBoundingClientRect(), + items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], + minX = items[0].x, minY = Math.min(items[0].y, items[1].y); + return {x: minX, y: minY, width: box.width, height: box.height}; + }, + generateCall = c3_chart_internal_fn.generateCall = function (f, context) { + return function (d, i) { return f.call(context, d, i); }; + }; diff --git a/src/zoom.js b/src/zoom.js new file mode 100644 index 0000000..cdbe784 --- /dev/null +++ b/src/zoom.js @@ -0,0 +1,52 @@ +c3_chart_internal_fn.initZoom = function () { + var $$ = this, d3 = $$.d3, config = $$.config; + $$.zoom = d3.behavior.zoom() + .on("zoomstart", function () { + $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; + }) + .on("zoom", $$.redrawForZoom); + $$.zoom.scale = function (scale) { + return config[__axis_rotated] ? this.y(scale) : this.x(scale); + }; + $$.zoom.orgScaleExtent = function () { + var extent = config[__zoom_extent] ? config[__zoom_extent] : [1, 10]; + return [extent[0], Math.max($$.getMaxDataCount() / extent[1], extent[1])]; + }; + $$.zoom.updateScaleExtent = function () { + var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), + extent = $$.orgScaleExtent(); + $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + return this; + }; +}; +c3_chart_internal_fn.updateZoom = function () { + var $$ = this, z = $$.config[__zoom_enabled] ? $$.zoom : function () {}; + $$.main.select('.' + $$.CLASS[_zoomRect]).call(z); + $$.main.selectAll('.' + $$.CLASS[_eventRect]).call(z); +}; +c3_chart_internal_fn.redrawForZoom = function () { + var $$ = this, d3 = $$.d3, config = $$.config, zoom = $$.zoom, x = $$.x, orgXDomain = $$.orgXDomain; + if (!config[__zoom_enabled]) { + return; + } + if ($$.filterTargetsToShow($$.data.targets).length === 0) { + return; + } + if (d3.event.sourceEvent.type === 'mousemove' && zoom.altDomain) { + x.domain(zoom.altDomain); + zoom.scale(x).updateScaleExtent(); + return; + } + if ($$.isCategorized() && x.orgDomain()[0] === orgXDomain[0]) { + x.domain([orgXDomain[0] - 1e-10, x.orgDomain()[1]]); + } + $$.redraw({ + withTransition: false, + withY: false, + withSubchart: false + }); + if (d3.event.sourceEvent.type === 'mousemove') { + $$.cancelClick = true; + } + config[__zoom_onzoom].call(c3, x.orgDomain()); +}; From 3aae9ba4df64409d5ca64c849692c9cfb9bcfeb4 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 1 Aug 2014 21:54:42 +0100 Subject: [PATCH 24/44] Fix gauge --- src/arc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/arc.js b/src/arc.js index f729a73..9ebfa74 100644 --- a/src/arc.js +++ b/src/arc.js @@ -211,11 +211,11 @@ c3_chart_internal_fn.updateTargetsForArc = function (targets) { }; c3_chart_internal_fn.initArc = function () { - var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS[_chart]).append("g") + var $$ = this; + $$.arcs = $$.main.select('.' + CLASS[_chart]).append("g") .attr("class", CLASS[_chartArcs]) .attr("transform", $$.getTranslate('arc')); - arcs.append('text') + $$.arcs.append('text') .attr('class', CLASS[_chartArcsTitle]) .style("text-anchor", "middle") .text($$.getArcTitle()); @@ -323,7 +323,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf }; c3_chart_internal_fn.initGauge = function () { - var $$ = this, config = $$.config, arcs; + var $$ = this, config = $$.config, arcs = $$.arcs; if ($$.hasType('gauge')) { arcs.append('path') .attr("class", CLASS[_chartArcsBackground]) From bc8226a7f99f7a79ed24d8e35d71fdfbbf412c27 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 2 Aug 2014 17:58:33 +0100 Subject: [PATCH 25/44] Fix bugs --- Gruntfile.coffee | 1 + c3.js | 560 ++++++++++++--------- c3.min.js | 8 +- htdocs/samples/axes_range.html | 4 +- htdocs/samples/categorized.html | 1 + htdocs/samples/data_region.html | 2 +- htdocs/samples/data_region_timeseries.html | 4 +- htdocs/samples/grid_x_lines.html | 2 +- htdocs/samples/timeseries.html | 2 +- htdocs/samples/timeseries_date.html | 2 +- src/api.js | 11 +- src/config.js | 360 ++++++------- src/core.js | 64 ++- src/data.convert.js | 5 +- src/drag.js | 2 +- src/format.js | 2 +- src/grid.js | 3 +- src/legend.js | 6 +- src/selection.js | 156 +++--- src/shape.js | 6 +- src/subchart.js | 2 +- src/zoom.js | 8 +- 22 files changed, 664 insertions(+), 547 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 4f22aed..b48e006 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -39,6 +39,7 @@ module.exports = (grunt) -> 'src/arc.js', 'src/region.js', 'src/drag.js', + 'src/selection.js', 'src/subchart.js', 'src/zoom.js', 'src/color.js', diff --git a/c3.js b/c3.js index d950b3f..6fdb0cc 100644 --- a/c3.js +++ b/c3.js @@ -8,15 +8,26 @@ var c3_chart_fn, c3_chart_internal_fn; function Chart(config) { - var $$ = this.internal = new ChartInternal(config, this); + var $$ = this.internal = new ChartInternal(this); $$.loadConfig(config); $$.init(); + + // bind "this" to nested API + (function bindThis(fn, target, argThis) { + for (var key in fn) { + target[key] = fn[key].bind(argThis); + if (Object.keys(fn[key]).length > 0) { + bindThis(fn[key], target[key], argThis); + } + } + })(c3_chart_fn, this, this); } - function ChartInternal(config, api) { + function ChartInternal(api) { var $$ = this; $$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined; $$.api = api; + $$.config = $$.getDefaultConfig(); $$.data = {}; $$.cache = {}; $$.axes = {}; @@ -59,7 +70,7 @@ }; c3_chart_internal_fn.initParams = function () { - var $$ = this, d3 = $$.d3; + var $$ = this, d3 = $$.d3, config = $$.config; // MEMO: clipId needs to be unique because it conflicts when multiple charts exist $$.clipId = "c3-" + (+new Date()) + '-clip', @@ -78,7 +89,7 @@ $$.color = $$.generateColor(); $$.levelColor = $$.generateLevelColor(); - $$.dataTimeFormat = config[__data_x_localtime] ? 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; $$.defaultAxisTimeFormat = $$.axisTimeFormat.multi([ [".%L", function (d) { return d.getMilliseconds(); }], @@ -505,6 +516,7 @@ var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; + var xv, cx, cy; xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); @@ -870,13 +882,13 @@ } } - var xv_ = generateCall($$.xv, $$); + xv = generateCall($$.xv, $$); + cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$); + cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); // transition should be derived from one transition d3.transition().duration(duration).each(function () { - var transitions = [], - cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), - cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); + var transitions = []; transitions.push(mainBar.transition() .attr('d', drawBar) @@ -904,20 +916,20 @@ .style("fill", $$.color) .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); transitions.push(mainRegion.selectAll('rect').transition() - .attr("x", $$.regionX) - .attr("y", $$.regionY) - .attr("width", $$.regionWidth) - .attr("height", $$.regionHeight) + .attr("x", generateCall($$.regionX, $$)) + .attr("y", generateCall($$.regionY, $$)) + .attr("width", generateCall($$.regionWidth, $$)) + .attr("height", generateCall($$.regionHeight, $$)) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); transitions.push(xgridLines.select('line').transition() - .attr("x1", config[__axis_rotated] ? 0 : xv_) - .attr("x2", config[__axis_rotated] ? $$.width : xv_) - .attr("y1", config[__axis_rotated] ? xv_ : $$.margin.top) - .attr("y2", config[__axis_rotated] ? xv_ : $$.height) + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv) + .attr("y1", config[__axis_rotated] ? xv : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv : $$.height) .style("opacity", 1)); transitions.push(xgridLines.select('text').transition() .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv_) + .attr("y", xv) .text(function (d) { return d.text; }) .style("opacity", 1)); // Wait for end of transitions if called from flow API @@ -1008,11 +1020,11 @@ xgridLines .attr('transform', null); xgridLines.select('line') - .attr("x1", config[__axis_rotated] ? 0 : xv_) - .attr("x2", config[__axis_rotated] ? $$.width : xv_); + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv); xgridLines.select('text') .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv_); + .attr("y", xv); mainBar .attr('transform', null) .attr("d", drawBar); @@ -1024,8 +1036,8 @@ .attr("d", drawArea); mainCircle .attr('transform', null) - .attr("cx", config[__axis_rotated] ? $$.circleY : $$.circleX) - .attr("cy", config[__axis_rotated] ? $$.circleX : $$.circleY); + .attr("cx", cx) + .attr("cy", cy); mainText .attr('transform', null) .attr('x', xForText) @@ -1034,8 +1046,8 @@ mainRegion .attr('transform', null); mainRegion.select('rect').filter($$.isRegionOnX) - .attr("x", $$.regionX) - .attr("width", $$.regionWidth); + .attr("x", generateCall($$.regionX, $$)) + .attr("width", generateCall($$.regionWidth, $$)); eventRectUpdate .attr("x", config[__axis_rotated] ? 0 : rectX) .attr("y", config[__axis_rotated] ? rectX : 0) @@ -1391,7 +1403,7 @@ c3_chart_internal_fn.transformAll = function (withTransition, transitions) { var $$ = this; $$.transformMain(withTransition, transitions); - if (config[__subchart_show]) { $$.transformContext(withTransition, transitions); } + if ($$.config[__subchart_show]) { $$.transformContext(withTransition, transitions); } if ($$.legend) { $$.transformLegend(withTransition); } }; @@ -1538,7 +1550,7 @@ } else if (typeof date === 'number') { parsedDate = new Date(date); } else { - parsedDate = $$.dataTimeFormat(config[__data_x_format]).parse(date); + parsedDate = $$.dataTimeFormat($$.config[__data_xFormat]).parse(date); } if (!parsedDate || isNaN(+parsedDate)) { window.console.error("Failed to parse x '" + date + "' to Date object"); @@ -1565,9 +1577,9 @@ __transition_duration = 'transition_duration', __data_x = 'data_x', __data_xs = 'data_xs', - __data_x_format = 'data_x_format', - __data_x_localtime = 'data_x_localtime', - __data_id_converter = 'data_id_converter', + __data_xFormat = 'data_xFormat', + __data_xLocaltime = 'data_xLocaltime', + __data_idConverter = 'data_idConverter', __data_names = 'data_names', __data_classes = 'data_classes', __data_groups = 'data_groups', @@ -1700,185 +1712,189 @@ __tooltip_init_x = 'tooltip_init_x', __tooltip_init_position = 'tooltip_init_position'; - var config = c3_chart_internal_fn.config = {}; - config[__bindto] = '#chart'; - config[__size_width] = undefined; - config[__size_height] = undefined; - config[__padding_left] = undefined; - config[__padding_right] = undefined; - config[__padding_top] = undefined; - config[__padding_bottom] = undefined; - config[__zoom_enabled] = false; - config[__zoom_extent] = undefined; - config[__zoom_privileged] = false; - config[__zoom_onzoom] = function () {}; - config[__interaction_enabled] = true; - config[__onmouseover] = function () {}; - config[__onmouseout] = function () {}; - config[__onresize] = function () {}; - config[__onresized] = function () {}; - config[__transition_duration] = 350; - config[__data_x] = undefined; - config[__data_xs] = {}; - config[__data_x_format] = '%Y-%m-%d'; - config[__data_x_localtime] = true; - config[__data_id_converter] = function (id) { return id; }; - config[__data_names] = {}; - config[__data_classes] = {}; - config[__data_groups] = []; - config[__data_axes] = {}; - config[__data_type] = undefined; - config[__data_types] = {}; - config[__data_labels] = {}; - config[__data_order] = 'desc'; - config[__data_regions] = {}; - config[__data_color] = undefined; - config[__data_colors] = {}; - config[__data_hide] = false; - config[__data_filter] = undefined; - config[__data_selection_enabled] = false; - config[__data_selection_grouped] = false; - config[__data_selection_isselectable] = function () { return true; }; - config[__data_selection_multiple] = true; - config[__data_onclick] = function () {}; - config[__data_onmouseover] = function () {}; - config[__data_onmouseout] = function () {}; - config[__data_onselected] = function () {}; - config[__data_onunselected] = function () {}; - config[__data_ondragstart] = function () {}; - config[__data_ondragend] = function () {}; - config[__data_url] = undefined; - config[__data_json] = undefined; - config[__data_rows] = undefined; - config[__data_columns] = undefined; - config[__data_mimeType] = undefined; - config[__data_keys] = undefined; - // configuration for no plot-able data supplied. - config[__data_empty_label_text] = ""; - // subchart - config[__subchart_show] = false; - config[__subchart_size_height] = 60; - config[__subchart_onbrush] = function () {}; - // color - config[__color_pattern] = []; - config[__color_threshold] = {}; - // legend - config[__legend_show] = true; - config[__legend_position] = 'bottom'; - config[__legend_inset_anchor] = 'top-left'; - config[__legend_inset_x] = 10; - config[__legend_inset_y] = 0; - config[__legend_inset_step] = undefined; - config[__legend_item_onclick] = undefined; - config[__legend_item_onmouseover] = undefined; - config[__legend_item_onmouseout] = undefined; - config[__legend_equally] = false; - // axis - config[__axis_rotated] = false; - config[__axis_x_show] = true; - config[__axis_x_type] = 'indexed'; - config[__axis_x_localtime] = true; - config[__axis_x_categories] = []; - config[__axis_x_tick_centered] = false; - config[__axis_x_tick_format] = undefined; - config[__axis_x_tick_culling] = {}; - config[__axis_x_tick_culling_max] = 10; - config[__axis_x_tick_count] = undefined; - config[__axis_x_tick_fit] = true; - config[__axis_x_tick_values] = null; - config[__axis_x_tick_rotate] = undefined; - config[__axis_x_tick_outer] = true; - config[__axis_x_max] = null; - config[__axis_x_min] = null; - config[__axis_x_padding] = {}; - config[__axis_x_height] = undefined; - config[__axis_x_default] = undefined; - config[__axis_x_label] = {}; - config[__axis_y_show] = true; - config[__axis_y_max] = undefined; - config[__axis_y_min] = undefined; - config[__axis_y_center] = undefined; - config[__axis_y_label] = {}; - config[__axis_y_tick_format] = undefined; - config[__axis_y_tick_outer] = true; - config[__axis_y_padding] = undefined; - config[__axis_y_ticks] = 10; - config[__axis_y2_show] = false; - config[__axis_y2_max] = undefined; - config[__axis_y2_min] = undefined; - config[__axis_y2_center] = undefined; - config[__axis_y2_label] = {}; - config[__axis_y2_tick_format] = undefined; - config[__axis_y2_tick_outer] = true; - config[__axis_y2_padding] = undefined; - config[__axis_y2_ticks] = 10; - // grid - config[__grid_x_show] = false; - config[__grid_x_type] = 'tick'; - config[__grid_x_lines] = []; - config[__grid_y_show] = false; - // not used - // grid_y_type: {}, 'tick'), - config[__grid_y_lines] = []; - config[__grid_y_ticks] = 10; - config[__grid_focus_show] = true; - // point - point of each data - config[__point_show] = true; - config[__point_r] = 2.5; - config[__point_focus_expand_enabled] = true; - config[__point_focus_expand_r] = undefined; - config[__point_select_r] = undefined; - config[__line_connect_null] = false; - // bar - config[__bar_width] = undefined; - config[__bar_width_ratio] = 0.6; - config[__bar_width_max] = undefined; - config[__bar_zerobased] = true; - // area - config[__area_zerobased] = true; - // pie - config[__pie_label_show] = true; - config[__pie_label_format] = undefined; - config[__pie_label_threshold] = 0.05; - config[__pie_sort] = true; - config[__pie_expand] = true; - // gauge - config[__gauge_label_show] = true; - config[__gauge_label_format] = undefined; - config[__gauge_expand] = true; - config[__gauge_min] = 0; - config[__gauge_max] = 100; - config[__gauge_units] = undefined; - config[__gauge_width] = undefined; - // donut - config[__donut_label_show] = true; - config[__donut_label_format] = undefined; - config[__donut_label_threshold] = 0.05; - config[__donut_width] = undefined; - config[__donut_sort] = true; - config[__donut_expand] = true; - config[__donut_title] = ""; - // region - region to change style - config[__regions] = []; - // tooltip - show when mouseover on each data - config[__tooltip_show] = true; - config[__tooltip_grouped] = true; - config[__tooltip_format_title] = undefined; - config[__tooltip_format_name] = undefined; - config[__tooltip_format_value] = undefined; - config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { - return this.getTooltipContent ? this.getTooltipContent(d, defaultValueFormat, defaultValueFormat, color) : ''; - }, - config[__tooltip_init_show] = false; - config[__tooltip_init_x] = 0; - config[__tooltip_init_position] = {top: '0px', left: '50px'}; + c3_chart_internal_fn.getDefaultConfig = function () { + var config = {}; + config[__bindto] = '#chart'; + config[__size_width] = undefined; + config[__size_height] = undefined; + config[__padding_left] = undefined; + config[__padding_right] = undefined; + config[__padding_top] = undefined; + config[__padding_bottom] = undefined; + config[__zoom_enabled] = false; + config[__zoom_extent] = undefined; + config[__zoom_privileged] = false; + config[__zoom_onzoom] = function () {}; + config[__interaction_enabled] = true; + config[__onmouseover] = function () {}; + config[__onmouseout] = function () {}; + config[__onresize] = function () {}; + config[__onresized] = function () {}; + config[__transition_duration] = 350; + config[__data_x] = undefined; + config[__data_xs] = {}; + config[__data_xFormat] = '%Y-%m-%d'; + config[__data_xLocaltime] = true; + config[__data_idConverter] = function (id) { return id; }; + config[__data_names] = {}; + config[__data_classes] = {}; + config[__data_groups] = []; + config[__data_axes] = {}; + config[__data_type] = undefined; + config[__data_types] = {}; + config[__data_labels] = {}; + config[__data_order] = 'desc'; + config[__data_regions] = {}; + config[__data_color] = undefined; + config[__data_colors] = {}; + config[__data_hide] = false; + config[__data_filter] = undefined; + config[__data_selection_enabled] = false; + config[__data_selection_grouped] = false; + config[__data_selection_isselectable] = function () { return true; }; + config[__data_selection_multiple] = true; + config[__data_onclick] = function () {}; + config[__data_onmouseover] = function () {}; + config[__data_onmouseout] = function () {}; + config[__data_onselected] = function () {}; + config[__data_onunselected] = function () {}; + config[__data_ondragstart] = function () {}; + config[__data_ondragend] = function () {}; + config[__data_url] = undefined; + config[__data_json] = undefined; + config[__data_rows] = undefined; + config[__data_columns] = undefined; + config[__data_mimeType] = undefined; + config[__data_keys] = undefined; + // configuration for no plot-able data supplied. + config[__data_empty_label_text] = ""; + // subchart + config[__subchart_show] = false; + config[__subchart_size_height] = 60; + config[__subchart_onbrush] = function () {}; + // color + config[__color_pattern] = []; + config[__color_threshold] = {}; + // legend + config[__legend_show] = true; + config[__legend_position] = 'bottom'; + config[__legend_inset_anchor] = 'top-left'; + config[__legend_inset_x] = 10; + config[__legend_inset_y] = 0; + config[__legend_inset_step] = undefined; + config[__legend_item_onclick] = undefined; + config[__legend_item_onmouseover] = undefined; + config[__legend_item_onmouseout] = undefined; + config[__legend_equally] = false; + // axis + config[__axis_rotated] = false; + config[__axis_x_show] = true; + config[__axis_x_type] = 'indexed'; + config[__axis_x_localtime] = true; + config[__axis_x_categories] = []; + config[__axis_x_tick_centered] = false; + config[__axis_x_tick_format] = undefined; + config[__axis_x_tick_culling] = {}; + config[__axis_x_tick_culling_max] = 10; + config[__axis_x_tick_count] = undefined; + config[__axis_x_tick_fit] = true; + config[__axis_x_tick_values] = null; + config[__axis_x_tick_rotate] = undefined; + config[__axis_x_tick_outer] = true; + config[__axis_x_max] = null; + config[__axis_x_min] = null; + config[__axis_x_padding] = {}; + config[__axis_x_height] = undefined; + config[__axis_x_default] = undefined; + config[__axis_x_label] = {}; + config[__axis_y_show] = true; + config[__axis_y_max] = undefined; + config[__axis_y_min] = undefined; + config[__axis_y_center] = undefined; + config[__axis_y_label] = {}; + config[__axis_y_tick_format] = undefined; + config[__axis_y_tick_outer] = true; + config[__axis_y_padding] = undefined; + config[__axis_y_ticks] = 10; + config[__axis_y2_show] = false; + config[__axis_y2_max] = undefined; + config[__axis_y2_min] = undefined; + config[__axis_y2_center] = undefined; + config[__axis_y2_label] = {}; + config[__axis_y2_tick_format] = undefined; + config[__axis_y2_tick_outer] = true; + config[__axis_y2_padding] = undefined; + config[__axis_y2_ticks] = 10; + // grid + config[__grid_x_show] = false; + config[__grid_x_type] = 'tick'; + config[__grid_x_lines] = []; + config[__grid_y_show] = false; + // not used + // grid_y_type: {}, 'tick'), + config[__grid_y_lines] = []; + config[__grid_y_ticks] = 10; + config[__grid_focus_show] = true; + // point - point of each data + config[__point_show] = true; + config[__point_r] = 2.5; + config[__point_focus_expand_enabled] = true; + config[__point_focus_expand_r] = undefined; + config[__point_select_r] = undefined; + config[__line_connect_null] = false; + // bar + config[__bar_width] = undefined; + config[__bar_width_ratio] = 0.6; + config[__bar_width_max] = undefined; + config[__bar_zerobased] = true; + // area + config[__area_zerobased] = true; + // pie + config[__pie_label_show] = true; + config[__pie_label_format] = undefined; + config[__pie_label_threshold] = 0.05; + config[__pie_sort] = true; + config[__pie_expand] = true; + // gauge + config[__gauge_label_show] = true; + config[__gauge_label_format] = undefined; + config[__gauge_expand] = true; + config[__gauge_min] = 0; + config[__gauge_max] = 100; + config[__gauge_units] = undefined; + config[__gauge_width] = undefined; + // donut + config[__donut_label_show] = true; + config[__donut_label_format] = undefined; + config[__donut_label_threshold] = 0.05; + config[__donut_width] = undefined; + config[__donut_sort] = true; + config[__donut_expand] = true; + config[__donut_title] = ""; + // region - region to change style + config[__regions] = []; + // tooltip - show when mouseover on each data + config[__tooltip_show] = true; + config[__tooltip_grouped] = true; + config[__tooltip_format_title] = undefined; + config[__tooltip_format_name] = undefined; + config[__tooltip_format_value] = undefined; + config[__tooltip_contents] = function (d, defaultTitleFormat, defaultValueFormat, color) { + return this.getTooltipContent ? this.getTooltipContent(d, defaultTitleFormat, defaultValueFormat, color) : ''; + }, + config[__tooltip_init_show] = false; + config[__tooltip_init_x] = 0; + config[__tooltip_init_position] = {top: '0px', left: '50px'}; + + return config; + }; c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; function find() { var key = keys.shift(); - // console.log("key =>", key, ", target =>", target); - if (key && target && key in target) { + // console.log("key =>", key, ", target =>", target); + if (key && target && typeof target === 'object' && key in target) { target = target[key]; return find(); } @@ -1893,7 +1909,7 @@ target = config; keys = key.split('_'); read = find(); - // console.log("CONFIG : ", key, read); + // console.log("CONFIG : ", key, read); if (isDefined(read)) { this_config[key] = read; } @@ -2519,7 +2535,7 @@ } else { d = $$.convertCsvToData(data.response); } - done(d); + done.call($$, d); }); }; c3_chart_internal_fn.convertCsvToData = function (csv) { @@ -2625,6 +2641,7 @@ } }); + // check x is defined ids.forEach(function (id) { if (!$$.data.xs[id]) { @@ -2634,7 +2651,7 @@ // convert to target targets = ids.map(function (id, index) { - var convertedId = config[__data_id_converter](id); + var convertedId = config[__data_idConverter](id); return { id: convertedId, id_org: id, @@ -3108,13 +3125,13 @@ getPoints = $$.generateGetBarPoints(barIndices, false), getter = forX ? $$.getXForText : $$.getYForText; return function (d, i) { - return getter(getPoints(d, i), d, this); + return getter.call($$, getPoints(d, i), d, this); }; }; c3_chart_internal_fn.getXForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), xPos, padding; - if (config[__axis_rotated]) { + if ($$.config[__axis_rotated]) { padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { @@ -3125,7 +3142,7 @@ c3_chart_internal_fn.getYForText = function (points, d, textElement) { var $$ = this, box = textElement.getBoundingClientRect(), yPos; - if (config[__axis_rotated]) { + if ($$.config[__axis_rotated]) { yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; } else { yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); @@ -3366,7 +3383,8 @@ }; c3_chart_internal_fn.showXGridFocus = function (selectedData) { - var $$ = this, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + var $$ = this, config = $$.config, + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists if ($$.hasType('scatter') || $$.hasArcType()) { return; } @@ -3537,7 +3555,7 @@ c3_chart_internal_fn.initLegend = function () { var $$ = this; $$.legend = $$.svg.append("g").attr("transform", $$.getTranslate('legend')); - if (!config[__legend_show]) { + if (!$$.config[__legend_show]) { $$.legend.style('visibility', 'hidden'); $$.hiddenLegendIds = $$.mapToIds($$.data.targets); } @@ -3546,7 +3564,7 @@ $$.updateLegend($$.mapToIds($$.data.targets), {withTransform: false, withTransitionForTransform: false, withTransition: false}); }; c3_chart_internal_fn.updateSizeForLegend = function (legendHeight, legendWidth) { - var $$ = this, insetLegendPosition = { + var $$ = this, config = $$.config, insetLegendPosition = { 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 }; @@ -3733,7 +3751,7 @@ .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call(c3, id) : $$.api.toggle(id); + isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call($$, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed(CLASS[_legendItemFocused], true); @@ -4379,11 +4397,11 @@ }; c3_chart_internal_fn.initArc = function () { - var $$ = this, arcs; - arcs = $$.main.select('.' + CLASS[_chart]).append("g") + var $$ = this; + $$.arcs = $$.main.select('.' + CLASS[_chart]).append("g") .attr("class", CLASS[_chartArcs]) .attr("transform", $$.getTranslate('arc')); - arcs.append('text') + $$.arcs.append('text') .attr('class', CLASS[_chartArcsTitle]) .style("text-anchor", "middle") .text($$.getArcTitle()); @@ -4491,7 +4509,7 @@ }; c3_chart_internal_fn.initGauge = function () { - var $$ = this, config = $$.config, arcs; + var $$ = this, config = $$.config, arcs = $$.arcs; if ($$.hasType('gauge')) { arcs.append('path') .attr("class", CLASS[_chartArcsBackground]) @@ -4623,7 +4641,7 @@ shape.classed(CLASS[_INCLUDED], !isIncluded); // TODO: included/unincluded callback here shape.classed(CLASS[_SELECTED], !isSelected); - $$.toggle(!isSelected, shape, d, i); + toggle.call($$, !isSelected, shape, d, i); } }); }; @@ -4655,6 +4673,89 @@ }; + c3_chart_internal_fn.selectPoint = function (target, d, i) { + var $$ = this, config = $$.config, + cx = generateCall(config[__axis_rotated] ? $$.circleY : $$.circleX, $$), + cy = generateCall(config[__axis_rotated] ? $$.circleX : $$.circleY, $$); + + config[__data_onselected].call($$.api, d, target.node()); + // add selected-circle on low layer g + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) + .data([d]) + .enter().append('circle') + .attr("class", function () { return $$.generateClass(CLASS[_selectedCircle], i); }) + .attr("cx", cx) + .attr("cy", cy) + .attr("stroke", function () { return $$.color(d); }) + .attr("r", function (d) { return $$.pointSelectR(d) * 1.4; }) + .transition().duration(100) + .attr("r", generateCall($$.pointSelectR, $$)); + }; + c3_chart_internal_fn.unselectPoint = function (target, d, i) { + var $$ = this; + $$.config[__data_onunselected](d, target.node()); + // remove selected-circle from low layer g + $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) + .transition().duration(100).attr('r', 0) + .remove(); + }; + c3_chart_internal_fn.togglePoint = function (selected, target, d, i) { + selected ? this.selectPoint(target, d, i) : this.unselectPoint(target, d, i); + }; + c3_chart_internal_fn.selectBar = function (target, d) { + var $$ = this; + $$.config[__data_onselected].call($$, d, target.node()); + target.transition().duration(100) + .style("fill", function () { return $$.d3.rgb($$.color(d)).brighter(0.75); }); + }; + c3_chart_internal_fn.unselectBar = function (target, d) { + var $$ = this; + $$.config[__data_onunselected].call($$, d, target.node()); + target.transition().duration(100) + .style("fill", function () { return $$.color(d); }); + }; + c3_chart_internal_fn.toggleBar = function (selected, target, d, i) { + selected ? this.selectBar(target, d, i) : this.unselectBar(target, d, i); + }; + c3_chart_internal_fn.toggleArc = function (selected, target, d, i) { + this.toggleBar(selected, target, d.data, i); + }; + c3_chart_internal_fn.getToggle = function (that) { + var $$ = this; + // path selection not supported yet + return that.nodeName === 'circle' ? $$.togglePoint : ($$.d3.select(that).classed(CLASS[_bar]) ? $$.toggleBar : $$.toggleArc); + }; + c3_chart_internal_fn.toggleShape = function (that, d, i) { + var $$ = this, d3 = $$.d3, config = $$.config, + shape = d3.select(that), isSelected = shape.classed(CLASS[_SELECTED]), isWithin, toggle; + if (that.nodeName === 'circle') { + isWithin = $$.isWithinCircle(that, $$.pointSelectR(d) * 1.5); + toggle = $$.togglePoint; + } + else if (that.nodeName === 'path') { + if (shape.classed(CLASS[_bar])) { + isWithin = $$.isWithinBar(that); + toggle = $$.toggleBar; + } else { // would be arc + isWithin = true; + toggle = $$.toggleArc; + } + } + if (config[__data_selection_grouped] || isWithin) { + if (config[__data_selection_enabled] && config[__data_selection_isselectable](d)) { + if (!config[__data_selection_multiple]) { + $$.main.selectAll('.' + CLASS[_shapes] + (config[__data_selection_grouped] ? $$.getTargetSelectorSuffix(d.id) : "")).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this); + if (shape.classed(CLASS[_SELECTED])) { toggle.call($$, false, shape.classed(CLASS[_SELECTED], false), d, i); } + }); + } + shape.classed(CLASS[_SELECTED], !isSelected); + toggle.call($$, !isSelected, shape, d, i); + } + $$.config[__data_onclick].call($$.api, d, that); + } + }; + c3_chart_internal_fn.initBrush = function () { var $$ = this, d3 = $$.d3; $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); @@ -4815,7 +4916,7 @@ withSubchart: false, withUpdateXDomain: true }); - $$.config[__subchart_onbrush].call($$, x.orgDomain()); + $$.config[__subchart_onbrush].call($$.api, x.orgDomain()); }; c3_chart_internal_fn.transformContext = function (withTransition, transitions) { var $$ = this, subXAxis; @@ -4835,7 +4936,7 @@ .on("zoomstart", function () { $$.zoom.altDomain = d3.event.sourceEvent.altKey ? $$.x.orgDomain() : null; }) - .on("zoom", $$.redrawForZoom); + .on("zoom", function () { $$.redrawForZoom.call($$); }); $$.zoom.scale = function (scale) { return config[__axis_rotated] ? this.y(scale) : this.x(scale); }; @@ -4845,8 +4946,8 @@ }; $$.zoom.updateScaleExtent = function () { var ratio = diffDomain($$.x.orgDomain()) / diffDomain($$.orgXDomain), - extent = $$.orgScaleExtent(); - $$.scaleExtent([extent[0] * ratio, extent[1] * ratio]); + extent = this.orgScaleExtent(); + this.scaleExtent([extent[0] * ratio, extent[1] * ratio]); return this; }; }; @@ -4879,7 +4980,7 @@ if (d3.event.sourceEvent.type === 'mousemove') { $$.cancelClick = true; } - config[__zoom_onzoom].call(c3, x.orgDomain()); + config[__zoom_onzoom].call($$.api, x.orgDomain()); }; c3_chart_internal_fn.generateColor = function () { @@ -4955,7 +5056,7 @@ return (ratio * 100).toFixed(1) + '%'; }; c3_chart_internal_fn.formatByAxisId = function (axisId) { - var $$ = this.internal, data_labels = $$.config[__data_labels], + var $$ = this, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id if (isFunction(data_labels.format)) { @@ -5648,7 +5749,7 @@ }; c3_chart_fn.ygrids.add = function (grids) { var $$ = this.internal; - return c3.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); + return this.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); }; c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple var $$ = this.internal; @@ -5696,8 +5797,7 @@ return config[__regions]; }; - c3_chart_fn.data = function () { - }; + c3_chart_fn.data = function () {}; c3_chart_fn.data.get = function (targetId) { var target = this.data.getAsTarget(targetId); return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; @@ -5764,8 +5864,7 @@ }; - c3_chart_fn.axis = function () { - }; + c3_chart_fn.axis = function () {}; c3_chart_fn.axis.labels = function (labels) { var $$ = this.internal; if (arguments.length) { @@ -5810,8 +5909,7 @@ }; - c3_chart_fn.legend = function () { - }; + c3_chart_fn.legend = function () {}; c3_chart_fn.legend.show = function (targetIds) { var $$ = this.internal; $$.showLegend($$.mapToTargetIds(targetIds)); diff --git a/c3.min.js b/c3.min.js index 8aa3c63..af01044 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(a,this);b.loadConfig(a),b.init()}function c(b,c){var d=this;d.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,d.api=c,d.data={},d.cache={},d.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&Y.select(this).style("display",b%V?"none":"block")})}else W.svg.selectAll("."+qe[ae]+" .tick text").style("display","block");if(!Z[vb]&&Z[Hb]&&W.rotateTickText(W.axes.x,b.axisX,Z[Hb]),K=W.generateDrawArea($,!1),L=W.generateDrawBar(_),M=W.generateDrawLine(ab,!1),N=W.generateXYForText(_,!0),O=W.generateXYForText(_,!1),W.subY.domain(W.y.domain()),W.subY2.domain(W.y2.domain()),W.tooltip.style("display","none"),W.updateXgridFocus(),X.select("text."+qe[Od]+"."+qe[Nd]).attr("x",W.width/2).attr("y",W.height/2).text(Z[fb]).transition().style("opacity",cb.length?0:1),X.select("line."+qe[Wd]).style("visibility","hidden"),Z[fc]&&(d=Z[vb]?{x1:0,x2:W.width,y1:function(a){return W.x(a)-w},y2:function(a){return W.x(a)-w}}:{x1:function(a){return W.x(a)+w},x2:function(a){return W.x(a)+w},y1:0,y2:W.height},(k=function(a){e=W.generateGridData(Z[gc],W.x),w=W.isCategorized()?W.xAxis.tickOffset():0,c=X.select("."+qe[Td]).selectAll("."+qe[Sd]).data(e),c.enter().append("line").attr("class",qe[Sd]),a||c.attr(d).style("opacity",function(){return+Y.select(this).attr(Z[vb]?"y1":"x1")===(Z[vb]?W.height:0)?0:1}),c.exit().remove()})()),f=X.select("."+qe[Vd]).selectAll("."+qe[Ud]).data(Z[hc]),g=f.enter().append("g").attr("class",function(a){return qe[Ud]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",Z[vb]?"":"rotate(-90)").attr("dx",Z[vb]?0:-W.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&Z[ic]&&(h=X.select("."+qe[Yd]).selectAll("."+qe[Xd]).data(W.y.ticks(Z[kc])),h.enter().append("line").attr("class",qe[Xd]),h.attr("x1",Z[vb]?W.y:0).attr("x2",Z[vb]?W.y:W.width).attr("y1",Z[vb]?0:W.y).attr("y2",Z[vb]?W.height:W.y),h.exit().remove(),W.smoothLines(h,"grid")),B){i=X.select("."+qe[$d]).selectAll("."+qe[Zd]).data(Z[jc]),j=i.enter().append("g").attr("class",function(a){return qe[Zd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",Z[vb]?"rotate(-90)":"").attr("dx",Z[vb]?0:-W.margin.top).attr("dy",-5).style("opacity",0);var db=Ee(W.yv,W);i.select("line").transition().duration(P).attr("x1",Z[vb]?db:0).attr("x2",Z[vb]?db:W.width).attr("y1",Z[vb]?0:db).attr("y2",Z[vb]?W.height:db).style("opacity",1),i.select("text").transition().duration(P).attr("x",Z[vb]?0:W.width).attr("y",db).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()}q=X.select("."+qe[yd]).selectAll("."+qe[xd]).data(Z[Qc]),q.enter().append("g").attr("class",Ee(W.classRegion,W)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=X.selectAll("."+qe[Gd]).selectAll("."+qe[Fd]).data(Ee(W.barData,W)),p.enter().append("path").attr("class",Ee(W.classBar,W)).style("stroke",function(a){return W.color(a.id)}).style("fill",function(a){return W.color(a.id)}),p.style("opacity",Ee(W.initialOpacity,W)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=X.selectAll("."+qe[Ed]).selectAll("."+qe[Dd]).data(Ee(W.lineData,W)),l.enter().append("path").attr("class",Ee(W.classLine,W)).style("stroke",W.color),l.style("opacity",Ee(W.initialOpacity,W)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=X.selectAll("."+qe[Md]).selectAll("."+qe[Ld]).data(Ee(W.lineData,W)),m.enter().append("path").attr("class",Ee(W.classArea,W)).style("fill",W.color).style("opacity",function(){return W.orgAreaOpacity=+Y.select(this).style("opacity"),0}),m.style("opacity",W.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),Z[mc]&&(n=X.selectAll("."+qe[Id]).selectAll("."+qe[Hd]).data(Ee(W.lineOrScatterData,W)),n.enter().append("circle").attr("class",Ee(W.classCircle,W)).attr("r",Ee(W.pointR,W)).style("fill",W.color),n.style("opacity",Ee(W.initialOpacity,W)),n.exit().remove()),W.hasDataLabel()&&(r=X.selectAll("."+qe[Pd]).selectAll("."+qe[Od]).data(Ee(W.barOrLineData,W)),r.enter().append("text").attr("class",Ee(W.classText,W)).attr("text-anchor",function(a){return Z[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return W.color(a)}).style("fill-opacity",0),r.text(function(a){return W.formatByAxisId(W.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),se(W.redrawArc)&&W.redrawArc(P,Q,G),se(W.redrawSubchart)&&W.redrawSubchart(C,b,P,Q,$,_,ab),X.selectAll("."+qe[pd]).filter(Ee(W.isBarType,W)).selectAll("circle").remove(),Z[s]&&(t=X.select("."+qe[rd]).style("cursor",Z[o]?Z[vb]?"ns-resize":"ew-resize":null),Ae(Z[z])&&!W.isSingleX(Z[z])?(t.classed(qe[td])||t.classed(qe[td],!0).classed(qe[sd],!1).selectAll("."+qe[qd]).remove(),u=X.select("."+qe[rd]).selectAll("."+qe[qd]).data([0]),W.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",W.width).attr("height",W.height)):(t.classed(qe[sd])||t.classed(qe[td],!1).classed(qe[sd],!0).selectAll("."+qe[qd]).remove(),!W.isCustomX()&&!W.isTimeSeries()||W.isCategorized()?(A=W.getEventRectWidth(),y=function(a){return W.x(a.x)-A/2}):(A=function(a){var b=W.getPrevX(a.index),c=W.getNextX(a.index),d=W.data.xs[a.id][a.index],e=(W.x(c?c:d)-W.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=W.getPrevX(a.index),c=W.data.xs[a.id][a.index];return(W.x(c)+W.x(b?b:c))/2}),v=W.getMaxDataCountTarget(W.data.targets),X.select("."+qe[rd]).datum(v?v.values:[]),u=X.select("."+qe[rd]).selectAll("."+qe[qd]).data(function(a){return a}),W.generateEventRectsForSingleX(u.enter()),u.attr("class",Ee(W.classEvent,W)).attr("x",Z[vb]?0:y).attr("y",Z[vb]?y:0).attr("width",Z[vb]?W.width:A).attr("height",Z[vb]?A:W.height),u.exit().remove()));var eb=Ee(W.xv,W);Y.transition().duration(P).each(function(){var b=[],c=Ee(W.config[vb]?W.circleY:W.circleX,W),d=Ee(W.config[vb]?W.circleX:W.circleY,W);b.push(p.transition().attr("d",L).style("fill",W.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",W.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",W.color).style("opacity",W.orgAreaOpacity)),b.push(n.transition().style("opacity",Ee(W.opacityForCircle,W)).style("fill",W.color).attr("cx",c).attr("cy",d)),b.push(X.selectAll("."+qe[od]).transition().attr("cx",c).attr("cy",d)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",W.color).style("fill-opacity",a.flow?0:Ee(W.opacityForText,W))),b.push(q.selectAll("rect").transition().attr("x",W.regionX).attr("y",W.regionY).attr("width",W.regionWidth).attr("height",W.regionHeight).style("fill-opacity",function(a){return re(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",Z[vb]?0:eb).attr("x2",Z[vb]?W.width:eb).attr("y1",Z[vb]?eb:W.margin.top).attr("y2",Z[vb]?eb:W.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",Z[vb]?W.width:0).attr("y",eb).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=W.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=W.getValueOnIndex(W.data.targets[0].values,i),s=W.getValueOnIndex(W.data.targets[0].values,i+j),t=W.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=W.generateWait();W.data.targets.forEach(function(a){a.values.splice(0,j)}),g=W.updateXDomain(cb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?W.x(t[0])-W.x(g[0]):W.isTimeSeries()?W.x(t[0])-W.x(g[0]):W.x(o.x)-W.x(s.x):1!==W.data.targets[0].values.length?b=W.x(t[0])-W.x(g[0]):W.isTimeSeries()?(o=W.getValueOnIndex(W.data.targets[0].values,0),s=W.getValueOnIndex(W.data.targets[0].values,W.data.targets[0].values.length-1),b=W.x(o.x)-W.x(s.x)):b=ye(g)/2,h=ye(t)/ye(g),e="translate("+b+",0) scale("+h+",1)",Y.transition().ease("linear").duration(v).each(function(){x.add(W.axes.x.transition().call(W.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter(W.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+qe[Bd]+"-"+(i+a)),e.push("."+qe[Od]+"-"+(i+a)),g.push("."+qe[qd]+"-"+(i+a));W.svg.selectAll("."+qe[Cd]).selectAll(b).remove(),W.svg.selectAll("."+qe[Pd]).selectAll(e).remove(),W.svg.selectAll("."+qe[rd]).selectAll(g).remove(),W.svg.select("."+qe[Sd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",Z[vb]?0:eb).attr("x2",Z[vb]?W.width:eb),f.select("text").attr("x",Z[vb]?W.width:0).attr("y",eb),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Z[vb]?W.circleY:W.circleX).attr("cy",Z[vb]?W.circleX:W.circleY),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",Ee(W.opacityForText,W)),q.attr("transform",null),q.select("rect").filter(W.isRegionOnX).attr("x",W.regionX).attr("width",W.regionWidth),u.attr("x",Z[vb]?0:y).attr("y",Z[vb]?y:0).attr("width",Z[vb]?W.width:A).attr("height",Z[vb]?A:W.height),w()})}),W.mapToIds(W.data.targets).forEach(function(a){W.withoutFadeIn[a]=!0}),se(W.updateZoom)&&W.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Be(a,"withTransition",!0),a.withTransform=Be(a,"withTransform",!1),a.withLegend=Be(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Be(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",Ee(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||Ae(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=xe(d.margin.left),c=xe(d.margin.top)):"context"===a?(b=xe(d.margin2.left),c=xe(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return re(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+qe[ae]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+qe[ce]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+qe[ee]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+qe[id]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),$c[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",Ee(a.getXAxisClipX,a)).attr("y",Ee(a.getXAxisClipY,a)).attr("width",Ee(a.getXAxisClipWidth,a)).attr("height",Ee(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",Ee(a.getYAxisClipX,a)).attr("y",Ee(a.getYAxisClipY,a)).attr("width",Ee(a.getYAxisClipWidth,a)).attr("height",Ee(a.getYAxisClipHeight,a)),a.svg.select("."+qe[ud]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat($c[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_x_format",B="data_x_localtime",C="data_id_converter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position",$c=f.config={}; -$c[h]="#chart",$c[i]=void 0,$c[j]=void 0,$c[k]=void 0,$c[l]=void 0,$c[m]=void 0,$c[n]=void 0,$c[o]=!1,$c[p]=void 0,$c[q]=!1,$c[r]=function(){},$c[s]=!0,$c[t]=function(){},$c[u]=function(){},$c[v]=function(){},$c[w]=function(){},$c[x]=350,$c[y]=void 0,$c[z]={},$c[A]="%Y-%m-%d",$c[B]=!0,$c[C]=function(a){return a},$c[D]={},$c[E]={},$c[F]=[],$c[G]={},$c[H]=void 0,$c[I]={},$c[J]={},$c[K]="desc",$c[L]={},$c[M]=void 0,$c[N]={},$c[O]=!1,$c[P]=void 0,$c[Q]=!1,$c[R]=!1,$c[S]=function(){return!0},$c[T]=!0,$c[U]=function(){},$c[V]=function(){},$c[W]=function(){},$c[X]=function(){},$c[Y]=function(){},$c[Z]=function(){},$c[$]=function(){},$c[_]=void 0,$c[ab]=void 0,$c[bb]=void 0,$c[cb]=void 0,$c[db]=void 0,$c[eb]=void 0,$c[fb]="",$c[gb]=!1,$c[hb]=60,$c[ib]=function(){},$c[jb]=[],$c[kb]={},$c[lb]=!0,$c[mb]="bottom",$c[nb]="top-left",$c[ob]=10,$c[pb]=0,$c[qb]=void 0,$c[rb]=void 0,$c[sb]=void 0,$c[tb]=void 0,$c[ub]=!1,$c[vb]=!1,$c[wb]=!0,$c[xb]="indexed",$c[yb]=!0,$c[zb]=[],$c[Ab]=!1,$c[Bb]=void 0,$c[Cb]={},$c[Db]=10,$c[Eb]=void 0,$c[Fb]=!0,$c[Gb]=null,$c[Hb]=void 0,$c[Ib]=!0,$c[Jb]=null,$c[Kb]=null,$c[Lb]={},$c[Mb]=void 0,$c[Nb]=void 0,$c[Ob]={},$c[Pb]=!0,$c[Qb]=void 0,$c[Rb]=void 0,$c[Sb]=void 0,$c[Tb]={},$c[Ub]=void 0,$c[Vb]=!0,$c[Wb]=void 0,$c[Xb]=10,$c[Yb]=!1,$c[Zb]=void 0,$c[$b]=void 0,$c[_b]=void 0,$c[ac]={},$c[bc]=void 0,$c[cc]=!0,$c[dc]=void 0,$c[ec]=10,$c[fc]=!1,$c[gc]="tick",$c[hc]=[],$c[ic]=!1,$c[jc]=[],$c[kc]=10,$c[lc]=!0,$c[mc]=!0,$c[nc]=2.5,$c[oc]=!0,$c[pc]=void 0,$c[qc]=void 0,$c[rc]=!1,$c[sc]=void 0,$c[tc]=.6,$c[uc]=void 0,$c[vc]=!0,$c[wc]=!0,$c[xc]=!0,$c[yc]=void 0,$c[zc]=.05,$c[Ac]=!0,$c[Bc]=!0,$c[Cc]=!0,$c[Dc]=void 0,$c[Ec]=!0,$c[Fc]=0,$c[Gc]=100,$c[Hc]=void 0,$c[Ic]=void 0,$c[Jc]=!0,$c[Kc]=void 0,$c[Lc]=.05,$c[Mc]=void 0,$c[Nc]=!0,$c[Oc]=!0,$c[Pc]="",$c[Qc]=[],$c[Rc]=!0,$c[Sc]=!0,$c[Tc]=void 0,$c[Uc]=void 0,$c[Vc]=void 0,$c[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,c,c,d):""},$c[Xc]=!1,$c[Yc]=0,$c[Zc]={top:"0px",left:"50px"},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ve(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),se(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=re(p)?p:m.getYDomainMin(o),s=re(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=ye(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&Ae(g[Lb])?(d=re(g[Lb].left)?g[Lb].left:c,e=re(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||Ae(c[z])&&Ce(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:Ae(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&Ae(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&re(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?te(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):se(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return re(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&Ae(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d(g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=ue(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(re).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():Ae(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(ue(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ve(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return re(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return re(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return re(b[k])?b[k]:b[vb]?b[wb]?Math.max(we(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?we(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return re(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?we(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?qe[ae]:qe[ce],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+qe[Id]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+qe[Hd]+(re(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(qe[ne],!0).attr("r",Ee(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(qe[ne])}).classed(qe[ne],!1).attr("r",Ee(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?se(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+qe[Fd]+(re(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(qe[ne],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(qe[ne],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),function(a){var b,f=c.filterRemoveNull(a.values),g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e(d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return $c[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=$c[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ve(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=te(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=te(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=te(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=te(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=te(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=te(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=te(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=te(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=te(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=a.filter(function(a){return a&&re(a.value)});if($c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var d=b.main.selectAll("line."+qe[Wd]);d.style("visibility","visible").data([c[0]]).attr($c[vb]?"y1":"x1",Ee(b.xx,b)).attr($c[vb]?"y2":"x2",Ee(b.xx,b)),b.smoothLines(d,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+qe[Wd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+qe[Wd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+qe[ae]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?qe[Vd]:qe[$d],h=b?qe[Ud]:qe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&te(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&re(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),$c[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1}) -},f.updateSizeForLegend=function(a,b){var c=this,d={top:c.isLegendTop?c.getCurrentPaddingTop()+$c[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-$c[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+$c[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-$c[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?d.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?d.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(qe[ke])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(qe[ke])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+qe[he]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+qe[he]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ze(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-y-k)/2,x>f&&(f=(l-k)/2,y=0,F++)),E[a]=F,C[F]=r.isLegendInset?10:f,z[a]=y,y+=k}var f,g,h=r.getTextRect(b.textContent,qe[he]),i=10*Math.ceil((h.width+u)/10),j=10*Math.ceil((h.height+t)/10),k=r.isLegendRight||r.isLegendInset?j:i,l=r.isLegendRight||r.isLegendInset?r.getLegendHeight():r.getLegendWidth();return d&&(y=0,F=0,v=0,w=0),s[lb]&&!r.isLegendToShow(c)?void(A[c]=B[c]=E[c]=z[c]=0):(A[c]=i,B[c]=j,(!v||i>=v)&&(v=i),(!w||j>=w)&&(w=j),g=r.isLegendRight||r.isLegendInset?w:v,void(s[ub]?(Object.keys(A).forEach(function(a){A[a]=v}),Object.keys(B).forEach(function(a){B[a]=w}),f=(l-g*a.length)/2,x>f?(y=0,F=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,h,i,j,k,l,m,n,o,p,q,r=this,s=r.config,t=4,u=36,v=0,w=0,x=10,y=0,z={},A={},B={},C=[0],E={},F=0,G=r.legend.selectAll("."+qe[le]).size();b=b||{},m=Be(b,"withTransition",!0),n=Be(b,"withTransitionForTransform",!0),r.isLegendRight?(e=function(a){return v*E[a]},i=function(a){return C[E[a]]+z[a]}):r.isLegendInset?(e=function(a){return v*E[a]+10},i=function(a){return C[E[a]]+z[a]}):(e=function(a){return C[E[a]]+z[a]},i=function(a){return w*E[a]}),f=function(a,b){return e(a,b)+14},j=function(a,b){return i(a,b)+9},h=function(a,b){return e(a,b)-4},k=function(a,b){return i(a,b)-7},l=r.legend.selectAll("."+qe[he]).data(a).enter().append("g").attr("class",function(a){return r.generateClass(qe[he],a)}).style("visibility",function(a){return r.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){se(s[rb])?s[rb].call(g,a):r.api.toggle(a)}).on("mouseover",function(a){r.d3.select(this).classed(qe[le],!0),r.transiting||r.api.focus(a),se(s[sb])&&s[sb].call(r,a)}).on("mouseout",function(a){r.d3.select(this).classed(qe[le],!1),r.transiting||r.api.revert(),se(s[tb])&&s[tb].call(r,a)}),l.append("text").text(function(a){return ve(s[D][a])?s[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",r.isLegendRight||r.isLegendInset?f:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:j),l.append("rect").attr("class",qe[ie]).style("fill-opacity",0).attr("x",r.isLegendRight||r.isLegendInset?h:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:k),l.append("rect").attr("class",qe[je]).style("pointer-events","none").style("fill",r.color).attr("x",r.isLegendRight||r.isLegendInset?f:-200).attr("y",r.isLegendRight||r.isLegendInset?-200:i).attr("width",10).attr("height",10),r.isLegendInset&&0!==v&&r.legend.insert("g","."+qe[he]).attr("class",qe[ge]).append("rect").attr("height",r.getLegendHeight()-10).attr("width",v*(F+1)+10),o=r.legend.selectAll("text").data(a).text(function(a){return ve(s[D][a])?s[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(m?o.transition():o).attr("x",f).attr("y",j),p=r.legend.selectAll("rect."+qe[ie]).data(a),(m?p.transition():p).attr("width",function(a){return A[a]}).attr("height",function(a){return B[a]}).attr("x",h).attr("y",k),q=r.legend.selectAll("rect."+qe[je]).data(a),(m?q.transition():q).style("fill",r.color).attr("x",e).attr("y",i),r.legend.selectAll("."+qe[he]).classed(qe[ke],function(a){return!r.isTargetToShow(a)}).transition().style("opacity",function(a){var b=r.d3.select(this);return r.isTargetToShow(a)?!G||b.classed(qe[le])?r.opacityForLegend(b):r.opacityForUnfocusedLegend(b):r.legendOpacityForHidden}),r.updateLegendItemWidth(v),r.updateLegendItemHeight(w),r.updateLegendStep(F),r.updateSizes(),r.updateScales(),r.updateSvgSize(),r.transformAll(n,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ze(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(se(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return te(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);te(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+qe[ae]+" ."+qe[be]),d=b.main.select("."+qe[ce]+" ."+qe[de]),e=b.main.select("."+qe[ee]+" ."+qe[fe]);(a?c.transition():c).attr("x",Ee(b.xForXAxisLabel,b)).attr("dx",Ee(b.dxForXAxisLabel,b)).attr("dy",Ee(b.dyForXAxisLabel,b)).text(Ee(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",Ee(b.xForYAxisLabel,b)).attr("dx",Ee(b.dxForYAxisLabel,b)).attr("dy",Ee(b.dyForYAxisLabel,b)).text(Ee(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",Ee(b.xForY2AxisLabel,b)).attr("dx",Ee(b.dxForY2AxisLabel,b)).attr("dy",Ee(b.dyForY2AxisLabel,b)).text(Ee(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return re(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=se(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+qe[hd]+c.selectorTarget(a)),e=c.svg.selectAll("."+qe[Jd]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+qe[hd]+b.selectorTarget(a));c.selectAll("path."+qe[Jd]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+qe[Jd]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+qe[id]).selectAll("."+qe[hd]).data(d.pie(a)).attr("class",Ee(d.classChartArc,d)),c=b.enter().append("g").attr("class",Ee(d.classChartArc,d)),c.append("g").attr("class",Ee(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a,b=this;a=b.main.select("."+qe[ad]).append("g").attr("class",qe[id]).attr("transform",b.getTranslate("arc")),a.append("text").attr("class",qe[jd]).style("text-anchor","middle").text(b.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+qe[Kd]).selectAll("."+qe[Jd]).data(Ee(e.arcData,e)),d.enter().append("path").attr("class",Ee(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+qe[hd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?qe[Qd]:""}).text(Ee(e.textForArcLabel,e)).attr("transform",Ee(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+qe[jd]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a,b=this,c=b.config;b.hasType("gauge")&&(a.append("path").attr("class",qe[kd]).attr("d",function(){var a={data:[{value:c[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return b.getArc(a,!0,!0)}),a.append("text").attr("dy",".75em").attr("class",qe[ld]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Hc]:""),a.append("text").attr("dx",-1*(b.innerRadius+(b.radius-b.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",qe[nd]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Fc]:""),a.append("text").attr("dx",b.innerRadius+(b.radius-b.innerRadius)/2+"px").attr("dy","1.2em").attr("class",qe[md]).style("text-anchor","middle").style("pointer-events","none").text(c[Cc]?c[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+qe[me]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(qe[oe]),q=o.classed(qe[pe]),r=!1;if(o.classed(qe[Hd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(qe[Fd]))return;n=De(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(qe[pe],!q),o.classed(qe[oe],!p),j.toggle(!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+qe[ad]).append("rect").attr("class",qe[me]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+qe[me]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+qe[Bd]).classed(qe[pe],!1),a.dragging=!1,a.config[$]())},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[vd]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",qe[ad]),c.select("."+qe[ad]).append("g").attr("class",qe[ed]),c.select("."+qe[ad]).append("g").attr("class",qe[cd]),c.append("g").attr("clip-path",a.clipPath).attr("class",qe[vd]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",qe[ae]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+qe[ed]).selectAll("."+qe[dd]).data(a).attr("class",Ee(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",Ee(f.classChartBar,f)),d.append("g").attr("class",Ee(f.classBars,f)),c=g.select("."+qe[cd]).selectAll("."+qe[bd]).data(a).attr("class",Ee(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",Ee(f.classChartLine,f)),b.append("g").attr("class",Ee(f.classLines,f)),b.append("g").attr("class",Ee(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+qe[Gd]).selectAll("."+qe[Fd]).data(Ee(n.barData,n)),j.enter().append("path").attr("class",Ee(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",Ee(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+qe[Ed]).selectAll("."+qe[Dd]).data(Ee(n.lineData,n)),h.enter().append("path").attr("class",Ee(n.classLine,n)).style("stroke",n.color),h.style("opacity",Ee(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+qe[Md]).selectAll("."+qe[Ld]).data(Ee(n.lineData,n)),i.enter().append("path").attr("class",Ee(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+qe[ae]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",a.redrawForZoom),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=ye(a.x.orgDomain())/ye(a.orgXDomain),c=a.orgScaleExtent();return a.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[ud]).call(b),a.main.selectAll("."+a.CLASS[qd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(g,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=Ae(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return Ae(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Be=f.getOption=function(a,b,c){return ve(a[b])?a[b]:c},Ce=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},De=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},Ee=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),this.defocus(),b(e.classed(qe[wd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));this.revert(),b(e.classed(qe[wd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(Ee(c.isNoneArc,c)),f=d.filter(Ee(c.isArc,c));b(e.classed(qe[wd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),se(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ve(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:re(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+qe[Cd]+b.getTargetSelectorSuffix(a)).selectAll("."+qe[Bd]).filter(function(){return c.select(this).classed(qe[oe])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(qe[oe]);i.classed(qe[Dd])||i.classed(qe[Ld])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(qe[oe],!0),g,h):ve(c)&&c&&n&&k(!1,i.classed(qe[oe],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+qe[Cd]).selectAll("."+qe[Bd]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(qe[oe]);h.classed(qe[Dd])||h.classed(qe[Ld])||k&&l&&e[S](f)&&m&&j(!1,h.classed(qe[oe],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return ue(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return g.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[qe[xd]]),d=e.main.select("."+qe[yd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ve(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(re(a.x)&&(c[Jb]=a.x),re(a.y)&&(c[Qb]=a.y),re(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(re(a.x)&&(c[Kb]=a.x),re(a.y)&&(c[Rb]=a.y),re(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ve(a.max)&&this.axis.max(a.max),ve(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&_.select(this).style("display",b%V?"none":"block")})}else Z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");if(!ab[vb]&&ab[Hb]&&Z.rotateTickText(Z.axes.x,b.axisX,ab[Hb]),K=Z.generateDrawArea(bb,!1),L=Z.generateDrawBar(cb),M=Z.generateDrawLine(db,!1),N=Z.generateXYForText(cb,!0),O=Z.generateXYForText(cb,!1),Z.subY.domain(Z.y.domain()),Z.subY2.domain(Z.y2.domain()),Z.tooltip.style("display","none"),Z.updateXgridFocus(),$.select("text."+pe[Nd]+"."+pe[Md]).attr("x",Z.width/2).attr("y",Z.height/2).text(ab[fb]).transition().style("opacity",gb.length?0:1),$.select("line."+pe[Vd]).style("visibility","hidden"),ab[fc]&&(d=ab[vb]?{x1:0,x2:Z.width,y1:function(a){return Z.x(a)-w},y2:function(a){return Z.x(a)-w}}:{x1:function(a){return Z.x(a)+w},x2:function(a){return Z.x(a)+w},y1:0,y2:Z.height},(k=function(a){e=Z.generateGridData(ab[gc],Z.x),w=Z.isCategorized()?Z.xAxis.tickOffset():0,c=$.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+_.select(this).attr(ab[vb]?"y1":"x1")===(ab[vb]?Z.height:0)?0:1}),c.exit().remove()})()),f=$.select("."+pe[Ud]).selectAll("."+pe[Td]).data(ab[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",ab[vb]?"":"rotate(-90)").attr("dx",ab[vb]?0:-Z.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&ab[ic]&&(h=$.select("."+pe[Xd]).selectAll("."+pe[Wd]).data(Z.y.ticks(ab[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",ab[vb]?Z.y:0).attr("x2",ab[vb]?Z.y:Z.width).attr("y1",ab[vb]?0:Z.y).attr("y2",ab[vb]?Z.height:Z.y),h.exit().remove(),Z.smoothLines(h,"grid")),B){i=$.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(ab[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",ab[vb]?"rotate(-90)":"").attr("dx",ab[vb]?0:-Z.margin.top).attr("dy",-5).style("opacity",0);var hb=De(Z.yv,Z);i.select("line").transition().duration(P).attr("x1",ab[vb]?hb:0).attr("x2",ab[vb]?hb:Z.width).attr("y1",ab[vb]?0:hb).attr("y2",ab[vb]?Z.height:hb).style("opacity",1),i.select("text").transition().duration(P).attr("x",ab[vb]?0:Z.width).attr("y",hb).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()}q=$.select("."+pe[xd]).selectAll("."+pe[wd]).data(ab[Qc]),q.enter().append("g").attr("class",De(Z.classRegion,Z)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=$.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(Z.barData,Z)),p.enter().append("path").attr("class",De(Z.classBar,Z)).style("stroke",function(a){return Z.color(a.id)}).style("fill",function(a){return Z.color(a.id)}),p.style("opacity",De(Z.initialOpacity,Z)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=$.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(Z.lineData,Z)),l.enter().append("path").attr("class",De(Z.classLine,Z)).style("stroke",Z.color),l.style("opacity",De(Z.initialOpacity,Z)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=$.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(Z.lineData,Z)),m.enter().append("path").attr("class",De(Z.classArea,Z)).style("fill",Z.color).style("opacity",function(){return Z.orgAreaOpacity=+_.select(this).style("opacity"),0}),m.style("opacity",Z.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),ab[mc]&&(n=$.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(Z.lineOrScatterData,Z)),n.enter().append("circle").attr("class",De(Z.classCircle,Z)).attr("r",De(Z.pointR,Z)).style("fill",Z.color),n.style("opacity",De(Z.initialOpacity,Z)),n.exit().remove()),Z.hasDataLabel()&&(r=$.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(Z.barOrLineData,Z)),r.enter().append("text").attr("class",De(Z.classText,Z)).attr("text-anchor",function(a){return ab[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return Z.color(a)}).style("fill-opacity",0),r.text(function(a){return Z.formatByAxisId(Z.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re(Z.redrawArc)&&Z.redrawArc(P,Q,G),re(Z.redrawSubchart)&&Z.redrawSubchart(C,b,P,Q,bb,cb,db),$.selectAll("."+pe[od]).filter(De(Z.isBarType,Z)).selectAll("circle").remove(),ab[s]&&(t=$.select("."+pe[qd]).style("cursor",ab[o]?ab[vb]?"ns-resize":"ew-resize":null),ze(ab[z])&&!Z.isSingleX(ab[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=$.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),Z.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",Z.width).attr("height",Z.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!Z.isCustomX()&&!Z.isTimeSeries()||Z.isCategorized()?(A=Z.getEventRectWidth(),y=function(a){return Z.x(a.x)-A/2}):(A=function(a){var b=Z.getPrevX(a.index),c=Z.getNextX(a.index),d=Z.data.xs[a.id][a.index],e=(Z.x(c?c:d)-Z.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=Z.getPrevX(a.index),c=Z.data.xs[a.id][a.index];return(Z.x(c)+Z.x(b?b:c))/2}),v=Z.getMaxDataCountTarget(Z.data.targets),$.select("."+pe[qd]).datum(v?v.values:[]),u=$.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),Z.generateEventRectsForSingleX(u.enter()),u.attr("class",De(Z.classEvent,Z)).attr("x",ab[vb]?0:y).attr("y",ab[vb]?y:0).attr("width",ab[vb]?Z.width:A).attr("height",ab[vb]?A:Z.height),u.exit().remove())),W=De(Z.xv,Z),X=De(Z.config[vb]?Z.circleY:Z.circleX,Z),Y=De(Z.config[vb]?Z.circleX:Z.circleY,Z),_.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",Z.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",Z.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",Z.color).style("opacity",Z.orgAreaOpacity)),b.push(n.transition().style("opacity",De(Z.opacityForCircle,Z)).style("fill",Z.color).attr("cx",X).attr("cy",Y)),b.push($.selectAll("."+pe[nd]).transition().attr("cx",X).attr("cy",Y)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",Z.color).style("fill-opacity",a.flow?0:De(Z.opacityForText,Z))),b.push(q.selectAll("rect").transition().attr("x",De(Z.regionX,Z)).attr("y",De(Z.regionY,Z)).attr("width",De(Z.regionWidth,Z)).attr("height",De(Z.regionHeight,Z)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",ab[vb]?0:W).attr("x2",ab[vb]?Z.width:W).attr("y1",ab[vb]?W:Z.margin.top).attr("y2",ab[vb]?W:Z.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",ab[vb]?Z.width:0).attr("y",W).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=Z.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=Z.getValueOnIndex(Z.data.targets[0].values,i),s=Z.getValueOnIndex(Z.data.targets[0].values,i+j),t=Z.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=Z.generateWait();Z.data.targets.forEach(function(a){a.values.splice(0,j)}),g=Z.updateXDomain(gb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?Z.x(t[0])-Z.x(g[0]):Z.isTimeSeries()?Z.x(t[0])-Z.x(g[0]):Z.x(o.x)-Z.x(s.x):1!==Z.data.targets[0].values.length?b=Z.x(t[0])-Z.x(g[0]):Z.isTimeSeries()?(o=Z.getValueOnIndex(Z.data.targets[0].values,0),s=Z.getValueOnIndex(Z.data.targets[0].values,Z.data.targets[0].values.length-1),b=Z.x(o.x)-Z.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",_.transition().ease("linear").duration(v).each(function(){x.add(Z.axes.x.transition().call(Z.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter(Z.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));Z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),Z.svg.selectAll("."+pe[Od]).selectAll(e).remove(),Z.svg.selectAll("."+pe[qd]).selectAll(g).remove(),Z.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",ab[vb]?0:W).attr("x2",ab[vb]?Z.width:W),f.select("text").attr("x",ab[vb]?Z.width:0).attr("y",W),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",X).attr("cy",Y),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De(Z.opacityForText,Z)),q.attr("transform",null),q.select("rect").filter(Z.isRegionOnX).attr("x",De(Z.regionX,Z)).attr("width",De(Z.regionWidth,Z)),u.attr("x",ab[vb]?0:y).attr("y",ab[vb]?y:0).attr("width",ab[vb]?Z.width:A).attr("height",ab[vb]?A:Z.height),w()})}),Z.mapToIds(Z.data.targets).forEach(function(a){Z.withoutFadeIn[a]=!0}),re(Z.updateZoom)&&Z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; +f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},a},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),function(a){var b,f=c.filterRemoveNull(a.values),g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1}) +},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/htdocs/samples/axes_range.html b/htdocs/samples/axes_range.html index 768fdea..732200a 100644 --- a/htdocs/samples/axes_range.html +++ b/htdocs/samples/axes_range.html @@ -55,7 +55,7 @@ }, 2000); setTimeout(function () { - chart1.axis.range({max: {x: 5}, min: {x: 0}}); + chart1.axis.range({max: {x: 5}, min: {x: 0}}); }, 3000); setTimeout(function () { @@ -79,7 +79,7 @@ }, 5000); setTimeout(function () { - chart2.axis.range({max: {y: 400}, min: {y: 0}}); + chart2.axis.range({max: {y: 400}, min: {y: 0}}); }, 6000); diff --git a/htdocs/samples/categorized.html b/htdocs/samples/categorized.html index f96e4c1..0e4a1b5 100644 --- a/htdocs/samples/categorized.html +++ b/htdocs/samples/categorized.html @@ -9,6 +9,7 @@ - + - + - + + + + + + diff --git a/src/config.js b/src/config.js index 466cba0..56193a9 100644 --- a/src/config.js +++ b/src/config.js @@ -326,8 +326,13 @@ c3_chart_internal_fn.getDefaultConfig = function () { config[__tooltip_init_x] = 0; config[__tooltip_init_position] = {top: '0px', left: '50px'}; + Object.keys(this.additionalConfig).forEach(function (key) { + config[key] = this.additionalConfig[key]; + }, this); + return config; }; +c3_chart_internal_fn.additionalConfig = {}; c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; From 3ce01be5747ca752725f2710b6e3f6a6e8ffda09 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Mon, 4 Aug 2014 05:35:19 +0100 Subject: [PATCH 27/44] Fix trivial --- src/core.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core.js b/src/core.js index 2f4384f..e54e8dd 100644 --- a/src/core.js +++ b/src/core.js @@ -511,7 +511,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var xv, cx, cy; + var yv, xv, cx, cy; xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); @@ -697,18 +697,18 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .attr('dy', -5) .style("opacity", 0); // update - var yv_ = generateCall($$.yv, $$); + yv = generateCall($$.yv, $$); ygridLines.select('line') .transition().duration(duration) - .attr("x1", config[__axis_rotated] ? yv_ : 0) - .attr("x2", config[__axis_rotated] ? yv_ : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : yv_) - .attr("y2", config[__axis_rotated] ? $$.height : yv_) + .attr("x1", config[__axis_rotated] ? yv : 0) + .attr("x2", config[__axis_rotated] ? yv : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv) + .attr("y2", config[__axis_rotated] ? $$.height : yv) .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) .attr("x", config[__axis_rotated] ? 0 : $$.width) - .attr("y", yv_) + .attr("y", yv) .text(function (d) { return d.text; }) .style("opacity", 1); // exit From a0801cb4746bc3addf62de823fa8f732c1b17f69 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 9 Aug 2014 13:58:45 +0900 Subject: [PATCH 28/44] Merge master fix --- src/c3.axis.js | 11 +++++++++-- src/shape.js | 5 ++++- src/tooltip.js | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/c3.axis.js b/src/c3.axis.js index 02a514f..17b9ecf 100644 --- a/src/c3.axis.js +++ b/src/c3.axis.js @@ -176,8 +176,15 @@ function c3_axis(d3, isCategory) { return axis; }; axis.tickValues = function (x) { - if (!arguments.length) { return tickValues; } - tickValues = x; + if (typeof x === 'function') { + tickValues = function () { + return x(scale.domain()); + }; + } + else { + if (!arguments.length) { return tickValues; } + tickValues = x; + } return axis; }; return axis; diff --git a/src/shape.js b/src/shape.js index 1b3537d..1971f56 100644 --- a/src/shape.js +++ b/src/shape.js @@ -169,9 +169,12 @@ c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { }; area = config[__axis_rotated] ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); + if (!config[__line_connect_null]) { + area = area.defined(function (d) { return d.value !== null; }); + } return function (d) { - var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; if ($$.isAreaType(d)) { path = area.interpolate($$.getInterpolate(d))(data); } else { diff --git a/src/tooltip.js b/src/tooltip.js index 2b005d2..58a4364 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -84,7 +84,7 @@ c3_chart_internal_fn.showTooltip = function (selectedData, mouse) { if (tooltipRight > chartRight) { tooltipLeft -= tooltipRight - chartRight; } - if (tooltipTop + tHeight > $$.getCurrentHeight()) { + if (tooltipTop + tHeight > $$.getCurrentHeight() && tooltipTop > tHeight + 30) { tooltipTop -= tHeight + 30; } } From 1d105c1a342cd7bcc75f0d3166e22be6e672b3c9 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 9 Aug 2014 13:59:13 +0900 Subject: [PATCH 29/44] Update c3.js and c3.min.js --- c3.js | 37 ++++++++++++++++++++++++++----------- c3.min.js | 6 +++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/c3.js b/c3.js index 6fdb0cc..e5b50f3 100644 --- a/c3.js +++ b/c3.js @@ -516,7 +516,7 @@ var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var xv, cx, cy; + var yv, xv, cx, cy; xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); @@ -702,18 +702,18 @@ .attr('dy', -5) .style("opacity", 0); // update - var yv_ = generateCall($$.yv, $$); + yv = generateCall($$.yv, $$); ygridLines.select('line') .transition().duration(duration) - .attr("x1", config[__axis_rotated] ? yv_ : 0) - .attr("x2", config[__axis_rotated] ? yv_ : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : yv_) - .attr("y2", config[__axis_rotated] ? $$.height : yv_) + .attr("x1", config[__axis_rotated] ? yv : 0) + .attr("x2", config[__axis_rotated] ? yv : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv) + .attr("y2", config[__axis_rotated] ? $$.height : yv) .style("opacity", 1); ygridLines.select('text') .transition().duration(duration) .attr("x", config[__axis_rotated] ? 0 : $$.width) - .attr("y", yv_) + .attr("y", yv) .text(function (d) { return d.text; }) .style("opacity", 1); // exit @@ -1886,8 +1886,13 @@ config[__tooltip_init_x] = 0; config[__tooltip_init_position] = {top: '0px', left: '50px'}; + Object.keys(this.additionalConfig).forEach(function (key) { + config[key] = this.additionalConfig[key]; + }, this); + return config; }; + c3_chart_internal_fn.additionalConfig = {}; c3_chart_internal_fn.loadConfig = function (config) { var this_config = this.config, target, keys, read; @@ -3072,9 +3077,12 @@ }; area = config[__axis_rotated] ? area.x0(value0).x1(value1).y(xValue) : area.x(xValue).y0(value0).y1(value1); + if (!config[__line_connect_null]) { + area = area.defined(function (d) { return d.value !== null; }); + } return function (d) { - var data = $$.filterRemoveNull(d.values), x0 = 0, y0 = 0, path; + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; if ($$.isAreaType(d)) { path = area.interpolate($$.getInterpolate(d))(data); } else { @@ -3539,7 +3547,7 @@ if (tooltipRight > chartRight) { tooltipLeft -= tooltipRight - chartRight; } - if (tooltipTop + tHeight > $$.getCurrentHeight()) { + if (tooltipTop + tHeight > $$.getCurrentHeight() && tooltipTop > tHeight + 30) { tooltipTop -= tHeight + 30; } } @@ -6119,8 +6127,15 @@ return axis; }; axis.tickValues = function (x) { - if (!arguments.length) { return tickValues; } - tickValues = x; + if (typeof x === 'function') { + tickValues = function () { + return x(scale.domain()); + }; + } + else { + if (!arguments.length) { return tickValues; } + tickValues = x; + } return axis; }; return axis; diff --git a/c3.min.js b/c3.min.js index af01044..27c84ce 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&_.select(this).style("display",b%V?"none":"block")})}else Z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");if(!ab[vb]&&ab[Hb]&&Z.rotateTickText(Z.axes.x,b.axisX,ab[Hb]),K=Z.generateDrawArea(bb,!1),L=Z.generateDrawBar(cb),M=Z.generateDrawLine(db,!1),N=Z.generateXYForText(cb,!0),O=Z.generateXYForText(cb,!1),Z.subY.domain(Z.y.domain()),Z.subY2.domain(Z.y2.domain()),Z.tooltip.style("display","none"),Z.updateXgridFocus(),$.select("text."+pe[Nd]+"."+pe[Md]).attr("x",Z.width/2).attr("y",Z.height/2).text(ab[fb]).transition().style("opacity",gb.length?0:1),$.select("line."+pe[Vd]).style("visibility","hidden"),ab[fc]&&(d=ab[vb]?{x1:0,x2:Z.width,y1:function(a){return Z.x(a)-w},y2:function(a){return Z.x(a)-w}}:{x1:function(a){return Z.x(a)+w},x2:function(a){return Z.x(a)+w},y1:0,y2:Z.height},(k=function(a){e=Z.generateGridData(ab[gc],Z.x),w=Z.isCategorized()?Z.xAxis.tickOffset():0,c=$.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+_.select(this).attr(ab[vb]?"y1":"x1")===(ab[vb]?Z.height:0)?0:1}),c.exit().remove()})()),f=$.select("."+pe[Ud]).selectAll("."+pe[Td]).data(ab[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",ab[vb]?"":"rotate(-90)").attr("dx",ab[vb]?0:-Z.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&ab[ic]&&(h=$.select("."+pe[Xd]).selectAll("."+pe[Wd]).data(Z.y.ticks(ab[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",ab[vb]?Z.y:0).attr("x2",ab[vb]?Z.y:Z.width).attr("y1",ab[vb]?0:Z.y).attr("y2",ab[vb]?Z.height:Z.y),h.exit().remove(),Z.smoothLines(h,"grid")),B){i=$.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(ab[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",ab[vb]?"rotate(-90)":"").attr("dx",ab[vb]?0:-Z.margin.top).attr("dy",-5).style("opacity",0);var hb=De(Z.yv,Z);i.select("line").transition().duration(P).attr("x1",ab[vb]?hb:0).attr("x2",ab[vb]?hb:Z.width).attr("y1",ab[vb]?0:hb).attr("y2",ab[vb]?Z.height:hb).style("opacity",1),i.select("text").transition().duration(P).attr("x",ab[vb]?0:Z.width).attr("y",hb).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()}q=$.select("."+pe[xd]).selectAll("."+pe[wd]).data(ab[Qc]),q.enter().append("g").attr("class",De(Z.classRegion,Z)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=$.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(Z.barData,Z)),p.enter().append("path").attr("class",De(Z.classBar,Z)).style("stroke",function(a){return Z.color(a.id)}).style("fill",function(a){return Z.color(a.id)}),p.style("opacity",De(Z.initialOpacity,Z)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=$.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(Z.lineData,Z)),l.enter().append("path").attr("class",De(Z.classLine,Z)).style("stroke",Z.color),l.style("opacity",De(Z.initialOpacity,Z)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=$.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(Z.lineData,Z)),m.enter().append("path").attr("class",De(Z.classArea,Z)).style("fill",Z.color).style("opacity",function(){return Z.orgAreaOpacity=+_.select(this).style("opacity"),0}),m.style("opacity",Z.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),ab[mc]&&(n=$.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(Z.lineOrScatterData,Z)),n.enter().append("circle").attr("class",De(Z.classCircle,Z)).attr("r",De(Z.pointR,Z)).style("fill",Z.color),n.style("opacity",De(Z.initialOpacity,Z)),n.exit().remove()),Z.hasDataLabel()&&(r=$.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(Z.barOrLineData,Z)),r.enter().append("text").attr("class",De(Z.classText,Z)).attr("text-anchor",function(a){return ab[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return Z.color(a)}).style("fill-opacity",0),r.text(function(a){return Z.formatByAxisId(Z.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re(Z.redrawArc)&&Z.redrawArc(P,Q,G),re(Z.redrawSubchart)&&Z.redrawSubchart(C,b,P,Q,bb,cb,db),$.selectAll("."+pe[od]).filter(De(Z.isBarType,Z)).selectAll("circle").remove(),ab[s]&&(t=$.select("."+pe[qd]).style("cursor",ab[o]?ab[vb]?"ns-resize":"ew-resize":null),ze(ab[z])&&!Z.isSingleX(ab[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=$.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),Z.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",Z.width).attr("height",Z.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!Z.isCustomX()&&!Z.isTimeSeries()||Z.isCategorized()?(A=Z.getEventRectWidth(),y=function(a){return Z.x(a.x)-A/2}):(A=function(a){var b=Z.getPrevX(a.index),c=Z.getNextX(a.index),d=Z.data.xs[a.id][a.index],e=(Z.x(c?c:d)-Z.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=Z.getPrevX(a.index),c=Z.data.xs[a.id][a.index];return(Z.x(c)+Z.x(b?b:c))/2}),v=Z.getMaxDataCountTarget(Z.data.targets),$.select("."+pe[qd]).datum(v?v.values:[]),u=$.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),Z.generateEventRectsForSingleX(u.enter()),u.attr("class",De(Z.classEvent,Z)).attr("x",ab[vb]?0:y).attr("y",ab[vb]?y:0).attr("width",ab[vb]?Z.width:A).attr("height",ab[vb]?A:Z.height),u.exit().remove())),W=De(Z.xv,Z),X=De(Z.config[vb]?Z.circleY:Z.circleX,Z),Y=De(Z.config[vb]?Z.circleX:Z.circleY,Z),_.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",Z.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",Z.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",Z.color).style("opacity",Z.orgAreaOpacity)),b.push(n.transition().style("opacity",De(Z.opacityForCircle,Z)).style("fill",Z.color).attr("cx",X).attr("cy",Y)),b.push($.selectAll("."+pe[nd]).transition().attr("cx",X).attr("cy",Y)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",Z.color).style("fill-opacity",a.flow?0:De(Z.opacityForText,Z))),b.push(q.selectAll("rect").transition().attr("x",De(Z.regionX,Z)).attr("y",De(Z.regionY,Z)).attr("width",De(Z.regionWidth,Z)).attr("height",De(Z.regionHeight,Z)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",ab[vb]?0:W).attr("x2",ab[vb]?Z.width:W).attr("y1",ab[vb]?W:Z.margin.top).attr("y2",ab[vb]?W:Z.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",ab[vb]?Z.width:0).attr("y",W).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=Z.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=Z.getValueOnIndex(Z.data.targets[0].values,i),s=Z.getValueOnIndex(Z.data.targets[0].values,i+j),t=Z.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=Z.generateWait();Z.data.targets.forEach(function(a){a.values.splice(0,j)}),g=Z.updateXDomain(gb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?Z.x(t[0])-Z.x(g[0]):Z.isTimeSeries()?Z.x(t[0])-Z.x(g[0]):Z.x(o.x)-Z.x(s.x):1!==Z.data.targets[0].values.length?b=Z.x(t[0])-Z.x(g[0]):Z.isTimeSeries()?(o=Z.getValueOnIndex(Z.data.targets[0].values,0),s=Z.getValueOnIndex(Z.data.targets[0].values,Z.data.targets[0].values.length-1),b=Z.x(o.x)-Z.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",_.transition().ease("linear").duration(v).each(function(){x.add(Z.axes.x.transition().call(Z.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter(Z.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));Z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),Z.svg.selectAll("."+pe[Od]).selectAll(e).remove(),Z.svg.selectAll("."+pe[qd]).selectAll(g).remove(),Z.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",ab[vb]?0:W).attr("x2",ab[vb]?Z.width:W),f.select("text").attr("x",ab[vb]?Z.width:0).attr("y",W),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",X).attr("cy",Y),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De(Z.opacityForText,Z)),q.attr("transform",null),q.select("rect").filter(Z.isRegionOnX).attr("x",De(Z.regionX,Z)).attr("width",De(Z.regionWidth,Z)),u.attr("x",ab[vb]?0:y).attr("y",ab[vb]?y:0).attr("width",ab[vb]?Z.width:A).attr("height",ab[vb]?A:Z.height),w()})}),Z.mapToIds(Z.data.targets).forEach(function(a){Z.withoutFadeIn[a]=!0}),re(Z.updateZoom)&&Z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; -f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},a},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),function(a){var b,f=c.filterRemoveNull(a.values),g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1}) -},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&ab.select(this).style("display",b%V?"none":"block")})}else $.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!bb[vb]&&bb[Hb]&&$.rotateTickText($.axes.x,b.axisX,bb[Hb]),K=$.generateDrawArea(cb,!1),L=$.generateDrawBar(db),M=$.generateDrawLine(eb,!1),N=$.generateXYForText(db,!0),O=$.generateXYForText(db,!1),$.subY.domain($.y.domain()),$.subY2.domain($.y2.domain()),$.tooltip.style("display","none"),$.updateXgridFocus(),_.select("text."+pe[Nd]+"."+pe[Md]).attr("x",$.width/2).attr("y",$.height/2).text(bb[fb]).transition().style("opacity",hb.length?0:1),_.select("line."+pe[Vd]).style("visibility","hidden"),bb[fc]&&(d=bb[vb]?{x1:0,x2:$.width,y1:function(a){return $.x(a)-w},y2:function(a){return $.x(a)-w}}:{x1:function(a){return $.x(a)+w},x2:function(a){return $.x(a)+w},y1:0,y2:$.height},(k=function(a){e=$.generateGridData(bb[gc],$.x),w=$.isCategorized()?$.xAxis.tickOffset():0,c=_.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+ab.select(this).attr(bb[vb]?"y1":"x1")===(bb[vb]?$.height:0)?0:1}),c.exit().remove()})()),f=_.select("."+pe[Ud]).selectAll("."+pe[Td]).data(bb[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"":"rotate(-90)").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&bb[ic]&&(h=_.select("."+pe[Xd]).selectAll("."+pe[Wd]).data($.y.ticks(bb[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",bb[vb]?$.y:0).attr("x2",bb[vb]?$.y:$.width).attr("y1",bb[vb]?0:$.y).attr("y2",bb[vb]?$.height:$.y),h.exit().remove(),$.smoothLines(h,"grid")),B&&(i=_.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(bb[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"rotate(-90)":"").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),W=De($.yv,$),i.select("line").transition().duration(P).attr("x1",bb[vb]?W:0).attr("x2",bb[vb]?W:$.width).attr("y1",bb[vb]?0:W).attr("y2",bb[vb]?$.height:W).style("opacity",1),i.select("text").transition().duration(P).attr("x",bb[vb]?0:$.width).attr("y",W).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()),q=_.select("."+pe[xd]).selectAll("."+pe[wd]).data(bb[Qc]),q.enter().append("g").attr("class",De($.classRegion,$)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=_.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De($.barData,$)),p.enter().append("path").attr("class",De($.classBar,$)).style("stroke",function(a){return $.color(a.id)}).style("fill",function(a){return $.color(a.id)}),p.style("opacity",De($.initialOpacity,$)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=_.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De($.lineData,$)),l.enter().append("path").attr("class",De($.classLine,$)).style("stroke",$.color),l.style("opacity",De($.initialOpacity,$)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=_.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De($.lineData,$)),m.enter().append("path").attr("class",De($.classArea,$)).style("fill",$.color).style("opacity",function(){return $.orgAreaOpacity=+ab.select(this).style("opacity"),0}),m.style("opacity",$.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),bb[mc]&&(n=_.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De($.lineOrScatterData,$)),n.enter().append("circle").attr("class",De($.classCircle,$)).attr("r",De($.pointR,$)).style("fill",$.color),n.style("opacity",De($.initialOpacity,$)),n.exit().remove()),$.hasDataLabel()&&(r=_.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De($.barOrLineData,$)),r.enter().append("text").attr("class",De($.classText,$)).attr("text-anchor",function(a){return bb[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return $.color(a)}).style("fill-opacity",0),r.text(function(a){return $.formatByAxisId($.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re($.redrawArc)&&$.redrawArc(P,Q,G),re($.redrawSubchart)&&$.redrawSubchart(C,b,P,Q,cb,db,eb),_.selectAll("."+pe[od]).filter(De($.isBarType,$)).selectAll("circle").remove(),bb[s]&&(t=_.select("."+pe[qd]).style("cursor",bb[o]?bb[vb]?"ns-resize":"ew-resize":null),ze(bb[z])&&!$.isSingleX(bb[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),$.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",$.width).attr("height",$.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!$.isCustomX()&&!$.isTimeSeries()||$.isCategorized()?(A=$.getEventRectWidth(),y=function(a){return $.x(a.x)-A/2}):(A=function(a){var b=$.getPrevX(a.index),c=$.getNextX(a.index),d=$.data.xs[a.id][a.index],e=($.x(c?c:d)-$.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=$.getPrevX(a.index),c=$.data.xs[a.id][a.index];return($.x(c)+$.x(b?b:c))/2}),v=$.getMaxDataCountTarget($.data.targets),_.select("."+pe[qd]).datum(v?v.values:[]),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),$.generateEventRectsForSingleX(u.enter()),u.attr("class",De($.classEvent,$)).attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),u.exit().remove())),X=De($.xv,$),Y=De($.config[vb]?$.circleY:$.circleX,$),Z=De($.config[vb]?$.circleX:$.circleY,$),ab.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",$.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",$.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",$.color).style("opacity",$.orgAreaOpacity)),b.push(n.transition().style("opacity",De($.opacityForCircle,$)).style("fill",$.color).attr("cx",Y).attr("cy",Z)),b.push(_.selectAll("."+pe[nd]).transition().attr("cx",Y).attr("cy",Z)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",$.color).style("fill-opacity",a.flow?0:De($.opacityForText,$))),b.push(q.selectAll("rect").transition().attr("x",De($.regionX,$)).attr("y",De($.regionY,$)).attr("width",De($.regionWidth,$)).attr("height",De($.regionHeight,$)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X).attr("y1",bb[vb]?X:$.margin.top).attr("y2",bb[vb]?X:$.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",bb[vb]?$.width:0).attr("y",X).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=$.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=$.getValueOnIndex($.data.targets[0].values,i),s=$.getValueOnIndex($.data.targets[0].values,i+j),t=$.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=$.generateWait();$.data.targets.forEach(function(a){a.values.splice(0,j)}),g=$.updateXDomain(hb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?$.x(t[0])-$.x(g[0]):$.isTimeSeries()?$.x(t[0])-$.x(g[0]):$.x(o.x)-$.x(s.x):1!==$.data.targets[0].values.length?b=$.x(t[0])-$.x(g[0]):$.isTimeSeries()?(o=$.getValueOnIndex($.data.targets[0].values,0),s=$.getValueOnIndex($.data.targets[0].values,$.data.targets[0].values.length-1),b=$.x(o.x)-$.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",ab.transition().ease("linear").duration(v).each(function(){x.add($.axes.x.transition().call($.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter($.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));$.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),$.svg.selectAll("."+pe[Od]).selectAll(e).remove(),$.svg.selectAll("."+pe[qd]).selectAll(g).remove(),$.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X),f.select("text").attr("x",bb[vb]?$.width:0).attr("y",X),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Y).attr("cy",Z),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De($.opacityForText,$)),q.attr("transform",null),q.select("rect").filter($.isRegionOnX).attr("x",De($.regionX,$)).attr("width",De($.regionWidth,$)),u.attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),w()})}),$.mapToIds($.data.targets).forEach(function(a){$.withoutFadeIn[a]=!0}),re($.updateZoom)&&$.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; +f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none") +},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file From 8e9bd1a37769d247d0ad50bb5b6ccb249571c3ab Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Fri, 15 Aug 2014 23:03:24 +0900 Subject: [PATCH 30/44] Separate axis --- c3.js | 100 ++++++++++++++++++++++++++++------------------------ c3.min.js | 6 ++-- src/axis.js | 52 +++++++++++++++++++++++++++ src/core.js | 48 ++----------------------- 4 files changed, 111 insertions(+), 95 deletions(-) diff --git a/c3.js b/c3.js index e5b50f3..0c76619 100644 --- a/c3.js +++ b/c3.js @@ -281,35 +281,7 @@ } // Add Axis - $$.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", generateCall($$.textAnchorForXAxisLabel, $$)); - - $$.axes.y = main.append("g") - .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) - .attr("clip-path", $$.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", generateCall($$.textAnchorForYAxisLabel, $$)); - - $$.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", generateCall($$.textAnchorForY2AxisLabel, $$)); + $$.initAxis(); // Set targets $$.updateTargets($$.data.targets); @@ -564,14 +536,7 @@ $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); // axes - $$.axes.x.style("opacity", hideAxis ? 0 : 1); - $$.axes.y.style("opacity", hideAxis ? 0 : 1); - $$.axes.y2.style("opacity", hideAxis ? 0 : 1); - $$.axes.subx.style("opacity", hideAxis ? 0 : 1); - transitions.axisX.call($$.xAxis); - transitions.axisY.call($$.yAxis); - transitions.axisY2.call($$.y2Axis); - transitions.axisSubX.call($$.subXAxis); + $$.redrawAxis(transitions, hideAxis); // Update axis label $$.updateAxisLabels(withTransition); @@ -1498,15 +1463,6 @@ $$.updateAndRedraw(options); }; - c3_chart_internal_fn.generateAxisTransitions = function (duration) { - var $$ = this, 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 - }; - }; c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition @@ -3855,6 +3811,38 @@ $$.transformAll(withTransitionForTransform, transitions); }; + c3_chart_internal_fn.initAxis = function () { + var $$ = this, config = $$.config, main = $$.main, CLASS = $$.CLASS; + $$.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", generateCall($$.textAnchorForXAxisLabel, $$)); + + $$.axes.y = main.append("g") + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) + .attr("clip-path", $$.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", generateCall($$.textAnchorForYAxisLabel, $$)); + + $$.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", generateCall($$.textAnchorForY2AxisLabel, $$)); + }; c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, axis = c3_axis($$.d3, $$.isCategorized()).scale(scale).orient(orient); @@ -4138,6 +4126,26 @@ if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; + c3_chart_internal_fn.generateAxisTransitions = function (duration) { + var $$ = this, 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 + }; + }; + c3_chart_internal_fn.redrawAxis = function (transitions, isHidden) { + var $$ = this; + $$.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); + }; c3_chart_internal_fn.getClipPath = function (id) { var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; diff --git a/c3.min.js b/c3.min.js index 27c84ce..6bd2814 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&ab.select(this).style("display",b%V?"none":"block")})}else $.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!bb[vb]&&bb[Hb]&&$.rotateTickText($.axes.x,b.axisX,bb[Hb]),K=$.generateDrawArea(cb,!1),L=$.generateDrawBar(db),M=$.generateDrawLine(eb,!1),N=$.generateXYForText(db,!0),O=$.generateXYForText(db,!1),$.subY.domain($.y.domain()),$.subY2.domain($.y2.domain()),$.tooltip.style("display","none"),$.updateXgridFocus(),_.select("text."+pe[Nd]+"."+pe[Md]).attr("x",$.width/2).attr("y",$.height/2).text(bb[fb]).transition().style("opacity",hb.length?0:1),_.select("line."+pe[Vd]).style("visibility","hidden"),bb[fc]&&(d=bb[vb]?{x1:0,x2:$.width,y1:function(a){return $.x(a)-w},y2:function(a){return $.x(a)-w}}:{x1:function(a){return $.x(a)+w},x2:function(a){return $.x(a)+w},y1:0,y2:$.height},(k=function(a){e=$.generateGridData(bb[gc],$.x),w=$.isCategorized()?$.xAxis.tickOffset():0,c=_.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+ab.select(this).attr(bb[vb]?"y1":"x1")===(bb[vb]?$.height:0)?0:1}),c.exit().remove()})()),f=_.select("."+pe[Ud]).selectAll("."+pe[Td]).data(bb[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"":"rotate(-90)").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&bb[ic]&&(h=_.select("."+pe[Xd]).selectAll("."+pe[Wd]).data($.y.ticks(bb[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",bb[vb]?$.y:0).attr("x2",bb[vb]?$.y:$.width).attr("y1",bb[vb]?0:$.y).attr("y2",bb[vb]?$.height:$.y),h.exit().remove(),$.smoothLines(h,"grid")),B&&(i=_.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(bb[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"rotate(-90)":"").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),W=De($.yv,$),i.select("line").transition().duration(P).attr("x1",bb[vb]?W:0).attr("x2",bb[vb]?W:$.width).attr("y1",bb[vb]?0:W).attr("y2",bb[vb]?$.height:W).style("opacity",1),i.select("text").transition().duration(P).attr("x",bb[vb]?0:$.width).attr("y",W).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()),q=_.select("."+pe[xd]).selectAll("."+pe[wd]).data(bb[Qc]),q.enter().append("g").attr("class",De($.classRegion,$)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=_.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De($.barData,$)),p.enter().append("path").attr("class",De($.classBar,$)).style("stroke",function(a){return $.color(a.id)}).style("fill",function(a){return $.color(a.id)}),p.style("opacity",De($.initialOpacity,$)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=_.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De($.lineData,$)),l.enter().append("path").attr("class",De($.classLine,$)).style("stroke",$.color),l.style("opacity",De($.initialOpacity,$)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=_.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De($.lineData,$)),m.enter().append("path").attr("class",De($.classArea,$)).style("fill",$.color).style("opacity",function(){return $.orgAreaOpacity=+ab.select(this).style("opacity"),0}),m.style("opacity",$.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),bb[mc]&&(n=_.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De($.lineOrScatterData,$)),n.enter().append("circle").attr("class",De($.classCircle,$)).attr("r",De($.pointR,$)).style("fill",$.color),n.style("opacity",De($.initialOpacity,$)),n.exit().remove()),$.hasDataLabel()&&(r=_.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De($.barOrLineData,$)),r.enter().append("text").attr("class",De($.classText,$)).attr("text-anchor",function(a){return bb[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return $.color(a)}).style("fill-opacity",0),r.text(function(a){return $.formatByAxisId($.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re($.redrawArc)&&$.redrawArc(P,Q,G),re($.redrawSubchart)&&$.redrawSubchart(C,b,P,Q,cb,db,eb),_.selectAll("."+pe[od]).filter(De($.isBarType,$)).selectAll("circle").remove(),bb[s]&&(t=_.select("."+pe[qd]).style("cursor",bb[o]?bb[vb]?"ns-resize":"ew-resize":null),ze(bb[z])&&!$.isSingleX(bb[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),$.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",$.width).attr("height",$.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!$.isCustomX()&&!$.isTimeSeries()||$.isCategorized()?(A=$.getEventRectWidth(),y=function(a){return $.x(a.x)-A/2}):(A=function(a){var b=$.getPrevX(a.index),c=$.getNextX(a.index),d=$.data.xs[a.id][a.index],e=($.x(c?c:d)-$.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=$.getPrevX(a.index),c=$.data.xs[a.id][a.index];return($.x(c)+$.x(b?b:c))/2}),v=$.getMaxDataCountTarget($.data.targets),_.select("."+pe[qd]).datum(v?v.values:[]),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),$.generateEventRectsForSingleX(u.enter()),u.attr("class",De($.classEvent,$)).attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),u.exit().remove())),X=De($.xv,$),Y=De($.config[vb]?$.circleY:$.circleX,$),Z=De($.config[vb]?$.circleX:$.circleY,$),ab.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",$.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",$.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",$.color).style("opacity",$.orgAreaOpacity)),b.push(n.transition().style("opacity",De($.opacityForCircle,$)).style("fill",$.color).attr("cx",Y).attr("cy",Z)),b.push(_.selectAll("."+pe[nd]).transition().attr("cx",Y).attr("cy",Z)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",$.color).style("fill-opacity",a.flow?0:De($.opacityForText,$))),b.push(q.selectAll("rect").transition().attr("x",De($.regionX,$)).attr("y",De($.regionY,$)).attr("width",De($.regionWidth,$)).attr("height",De($.regionHeight,$)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X).attr("y1",bb[vb]?X:$.margin.top).attr("y2",bb[vb]?X:$.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",bb[vb]?$.width:0).attr("y",X).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=$.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=$.getValueOnIndex($.data.targets[0].values,i),s=$.getValueOnIndex($.data.targets[0].values,i+j),t=$.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=$.generateWait();$.data.targets.forEach(function(a){a.values.splice(0,j)}),g=$.updateXDomain(hb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?$.x(t[0])-$.x(g[0]):$.isTimeSeries()?$.x(t[0])-$.x(g[0]):$.x(o.x)-$.x(s.x):1!==$.data.targets[0].values.length?b=$.x(t[0])-$.x(g[0]):$.isTimeSeries()?(o=$.getValueOnIndex($.data.targets[0].values,0),s=$.getValueOnIndex($.data.targets[0].values,$.data.targets[0].values.length-1),b=$.x(o.x)-$.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",ab.transition().ease("linear").duration(v).each(function(){x.add($.axes.x.transition().call($.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter($.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));$.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),$.svg.selectAll("."+pe[Od]).selectAll(e).remove(),$.svg.selectAll("."+pe[qd]).selectAll(g).remove(),$.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X),f.select("text").attr("x",bb[vb]?$.width:0).attr("y",X),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Y).attr("cy",Z),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De($.opacityForText,$)),q.attr("transform",null),q.select("rect").filter($.isRegionOnX).attr("x",De($.regionX,$)).attr("width",De($.regionWidth,$)),u.attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),w()})}),$.mapToIds($.data.targets).forEach(function(a){$.withoutFadeIn[a]=!0}),re($.updateZoom)&&$.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&ab.select(this).style("display",b%V?"none":"block")})}else $.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!bb[vb]&&bb[Hb]&&$.rotateTickText($.axes.x,b.axisX,bb[Hb]),K=$.generateDrawArea(cb,!1),L=$.generateDrawBar(db),M=$.generateDrawLine(eb,!1),N=$.generateXYForText(db,!0),O=$.generateXYForText(db,!1),$.subY.domain($.y.domain()),$.subY2.domain($.y2.domain()),$.tooltip.style("display","none"),$.updateXgridFocus(),_.select("text."+pe[Nd]+"."+pe[Md]).attr("x",$.width/2).attr("y",$.height/2).text(bb[fb]).transition().style("opacity",hb.length?0:1),_.select("line."+pe[Vd]).style("visibility","hidden"),bb[fc]&&(d=bb[vb]?{x1:0,x2:$.width,y1:function(a){return $.x(a)-w},y2:function(a){return $.x(a)-w}}:{x1:function(a){return $.x(a)+w},x2:function(a){return $.x(a)+w},y1:0,y2:$.height},(k=function(a){e=$.generateGridData(bb[gc],$.x),w=$.isCategorized()?$.xAxis.tickOffset():0,c=_.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+ab.select(this).attr(bb[vb]?"y1":"x1")===(bb[vb]?$.height:0)?0:1}),c.exit().remove()})()),f=_.select("."+pe[Ud]).selectAll("."+pe[Td]).data(bb[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"":"rotate(-90)").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&bb[ic]&&(h=_.select("."+pe[Xd]).selectAll("."+pe[Wd]).data($.y.ticks(bb[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",bb[vb]?$.y:0).attr("x2",bb[vb]?$.y:$.width).attr("y1",bb[vb]?0:$.y).attr("y2",bb[vb]?$.height:$.y),h.exit().remove(),$.smoothLines(h,"grid")),B&&(i=_.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(bb[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"rotate(-90)":"").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),W=De($.yv,$),i.select("line").transition().duration(P).attr("x1",bb[vb]?W:0).attr("x2",bb[vb]?W:$.width).attr("y1",bb[vb]?0:W).attr("y2",bb[vb]?$.height:W).style("opacity",1),i.select("text").transition().duration(P).attr("x",bb[vb]?0:$.width).attr("y",W).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()),q=_.select("."+pe[xd]).selectAll("."+pe[wd]).data(bb[Qc]),q.enter().append("g").attr("class",De($.classRegion,$)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=_.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De($.barData,$)),p.enter().append("path").attr("class",De($.classBar,$)).style("stroke",function(a){return $.color(a.id)}).style("fill",function(a){return $.color(a.id)}),p.style("opacity",De($.initialOpacity,$)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=_.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De($.lineData,$)),l.enter().append("path").attr("class",De($.classLine,$)).style("stroke",$.color),l.style("opacity",De($.initialOpacity,$)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=_.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De($.lineData,$)),m.enter().append("path").attr("class",De($.classArea,$)).style("fill",$.color).style("opacity",function(){return $.orgAreaOpacity=+ab.select(this).style("opacity"),0}),m.style("opacity",$.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),bb[mc]&&(n=_.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De($.lineOrScatterData,$)),n.enter().append("circle").attr("class",De($.classCircle,$)).attr("r",De($.pointR,$)).style("fill",$.color),n.style("opacity",De($.initialOpacity,$)),n.exit().remove()),$.hasDataLabel()&&(r=_.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De($.barOrLineData,$)),r.enter().append("text").attr("class",De($.classText,$)).attr("text-anchor",function(a){return bb[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return $.color(a)}).style("fill-opacity",0),r.text(function(a){return $.formatByAxisId($.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re($.redrawArc)&&$.redrawArc(P,Q,G),re($.redrawSubchart)&&$.redrawSubchart(C,b,P,Q,cb,db,eb),_.selectAll("."+pe[od]).filter(De($.isBarType,$)).selectAll("circle").remove(),bb[s]&&(t=_.select("."+pe[qd]).style("cursor",bb[o]?bb[vb]?"ns-resize":"ew-resize":null),ze(bb[z])&&!$.isSingleX(bb[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),$.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",$.width).attr("height",$.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!$.isCustomX()&&!$.isTimeSeries()||$.isCategorized()?(A=$.getEventRectWidth(),y=function(a){return $.x(a.x)-A/2}):(A=function(a){var b=$.getPrevX(a.index),c=$.getNextX(a.index),d=$.data.xs[a.id][a.index],e=($.x(c?c:d)-$.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=$.getPrevX(a.index),c=$.data.xs[a.id][a.index];return($.x(c)+$.x(b?b:c))/2}),v=$.getMaxDataCountTarget($.data.targets),_.select("."+pe[qd]).datum(v?v.values:[]),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),$.generateEventRectsForSingleX(u.enter()),u.attr("class",De($.classEvent,$)).attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),u.exit().remove())),X=De($.xv,$),Y=De($.config[vb]?$.circleY:$.circleX,$),Z=De($.config[vb]?$.circleX:$.circleY,$),ab.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",$.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",$.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",$.color).style("opacity",$.orgAreaOpacity)),b.push(n.transition().style("opacity",De($.opacityForCircle,$)).style("fill",$.color).attr("cx",Y).attr("cy",Z)),b.push(_.selectAll("."+pe[nd]).transition().attr("cx",Y).attr("cy",Z)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",$.color).style("fill-opacity",a.flow?0:De($.opacityForText,$))),b.push(q.selectAll("rect").transition().attr("x",De($.regionX,$)).attr("y",De($.regionY,$)).attr("width",De($.regionWidth,$)).attr("height",De($.regionHeight,$)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X).attr("y1",bb[vb]?X:$.margin.top).attr("y2",bb[vb]?X:$.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",bb[vb]?$.width:0).attr("y",X).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=$.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=$.getValueOnIndex($.data.targets[0].values,i),s=$.getValueOnIndex($.data.targets[0].values,i+j),t=$.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=$.generateWait();$.data.targets.forEach(function(a){a.values.splice(0,j)}),g=$.updateXDomain(hb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?$.x(t[0])-$.x(g[0]):$.isTimeSeries()?$.x(t[0])-$.x(g[0]):$.x(o.x)-$.x(s.x):1!==$.data.targets[0].values.length?b=$.x(t[0])-$.x(g[0]):$.isTimeSeries()?(o=$.getValueOnIndex($.data.targets[0].values,0),s=$.getValueOnIndex($.data.targets[0].values,$.data.targets[0].values.length-1),b=$.x(o.x)-$.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",ab.transition().ease("linear").duration(v).each(function(){x.add($.axes.x.transition().call($.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter($.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));$.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),$.svg.selectAll("."+pe[Od]).selectAll(e).remove(),$.svg.selectAll("."+pe[qd]).selectAll(g).remove(),$.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X),f.select("text").attr("x",bb[vb]?$.width:0).attr("y",X),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Y).attr("cy",Z),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De($.opacityForText,$)),q.attr("transform",null),q.select("rect").filter($.isRegionOnX).attr("x",De($.regionX,$)).attr("width",De($.regionWidth,$)),u.attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),w()})}),$.mapToIds($.data.targets).forEach(function(a){$.withoutFadeIn[a]=!0}),re($.updateZoom)&&$.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none") -},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/axis.js b/src/axis.js index 63b3cd2..15e5c7f 100644 --- a/src/axis.js +++ b/src/axis.js @@ -1,3 +1,35 @@ +c3_chart_internal_fn.initAxis = function () { + var $$ = this, config = $$.config, main = $$.main, CLASS = $$.CLASS; + $$.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", generateCall($$.textAnchorForXAxisLabel, $$)); + + $$.axes.y = main.append("g") + .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) + .attr("clip-path", $$.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", generateCall($$.textAnchorForYAxisLabel, $$)); + + $$.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", generateCall($$.textAnchorForY2AxisLabel, $$)); +}; c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, axis = c3_axis($$.d3, $$.isCategorized()).scale(scale).orient(orient); @@ -281,3 +313,23 @@ c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } return tickValues; }; +c3_chart_internal_fn.generateAxisTransitions = function (duration) { + var $$ = this, 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 + }; +}; +c3_chart_internal_fn.redrawAxis = function (transitions, isHidden) { + var $$ = this; + $$.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); +}; diff --git a/src/core.js b/src/core.js index e54e8dd..8ddfe54 100644 --- a/src/core.js +++ b/src/core.js @@ -276,35 +276,7 @@ c3_chart_internal_fn.initWithData = function (data) { } // Add Axis - $$.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", generateCall($$.textAnchorForXAxisLabel, $$)); - - $$.axes.y = main.append("g") - .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) - .attr("clip-path", $$.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", generateCall($$.textAnchorForYAxisLabel, $$)); - - $$.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", generateCall($$.textAnchorForY2AxisLabel, $$)); + $$.initAxis(); // Set targets $$.updateTargets($$.data.targets); @@ -559,14 +531,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.y2.domain($$.getYDomain(targetsToShow, 'y2')); // axes - $$.axes.x.style("opacity", hideAxis ? 0 : 1); - $$.axes.y.style("opacity", hideAxis ? 0 : 1); - $$.axes.y2.style("opacity", hideAxis ? 0 : 1); - $$.axes.subx.style("opacity", hideAxis ? 0 : 1); - transitions.axisX.call($$.xAxis); - transitions.axisY.call($$.yAxis); - transitions.axisY2.call($$.y2Axis); - transitions.axisSubX.call($$.subXAxis); + $$.redrawAxis(transitions, hideAxis); // Update axis label $$.updateAxisLabels(withTransition); @@ -1493,15 +1458,6 @@ c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) $$.updateAndRedraw(options); }; -c3_chart_internal_fn.generateAxisTransitions = function (duration) { - var $$ = this, 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 - }; -}; c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition From 991edd3b9d8cf1bb0ab21060c6a688d0967c7173 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 16:32:16 +0900 Subject: [PATCH 31/44] Modularize grid --- c3.js | 291 ++++++++++++++++++++++++++++------------------------ c3.min.js | 8 +- src/core.js | 146 +++----------------------- src/grid.js | 145 ++++++++++++++++++++++++++ 4 files changed, 322 insertions(+), 268 deletions(-) diff --git a/c3.js b/c3.js index 0c76619..0b59826 100644 --- a/c3.js +++ b/c3.js @@ -219,23 +219,7 @@ .attr("class", CLASS[_regions]); // Grids - $$.grid = main.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS[_grid]); - if (config[__grid_x_show]) { - $$.grid.append("g").attr("class", CLASS[_xgrids]); - } - if (config[__grid_y_show]) { - $$.grid.append('g').attr('class', CLASS[_ygrids]); - } - $$.grid.append('g').attr("class", CLASS[_xgridLines]); - $$.grid.append('g').attr('class', CLASS[_ygridLines]); - if (config[__grid_focus_show]) { - $$.grid.append('g') - .attr("class", CLASS[_xgridFocus]) - .append('line') - .attr('class', CLASS[_xgridFocus]); - } + $$.initGrid(); // Define g for chart area main.append('g') @@ -479,18 +463,19 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var yv, xv, cx, cy; + var xv = generateCall($$.xv, $$), + cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), + cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); + mainCircle = mainText = d3.selectAll([]); options = options || {}; withY = getOption(options, "withY", true); @@ -592,100 +577,7 @@ .style('opacity', targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); - if (config[__grid_x_show]) { - xgridAttr = config[__axis_rotated] ? { - 'x1': 0, - 'x2': $$.width, - 'y1': function (d) { return $$.x(d) - tickOffset; }, - 'y2': function (d) { return $$.x(d) - tickOffset; } - } : { - 'x1': function (d) { return $$.x(d) + tickOffset; }, - 'x2': function (d) { return $$.x(d) + tickOffset; }, - 'y1': 0, - 'y2': $$.height - }; - // this is used to flow - flushXGrid = function (withoutUpdate) { - xgridData = $$.generateGridData(config[__grid_x_type], $$.x); - tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) - .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS[_xgrid]); - if (!withoutUpdate) { - xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); - } - xgrid.exit().remove(); - }; - flushXGrid(); - } - xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) - .data(config[__grid_x_lines]); - // enter - xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); - xgridLine.append('line') - .style("opacity", 0); - xgridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) - .attr('dy', -5) - .style("opacity", 0); - // udpate - // done in d3.transition() of the end of this function - // exit - xgridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - // Y-Grid - if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) - .data($$.y.ticks(config[__grid_y_ticks])); - ygrid.enter().append('line') - .attr('class', CLASS[_ygrid]); - ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) - .attr("x2", config[__axis_rotated] ? $$.y : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : $$.y) - .attr("y2", config[__axis_rotated] ? $$.height : $$.y); - ygrid.exit().remove(); - $$.smoothLines(ygrid, 'grid'); - } - if (withY) { - ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) - .data(config[__grid_y_lines]); - // enter - ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); - ygridLine.append('line') - .style("opacity", 0); - ygridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") - .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) - .attr('dy', -5) - .style("opacity", 0); - // update - yv = generateCall($$.yv, $$); - ygridLines.select('line') - .transition().duration(duration) - .attr("x1", config[__axis_rotated] ? yv : 0) - .attr("x2", config[__axis_rotated] ? yv : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : yv) - .attr("y2", config[__axis_rotated] ? $$.height : yv) - .style("opacity", 1); - ygridLines.select('text') - .transition().duration(duration) - .attr("x", config[__axis_rotated] ? 0 : $$.width) - .attr("y", yv) - .text(function (d) { return d.text; }) - .style("opacity", 1); - // exit - ygridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - } + $$.redrawGrid(duration, withY); // rect for regions mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) @@ -847,10 +739,6 @@ } } - xv = generateCall($$.xv, $$); - cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$); - cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - // transition should be derived from one transition d3.transition().duration(duration).each(function () { var transitions = []; @@ -886,17 +774,8 @@ .attr("width", generateCall($$.regionWidth, $$)) .attr("height", generateCall($$.regionHeight, $$)) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); - transitions.push(xgridLines.select('line').transition() - .attr("x1", config[__axis_rotated] ? 0 : xv) - .attr("x2", config[__axis_rotated] ? $$.width : xv) - .attr("y1", config[__axis_rotated] ? xv : $$.margin.top) - .attr("y2", config[__axis_rotated] ? xv : $$.height) - .style("opacity", 1)); - transitions.push(xgridLines.select('text').transition() - .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv) - .text(function (d) { return d.text; }) - .style("opacity", 1)); + $$.addTransitionForGrid(transitions); + // Wait for end of transitions if called from flow API if (options.flow) { waitForDraw = $$.generateWait(); @@ -916,6 +795,9 @@ done = options.flow.done || function () {}, wait = $$.generateWait(); + var xgrid = $$.xgrid || d3.selectAll([]), + xgridLines = $$.xgridLines || d3.selectAll([]); + // remove head data after rendered $$.data.targets.forEach(function (d) { d.values.splice(0, flowLength); @@ -924,7 +806,7 @@ // update x domain to generate axis elements for flow domain = $$.updateXDomain(targetsToShow, true, true); // update elements related to x scale - if (flushXGrid) { flushXGrid(true); } + if ($$.updateXGrid) { $$.updateXGrid(true); } // generate transform to flow if (!options.flow.orgDataCount) { // if empty @@ -981,7 +863,7 @@ // draw again for removing flowed elements and reverting attr xgrid .attr('transform', null) - .attr(xgridAttr); + .attr($$.xgridAttr); xgridLines .attr('transform', null); xgridLines.select('line') @@ -3346,6 +3228,151 @@ return this.isBarType(d) || this.isLineType(d) ? d.values : []; }; + c3_chart_internal_fn.initGrid = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS, d3 = $$.d3; + $$.grid = $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS[_grid]); + if (config[__grid_x_show]) { + $$.grid.append("g").attr("class", CLASS[_xgrids]); + } + if (config[__grid_y_show]) { + $$.grid.append('g').attr('class', CLASS[_ygrids]); + } + $$.grid.append('g').attr("class", CLASS[_xgridLines]); + $$.grid.append('g').attr('class', CLASS[_ygridLines]); + if (config[__grid_focus_show]) { + $$.grid.append('g') + .attr("class", CLASS[_xgridFocus]) + .append('line') + .attr('class', CLASS[_xgridFocus]); + } + $$.xgrid = d3.selectAll([]); + $$.xgridLines = d3.selectAll([]); + }; + + c3_chart_internal_fn.updateXGrid = function (withoutUpdate) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, d3 = $$.d3, + xgridData = $$.generateGridData(config[__grid_x_type], $$.x), + tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; + + $$.xgridAttr = config[__axis_rotated] ? { + 'x1': 0, + 'x2': $$.width, + 'y1': function (d) { return $$.x(d) - tickOffset; }, + 'y2': function (d) { return $$.x(d) - tickOffset; } + } : { + 'x1': function (d) { return $$.x(d) + tickOffset; }, + 'x2': function (d) { return $$.x(d) + tickOffset; }, + 'y1': 0, + 'y2': $$.height + }; + + $$.xgrid = $$.main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) + .data(xgridData); + $$.xgrid.enter().append('line').attr("class", CLASS[_xgrid]); + if (!withoutUpdate) { + $$.xgrid.attr($$.xgridAttr) + .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); + } + $$.xgrid.exit().remove(); + }; + + c3_chart_internal_fn.updateYGrid = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.ygrid = $$.main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) + .data($$.y.ticks(config[__grid_y_ticks])); + $$.ygrid.enter().append('line') + .attr('class', CLASS[_ygrid]); + $$.ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) + .attr("x2", config[__axis_rotated] ? $$.y : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : $$.y) + .attr("y2", config[__axis_rotated] ? $$.height : $$.y); + $$.ygrid.exit().remove(); + $$.smoothLines($$.ygrid, 'grid'); + }; + + + c3_chart_internal_fn.redrawGrid = function (duration, withY) { + var $$ = this, main = $$.main, config = $$.config, CLASS = $$.CLASS, + xgridLine, ygridLine, yv; + main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); + if (config[__grid_x_show]) { + $$.updateXGrid(); + } + $$.xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) + .data(config[__grid_x_lines]); + // enter + xgridLine = $$.xgridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); + xgridLine.append('line') + .style("opacity", 0); + xgridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // udpate + // done in d3.transition() of the end of this function + // exit + $$.xgridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + + // Y-Grid + if (withY && config[__grid_y_show]) { + $$.updateYGrid(); + } + if (withY) { + $$.ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) + .data(config[__grid_y_lines]); + // enter + ygridLine = $$.ygridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); + ygridLine.append('line') + .style("opacity", 0); + ygridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // update + yv = generateCall($$.yv, $$); + $$.ygridLines.select('line') + .transition().duration(duration) + .attr("x1", config[__axis_rotated] ? yv : 0) + .attr("x2", config[__axis_rotated] ? yv : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv) + .attr("y2", config[__axis_rotated] ? $$.height : yv) + .style("opacity", 1); + $$.ygridLines.select('text') + .transition().duration(duration) + .attr("x", config[__axis_rotated] ? 0 : $$.width) + .attr("y", yv) + .text(function (d) { return d.text; }) + .style("opacity", 1); + // exit + $$.ygridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + } + }; + c3_chart_internal_fn.addTransitionForGrid = function (transitions) { + var $$ = this, config = $$.config, xv = generateCall($$.xv, $$); + transitions.push($$.xgridLines.select('line').transition() + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv) + .attr("y1", config[__axis_rotated] ? xv : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv : $$.height) + .style("opacity", 1)); + transitions.push($$.xgridLines.select('text').transition() + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv) + .text(function (d) { return d.text; }) + .style("opacity", 1)); + }; c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, config = $$.config, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); diff --git a/c3.min.js b/c3.min.js index 6bd2814..c5df9ab 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&ab.select(this).style("display",b%V?"none":"block")})}else $.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!bb[vb]&&bb[Hb]&&$.rotateTickText($.axes.x,b.axisX,bb[Hb]),K=$.generateDrawArea(cb,!1),L=$.generateDrawBar(db),M=$.generateDrawLine(eb,!1),N=$.generateXYForText(db,!0),O=$.generateXYForText(db,!1),$.subY.domain($.y.domain()),$.subY2.domain($.y2.domain()),$.tooltip.style("display","none"),$.updateXgridFocus(),_.select("text."+pe[Nd]+"."+pe[Md]).attr("x",$.width/2).attr("y",$.height/2).text(bb[fb]).transition().style("opacity",hb.length?0:1),_.select("line."+pe[Vd]).style("visibility","hidden"),bb[fc]&&(d=bb[vb]?{x1:0,x2:$.width,y1:function(a){return $.x(a)-w},y2:function(a){return $.x(a)-w}}:{x1:function(a){return $.x(a)+w},x2:function(a){return $.x(a)+w},y1:0,y2:$.height},(k=function(a){e=$.generateGridData(bb[gc],$.x),w=$.isCategorized()?$.xAxis.tickOffset():0,c=_.select("."+pe[Sd]).selectAll("."+pe[Rd]).data(e),c.enter().append("line").attr("class",pe[Rd]),a||c.attr(d).style("opacity",function(){return+ab.select(this).attr(bb[vb]?"y1":"x1")===(bb[vb]?$.height:0)?0:1}),c.exit().remove()})()),f=_.select("."+pe[Ud]).selectAll("."+pe[Td]).data(bb[hc]),g=f.enter().append("g").attr("class",function(a){return pe[Td]+(a.class?" "+a.class:"")}),g.append("line").style("opacity",0),g.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"":"rotate(-90)").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),f.exit().transition().duration(P).style("opacity",0).remove(),B&&bb[ic]&&(h=_.select("."+pe[Xd]).selectAll("."+pe[Wd]).data($.y.ticks(bb[kc])),h.enter().append("line").attr("class",pe[Wd]),h.attr("x1",bb[vb]?$.y:0).attr("x2",bb[vb]?$.y:$.width).attr("y1",bb[vb]?0:$.y).attr("y2",bb[vb]?$.height:$.y),h.exit().remove(),$.smoothLines(h,"grid")),B&&(i=_.select("."+pe[Zd]).selectAll("."+pe[Yd]).data(bb[jc]),j=i.enter().append("g").attr("class",function(a){return pe[Yd]+(a.class?" "+a.class:"")}),j.append("line").style("opacity",0),j.append("text").attr("text-anchor","end").attr("transform",bb[vb]?"rotate(-90)":"").attr("dx",bb[vb]?0:-$.margin.top).attr("dy",-5).style("opacity",0),W=De($.yv,$),i.select("line").transition().duration(P).attr("x1",bb[vb]?W:0).attr("x2",bb[vb]?W:$.width).attr("y1",bb[vb]?0:W).attr("y2",bb[vb]?$.height:W).style("opacity",1),i.select("text").transition().duration(P).attr("x",bb[vb]?0:$.width).attr("y",W).text(function(a){return a.text}).style("opacity",1),i.exit().transition().duration(P).style("opacity",0).remove()),q=_.select("."+pe[xd]).selectAll("."+pe[wd]).data(bb[Qc]),q.enter().append("g").attr("class",De($.classRegion,$)).append("rect").style("fill-opacity",0),q.exit().transition().duration(P).style("opacity",0).remove(),p=_.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De($.barData,$)),p.enter().append("path").attr("class",De($.classBar,$)).style("stroke",function(a){return $.color(a.id)}).style("fill",function(a){return $.color(a.id)}),p.style("opacity",De($.initialOpacity,$)),p.exit().transition().duration(Q).style("opacity",0).remove(),l=_.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De($.lineData,$)),l.enter().append("path").attr("class",De($.classLine,$)).style("stroke",$.color),l.style("opacity",De($.initialOpacity,$)).attr("transform",null),l.exit().transition().duration(Q).style("opacity",0).remove(),m=_.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De($.lineData,$)),m.enter().append("path").attr("class",De($.classArea,$)).style("fill",$.color).style("opacity",function(){return $.orgAreaOpacity=+ab.select(this).style("opacity"),0}),m.style("opacity",$.orgAreaOpacity),m.exit().transition().duration(Q).style("opacity",0).remove(),bb[mc]&&(n=_.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De($.lineOrScatterData,$)),n.enter().append("circle").attr("class",De($.classCircle,$)).attr("r",De($.pointR,$)).style("fill",$.color),n.style("opacity",De($.initialOpacity,$)),n.exit().remove()),$.hasDataLabel()&&(r=_.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De($.barOrLineData,$)),r.enter().append("text").attr("class",De($.classText,$)).attr("text-anchor",function(a){return bb[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return $.color(a)}).style("fill-opacity",0),r.text(function(a){return $.formatByAxisId($.getAxisId(a.id))(a.value,a.id)}),r.exit().transition().duration(Q).style("fill-opacity",0).remove()),re($.redrawArc)&&$.redrawArc(P,Q,G),re($.redrawSubchart)&&$.redrawSubchart(C,b,P,Q,cb,db,eb),_.selectAll("."+pe[od]).filter(De($.isBarType,$)).selectAll("circle").remove(),bb[s]&&(t=_.select("."+pe[qd]).style("cursor",bb[o]?bb[vb]?"ns-resize":"ew-resize":null),ze(bb[z])&&!$.isSingleX(bb[z])?(t.classed(pe[sd])||t.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),$.generateEventRectsForMultipleXs(u.enter()),u.attr("x",0).attr("y",0).attr("width",$.width).attr("height",$.height)):(t.classed(pe[rd])||t.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!$.isCustomX()&&!$.isTimeSeries()||$.isCategorized()?(A=$.getEventRectWidth(),y=function(a){return $.x(a.x)-A/2}):(A=function(a){var b=$.getPrevX(a.index),c=$.getNextX(a.index),d=$.data.xs[a.id][a.index],e=($.x(c?c:d)-$.x(b?b:d))/2;return 0>e?0:e},y=function(a){var b=$.getPrevX(a.index),c=$.data.xs[a.id][a.index];return($.x(c)+$.x(b?b:c))/2}),v=$.getMaxDataCountTarget($.data.targets),_.select("."+pe[qd]).datum(v?v.values:[]),u=_.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),$.generateEventRectsForSingleX(u.enter()),u.attr("class",De($.classEvent,$)).attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),u.exit().remove())),X=De($.xv,$),Y=De($.config[vb]?$.circleY:$.circleX,$),Z=De($.config[vb]?$.circleX:$.circleY,$),ab.transition().duration(P).each(function(){var b=[];b.push(p.transition().attr("d",L).style("fill",$.color).style("opacity",1)),b.push(l.transition().attr("d",M).style("stroke",$.color).style("opacity",1)),b.push(m.transition().attr("d",K).style("fill",$.color).style("opacity",$.orgAreaOpacity)),b.push(n.transition().style("opacity",De($.opacityForCircle,$)).style("fill",$.color).attr("cx",Y).attr("cy",Z)),b.push(_.selectAll("."+pe[nd]).transition().attr("cx",Y).attr("cy",Z)),b.push(r.transition().attr("x",N).attr("y",O).style("fill",$.color).style("fill-opacity",a.flow?0:De($.opacityForText,$))),b.push(q.selectAll("rect").transition().attr("x",De($.regionX,$)).attr("y",De($.regionY,$)).attr("width",De($.regionWidth,$)).attr("height",De($.regionHeight,$)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),b.push(f.select("line").transition().attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X).attr("y1",bb[vb]?X:$.margin.top).attr("y2",bb[vb]?X:$.height).style("opacity",1)),b.push(f.select("text").transition().attr("x",bb[vb]?$.width:0).attr("y",X).text(function(a){return a.text}).style("opacity",1)),a.flow&&(S=$.generateWait(),b.forEach(function(a){S.add(a)}))}).call(S?S:function(){},function(){var b,e,g,h=1,i=a.flow.index,j=a.flow.length,o=$.getValueOnIndex($.data.targets[0].values,i),s=$.getValueOnIndex($.data.targets[0].values,i+j),t=$.x.domain(),v=a.flow.duration||P,w=a.flow.done||function(){},x=$.generateWait();$.data.targets.forEach(function(a){a.values.splice(0,j)}),g=$.updateXDomain(hb,!0,!0),k&&k(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===s.x?$.x(t[0])-$.x(g[0]):$.isTimeSeries()?$.x(t[0])-$.x(g[0]):$.x(o.x)-$.x(s.x):1!==$.data.targets[0].values.length?b=$.x(t[0])-$.x(g[0]):$.isTimeSeries()?(o=$.getValueOnIndex($.data.targets[0].values,0),s=$.getValueOnIndex($.data.targets[0].values,$.data.targets[0].values.length-1),b=$.x(o.x)-$.x(s.x)):b=xe(g)/2,h=xe(t)/xe(g),e="translate("+b+",0) scale("+h+",1)",ab.transition().ease("linear").duration(v).each(function(){x.add($.axes.x.transition().call($.xAxis)),x.add(p.transition().attr("transform",e)),x.add(l.transition().attr("transform",e)),x.add(m.transition().attr("transform",e)),x.add(n.transition().attr("transform",e)),x.add(r.transition().attr("transform",e)),x.add(q.filter($.isRegionOnX).transition().attr("transform",e)),x.add(c.transition().attr("transform",e)),x.add(f.transition().attr("transform",e))}).call(x,function(){var a,b=[],e=[],g=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),e.push("."+pe[Nd]+"-"+(i+a)),g.push("."+pe[pd]+"-"+(i+a));$.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),$.svg.selectAll("."+pe[Od]).selectAll(e).remove(),$.svg.selectAll("."+pe[qd]).selectAll(g).remove(),$.svg.select("."+pe[Rd]).remove()}c.attr("transform",null).attr(d),f.attr("transform",null),f.select("line").attr("x1",bb[vb]?0:X).attr("x2",bb[vb]?$.width:X),f.select("text").attr("x",bb[vb]?$.width:0).attr("y",X),p.attr("transform",null).attr("d",L),l.attr("transform",null).attr("d",M),m.attr("transform",null).attr("d",K),n.attr("transform",null).attr("cx",Y).attr("cy",Z),r.attr("transform",null).attr("x",N).attr("y",O).style("fill-opacity",De($.opacityForText,$)),q.attr("transform",null),q.select("rect").filter($.isRegionOnX).attr("x",De($.regionX,$)).attr("width",De($.regionWidth,$)),u.attr("x",bb[vb]?0:y).attr("y",bb[vb]?y:0).attr("width",bb[vb]?$.width:A).attr("height",bb[vb]?A:$.height),w()})}),$.mapToIds($.data.targets).forEach(function(a){$.withoutFadeIn[a]=!0}),re($.updateZoom)&&$.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position"; -f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none") -},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&O.select(this).style("display",b%L?"none":"block")})}else M.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!P[vb]&&P[Hb]&&M.rotateTickText(M.axes.x,b.axisX,P[Hb]),A=M.generateDrawArea(Q,!1),B=M.generateDrawBar(R),C=M.generateDrawLine(S,!1),D=M.generateXYForText(R,!0),E=M.generateXYForText(R,!1),M.subY.domain(M.y.domain()),M.subY2.domain(M.y2.domain()),M.tooltip.style("display","none"),M.updateXgridFocus(),N.select("text."+pe[Nd]+"."+pe[Md]).attr("x",M.width/2).attr("y",M.height/2).text(P[fb]).transition().style("opacity",U.length?0:1),M.redrawGrid(F,n),g=N.select("."+pe[xd]).selectAll("."+pe[wd]).data(P[Qc]),g.enter().append("g").attr("class",De(M.classRegion,M)).append("rect").style("fill-opacity",0),g.exit().transition().duration(F).style("opacity",0).remove(),f=N.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(M.barData,M)),f.enter().append("path").attr("class",De(M.classBar,M)).style("stroke",function(a){return M.color(a.id)}).style("fill",function(a){return M.color(a.id)}),f.style("opacity",De(M.initialOpacity,M)),f.exit().transition().duration(G).style("opacity",0).remove(),c=N.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(M.lineData,M)),c.enter().append("path").attr("class",De(M.classLine,M)).style("stroke",M.color),c.style("opacity",De(M.initialOpacity,M)).attr("transform",null),c.exit().transition().duration(G).style("opacity",0).remove(),d=N.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(M.lineData,M)),d.enter().append("path").attr("class",De(M.classArea,M)).style("fill",M.color).style("opacity",function(){return M.orgAreaOpacity=+O.select(this).style("opacity"),0}),d.style("opacity",M.orgAreaOpacity),d.exit().transition().duration(G).style("opacity",0).remove(),P[mc]&&(e=N.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(M.lineOrScatterData,M)),e.enter().append("circle").attr("class",De(M.classCircle,M)).attr("r",De(M.pointR,M)).style("fill",M.color),e.style("opacity",De(M.initialOpacity,M)),e.exit().remove()),M.hasDataLabel()&&(h=N.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(M.barOrLineData,M)),h.enter().append("text").attr("class",De(M.classText,M)).attr("text-anchor",function(a){return P[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return M.color(a)}).style("fill-opacity",0),h.text(function(a){return M.formatByAxisId(M.getAxisId(a.id))(a.value,a.id)}),h.exit().transition().duration(G).style("fill-opacity",0).remove()),re(M.redrawArc)&&M.redrawArc(F,G,u),re(M.redrawSubchart)&&M.redrawSubchart(p,b,F,G,Q,R,S),N.selectAll("."+pe[od]).filter(De(M.isBarType,M)).selectAll("circle").remove(),P[s]&&(i=N.select("."+pe[qd]).style("cursor",P[o]?P[vb]?"ns-resize":"ew-resize":null),ze(P[z])&&!M.isSingleX(P[z])?(i.classed(pe[sd])||i.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),M.generateEventRectsForMultipleXs(j.enter()),j.attr("x",0).attr("y",0).attr("width",M.width).attr("height",M.height)):(i.classed(pe[rd])||i.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!M.isCustomX()&&!M.isTimeSeries()||M.isCategorized()?(m=M.getEventRectWidth(),l=function(a){return M.x(a.x)-m/2}):(m=function(a){var b=M.getPrevX(a.index),c=M.getNextX(a.index),d=M.data.xs[a.id][a.index],e=(M.x(c?c:d)-M.x(b?b:d))/2;return 0>e?0:e},l=function(a){var b=M.getPrevX(a.index),c=M.data.xs[a.id][a.index];return(M.x(c)+M.x(b?b:c))/2}),k=M.getMaxDataCountTarget(M.data.targets),N.select("."+pe[qd]).datum(k?k.values:[]),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),M.generateEventRectsForSingleX(j.enter()),j.attr("class",De(M.classEvent,M)).attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),j.exit().remove())),O.transition().duration(F).each(function(){var b=[];b.push(f.transition().attr("d",B).style("fill",M.color).style("opacity",1)),b.push(c.transition().attr("d",C).style("stroke",M.color).style("opacity",1)),b.push(d.transition().attr("d",A).style("fill",M.color).style("opacity",M.orgAreaOpacity)),b.push(e.transition().style("opacity",De(M.opacityForCircle,M)).style("fill",M.color).attr("cx",W).attr("cy",X)),b.push(N.selectAll("."+pe[nd]).transition().attr("cx",W).attr("cy",X)),b.push(h.transition().attr("x",D).attr("y",E).style("fill",M.color).style("fill-opacity",a.flow?0:De(M.opacityForText,M))),b.push(g.selectAll("rect").transition().attr("x",De(M.regionX,M)).attr("y",De(M.regionY,M)).attr("width",De(M.regionWidth,M)).attr("height",De(M.regionHeight,M)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),M.addTransitionForGrid(b),a.flow&&(I=M.generateWait(),b.forEach(function(a){I.add(a)}))}).call(I?I:function(){},function(){var b,i,k,n=1,o=a.flow.index,p=a.flow.length,q=M.getValueOnIndex(M.data.targets[0].values,o),r=M.getValueOnIndex(M.data.targets[0].values,o+p),s=M.x.domain(),t=a.flow.duration||F,u=a.flow.done||function(){},v=M.generateWait(),w=M.xgrid||O.selectAll([]),x=M.xgridLines||O.selectAll([]);M.data.targets.forEach(function(a){a.values.splice(0,p)}),k=M.updateXDomain(U,!0,!0),M.updateXGrid&&M.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||q.x===r.x?M.x(s[0])-M.x(k[0]):M.isTimeSeries()?M.x(s[0])-M.x(k[0]):M.x(q.x)-M.x(r.x):1!==M.data.targets[0].values.length?b=M.x(s[0])-M.x(k[0]):M.isTimeSeries()?(q=M.getValueOnIndex(M.data.targets[0].values,0),r=M.getValueOnIndex(M.data.targets[0].values,M.data.targets[0].values.length-1),b=M.x(q.x)-M.x(r.x)):b=xe(k)/2,n=xe(s)/xe(k),i="translate("+b+",0) scale("+n+",1)",O.transition().ease("linear").duration(t).each(function(){v.add(M.axes.x.transition().call(M.xAxis)),v.add(f.transition().attr("transform",i)),v.add(c.transition().attr("transform",i)),v.add(d.transition().attr("transform",i)),v.add(e.transition().attr("transform",i)),v.add(h.transition().attr("transform",i)),v.add(g.filter(M.isRegionOnX).transition().attr("transform",i)),v.add(w.transition().attr("transform",i)),v.add(x.transition().attr("transform",i))}).call(v,function(){var a,b=[],i=[],k=[];if(p){for(a=0;p>a;a++)b.push("."+pe[Ad]+"-"+(o+a)),i.push("."+pe[Nd]+"-"+(o+a)),k.push("."+pe[pd]+"-"+(o+a));M.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),M.svg.selectAll("."+pe[Od]).selectAll(i).remove(),M.svg.selectAll("."+pe[qd]).selectAll(k).remove(),M.svg.select("."+pe[Rd]).remove()}w.attr("transform",null).attr(M.xgridAttr),x.attr("transform",null),x.select("line").attr("x1",P[vb]?0:V).attr("x2",P[vb]?M.width:V),x.select("text").attr("x",P[vb]?M.width:0).attr("y",V),f.attr("transform",null).attr("d",B),c.attr("transform",null).attr("d",C),d.attr("transform",null).attr("d",A),e.attr("transform",null).attr("cx",W).attr("cy",X),h.attr("transform",null).attr("x",D).attr("y",E).style("fill-opacity",De(M.opacityForText,M)),g.attr("transform",null),g.select("rect").filter(M.isRegionOnX).attr("x",De(M.regionX,M)).attr("width",De(M.regionWidth,M)),j.attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),u()})}),M.mapToIds(M.data.targets).forEach(function(a){M.withoutFadeIn[a]=!0}),re(M.updateZoom)&&M.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" +},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a; +return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 8ddfe54..b2636c2 100644 --- a/src/core.js +++ b/src/core.js @@ -214,23 +214,7 @@ c3_chart_internal_fn.initWithData = function (data) { .attr("class", CLASS[_regions]); // Grids - $$.grid = main.append('g') - .attr("clip-path", $$.clipPath) - .attr('class', CLASS[_grid]); - if (config[__grid_x_show]) { - $$.grid.append("g").attr("class", CLASS[_xgrids]); - } - if (config[__grid_y_show]) { - $$.grid.append('g').attr('class', CLASS[_ygrids]); - } - $$.grid.append('g').attr("class", CLASS[_xgridLines]); - $$.grid.append('g').attr('class', CLASS[_ygridLines]); - if (config[__grid_focus_show]) { - $$.grid.append('g') - .attr("class", CLASS[_xgridFocus]) - .append('line') - .attr('class', CLASS[_xgridFocus]); - } + $$.initGrid(); // Define g for chart area main.append('g') @@ -474,18 +458,19 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var xgrid, xgridAttr, xgridData, xgridLines, xgridLine, ygrid, ygridLines, ygridLine, flushXGrid; var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget, tickOffset; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var yv, xv, cx, cy; + var xv = generateCall($$.xv, $$), + cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), + cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - xgrid = xgridLines = mainCircle = mainText = d3.selectAll([]); + mainCircle = mainText = d3.selectAll([]); options = options || {}; withY = getOption(options, "withY", true); @@ -587,100 +572,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .style('opacity', targetsToShow.length ? 0 : 1); // grid - main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); - if (config[__grid_x_show]) { - xgridAttr = config[__axis_rotated] ? { - 'x1': 0, - 'x2': $$.width, - 'y1': function (d) { return $$.x(d) - tickOffset; }, - 'y2': function (d) { return $$.x(d) - tickOffset; } - } : { - 'x1': function (d) { return $$.x(d) + tickOffset; }, - 'x2': function (d) { return $$.x(d) + tickOffset; }, - 'y1': 0, - 'y2': $$.height - }; - // this is used to flow - flushXGrid = function (withoutUpdate) { - xgridData = $$.generateGridData(config[__grid_x_type], $$.x); - tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; - xgrid = main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) - .data(xgridData); - xgrid.enter().append('line').attr("class", CLASS[_xgrid]); - if (!withoutUpdate) { - xgrid.attr(xgridAttr) - .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); - } - xgrid.exit().remove(); - }; - flushXGrid(); - } - xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) - .data(config[__grid_x_lines]); - // enter - xgridLine = xgridLines.enter().append('g') - .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); - xgridLine.append('line') - .style("opacity", 0); - xgridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) - .attr('dy', -5) - .style("opacity", 0); - // udpate - // done in d3.transition() of the end of this function - // exit - xgridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - // Y-Grid - if (withY && config[__grid_y_show]) { - ygrid = main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) - .data($$.y.ticks(config[__grid_y_ticks])); - ygrid.enter().append('line') - .attr('class', CLASS[_ygrid]); - ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) - .attr("x2", config[__axis_rotated] ? $$.y : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : $$.y) - .attr("y2", config[__axis_rotated] ? $$.height : $$.y); - ygrid.exit().remove(); - $$.smoothLines(ygrid, 'grid'); - } - if (withY) { - ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) - .data(config[__grid_y_lines]); - // enter - ygridLine = ygridLines.enter().append('g') - .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); - ygridLine.append('line') - .style("opacity", 0); - ygridLine.append('text') - .attr("text-anchor", "end") - .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") - .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) - .attr('dy', -5) - .style("opacity", 0); - // update - yv = generateCall($$.yv, $$); - ygridLines.select('line') - .transition().duration(duration) - .attr("x1", config[__axis_rotated] ? yv : 0) - .attr("x2", config[__axis_rotated] ? yv : $$.width) - .attr("y1", config[__axis_rotated] ? 0 : yv) - .attr("y2", config[__axis_rotated] ? $$.height : yv) - .style("opacity", 1); - ygridLines.select('text') - .transition().duration(duration) - .attr("x", config[__axis_rotated] ? 0 : $$.width) - .attr("y", yv) - .text(function (d) { return d.text; }) - .style("opacity", 1); - // exit - ygridLines.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); - } + $$.redrawGrid(duration, withY); // rect for regions mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) @@ -842,10 +734,6 @@ c3_chart_internal_fn.redraw = function (options, transitions) { } } - xv = generateCall($$.xv, $$); - cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$); - cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - // transition should be derived from one transition d3.transition().duration(duration).each(function () { var transitions = []; @@ -881,17 +769,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .attr("width", generateCall($$.regionWidth, $$)) .attr("height", generateCall($$.regionHeight, $$)) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); - transitions.push(xgridLines.select('line').transition() - .attr("x1", config[__axis_rotated] ? 0 : xv) - .attr("x2", config[__axis_rotated] ? $$.width : xv) - .attr("y1", config[__axis_rotated] ? xv : $$.margin.top) - .attr("y2", config[__axis_rotated] ? xv : $$.height) - .style("opacity", 1)); - transitions.push(xgridLines.select('text').transition() - .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv) - .text(function (d) { return d.text; }) - .style("opacity", 1)); + $$.addTransitionForGrid(transitions); + // Wait for end of transitions if called from flow API if (options.flow) { waitForDraw = $$.generateWait(); @@ -911,6 +790,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) { done = options.flow.done || function () {}, wait = $$.generateWait(); + var xgrid = $$.xgrid || d3.selectAll([]), + xgridLines = $$.xgridLines || d3.selectAll([]); + // remove head data after rendered $$.data.targets.forEach(function (d) { d.values.splice(0, flowLength); @@ -919,7 +801,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { // update x domain to generate axis elements for flow domain = $$.updateXDomain(targetsToShow, true, true); // update elements related to x scale - if (flushXGrid) { flushXGrid(true); } + if ($$.updateXGrid) { $$.updateXGrid(true); } // generate transform to flow if (!options.flow.orgDataCount) { // if empty @@ -976,7 +858,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { // draw again for removing flowed elements and reverting attr xgrid .attr('transform', null) - .attr(xgridAttr); + .attr($$.xgridAttr); xgridLines .attr('transform', null); xgridLines.select('line') diff --git a/src/grid.js b/src/grid.js index 58db45c..ef5879b 100644 --- a/src/grid.js +++ b/src/grid.js @@ -1,3 +1,148 @@ +c3_chart_internal_fn.initGrid = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS, d3 = $$.d3; + $$.grid = $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr('class', CLASS[_grid]); + if (config[__grid_x_show]) { + $$.grid.append("g").attr("class", CLASS[_xgrids]); + } + if (config[__grid_y_show]) { + $$.grid.append('g').attr('class', CLASS[_ygrids]); + } + $$.grid.append('g').attr("class", CLASS[_xgridLines]); + $$.grid.append('g').attr('class', CLASS[_ygridLines]); + if (config[__grid_focus_show]) { + $$.grid.append('g') + .attr("class", CLASS[_xgridFocus]) + .append('line') + .attr('class', CLASS[_xgridFocus]); + } + $$.xgrid = d3.selectAll([]); + $$.xgridLines = d3.selectAll([]); +}; + +c3_chart_internal_fn.updateXGrid = function (withoutUpdate) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, d3 = $$.d3, + xgridData = $$.generateGridData(config[__grid_x_type], $$.x), + tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; + + $$.xgridAttr = config[__axis_rotated] ? { + 'x1': 0, + 'x2': $$.width, + 'y1': function (d) { return $$.x(d) - tickOffset; }, + 'y2': function (d) { return $$.x(d) - tickOffset; } + } : { + 'x1': function (d) { return $$.x(d) + tickOffset; }, + 'x2': function (d) { return $$.x(d) + tickOffset; }, + 'y1': 0, + 'y2': $$.height + }; + + $$.xgrid = $$.main.select('.' + CLASS[_xgrids]).selectAll('.' + CLASS[_xgrid]) + .data(xgridData); + $$.xgrid.enter().append('line').attr("class", CLASS[_xgrid]); + if (!withoutUpdate) { + $$.xgrid.attr($$.xgridAttr) + .style("opacity", function () { return +d3.select(this).attr(config[__axis_rotated] ? 'y1' : 'x1') === (config[__axis_rotated] ? $$.height : 0) ? 0 : 1; }); + } + $$.xgrid.exit().remove(); +}; + +c3_chart_internal_fn.updateYGrid = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.ygrid = $$.main.select('.' + CLASS[_ygrids]).selectAll('.' + CLASS[_ygrid]) + .data($$.y.ticks(config[__grid_y_ticks])); + $$.ygrid.enter().append('line') + .attr('class', CLASS[_ygrid]); + $$.ygrid.attr("x1", config[__axis_rotated] ? $$.y : 0) + .attr("x2", config[__axis_rotated] ? $$.y : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : $$.y) + .attr("y2", config[__axis_rotated] ? $$.height : $$.y); + $$.ygrid.exit().remove(); + $$.smoothLines($$.ygrid, 'grid'); +}; + + +c3_chart_internal_fn.redrawGrid = function (duration, withY) { + var $$ = this, main = $$.main, config = $$.config, CLASS = $$.CLASS, + xgridLine, ygridLine, yv; + main.select('line.' + CLASS[_xgridFocus]).style("visibility", "hidden"); + if (config[__grid_x_show]) { + $$.updateXGrid(); + } + $$.xgridLines = main.select('.' + CLASS[_xgridLines]).selectAll('.' + CLASS[_xgridLine]) + .data(config[__grid_x_lines]); + // enter + xgridLine = $$.xgridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_xgridLine] + (d.class ? ' ' + d.class : ''); }); + xgridLine.append('line') + .style("opacity", 0); + xgridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // udpate + // done in d3.transition() of the end of this function + // exit + $$.xgridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + + // Y-Grid + if (withY && config[__grid_y_show]) { + $$.updateYGrid(); + } + if (withY) { + $$.ygridLines = main.select('.' + CLASS[_ygridLines]).selectAll('.' + CLASS[_ygridLine]) + .data(config[__grid_y_lines]); + // enter + ygridLine = $$.ygridLines.enter().append('g') + .attr("class", function (d) { return CLASS[_ygridLine] + (d.class ? ' ' + d.class : ''); }); + ygridLine.append('line') + .style("opacity", 0); + ygridLine.append('text') + .attr("text-anchor", "end") + .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") + .attr('dx', config[__axis_rotated] ? 0 : -$$.margin.top) + .attr('dy', -5) + .style("opacity", 0); + // update + yv = generateCall($$.yv, $$); + $$.ygridLines.select('line') + .transition().duration(duration) + .attr("x1", config[__axis_rotated] ? yv : 0) + .attr("x2", config[__axis_rotated] ? yv : $$.width) + .attr("y1", config[__axis_rotated] ? 0 : yv) + .attr("y2", config[__axis_rotated] ? $$.height : yv) + .style("opacity", 1); + $$.ygridLines.select('text') + .transition().duration(duration) + .attr("x", config[__axis_rotated] ? 0 : $$.width) + .attr("y", yv) + .text(function (d) { return d.text; }) + .style("opacity", 1); + // exit + $$.ygridLines.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + } +}; +c3_chart_internal_fn.addTransitionForGrid = function (transitions) { + var $$ = this, config = $$.config, xv = generateCall($$.xv, $$); + transitions.push($$.xgridLines.select('line').transition() + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv) + .attr("y1", config[__axis_rotated] ? xv : $$.margin.top) + .attr("y2", config[__axis_rotated] ? xv : $$.height) + .style("opacity", 1)); + transitions.push($$.xgridLines.select('text').transition() + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv) + .text(function (d) { return d.text; }) + .style("opacity", 1)); +}; c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, config = $$.config, dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); From 248324db32784220a3b96fda3fad3946b9a75d2b Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 20:09:56 +0900 Subject: [PATCH 32/44] Fix position of data label on flow --- c3.js | 2 +- c3.min.js | 2 +- src/shape.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/c3.js b/c3.js index 0b59826..793c8f5 100644 --- a/c3.js +++ b/c3.js @@ -2981,7 +2981,7 @@ padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { - xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; } return xPos > $$.width ? $$.width - box.width : xPos; }; diff --git a/c3.min.js b/c3.min.js index c5df9ab..cc5a5c9 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ !function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&O.select(this).style("display",b%L?"none":"block")})}else M.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!P[vb]&&P[Hb]&&M.rotateTickText(M.axes.x,b.axisX,P[Hb]),A=M.generateDrawArea(Q,!1),B=M.generateDrawBar(R),C=M.generateDrawLine(S,!1),D=M.generateXYForText(R,!0),E=M.generateXYForText(R,!1),M.subY.domain(M.y.domain()),M.subY2.domain(M.y2.domain()),M.tooltip.style("display","none"),M.updateXgridFocus(),N.select("text."+pe[Nd]+"."+pe[Md]).attr("x",M.width/2).attr("y",M.height/2).text(P[fb]).transition().style("opacity",U.length?0:1),M.redrawGrid(F,n),g=N.select("."+pe[xd]).selectAll("."+pe[wd]).data(P[Qc]),g.enter().append("g").attr("class",De(M.classRegion,M)).append("rect").style("fill-opacity",0),g.exit().transition().duration(F).style("opacity",0).remove(),f=N.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(M.barData,M)),f.enter().append("path").attr("class",De(M.classBar,M)).style("stroke",function(a){return M.color(a.id)}).style("fill",function(a){return M.color(a.id)}),f.style("opacity",De(M.initialOpacity,M)),f.exit().transition().duration(G).style("opacity",0).remove(),c=N.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(M.lineData,M)),c.enter().append("path").attr("class",De(M.classLine,M)).style("stroke",M.color),c.style("opacity",De(M.initialOpacity,M)).attr("transform",null),c.exit().transition().duration(G).style("opacity",0).remove(),d=N.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(M.lineData,M)),d.enter().append("path").attr("class",De(M.classArea,M)).style("fill",M.color).style("opacity",function(){return M.orgAreaOpacity=+O.select(this).style("opacity"),0}),d.style("opacity",M.orgAreaOpacity),d.exit().transition().duration(G).style("opacity",0).remove(),P[mc]&&(e=N.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(M.lineOrScatterData,M)),e.enter().append("circle").attr("class",De(M.classCircle,M)).attr("r",De(M.pointR,M)).style("fill",M.color),e.style("opacity",De(M.initialOpacity,M)),e.exit().remove()),M.hasDataLabel()&&(h=N.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(M.barOrLineData,M)),h.enter().append("text").attr("class",De(M.classText,M)).attr("text-anchor",function(a){return P[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return M.color(a)}).style("fill-opacity",0),h.text(function(a){return M.formatByAxisId(M.getAxisId(a.id))(a.value,a.id)}),h.exit().transition().duration(G).style("fill-opacity",0).remove()),re(M.redrawArc)&&M.redrawArc(F,G,u),re(M.redrawSubchart)&&M.redrawSubchart(p,b,F,G,Q,R,S),N.selectAll("."+pe[od]).filter(De(M.isBarType,M)).selectAll("circle").remove(),P[s]&&(i=N.select("."+pe[qd]).style("cursor",P[o]?P[vb]?"ns-resize":"ew-resize":null),ze(P[z])&&!M.isSingleX(P[z])?(i.classed(pe[sd])||i.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),M.generateEventRectsForMultipleXs(j.enter()),j.attr("x",0).attr("y",0).attr("width",M.width).attr("height",M.height)):(i.classed(pe[rd])||i.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!M.isCustomX()&&!M.isTimeSeries()||M.isCategorized()?(m=M.getEventRectWidth(),l=function(a){return M.x(a.x)-m/2}):(m=function(a){var b=M.getPrevX(a.index),c=M.getNextX(a.index),d=M.data.xs[a.id][a.index],e=(M.x(c?c:d)-M.x(b?b:d))/2;return 0>e?0:e},l=function(a){var b=M.getPrevX(a.index),c=M.data.xs[a.id][a.index];return(M.x(c)+M.x(b?b:c))/2}),k=M.getMaxDataCountTarget(M.data.targets),N.select("."+pe[qd]).datum(k?k.values:[]),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),M.generateEventRectsForSingleX(j.enter()),j.attr("class",De(M.classEvent,M)).attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),j.exit().remove())),O.transition().duration(F).each(function(){var b=[];b.push(f.transition().attr("d",B).style("fill",M.color).style("opacity",1)),b.push(c.transition().attr("d",C).style("stroke",M.color).style("opacity",1)),b.push(d.transition().attr("d",A).style("fill",M.color).style("opacity",M.orgAreaOpacity)),b.push(e.transition().style("opacity",De(M.opacityForCircle,M)).style("fill",M.color).attr("cx",W).attr("cy",X)),b.push(N.selectAll("."+pe[nd]).transition().attr("cx",W).attr("cy",X)),b.push(h.transition().attr("x",D).attr("y",E).style("fill",M.color).style("fill-opacity",a.flow?0:De(M.opacityForText,M))),b.push(g.selectAll("rect").transition().attr("x",De(M.regionX,M)).attr("y",De(M.regionY,M)).attr("width",De(M.regionWidth,M)).attr("height",De(M.regionHeight,M)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),M.addTransitionForGrid(b),a.flow&&(I=M.generateWait(),b.forEach(function(a){I.add(a)}))}).call(I?I:function(){},function(){var b,i,k,n=1,o=a.flow.index,p=a.flow.length,q=M.getValueOnIndex(M.data.targets[0].values,o),r=M.getValueOnIndex(M.data.targets[0].values,o+p),s=M.x.domain(),t=a.flow.duration||F,u=a.flow.done||function(){},v=M.generateWait(),w=M.xgrid||O.selectAll([]),x=M.xgridLines||O.selectAll([]);M.data.targets.forEach(function(a){a.values.splice(0,p)}),k=M.updateXDomain(U,!0,!0),M.updateXGrid&&M.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||q.x===r.x?M.x(s[0])-M.x(k[0]):M.isTimeSeries()?M.x(s[0])-M.x(k[0]):M.x(q.x)-M.x(r.x):1!==M.data.targets[0].values.length?b=M.x(s[0])-M.x(k[0]):M.isTimeSeries()?(q=M.getValueOnIndex(M.data.targets[0].values,0),r=M.getValueOnIndex(M.data.targets[0].values,M.data.targets[0].values.length-1),b=M.x(q.x)-M.x(r.x)):b=xe(k)/2,n=xe(s)/xe(k),i="translate("+b+",0) scale("+n+",1)",O.transition().ease("linear").duration(t).each(function(){v.add(M.axes.x.transition().call(M.xAxis)),v.add(f.transition().attr("transform",i)),v.add(c.transition().attr("transform",i)),v.add(d.transition().attr("transform",i)),v.add(e.transition().attr("transform",i)),v.add(h.transition().attr("transform",i)),v.add(g.filter(M.isRegionOnX).transition().attr("transform",i)),v.add(w.transition().attr("transform",i)),v.add(x.transition().attr("transform",i))}).call(v,function(){var a,b=[],i=[],k=[];if(p){for(a=0;p>a;a++)b.push("."+pe[Ad]+"-"+(o+a)),i.push("."+pe[Nd]+"-"+(o+a)),k.push("."+pe[pd]+"-"+(o+a));M.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),M.svg.selectAll("."+pe[Od]).selectAll(i).remove(),M.svg.selectAll("."+pe[qd]).selectAll(k).remove(),M.svg.select("."+pe[Rd]).remove()}w.attr("transform",null).attr(M.xgridAttr),x.attr("transform",null),x.select("line").attr("x1",P[vb]?0:V).attr("x2",P[vb]?M.width:V),x.select("text").attr("x",P[vb]?M.width:0).attr("y",V),f.attr("transform",null).attr("d",B),c.attr("transform",null).attr("d",C),d.attr("transform",null).attr("d",A),e.attr("transform",null).attr("cx",W).attr("cy",X),h.attr("transform",null).attr("x",D).attr("y",E).style("fill-opacity",De(M.opacityForText,M)),g.attr("transform",null),g.select("rect").filter(M.isRegionOnX).attr("x",De(M.regionX,M)).attr("width",De(M.regionWidth,M)),j.attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),u()})}),M.mapToIds(M.data.targets).forEach(function(a){M.withoutFadeIn[a]=!0}),re(M.updateZoom)&&M.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" -},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=a[0][0]+(a[2][0]-a[0][0])/2,d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a; return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/shape.js b/src/shape.js index 1971f56..21dbffb 100644 --- a/src/shape.js +++ b/src/shape.js @@ -235,7 +235,7 @@ c3_chart_internal_fn.getXForText = function (points, d, textElement) { padding = $$.isBarType(d) ? 4 : 6; xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); } else { - xPos = points[0][0] + (points[2][0] - points[0][0]) / 2; + xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; } return xPos > $$.width ? $$.width - box.width : xPos; }; From 2fa6a3b53ffbde916d7f587984d6be6231235e9b Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 20:20:29 +0900 Subject: [PATCH 33/44] Remove isFunction --- c3.js | 68 ++++++++++++++++++------------------------------ c3.min.js | 8 +++--- src/api.js | 2 +- src/axis.js | 2 +- src/core.js | 44 ++++++++++++------------------- src/data.load.js | 6 ++--- src/format.js | 4 +-- src/legend.js | 6 ++--- src/scale.js | 4 +-- 9 files changed, 56 insertions(+), 88 deletions(-) diff --git a/c3.js b/c3.js index 793c8f5..9ebf0c6 100644 --- a/c3.js +++ b/c3.js @@ -134,9 +134,9 @@ var $$ = this, d3 = $$.d3, config = $$.config; var main, eventRect, binding = true; - if (isFunction($$.initPie)) { $$.initPie(); } - if (isFunction($$.initBrush)) { $$.initBrush(); } - if (isFunction($$.initZoom)) { $$.initZoom(); } + if ($$.initPie) { $$.initPie(); } + if ($$.initBrush) { $$.initBrush(); } + if ($$.initZoom) { $$.initZoom(); } $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { @@ -201,9 +201,9 @@ // Define regions main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); - if (isFunction($$.initSubchart)) { $$.initSubchart(); } - if (isFunction($$.initTooltip)) { $$.initTooltip(); } - if (isFunction($$.initLegend)) { $$.initLegend(); } + if ($$.initSubchart) { $$.initSubchart(); } + if ($$.initTooltip) { $$.initTooltip(); } + if ($$.initLegend) { $$.initLegend(); } /*-- Main Region --*/ @@ -240,12 +240,8 @@ .attr("class", CLASS[_chartLines]); // Define g for arc chart area - if (isFunction($$.initArc)) { - $$.initArc(); - } - if (isFunction($$.initGauge)) { - $$.initGauge(); - } + if ($$.initArc) { $$.initArc(); } + if ($$.initGauge) { $$.initGauge(); } main.select('.' + CLASS[_chart]).append("g") .attr("class", CLASS[_chartTexts]); @@ -261,7 +257,7 @@ // Set default extent if defined if (config[__axis_x_default]) { - $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); + $$.brush.extent(isFunction(config[__axis_x_default]) ? config[__axis_x_default]($$.getXDomain()) : config[__axis_x_default]); } // Add Axis @@ -363,7 +359,7 @@ } // for legend - if (isFunction($$.updateSizeForLegend)) { $$.updateSizeForLegend(legendHeight, legendWidth); } + if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); } $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; @@ -378,9 +374,7 @@ // for arc $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); - if (isFunction($$.updateRadius)) { - $$.updateRadius(); - } + if ($$.updateRadius) { $$.updateRadius(); } if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; @@ -446,12 +440,8 @@ // MEMO: can not keep same color... //mainLineUpdate.exit().remove(); - if (isFunction($$.updateTargetsForArc)) { - $$.updateTargetsForArc(targets); - } - if (isFunction($$.updateTargetsForSubchart)) { - $$.updateTargetsForSubchart(targets); - } + if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); } + if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); } /*-- Show --*/ @@ -658,12 +648,10 @@ } // arc - if (isFunction($$.redrawArc)) { - $$.redrawArc(duration, durationForExit, withTransform); - } + if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); } // subchart - if (isFunction($$.redrawSubchart)) { + if ($$.redrawSubchart) { $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } @@ -911,7 +899,7 @@ $$.withoutFadeIn[id] = true; }); - if (isFunction($$.updateZoom)) { $$.updateZoom(); } + if ($$.updateZoom) { $$.updateZoom(); } }; c3_chart_internal_fn.updateAndRedraw = function (options) { @@ -1842,9 +1830,7 @@ if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } } // update for arc - if (isFunction($$.updateArc)) { - $$.updateArc(); - } + if ($$.updateArc) { $$.updateArc(); } }; c3_chart_internal_fn.getYDomainMin = function (targets) { @@ -2579,9 +2565,7 @@ // Redraw with new targets $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (isFunction(args.done)) { - args.done(); - } + if (args.done) { args.done(); } }; c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; @@ -2608,7 +2592,7 @@ }; c3_chart_internal_fn.unload = function (targetIds, done) { var $$ = this; - if (!isFunction(done)) { + if (!done) { done = function () {}; } // filter existing target @@ -3742,14 +3726,14 @@ .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call($$, id) : $$.api.toggle(id); + config[__legend_item_onclick] ? config[__legend_item_onclick].call($$, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed(CLASS[_legendItemFocused], true); if (!$$.transiting) { $$.api.focus(id); } - if (isFunction(config[__legend_item_onmouseover])) { + if (config[__legend_item_onmouseover]) { config[__legend_item_onmouseover].call($$, id); } }) @@ -3758,7 +3742,7 @@ if (!$$.transiting) { $$.api.revert(); } - if (isFunction(config[__legend_item_onmouseout])) { + if (config[__legend_item_onmouseout]) { config[__legend_item_onmouseout].call($$, id); } }); @@ -3903,7 +3887,7 @@ var $$ = this, 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])) { + if (config[__axis_x_tick_format]) { format = config[__axis_x_tick_format]; } else if ($$.isTimeSeries()) { format = function (date) { @@ -5102,10 +5086,10 @@ var $$ = this, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id - if (isFunction(data_labels.format)) { + if (data_labels.format) { format = data_labels.format; } else if (typeof data_labels.format === 'object') { - if (isFunction(data_labels.format[axisId])) { + if (data_labels.format[axisId]) { format = data_labels.format[axisId]; } } @@ -5555,7 +5539,7 @@ args = args || {}; $$.unload($$.mapToTargetIds(args.ids), function () { $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (isFunction(args.done)) { args.done(); } + if (args.done) { args.done(); } }); }; diff --git a/c3.min.js b/c3.min.js index cc5a5c9..bdf53ac 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&O.select(this).style("display",b%L?"none":"block")})}else M.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!P[vb]&&P[Hb]&&M.rotateTickText(M.axes.x,b.axisX,P[Hb]),A=M.generateDrawArea(Q,!1),B=M.generateDrawBar(R),C=M.generateDrawLine(S,!1),D=M.generateXYForText(R,!0),E=M.generateXYForText(R,!1),M.subY.domain(M.y.domain()),M.subY2.domain(M.y2.domain()),M.tooltip.style("display","none"),M.updateXgridFocus(),N.select("text."+pe[Nd]+"."+pe[Md]).attr("x",M.width/2).attr("y",M.height/2).text(P[fb]).transition().style("opacity",U.length?0:1),M.redrawGrid(F,n),g=N.select("."+pe[xd]).selectAll("."+pe[wd]).data(P[Qc]),g.enter().append("g").attr("class",De(M.classRegion,M)).append("rect").style("fill-opacity",0),g.exit().transition().duration(F).style("opacity",0).remove(),f=N.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(M.barData,M)),f.enter().append("path").attr("class",De(M.classBar,M)).style("stroke",function(a){return M.color(a.id)}).style("fill",function(a){return M.color(a.id)}),f.style("opacity",De(M.initialOpacity,M)),f.exit().transition().duration(G).style("opacity",0).remove(),c=N.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(M.lineData,M)),c.enter().append("path").attr("class",De(M.classLine,M)).style("stroke",M.color),c.style("opacity",De(M.initialOpacity,M)).attr("transform",null),c.exit().transition().duration(G).style("opacity",0).remove(),d=N.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(M.lineData,M)),d.enter().append("path").attr("class",De(M.classArea,M)).style("fill",M.color).style("opacity",function(){return M.orgAreaOpacity=+O.select(this).style("opacity"),0}),d.style("opacity",M.orgAreaOpacity),d.exit().transition().duration(G).style("opacity",0).remove(),P[mc]&&(e=N.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(M.lineOrScatterData,M)),e.enter().append("circle").attr("class",De(M.classCircle,M)).attr("r",De(M.pointR,M)).style("fill",M.color),e.style("opacity",De(M.initialOpacity,M)),e.exit().remove()),M.hasDataLabel()&&(h=N.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(M.barOrLineData,M)),h.enter().append("text").attr("class",De(M.classText,M)).attr("text-anchor",function(a){return P[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return M.color(a)}).style("fill-opacity",0),h.text(function(a){return M.formatByAxisId(M.getAxisId(a.id))(a.value,a.id)}),h.exit().transition().duration(G).style("fill-opacity",0).remove()),re(M.redrawArc)&&M.redrawArc(F,G,u),re(M.redrawSubchart)&&M.redrawSubchart(p,b,F,G,Q,R,S),N.selectAll("."+pe[od]).filter(De(M.isBarType,M)).selectAll("circle").remove(),P[s]&&(i=N.select("."+pe[qd]).style("cursor",P[o]?P[vb]?"ns-resize":"ew-resize":null),ze(P[z])&&!M.isSingleX(P[z])?(i.classed(pe[sd])||i.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),M.generateEventRectsForMultipleXs(j.enter()),j.attr("x",0).attr("y",0).attr("width",M.width).attr("height",M.height)):(i.classed(pe[rd])||i.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!M.isCustomX()&&!M.isTimeSeries()||M.isCategorized()?(m=M.getEventRectWidth(),l=function(a){return M.x(a.x)-m/2}):(m=function(a){var b=M.getPrevX(a.index),c=M.getNextX(a.index),d=M.data.xs[a.id][a.index],e=(M.x(c?c:d)-M.x(b?b:d))/2;return 0>e?0:e},l=function(a){var b=M.getPrevX(a.index),c=M.data.xs[a.id][a.index];return(M.x(c)+M.x(b?b:c))/2}),k=M.getMaxDataCountTarget(M.data.targets),N.select("."+pe[qd]).datum(k?k.values:[]),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),M.generateEventRectsForSingleX(j.enter()),j.attr("class",De(M.classEvent,M)).attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),j.exit().remove())),O.transition().duration(F).each(function(){var b=[];b.push(f.transition().attr("d",B).style("fill",M.color).style("opacity",1)),b.push(c.transition().attr("d",C).style("stroke",M.color).style("opacity",1)),b.push(d.transition().attr("d",A).style("fill",M.color).style("opacity",M.orgAreaOpacity)),b.push(e.transition().style("opacity",De(M.opacityForCircle,M)).style("fill",M.color).attr("cx",W).attr("cy",X)),b.push(N.selectAll("."+pe[nd]).transition().attr("cx",W).attr("cy",X)),b.push(h.transition().attr("x",D).attr("y",E).style("fill",M.color).style("fill-opacity",a.flow?0:De(M.opacityForText,M))),b.push(g.selectAll("rect").transition().attr("x",De(M.regionX,M)).attr("y",De(M.regionY,M)).attr("width",De(M.regionWidth,M)).attr("height",De(M.regionHeight,M)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),M.addTransitionForGrid(b),a.flow&&(I=M.generateWait(),b.forEach(function(a){I.add(a)}))}).call(I?I:function(){},function(){var b,i,k,n=1,o=a.flow.index,p=a.flow.length,q=M.getValueOnIndex(M.data.targets[0].values,o),r=M.getValueOnIndex(M.data.targets[0].values,o+p),s=M.x.domain(),t=a.flow.duration||F,u=a.flow.done||function(){},v=M.generateWait(),w=M.xgrid||O.selectAll([]),x=M.xgridLines||O.selectAll([]);M.data.targets.forEach(function(a){a.values.splice(0,p)}),k=M.updateXDomain(U,!0,!0),M.updateXGrid&&M.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||q.x===r.x?M.x(s[0])-M.x(k[0]):M.isTimeSeries()?M.x(s[0])-M.x(k[0]):M.x(q.x)-M.x(r.x):1!==M.data.targets[0].values.length?b=M.x(s[0])-M.x(k[0]):M.isTimeSeries()?(q=M.getValueOnIndex(M.data.targets[0].values,0),r=M.getValueOnIndex(M.data.targets[0].values,M.data.targets[0].values.length-1),b=M.x(q.x)-M.x(r.x)):b=xe(k)/2,n=xe(s)/xe(k),i="translate("+b+",0) scale("+n+",1)",O.transition().ease("linear").duration(t).each(function(){v.add(M.axes.x.transition().call(M.xAxis)),v.add(f.transition().attr("transform",i)),v.add(c.transition().attr("transform",i)),v.add(d.transition().attr("transform",i)),v.add(e.transition().attr("transform",i)),v.add(h.transition().attr("transform",i)),v.add(g.filter(M.isRegionOnX).transition().attr("transform",i)),v.add(w.transition().attr("transform",i)),v.add(x.transition().attr("transform",i))}).call(v,function(){var a,b=[],i=[],k=[];if(p){for(a=0;p>a;a++)b.push("."+pe[Ad]+"-"+(o+a)),i.push("."+pe[Nd]+"-"+(o+a)),k.push("."+pe[pd]+"-"+(o+a));M.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),M.svg.selectAll("."+pe[Od]).selectAll(i).remove(),M.svg.selectAll("."+pe[qd]).selectAll(k).remove(),M.svg.select("."+pe[Rd]).remove()}w.attr("transform",null).attr(M.xgridAttr),x.attr("transform",null),x.select("line").attr("x1",P[vb]?0:V).attr("x2",P[vb]?M.width:V),x.select("text").attr("x",P[vb]?M.width:0).attr("y",V),f.attr("transform",null).attr("d",B),c.attr("transform",null).attr("d",C),d.attr("transform",null).attr("d",A),e.attr("transform",null).attr("cx",W).attr("cy",X),h.attr("transform",null).attr("x",D).attr("y",E).style("fill-opacity",De(M.opacityForText,M)),g.attr("transform",null),g.select("rect").filter(M.isRegionOnX).attr("x",De(M.regionX,M)).attr("width",De(M.regionWidth,M)),j.attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),u()})}),M.mapToIds(M.data.targets).forEach(function(a){M.withoutFadeIn[a]=!0}),re(M.updateZoom)&&M.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" -},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),re(a.updateArc)&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){re(r[rb])?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),re(r[sb])&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),re(r[tb])&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a; -return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),re(a.done)&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&O.select(this).style("display",b%L?"none":"block")})}else M.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!P[vb]&&P[Hb]&&M.rotateTickText(M.axes.x,b.axisX,P[Hb]),A=M.generateDrawArea(Q,!1),B=M.generateDrawBar(R),C=M.generateDrawLine(S,!1),D=M.generateXYForText(R,!0),E=M.generateXYForText(R,!1),M.subY.domain(M.y.domain()),M.subY2.domain(M.y2.domain()),M.tooltip.style("display","none"),M.updateXgridFocus(),N.select("text."+pe[Nd]+"."+pe[Md]).attr("x",M.width/2).attr("y",M.height/2).text(P[fb]).transition().style("opacity",U.length?0:1),M.redrawGrid(F,n),g=N.select("."+pe[xd]).selectAll("."+pe[wd]).data(P[Qc]),g.enter().append("g").attr("class",De(M.classRegion,M)).append("rect").style("fill-opacity",0),g.exit().transition().duration(F).style("opacity",0).remove(),f=N.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(M.barData,M)),f.enter().append("path").attr("class",De(M.classBar,M)).style("stroke",function(a){return M.color(a.id)}).style("fill",function(a){return M.color(a.id)}),f.style("opacity",De(M.initialOpacity,M)),f.exit().transition().duration(G).style("opacity",0).remove(),c=N.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(M.lineData,M)),c.enter().append("path").attr("class",De(M.classLine,M)).style("stroke",M.color),c.style("opacity",De(M.initialOpacity,M)).attr("transform",null),c.exit().transition().duration(G).style("opacity",0).remove(),d=N.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(M.lineData,M)),d.enter().append("path").attr("class",De(M.classArea,M)).style("fill",M.color).style("opacity",function(){return M.orgAreaOpacity=+O.select(this).style("opacity"),0}),d.style("opacity",M.orgAreaOpacity),d.exit().transition().duration(G).style("opacity",0).remove(),P[mc]&&(e=N.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(M.lineOrScatterData,M)),e.enter().append("circle").attr("class",De(M.classCircle,M)).attr("r",De(M.pointR,M)).style("fill",M.color),e.style("opacity",De(M.initialOpacity,M)),e.exit().remove()),M.hasDataLabel()&&(h=N.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(M.barOrLineData,M)),h.enter().append("text").attr("class",De(M.classText,M)).attr("text-anchor",function(a){return P[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return M.color(a)}).style("fill-opacity",0),h.text(function(a){return M.formatByAxisId(M.getAxisId(a.id))(a.value,a.id)}),h.exit().transition().duration(G).style("fill-opacity",0).remove()),M.redrawArc&&M.redrawArc(F,G,u),M.redrawSubchart&&M.redrawSubchart(p,b,F,G,Q,R,S),N.selectAll("."+pe[od]).filter(De(M.isBarType,M)).selectAll("circle").remove(),P[s]&&(i=N.select("."+pe[qd]).style("cursor",P[o]?P[vb]?"ns-resize":"ew-resize":null),ze(P[z])&&!M.isSingleX(P[z])?(i.classed(pe[sd])||i.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),M.generateEventRectsForMultipleXs(j.enter()),j.attr("x",0).attr("y",0).attr("width",M.width).attr("height",M.height)):(i.classed(pe[rd])||i.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!M.isCustomX()&&!M.isTimeSeries()||M.isCategorized()?(m=M.getEventRectWidth(),l=function(a){return M.x(a.x)-m/2}):(m=function(a){var b=M.getPrevX(a.index),c=M.getNextX(a.index),d=M.data.xs[a.id][a.index],e=(M.x(c?c:d)-M.x(b?b:d))/2;return 0>e?0:e},l=function(a){var b=M.getPrevX(a.index),c=M.data.xs[a.id][a.index];return(M.x(c)+M.x(b?b:c))/2}),k=M.getMaxDataCountTarget(M.data.targets),N.select("."+pe[qd]).datum(k?k.values:[]),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),M.generateEventRectsForSingleX(j.enter()),j.attr("class",De(M.classEvent,M)).attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),j.exit().remove())),O.transition().duration(F).each(function(){var b=[];b.push(f.transition().attr("d",B).style("fill",M.color).style("opacity",1)),b.push(c.transition().attr("d",C).style("stroke",M.color).style("opacity",1)),b.push(d.transition().attr("d",A).style("fill",M.color).style("opacity",M.orgAreaOpacity)),b.push(e.transition().style("opacity",De(M.opacityForCircle,M)).style("fill",M.color).attr("cx",W).attr("cy",X)),b.push(N.selectAll("."+pe[nd]).transition().attr("cx",W).attr("cy",X)),b.push(h.transition().attr("x",D).attr("y",E).style("fill",M.color).style("fill-opacity",a.flow?0:De(M.opacityForText,M))),b.push(g.selectAll("rect").transition().attr("x",De(M.regionX,M)).attr("y",De(M.regionY,M)).attr("width",De(M.regionWidth,M)).attr("height",De(M.regionHeight,M)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),M.addTransitionForGrid(b),a.flow&&(I=M.generateWait(),b.forEach(function(a){I.add(a)}))}).call(I?I:function(){},function(){var b,i,k,n=1,o=a.flow.index,p=a.flow.length,q=M.getValueOnIndex(M.data.targets[0].values,o),r=M.getValueOnIndex(M.data.targets[0].values,o+p),s=M.x.domain(),t=a.flow.duration||F,u=a.flow.done||function(){},v=M.generateWait(),w=M.xgrid||O.selectAll([]),x=M.xgridLines||O.selectAll([]);M.data.targets.forEach(function(a){a.values.splice(0,p)}),k=M.updateXDomain(U,!0,!0),M.updateXGrid&&M.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||q.x===r.x?M.x(s[0])-M.x(k[0]):M.isTimeSeries()?M.x(s[0])-M.x(k[0]):M.x(q.x)-M.x(r.x):1!==M.data.targets[0].values.length?b=M.x(s[0])-M.x(k[0]):M.isTimeSeries()?(q=M.getValueOnIndex(M.data.targets[0].values,0),r=M.getValueOnIndex(M.data.targets[0].values,M.data.targets[0].values.length-1),b=M.x(q.x)-M.x(r.x)):b=xe(k)/2,n=xe(s)/xe(k),i="translate("+b+",0) scale("+n+",1)",O.transition().ease("linear").duration(t).each(function(){v.add(M.axes.x.transition().call(M.xAxis)),v.add(f.transition().attr("transform",i)),v.add(c.transition().attr("transform",i)),v.add(d.transition().attr("transform",i)),v.add(e.transition().attr("transform",i)),v.add(h.transition().attr("transform",i)),v.add(g.filter(M.isRegionOnX).transition().attr("transform",i)),v.add(w.transition().attr("transform",i)),v.add(x.transition().attr("transform",i))}).call(v,function(){var a,b=[],i=[],k=[];if(p){for(a=0;p>a;a++)b.push("."+pe[Ad]+"-"+(o+a)),i.push("."+pe[Nd]+"-"+(o+a)),k.push("."+pe[pd]+"-"+(o+a));M.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),M.svg.selectAll("."+pe[Od]).selectAll(i).remove(),M.svg.selectAll("."+pe[qd]).selectAll(k).remove(),M.svg.select("."+pe[Rd]).remove()}w.attr("transform",null).attr(M.xgridAttr),x.attr("transform",null),x.select("line").attr("x1",P[vb]?0:V).attr("x2",P[vb]?M.width:V),x.select("text").attr("x",P[vb]?M.width:0).attr("y",V),f.attr("transform",null).attr("d",B),c.attr("transform",null).attr("d",C),d.attr("transform",null).attr("d",A),e.attr("transform",null).attr("cx",W).attr("cy",X),h.attr("transform",null).attr("x",D).attr("y",E).style("fill-opacity",De(M.opacityForText,M)),g.attr("transform",null),g.select("rect").filter(M.isRegionOnX).attr("x",De(M.regionX,M)).attr("width",De(M.regionWidth,M)),j.attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),u()})}),M.mapToIds(M.data.targets).forEach(function(a){M.withoutFadeIn[a]=!0}),M.updateZoom&&M.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" +},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b +}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/api.js b/src/api.js index 26ca9de..5d7eaa6 100644 --- a/src/api.js +++ b/src/api.js @@ -140,7 +140,7 @@ c3_chart_fn.unload = function (args) { args = args || {}; $$.unload($$.mapToTargetIds(args.ids), function () { $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (isFunction(args.done)) { args.done(); } + if (args.done) { args.done(); } }); }; diff --git a/src/axis.js b/src/axis.js index 15e5c7f..200807f 100644 --- a/src/axis.js +++ b/src/axis.js @@ -63,7 +63,7 @@ c3_chart_internal_fn.getXAxisTickFormat = function () { var $$ = this, 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])) { + if (config[__axis_x_tick_format]) { format = config[__axis_x_tick_format]; } else if ($$.isTimeSeries()) { format = function (date) { diff --git a/src/core.js b/src/core.js index b2636c2..8f301f2 100644 --- a/src/core.js +++ b/src/core.js @@ -129,9 +129,9 @@ c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; var main, eventRect, binding = true; - if (isFunction($$.initPie)) { $$.initPie(); } - if (isFunction($$.initBrush)) { $$.initBrush(); } - if (isFunction($$.initZoom)) { $$.initZoom(); } + if ($$.initPie) { $$.initPie(); } + if ($$.initBrush) { $$.initBrush(); } + if ($$.initZoom) { $$.initZoom(); } $$.selectChart = d3.select(config[__bindto]); if ($$.selectChart.empty()) { @@ -196,9 +196,9 @@ c3_chart_internal_fn.initWithData = function (data) { // Define regions main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); - if (isFunction($$.initSubchart)) { $$.initSubchart(); } - if (isFunction($$.initTooltip)) { $$.initTooltip(); } - if (isFunction($$.initLegend)) { $$.initLegend(); } + if ($$.initSubchart) { $$.initSubchart(); } + if ($$.initTooltip) { $$.initTooltip(); } + if ($$.initLegend) { $$.initLegend(); } /*-- Main Region --*/ @@ -235,12 +235,8 @@ c3_chart_internal_fn.initWithData = function (data) { .attr("class", CLASS[_chartLines]); // Define g for arc chart area - if (isFunction($$.initArc)) { - $$.initArc(); - } - if (isFunction($$.initGauge)) { - $$.initGauge(); - } + if ($$.initArc) { $$.initArc(); } + if ($$.initGauge) { $$.initGauge(); } main.select('.' + CLASS[_chart]).append("g") .attr("class", CLASS[_chartTexts]); @@ -256,7 +252,7 @@ c3_chart_internal_fn.initWithData = function (data) { // Set default extent if defined if (config[__axis_x_default]) { - $$.brush.extent(!isFunction(config[__axis_x_default]) ? config[__axis_x_default] : config[__axis_x_default]($$.getXDomain())); + $$.brush.extent(isFunction(config[__axis_x_default]) ? config[__axis_x_default]($$.getXDomain()) : config[__axis_x_default]); } // Add Axis @@ -358,7 +354,7 @@ c3_chart_internal_fn.updateSizes = function () { } // for legend - if (isFunction($$.updateSizeForLegend)) { $$.updateSizeForLegend(legendHeight, legendWidth); } + if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); } $$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; @@ -373,9 +369,7 @@ c3_chart_internal_fn.updateSizes = function () { // for arc $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); - if (isFunction($$.updateRadius)) { - $$.updateRadius(); - } + if ($$.updateRadius) { $$.updateRadius(); } if ($$.isLegendRight && hasArc) { $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; @@ -441,12 +435,8 @@ c3_chart_internal_fn.updateTargets = function (targets) { // MEMO: can not keep same color... //mainLineUpdate.exit().remove(); - if (isFunction($$.updateTargetsForArc)) { - $$.updateTargetsForArc(targets); - } - if (isFunction($$.updateTargetsForSubchart)) { - $$.updateTargetsForSubchart(targets); - } + if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); } + if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); } /*-- Show --*/ @@ -653,12 +643,10 @@ c3_chart_internal_fn.redraw = function (options, transitions) { } // arc - if (isFunction($$.redrawArc)) { - $$.redrawArc(duration, durationForExit, withTransform); - } + if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); } // subchart - if (isFunction($$.redrawSubchart)) { + if ($$.redrawSubchart) { $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); } @@ -906,7 +894,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.withoutFadeIn[id] = true; }); - if (isFunction($$.updateZoom)) { $$.updateZoom(); } + if ($$.updateZoom) { $$.updateZoom(); } }; c3_chart_internal_fn.updateAndRedraw = function (options) { diff --git a/src/data.load.js b/src/data.load.js index e161303..0a5fc05 100644 --- a/src/data.load.js +++ b/src/data.load.js @@ -30,9 +30,7 @@ c3_chart_internal_fn.load = function (targets, args) { // Redraw with new targets $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (isFunction(args.done)) { - args.done(); - } + if (args.done) { args.done(); } }; c3_chart_internal_fn.loadFromArgs = function (args) { var $$ = this; @@ -59,7 +57,7 @@ c3_chart_internal_fn.loadFromArgs = function (args) { }; c3_chart_internal_fn.unload = function (targetIds, done) { var $$ = this; - if (!isFunction(done)) { + if (!done) { done = function () {}; } // filter existing target diff --git a/src/format.js b/src/format.js index 174aa3a..58c6b1f 100644 --- a/src/format.js +++ b/src/format.js @@ -27,10 +27,10 @@ c3_chart_internal_fn.formatByAxisId = function (axisId) { var $$ = this, data_labels = $$.config[__data_labels], format = function (v) { return isValue(v) ? +v : ""; }; // find format according to axis id - if (isFunction(data_labels.format)) { + if (data_labels.format) { format = data_labels.format; } else if (typeof data_labels.format === 'object') { - if (isFunction(data_labels.format[axisId])) { + if (data_labels.format[axisId]) { format = data_labels.format[axisId]; } } diff --git a/src/legend.js b/src/legend.js index fb4a021..d7159e8 100644 --- a/src/legend.js +++ b/src/legend.js @@ -197,14 +197,14 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('cursor', 'pointer') .on('click', function (id) { - isFunction(config[__legend_item_onclick]) ? config[__legend_item_onclick].call($$, id) : $$.api.toggle(id); + config[__legend_item_onclick] ? config[__legend_item_onclick].call($$, id) : $$.api.toggle(id); }) .on('mouseover', function (id) { $$.d3.select(this).classed(CLASS[_legendItemFocused], true); if (!$$.transiting) { $$.api.focus(id); } - if (isFunction(config[__legend_item_onmouseover])) { + if (config[__legend_item_onmouseover]) { config[__legend_item_onmouseover].call($$, id); } }) @@ -213,7 +213,7 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) { if (!$$.transiting) { $$.api.revert(); } - if (isFunction(config[__legend_item_onmouseout])) { + if (config[__legend_item_onmouseout]) { config[__legend_item_onmouseout].call($$, id); } }); diff --git a/src/scale.js b/src/scale.js index 3f2c35d..deca515 100644 --- a/src/scale.js +++ b/src/scale.js @@ -81,7 +81,5 @@ c3_chart_internal_fn.updateScales = function () { if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } } // update for arc - if (isFunction($$.updateArc)) { - $$.updateArc(); - } + if ($$.updateArc) { $$.updateArc(); } }; From 1e6867acb5cdfc76ffdaeb28b24f217078137409 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 20:33:56 +0900 Subject: [PATCH 34/44] Modularize region --- c3.js | 53 ++++++++++++++++++++++++++++++++------------------- c3.min.js | 6 +++--- src/core.js | 26 ++++++------------------- src/region.js | 27 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/c3.js b/c3.js index 9ebf0c6..93388ec 100644 --- a/c3.js +++ b/c3.js @@ -214,9 +214,7 @@ .attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE. // Regions - main.append('g') - .attr("clip-path", $$.clipPath) - .attr("class", CLASS[_regions]); + $$.initRegion(); // Grids $$.initGrid(); @@ -453,7 +451,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -570,15 +568,7 @@ $$.redrawGrid(duration, withY); // rect for regions - mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) - .data(config[__regions]); - mainRegion.enter().append('g') - .attr('class', generateCall($$.classRegion, $$)) - .append('rect') - .style("fill-opacity", 0); - mainRegion.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); + $$.redrawRegion(duration); // bars mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) @@ -756,12 +746,7 @@ .attr('y', yForText) .style("fill", $$.color) .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); - transitions.push(mainRegion.selectAll('rect').transition() - .attr("x", generateCall($$.regionX, $$)) - .attr("y", generateCall($$.regionY, $$)) - .attr("width", generateCall($$.regionWidth, $$)) - .attr("height", generateCall($$.regionHeight, $$)) - .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); // Wait for end of transitions if called from flow API @@ -784,7 +769,8 @@ wait = $$.generateWait(); var xgrid = $$.xgrid || d3.selectAll([]), - xgridLines = $$.xgridLines || d3.selectAll([]); + xgridLines = $$.xgridLines || d3.selectAll([]), + mainRegion = $$.mainRegion || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -4571,6 +4557,33 @@ } }; + c3_chart_internal_fn.initRegion = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr("class", CLASS[_regions]); + }; + c3_chart_internal_fn.redrawRegion = function (duration) { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) + .data(config[__regions]); + $$.mainRegion.enter().append('g') + .attr('class', generateCall($$.classRegion, $$)) + .append('rect') + .style("fill-opacity", 0); + $$.mainRegion.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); + }; + c3_chart_internal_fn.addTransitionForRegion = function (transitions) { + var $$ = this; + transitions.push($$.mainRegion.selectAll('rect').transition() + .attr("x", generateCall($$.regionX, $$)) + .attr("y", generateCall($$.regionY, $$)) + .attr("width", generateCall($$.regionWidth, $$)) + .attr("height", generateCall($$.regionHeight, $$)) + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + }; c3_chart_internal_fn.regionX = function (d) { var $$ = this, config = $$.config, xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; diff --git a/c3.min.js b/c3.min.js index bdf53ac..b27dbeb 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&O.select(this).style("display",b%L?"none":"block")})}else M.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!P[vb]&&P[Hb]&&M.rotateTickText(M.axes.x,b.axisX,P[Hb]),A=M.generateDrawArea(Q,!1),B=M.generateDrawBar(R),C=M.generateDrawLine(S,!1),D=M.generateXYForText(R,!0),E=M.generateXYForText(R,!1),M.subY.domain(M.y.domain()),M.subY2.domain(M.y2.domain()),M.tooltip.style("display","none"),M.updateXgridFocus(),N.select("text."+pe[Nd]+"."+pe[Md]).attr("x",M.width/2).attr("y",M.height/2).text(P[fb]).transition().style("opacity",U.length?0:1),M.redrawGrid(F,n),g=N.select("."+pe[xd]).selectAll("."+pe[wd]).data(P[Qc]),g.enter().append("g").attr("class",De(M.classRegion,M)).append("rect").style("fill-opacity",0),g.exit().transition().duration(F).style("opacity",0).remove(),f=N.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(M.barData,M)),f.enter().append("path").attr("class",De(M.classBar,M)).style("stroke",function(a){return M.color(a.id)}).style("fill",function(a){return M.color(a.id)}),f.style("opacity",De(M.initialOpacity,M)),f.exit().transition().duration(G).style("opacity",0).remove(),c=N.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(M.lineData,M)),c.enter().append("path").attr("class",De(M.classLine,M)).style("stroke",M.color),c.style("opacity",De(M.initialOpacity,M)).attr("transform",null),c.exit().transition().duration(G).style("opacity",0).remove(),d=N.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(M.lineData,M)),d.enter().append("path").attr("class",De(M.classArea,M)).style("fill",M.color).style("opacity",function(){return M.orgAreaOpacity=+O.select(this).style("opacity"),0}),d.style("opacity",M.orgAreaOpacity),d.exit().transition().duration(G).style("opacity",0).remove(),P[mc]&&(e=N.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(M.lineOrScatterData,M)),e.enter().append("circle").attr("class",De(M.classCircle,M)).attr("r",De(M.pointR,M)).style("fill",M.color),e.style("opacity",De(M.initialOpacity,M)),e.exit().remove()),M.hasDataLabel()&&(h=N.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(M.barOrLineData,M)),h.enter().append("text").attr("class",De(M.classText,M)).attr("text-anchor",function(a){return P[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return M.color(a)}).style("fill-opacity",0),h.text(function(a){return M.formatByAxisId(M.getAxisId(a.id))(a.value,a.id)}),h.exit().transition().duration(G).style("fill-opacity",0).remove()),M.redrawArc&&M.redrawArc(F,G,u),M.redrawSubchart&&M.redrawSubchart(p,b,F,G,Q,R,S),N.selectAll("."+pe[od]).filter(De(M.isBarType,M)).selectAll("circle").remove(),P[s]&&(i=N.select("."+pe[qd]).style("cursor",P[o]?P[vb]?"ns-resize":"ew-resize":null),ze(P[z])&&!M.isSingleX(P[z])?(i.classed(pe[sd])||i.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),M.generateEventRectsForMultipleXs(j.enter()),j.attr("x",0).attr("y",0).attr("width",M.width).attr("height",M.height)):(i.classed(pe[rd])||i.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!M.isCustomX()&&!M.isTimeSeries()||M.isCategorized()?(m=M.getEventRectWidth(),l=function(a){return M.x(a.x)-m/2}):(m=function(a){var b=M.getPrevX(a.index),c=M.getNextX(a.index),d=M.data.xs[a.id][a.index],e=(M.x(c?c:d)-M.x(b?b:d))/2;return 0>e?0:e},l=function(a){var b=M.getPrevX(a.index),c=M.data.xs[a.id][a.index];return(M.x(c)+M.x(b?b:c))/2}),k=M.getMaxDataCountTarget(M.data.targets),N.select("."+pe[qd]).datum(k?k.values:[]),j=N.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),M.generateEventRectsForSingleX(j.enter()),j.attr("class",De(M.classEvent,M)).attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),j.exit().remove())),O.transition().duration(F).each(function(){var b=[];b.push(f.transition().attr("d",B).style("fill",M.color).style("opacity",1)),b.push(c.transition().attr("d",C).style("stroke",M.color).style("opacity",1)),b.push(d.transition().attr("d",A).style("fill",M.color).style("opacity",M.orgAreaOpacity)),b.push(e.transition().style("opacity",De(M.opacityForCircle,M)).style("fill",M.color).attr("cx",W).attr("cy",X)),b.push(N.selectAll("."+pe[nd]).transition().attr("cx",W).attr("cy",X)),b.push(h.transition().attr("x",D).attr("y",E).style("fill",M.color).style("fill-opacity",a.flow?0:De(M.opacityForText,M))),b.push(g.selectAll("rect").transition().attr("x",De(M.regionX,M)).attr("y",De(M.regionY,M)).attr("width",De(M.regionWidth,M)).attr("height",De(M.regionHeight,M)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1})),M.addTransitionForGrid(b),a.flow&&(I=M.generateWait(),b.forEach(function(a){I.add(a)}))}).call(I?I:function(){},function(){var b,i,k,n=1,o=a.flow.index,p=a.flow.length,q=M.getValueOnIndex(M.data.targets[0].values,o),r=M.getValueOnIndex(M.data.targets[0].values,o+p),s=M.x.domain(),t=a.flow.duration||F,u=a.flow.done||function(){},v=M.generateWait(),w=M.xgrid||O.selectAll([]),x=M.xgridLines||O.selectAll([]);M.data.targets.forEach(function(a){a.values.splice(0,p)}),k=M.updateXDomain(U,!0,!0),M.updateXGrid&&M.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||q.x===r.x?M.x(s[0])-M.x(k[0]):M.isTimeSeries()?M.x(s[0])-M.x(k[0]):M.x(q.x)-M.x(r.x):1!==M.data.targets[0].values.length?b=M.x(s[0])-M.x(k[0]):M.isTimeSeries()?(q=M.getValueOnIndex(M.data.targets[0].values,0),r=M.getValueOnIndex(M.data.targets[0].values,M.data.targets[0].values.length-1),b=M.x(q.x)-M.x(r.x)):b=xe(k)/2,n=xe(s)/xe(k),i="translate("+b+",0) scale("+n+",1)",O.transition().ease("linear").duration(t).each(function(){v.add(M.axes.x.transition().call(M.xAxis)),v.add(f.transition().attr("transform",i)),v.add(c.transition().attr("transform",i)),v.add(d.transition().attr("transform",i)),v.add(e.transition().attr("transform",i)),v.add(h.transition().attr("transform",i)),v.add(g.filter(M.isRegionOnX).transition().attr("transform",i)),v.add(w.transition().attr("transform",i)),v.add(x.transition().attr("transform",i))}).call(v,function(){var a,b=[],i=[],k=[];if(p){for(a=0;p>a;a++)b.push("."+pe[Ad]+"-"+(o+a)),i.push("."+pe[Nd]+"-"+(o+a)),k.push("."+pe[pd]+"-"+(o+a));M.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),M.svg.selectAll("."+pe[Od]).selectAll(i).remove(),M.svg.selectAll("."+pe[qd]).selectAll(k).remove(),M.svg.select("."+pe[Rd]).remove()}w.attr("transform",null).attr(M.xgridAttr),x.attr("transform",null),x.select("line").attr("x1",P[vb]?0:V).attr("x2",P[vb]?M.width:V),x.select("text").attr("x",P[vb]?M.width:0).attr("y",V),f.attr("transform",null).attr("d",B),c.attr("transform",null).attr("d",C),d.attr("transform",null).attr("d",A),e.attr("transform",null).attr("cx",W).attr("cy",X),h.attr("transform",null).attr("x",D).attr("y",E).style("fill-opacity",De(M.opacityForText,M)),g.attr("transform",null),g.select("rect").filter(M.isRegionOnX).attr("x",De(M.regionX,M)).attr("width",De(M.regionWidth,M)),j.attr("x",P[vb]?0:l).attr("y",P[vb]?l:0).attr("width",P[vb]?M.width:m).attr("height",P[vb]?m:M.height),u()})}),M.mapToIds(M.data.targets).forEach(function(a){M.withoutFadeIn[a]=!0}),M.updateZoom&&M.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&N.select(this).style("display",b%K?"none":"block")})}else L.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!O[vb]&&O[Hb]&&L.rotateTickText(L.axes.x,b.axisX,O[Hb]),y=L.generateDrawArea(P,!1),A=L.generateDrawBar(Q),B=L.generateDrawLine(R,!1),C=L.generateXYForText(Q,!0),D=L.generateXYForText(Q,!1),L.subY.domain(L.y.domain()),L.subY2.domain(L.y2.domain()),L.tooltip.style("display","none"),L.updateXgridFocus(),M.select("text."+pe[Nd]+"."+pe[Md]).attr("x",L.width/2).attr("y",L.height/2).text(O[fb]).transition().style("opacity",T.length?0:1),L.redrawGrid(E,m),L.redrawRegion(E),f=M.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(L.barData,L)),f.enter().append("path").attr("class",De(L.classBar,L)).style("stroke",function(a){return L.color(a.id)}).style("fill",function(a){return L.color(a.id)}),f.style("opacity",De(L.initialOpacity,L)),f.exit().transition().duration(F).style("opacity",0).remove(),c=M.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(L.lineData,L)),c.enter().append("path").attr("class",De(L.classLine,L)).style("stroke",L.color),c.style("opacity",De(L.initialOpacity,L)).attr("transform",null),c.exit().transition().duration(F).style("opacity",0).remove(),d=M.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(L.lineData,L)),d.enter().append("path").attr("class",De(L.classArea,L)).style("fill",L.color).style("opacity",function(){return L.orgAreaOpacity=+N.select(this).style("opacity"),0}),d.style("opacity",L.orgAreaOpacity),d.exit().transition().duration(F).style("opacity",0).remove(),O[mc]&&(e=M.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(L.lineOrScatterData,L)),e.enter().append("circle").attr("class",De(L.classCircle,L)).attr("r",De(L.pointR,L)).style("fill",L.color),e.style("opacity",De(L.initialOpacity,L)),e.exit().remove()),L.hasDataLabel()&&(g=M.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(L.barOrLineData,L)),g.enter().append("text").attr("class",De(L.classText,L)).attr("text-anchor",function(a){return O[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return L.color(a)}).style("fill-opacity",0),g.text(function(a){return L.formatByAxisId(L.getAxisId(a.id))(a.value,a.id)}),g.exit().transition().duration(F).style("fill-opacity",0).remove()),L.redrawArc&&L.redrawArc(E,F,t),L.redrawSubchart&&L.redrawSubchart(n,b,E,F,P,Q,R),M.selectAll("."+pe[od]).filter(De(L.isBarType,L)).selectAll("circle").remove(),O[s]&&(h=M.select("."+pe[qd]).style("cursor",O[o]?O[vb]?"ns-resize":"ew-resize":null),ze(O[z])&&!L.isSingleX(O[z])?(h.classed(pe[sd])||h.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),i=M.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),L.generateEventRectsForMultipleXs(i.enter()),i.attr("x",0).attr("y",0).attr("width",L.width).attr("height",L.height)):(h.classed(pe[rd])||h.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!L.isCustomX()&&!L.isTimeSeries()||L.isCategorized()?(l=L.getEventRectWidth(),k=function(a){return L.x(a.x)-l/2}):(l=function(a){var b=L.getPrevX(a.index),c=L.getNextX(a.index),d=L.data.xs[a.id][a.index],e=(L.x(c?c:d)-L.x(b?b:d))/2;return 0>e?0:e},k=function(a){var b=L.getPrevX(a.index),c=L.data.xs[a.id][a.index];return(L.x(c)+L.x(b?b:c))/2}),j=L.getMaxDataCountTarget(L.data.targets),M.select("."+pe[qd]).datum(j?j.values:[]),i=M.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),L.generateEventRectsForSingleX(i.enter()),i.attr("class",De(L.classEvent,L)).attr("x",O[vb]?0:k).attr("y",O[vb]?k:0).attr("width",O[vb]?L.width:l).attr("height",O[vb]?l:L.height),i.exit().remove())),N.transition().duration(E).each(function(){var b=[];b.push(f.transition().attr("d",A).style("fill",L.color).style("opacity",1)),b.push(c.transition().attr("d",B).style("stroke",L.color).style("opacity",1)),b.push(d.transition().attr("d",y).style("fill",L.color).style("opacity",L.orgAreaOpacity)),b.push(e.transition().style("opacity",De(L.opacityForCircle,L)).style("fill",L.color).attr("cx",V).attr("cy",W)),b.push(M.selectAll("."+pe[nd]).transition().attr("cx",V).attr("cy",W)),b.push(g.transition().attr("x",C).attr("y",D).style("fill",L.color).style("fill-opacity",a.flow?0:De(L.opacityForText,L))),L.addTransitionForRegion(b),L.addTransitionForGrid(b),a.flow&&(H=L.generateWait(),b.forEach(function(a){H.add(a)}))}).call(H?H:function(){},function(){var b,h,j,m=1,n=a.flow.index,o=a.flow.length,p=L.getValueOnIndex(L.data.targets[0].values,n),q=L.getValueOnIndex(L.data.targets[0].values,n+o),r=L.x.domain(),s=a.flow.duration||E,t=a.flow.done||function(){},u=L.generateWait(),v=L.xgrid||N.selectAll([]),w=L.xgridLines||N.selectAll([]),x=L.mainRegion||N.selectAll([]);L.data.targets.forEach(function(a){a.values.splice(0,o)}),j=L.updateXDomain(T,!0,!0),L.updateXGrid&&L.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||p.x===q.x?L.x(r[0])-L.x(j[0]):L.isTimeSeries()?L.x(r[0])-L.x(j[0]):L.x(p.x)-L.x(q.x):1!==L.data.targets[0].values.length?b=L.x(r[0])-L.x(j[0]):L.isTimeSeries()?(p=L.getValueOnIndex(L.data.targets[0].values,0),q=L.getValueOnIndex(L.data.targets[0].values,L.data.targets[0].values.length-1),b=L.x(p.x)-L.x(q.x)):b=xe(j)/2,m=xe(r)/xe(j),h="translate("+b+",0) scale("+m+",1)",N.transition().ease("linear").duration(s).each(function(){u.add(L.axes.x.transition().call(L.xAxis)),u.add(f.transition().attr("transform",h)),u.add(c.transition().attr("transform",h)),u.add(d.transition().attr("transform",h)),u.add(e.transition().attr("transform",h)),u.add(g.transition().attr("transform",h)),u.add(x.filter(L.isRegionOnX).transition().attr("transform",h)),u.add(v.transition().attr("transform",h)),u.add(w.transition().attr("transform",h))}).call(u,function(){var a,b=[],h=[],j=[];if(o){for(a=0;o>a;a++)b.push("."+pe[Ad]+"-"+(n+a)),h.push("."+pe[Nd]+"-"+(n+a)),j.push("."+pe[pd]+"-"+(n+a));L.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),L.svg.selectAll("."+pe[Od]).selectAll(h).remove(),L.svg.selectAll("."+pe[qd]).selectAll(j).remove(),L.svg.select("."+pe[Rd]).remove()}v.attr("transform",null).attr(L.xgridAttr),w.attr("transform",null),w.select("line").attr("x1",O[vb]?0:U).attr("x2",O[vb]?L.width:U),w.select("text").attr("x",O[vb]?L.width:0).attr("y",U),f.attr("transform",null).attr("d",A),c.attr("transform",null).attr("d",B),d.attr("transform",null).attr("d",y),e.attr("transform",null).attr("cx",V).attr("cy",W),g.attr("transform",null).attr("x",C).attr("y",D).style("fill-opacity",De(L.opacityForText,L)),x.attr("transform",null),x.select("rect").filter(L.isRegionOnX).attr("x",De(L.regionX,L)).attr("width",De(L.regionWidth,L)),i.attr("x",O[vb]?0:k).attr("y",O[vb]?k:0).attr("width",O[vb]?L.width:l).attr("height",O[vb]?l:L.height),t()})}),L.mapToIds(L.data.targets).forEach(function(a){L.withoutFadeIn[a]=!0}),L.updateZoom&&L.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" },a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b -}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +},o=l[Vc]||c;for(f=0;f"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b) +},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 8f301f2..541da1e 100644 --- a/src/core.js +++ b/src/core.js @@ -209,9 +209,7 @@ c3_chart_internal_fn.initWithData = function (data) { .attr("dominant-baseline", "middle"); // vertical centering of text at y position in all browsers, except IE. // Regions - main.append('g') - .attr("clip-path", $$.clipPath) - .attr("class", CLASS[_regions]); + $$.initRegion(); // Grids $$.initGrid(); @@ -448,7 +446,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, mainRegion, mainText, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -565,15 +563,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.redrawGrid(duration, withY); // rect for regions - mainRegion = main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) - .data(config[__regions]); - mainRegion.enter().append('g') - .attr('class', generateCall($$.classRegion, $$)) - .append('rect') - .style("fill-opacity", 0); - mainRegion.exit().transition().duration(duration) - .style("opacity", 0) - .remove(); + $$.redrawRegion(duration); // bars mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) @@ -751,12 +741,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .attr('y', yForText) .style("fill", $$.color) .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); - transitions.push(mainRegion.selectAll('rect').transition() - .attr("x", generateCall($$.regionX, $$)) - .attr("y", generateCall($$.regionY, $$)) - .attr("width", generateCall($$.regionWidth, $$)) - .attr("height", generateCall($$.regionHeight, $$)) - .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); + $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); // Wait for end of transitions if called from flow API @@ -779,7 +764,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { wait = $$.generateWait(); var xgrid = $$.xgrid || d3.selectAll([]), - xgridLines = $$.xgridLines || d3.selectAll([]); + xgridLines = $$.xgridLines || d3.selectAll([]), + mainRegion = $$.mainRegion || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { diff --git a/src/region.js b/src/region.js index 1587fa3..d1ff972 100644 --- a/src/region.js +++ b/src/region.js @@ -1,3 +1,30 @@ +c3_chart_internal_fn.initRegion = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.append('g') + .attr("clip-path", $$.clipPath) + .attr("class", CLASS[_regions]); +}; +c3_chart_internal_fn.redrawRegion = function (duration) { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) + .data(config[__regions]); + $$.mainRegion.enter().append('g') + .attr('class', generateCall($$.classRegion, $$)) + .append('rect') + .style("fill-opacity", 0); + $$.mainRegion.exit().transition().duration(duration) + .style("opacity", 0) + .remove(); +}; +c3_chart_internal_fn.addTransitionForRegion = function (transitions) { + var $$ = this; + transitions.push($$.mainRegion.selectAll('rect').transition() + .attr("x", generateCall($$.regionX, $$)) + .attr("y", generateCall($$.regionY, $$)) + .attr("width", generateCall($$.regionWidth, $$)) + .attr("height", generateCall($$.regionHeight, $$)) + .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); +}; c3_chart_internal_fn.regionX = function (d) { var $$ = this, config = $$.config, xPos, yScale = d.axis === 'y' ? $$.y : $$.y2; From 55c1a2af6a410d26983f5b6a47e224f0fa2a4c3f Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 21:26:40 +0900 Subject: [PATCH 35/44] Modularize text --- c3.js | 89 +++++++++++++++++++++++++++++++++-------------------- c3.min.js | 8 ++--- src/core.js | 44 ++++++-------------------- src/text.js | 45 +++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 72 deletions(-) diff --git a/c3.js b/c3.js index 93388ec..8b6a4c9 100644 --- a/c3.js +++ b/c3.js @@ -241,8 +241,8 @@ if ($$.initArc) { $$.initArc(); } if ($$.initGauge) { $$.initGauge(); } - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartTexts]); + // Define g for text area + if ($$.initText) { $$.initText(); } // if zoom privileged, insert rect to forefront // TODO: is this needed? @@ -380,21 +380,13 @@ }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) - .data(targets) - .attr('class', generateCall($$.classChartText, $$)); - mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', generateCall($$.classChartText, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - mainTextEnter.append('g') - .attr('class', generateCall($$.classTexts, $$)); + $$.updateTargetsForText(targets); //-- Bar --// mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) @@ -451,7 +443,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, mainBar, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -463,7 +455,7 @@ cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - mainCircle = mainText = d3.selectAll([]); + mainCircle = d3.selectAll([]); options = options || {}; withY = getOption(options, "withY", true); @@ -621,20 +613,7 @@ } if ($$.hasDataLabel()) { - mainText = main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) - .data(generateCall($$.barOrLineData, $$)); - mainText.enter().append('text') - .attr("class", generateCall($$.classText, $$)) - .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) - .style("stroke", 'none') - .style("fill", function (d) { return $$.color(d); }) - .style("fill-opacity", 0); - mainText - .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); - mainText.exit() - .transition().duration(durationForExit) - .style('fill-opacity', 0) - .remove(); + $$.redrawText(durationForExit); } // arc @@ -741,11 +720,7 @@ transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); - transitions.push(mainText.transition() - .attr('x', xForText) - .attr('y', yForText) - .style("fill", $$.color) - .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); + $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -770,7 +745,8 @@ var xgrid = $$.xgrid || d3.selectAll([]), xgridLines = $$.xgridLines || d3.selectAll([]), - mainRegion = $$.mainRegion || d3.selectAll([]); + mainRegion = $$.mainRegion || d3.selectAll([]), + mainText = $$.mainText || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -3104,6 +3080,51 @@ return false; }; + c3_chart_internal_fn.initText = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartTexts]); + $$.mainText = $$.d3.selectAll([]); + }; + c3_chart_internal_fn.updateTargetsForText = function (targets) { + var $$ = this, CLASS = $$.CLASS, mainTextUpdate, mainTextEnter, + classChartText = $$.classChartText.bind($$), + classTexts = $$.classTexts.bind($$); + mainTextUpdate = $$.main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) + .data(targets) + .attr('class', classChartText); + mainTextEnter = mainTextUpdate.enter().append('g') + .attr('class', classChartText) + .style('opacity', 0) + .style("pointer-events", "none"); + mainTextEnter.append('g') + .attr('class', classTexts); + }; + c3_chart_internal_fn.redrawText = function (durationForExit) { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.mainText = $$.main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) + .data(generateCall($$.barOrLineData, $$)); + $$.mainText.enter().append('text') + .attr("class", generateCall($$.classText, $$)) + .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .style("stroke", 'none') + .style("fill", function (d) { return $$.color(d); }) + .style("fill-opacity", 0); + $$.mainText + .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); + $$.mainText.exit() + .transition().duration(durationForExit) + .style('fill-opacity', 0) + .remove(); + }; + c3_chart_internal_fn.addTransitionForText = function (transitions, xForText, yForText, forFlow) { + var $$ = this; + transitions.push($$.mainText.transition() + .attr('x', xForText) + .attr('y', yForText) + .style("fill", $$.color) + .style("fill-opacity", forFlow ? 0 : generateCall($$.opacityForText, $$))); + }; c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; this.d3.select('body').selectAll('.dummy') diff --git a/c3.min.js b/c3.min.js index b27dbeb..fee4f47 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&N.select(this).style("display",b%K?"none":"block")})}else L.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!O[vb]&&O[Hb]&&L.rotateTickText(L.axes.x,b.axisX,O[Hb]),y=L.generateDrawArea(P,!1),A=L.generateDrawBar(Q),B=L.generateDrawLine(R,!1),C=L.generateXYForText(Q,!0),D=L.generateXYForText(Q,!1),L.subY.domain(L.y.domain()),L.subY2.domain(L.y2.domain()),L.tooltip.style("display","none"),L.updateXgridFocus(),M.select("text."+pe[Nd]+"."+pe[Md]).attr("x",L.width/2).attr("y",L.height/2).text(O[fb]).transition().style("opacity",T.length?0:1),L.redrawGrid(E,m),L.redrawRegion(E),f=M.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(L.barData,L)),f.enter().append("path").attr("class",De(L.classBar,L)).style("stroke",function(a){return L.color(a.id)}).style("fill",function(a){return L.color(a.id)}),f.style("opacity",De(L.initialOpacity,L)),f.exit().transition().duration(F).style("opacity",0).remove(),c=M.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(L.lineData,L)),c.enter().append("path").attr("class",De(L.classLine,L)).style("stroke",L.color),c.style("opacity",De(L.initialOpacity,L)).attr("transform",null),c.exit().transition().duration(F).style("opacity",0).remove(),d=M.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(L.lineData,L)),d.enter().append("path").attr("class",De(L.classArea,L)).style("fill",L.color).style("opacity",function(){return L.orgAreaOpacity=+N.select(this).style("opacity"),0}),d.style("opacity",L.orgAreaOpacity),d.exit().transition().duration(F).style("opacity",0).remove(),O[mc]&&(e=M.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(L.lineOrScatterData,L)),e.enter().append("circle").attr("class",De(L.classCircle,L)).attr("r",De(L.pointR,L)).style("fill",L.color),e.style("opacity",De(L.initialOpacity,L)),e.exit().remove()),L.hasDataLabel()&&(g=M.selectAll("."+pe[Od]).selectAll("."+pe[Nd]).data(De(L.barOrLineData,L)),g.enter().append("text").attr("class",De(L.classText,L)).attr("text-anchor",function(a){return O[vb]?a.value<0?"end":"start":"middle"}).style("stroke","none").style("fill",function(a){return L.color(a)}).style("fill-opacity",0),g.text(function(a){return L.formatByAxisId(L.getAxisId(a.id))(a.value,a.id)}),g.exit().transition().duration(F).style("fill-opacity",0).remove()),L.redrawArc&&L.redrawArc(E,F,t),L.redrawSubchart&&L.redrawSubchart(n,b,E,F,P,Q,R),M.selectAll("."+pe[od]).filter(De(L.isBarType,L)).selectAll("circle").remove(),O[s]&&(h=M.select("."+pe[qd]).style("cursor",O[o]?O[vb]?"ns-resize":"ew-resize":null),ze(O[z])&&!L.isSingleX(O[z])?(h.classed(pe[sd])||h.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),i=M.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),L.generateEventRectsForMultipleXs(i.enter()),i.attr("x",0).attr("y",0).attr("width",L.width).attr("height",L.height)):(h.classed(pe[rd])||h.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!L.isCustomX()&&!L.isTimeSeries()||L.isCategorized()?(l=L.getEventRectWidth(),k=function(a){return L.x(a.x)-l/2}):(l=function(a){var b=L.getPrevX(a.index),c=L.getNextX(a.index),d=L.data.xs[a.id][a.index],e=(L.x(c?c:d)-L.x(b?b:d))/2;return 0>e?0:e},k=function(a){var b=L.getPrevX(a.index),c=L.data.xs[a.id][a.index];return(L.x(c)+L.x(b?b:c))/2}),j=L.getMaxDataCountTarget(L.data.targets),M.select("."+pe[qd]).datum(j?j.values:[]),i=M.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),L.generateEventRectsForSingleX(i.enter()),i.attr("class",De(L.classEvent,L)).attr("x",O[vb]?0:k).attr("y",O[vb]?k:0).attr("width",O[vb]?L.width:l).attr("height",O[vb]?l:L.height),i.exit().remove())),N.transition().duration(E).each(function(){var b=[];b.push(f.transition().attr("d",A).style("fill",L.color).style("opacity",1)),b.push(c.transition().attr("d",B).style("stroke",L.color).style("opacity",1)),b.push(d.transition().attr("d",y).style("fill",L.color).style("opacity",L.orgAreaOpacity)),b.push(e.transition().style("opacity",De(L.opacityForCircle,L)).style("fill",L.color).attr("cx",V).attr("cy",W)),b.push(M.selectAll("."+pe[nd]).transition().attr("cx",V).attr("cy",W)),b.push(g.transition().attr("x",C).attr("y",D).style("fill",L.color).style("fill-opacity",a.flow?0:De(L.opacityForText,L))),L.addTransitionForRegion(b),L.addTransitionForGrid(b),a.flow&&(H=L.generateWait(),b.forEach(function(a){H.add(a)}))}).call(H?H:function(){},function(){var b,h,j,m=1,n=a.flow.index,o=a.flow.length,p=L.getValueOnIndex(L.data.targets[0].values,n),q=L.getValueOnIndex(L.data.targets[0].values,n+o),r=L.x.domain(),s=a.flow.duration||E,t=a.flow.done||function(){},u=L.generateWait(),v=L.xgrid||N.selectAll([]),w=L.xgridLines||N.selectAll([]),x=L.mainRegion||N.selectAll([]);L.data.targets.forEach(function(a){a.values.splice(0,o)}),j=L.updateXDomain(T,!0,!0),L.updateXGrid&&L.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||p.x===q.x?L.x(r[0])-L.x(j[0]):L.isTimeSeries()?L.x(r[0])-L.x(j[0]):L.x(p.x)-L.x(q.x):1!==L.data.targets[0].values.length?b=L.x(r[0])-L.x(j[0]):L.isTimeSeries()?(p=L.getValueOnIndex(L.data.targets[0].values,0),q=L.getValueOnIndex(L.data.targets[0].values,L.data.targets[0].values.length-1),b=L.x(p.x)-L.x(q.x)):b=xe(j)/2,m=xe(r)/xe(j),h="translate("+b+",0) scale("+m+",1)",N.transition().ease("linear").duration(s).each(function(){u.add(L.axes.x.transition().call(L.xAxis)),u.add(f.transition().attr("transform",h)),u.add(c.transition().attr("transform",h)),u.add(d.transition().attr("transform",h)),u.add(e.transition().attr("transform",h)),u.add(g.transition().attr("transform",h)),u.add(x.filter(L.isRegionOnX).transition().attr("transform",h)),u.add(v.transition().attr("transform",h)),u.add(w.transition().attr("transform",h))}).call(u,function(){var a,b=[],h=[],j=[];if(o){for(a=0;o>a;a++)b.push("."+pe[Ad]+"-"+(n+a)),h.push("."+pe[Nd]+"-"+(n+a)),j.push("."+pe[pd]+"-"+(n+a));L.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),L.svg.selectAll("."+pe[Od]).selectAll(h).remove(),L.svg.selectAll("."+pe[qd]).selectAll(j).remove(),L.svg.select("."+pe[Rd]).remove()}v.attr("transform",null).attr(L.xgridAttr),w.attr("transform",null),w.select("line").attr("x1",O[vb]?0:U).attr("x2",O[vb]?L.width:U),w.select("text").attr("x",O[vb]?L.width:0).attr("y",U),f.attr("transform",null).attr("d",A),c.attr("transform",null).attr("d",B),d.attr("transform",null).attr("d",y),e.attr("transform",null).attr("cx",V).attr("cy",W),g.attr("transform",null).attr("x",C).attr("y",D).style("fill-opacity",De(L.opacityForText,L)),x.attr("transform",null),x.select("rect").filter(L.isRegionOnX).attr("x",De(L.regionX,L)).attr("width",De(L.regionWidth,L)),i.attr("x",O[vb]?0:k).attr("y",O[vb]?k:0).attr("width",O[vb]?L.width:l).attr("height",O[vb]?l:L.height),t()})}),L.mapToIds(L.data.targets).forEach(function(a){L.withoutFadeIn[a]=!0}),L.updateZoom&&L.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):"" -},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b) -},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&M.select(this).style("display",b%J?"none":"block")})}else K.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!N[vb]&&N[Hb]&&K.rotateTickText(K.axes.x,b.axisX,N[Hb]),w=K.generateDrawArea(O,!1),y=K.generateDrawBar(P),A=K.generateDrawLine(Q,!1),B=K.generateXYForText(P,!0),C=K.generateXYForText(P,!1),K.subY.domain(K.y.domain()),K.subY2.domain(K.y2.domain()),K.tooltip.style("display","none"),K.updateXgridFocus(),L.select("text."+pe[Nd]+"."+pe[Md]).attr("x",K.width/2).attr("y",K.height/2).text(N[fb]).transition().style("opacity",S.length?0:1),K.redrawGrid(D,l),K.redrawRegion(D),f=L.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(K.barData,K)),f.enter().append("path").attr("class",De(K.classBar,K)).style("stroke",function(a){return K.color(a.id)}).style("fill",function(a){return K.color(a.id)}),f.style("opacity",De(K.initialOpacity,K)),f.exit().transition().duration(E).style("opacity",0).remove(),c=L.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(K.lineData,K)),c.enter().append("path").attr("class",De(K.classLine,K)).style("stroke",K.color),c.style("opacity",De(K.initialOpacity,K)).attr("transform",null),c.exit().transition().duration(E).style("opacity",0).remove(),d=L.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(K.lineData,K)),d.enter().append("path").attr("class",De(K.classArea,K)).style("fill",K.color).style("opacity",function(){return K.orgAreaOpacity=+M.select(this).style("opacity"),0}),d.style("opacity",K.orgAreaOpacity),d.exit().transition().duration(E).style("opacity",0).remove(),N[mc]&&(e=L.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(K.lineOrScatterData,K)),e.enter().append("circle").attr("class",De(K.classCircle,K)).attr("r",De(K.pointR,K)).style("fill",K.color),e.style("opacity",De(K.initialOpacity,K)),e.exit().remove()),K.hasDataLabel()&&K.redrawText(E),K.redrawArc&&K.redrawArc(D,E,r),K.redrawSubchart&&K.redrawSubchart(m,b,D,E,O,P,Q),L.selectAll("."+pe[od]).filter(De(K.isBarType,K)).selectAll("circle").remove(),N[s]&&(g=L.select("."+pe[qd]).style("cursor",N[o]?N[vb]?"ns-resize":"ew-resize":null),ze(N[z])&&!K.isSingleX(N[z])?(g.classed(pe[sd])||g.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),h=L.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),K.generateEventRectsForMultipleXs(h.enter()),h.attr("x",0).attr("y",0).attr("width",K.width).attr("height",K.height)):(g.classed(pe[rd])||g.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!K.isCustomX()&&!K.isTimeSeries()||K.isCategorized()?(k=K.getEventRectWidth(),j=function(a){return K.x(a.x)-k/2}):(k=function(a){var b=K.getPrevX(a.index),c=K.getNextX(a.index),d=K.data.xs[a.id][a.index],e=(K.x(c?c:d)-K.x(b?b:d))/2;return 0>e?0:e},j=function(a){var b=K.getPrevX(a.index),c=K.data.xs[a.id][a.index];return(K.x(c)+K.x(b?b:c))/2}),i=K.getMaxDataCountTarget(K.data.targets),L.select("."+pe[qd]).datum(i?i.values:[]),h=L.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),K.generateEventRectsForSingleX(h.enter()),h.attr("class",De(K.classEvent,K)).attr("x",N[vb]?0:j).attr("y",N[vb]?j:0).attr("width",N[vb]?K.width:k).attr("height",N[vb]?k:K.height),h.exit().remove())),M.transition().duration(D).each(function(){var b=[];b.push(f.transition().attr("d",y).style("fill",K.color).style("opacity",1)),b.push(c.transition().attr("d",A).style("stroke",K.color).style("opacity",1)),b.push(d.transition().attr("d",w).style("fill",K.color).style("opacity",K.orgAreaOpacity)),b.push(e.transition().style("opacity",De(K.opacityForCircle,K)).style("fill",K.color).attr("cx",U).attr("cy",V)),b.push(L.selectAll("."+pe[nd]).transition().attr("cx",U).attr("cy",V)),K.addTransitionForText(b,B,C,a.flow),K.addTransitionForRegion(b),K.addTransitionForGrid(b),a.flow&&(G=K.generateWait(),b.forEach(function(a){G.add(a)}))}).call(G?G:function(){},function(){var b,g,i,l=1,m=a.flow.index,n=a.flow.length,o=K.getValueOnIndex(K.data.targets[0].values,m),p=K.getValueOnIndex(K.data.targets[0].values,m+n),q=K.x.domain(),r=a.flow.duration||D,s=a.flow.done||function(){},t=K.generateWait(),u=K.xgrid||M.selectAll([]),v=K.xgridLines||M.selectAll([]),x=K.mainRegion||M.selectAll([]),z=K.mainText||M.selectAll([]);K.data.targets.forEach(function(a){a.values.splice(0,n)}),i=K.updateXDomain(S,!0,!0),K.updateXGrid&&K.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===p.x?K.x(q[0])-K.x(i[0]):K.isTimeSeries()?K.x(q[0])-K.x(i[0]):K.x(o.x)-K.x(p.x):1!==K.data.targets[0].values.length?b=K.x(q[0])-K.x(i[0]):K.isTimeSeries()?(o=K.getValueOnIndex(K.data.targets[0].values,0),p=K.getValueOnIndex(K.data.targets[0].values,K.data.targets[0].values.length-1),b=K.x(o.x)-K.x(p.x)):b=xe(i)/2,l=xe(q)/xe(i),g="translate("+b+",0) scale("+l+",1)",M.transition().ease("linear").duration(r).each(function(){t.add(K.axes.x.transition().call(K.xAxis)),t.add(f.transition().attr("transform",g)),t.add(c.transition().attr("transform",g)),t.add(d.transition().attr("transform",g)),t.add(e.transition().attr("transform",g)),t.add(z.transition().attr("transform",g)),t.add(x.filter(K.isRegionOnX).transition().attr("transform",g)),t.add(u.transition().attr("transform",g)),t.add(v.transition().attr("transform",g))}).call(t,function(){var a,b=[],g=[],i=[];if(n){for(a=0;n>a;a++)b.push("."+pe[Ad]+"-"+(m+a)),g.push("."+pe[Nd]+"-"+(m+a)),i.push("."+pe[pd]+"-"+(m+a));K.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),K.svg.selectAll("."+pe[Od]).selectAll(g).remove(),K.svg.selectAll("."+pe[qd]).selectAll(i).remove(),K.svg.select("."+pe[Rd]).remove()}u.attr("transform",null).attr(K.xgridAttr),v.attr("transform",null),v.select("line").attr("x1",N[vb]?0:T).attr("x2",N[vb]?K.width:T),v.select("text").attr("x",N[vb]?K.width:0).attr("y",T),f.attr("transform",null).attr("d",y),c.attr("transform",null).attr("d",A),d.attr("transform",null).attr("d",w),e.attr("transform",null).attr("cx",U).attr("cy",V),z.attr("transform",null).attr("x",B).attr("y",C).style("fill-opacity",De(K.opacityForText,K)),x.attr("transform",null),x.select("rect").filter(K.isRegionOnX).attr("x",De(K.regionX,K)).attr("width",De(K.regionWidth,K)),h.attr("x",N[vb]?0:j).attr("y",N[vb]?j:0).attr("width",N[vb]?K.width:k).attr("height",N[vb]?k:K.height),s()})}),K.mapToIds(K.data.targets).forEach(function(a){K.withoutFadeIn[a]=!0}),K.updateZoom&&K.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a); +return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a) +},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 541da1e..57a002d 100644 --- a/src/core.js +++ b/src/core.js @@ -236,8 +236,8 @@ c3_chart_internal_fn.initWithData = function (data) { if ($$.initArc) { $$.initArc(); } if ($$.initGauge) { $$.initGauge(); } - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartTexts]); + // Define g for text area + if ($$.initText) { $$.initText(); } // if zoom privileged, insert rect to forefront // TODO: is this needed? @@ -375,21 +375,13 @@ c3_chart_internal_fn.updateSizes = function () { }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate, mainTextUpdate, mainTextEnter; + var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ //-- Text --// - mainTextUpdate = main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) - .data(targets) - .attr('class', generateCall($$.classChartText, $$)); - mainTextEnter = mainTextUpdate.enter().append('g') - .attr('class', generateCall($$.classChartText, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - mainTextEnter.append('g') - .attr('class', generateCall($$.classTexts, $$)); + $$.updateTargetsForText(targets); //-- Bar --// mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) @@ -446,7 +438,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, mainText, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, mainBar, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -458,7 +450,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - mainCircle = mainText = d3.selectAll([]); + mainCircle = d3.selectAll([]); options = options || {}; withY = getOption(options, "withY", true); @@ -616,20 +608,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { } if ($$.hasDataLabel()) { - mainText = main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) - .data(generateCall($$.barOrLineData, $$)); - mainText.enter().append('text') - .attr("class", generateCall($$.classText, $$)) - .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) - .style("stroke", 'none') - .style("fill", function (d) { return $$.color(d); }) - .style("fill-opacity", 0); - mainText - .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); - mainText.exit() - .transition().duration(durationForExit) - .style('fill-opacity', 0) - .remove(); + $$.redrawText(durationForExit); } // arc @@ -736,11 +715,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); - transitions.push(mainText.transition() - .attr('x', xForText) - .attr('y', yForText) - .style("fill", $$.color) - .style("fill-opacity", options.flow ? 0 : generateCall($$.opacityForText, $$))); + $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -765,7 +740,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var xgrid = $$.xgrid || d3.selectAll([]), xgridLines = $$.xgridLines || d3.selectAll([]), - mainRegion = $$.mainRegion || d3.selectAll([]); + mainRegion = $$.mainRegion || d3.selectAll([]), + mainText = $$.mainText || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { diff --git a/src/text.js b/src/text.js index 0aa6e62..45ec347 100644 --- a/src/text.js +++ b/src/text.js @@ -1,3 +1,48 @@ +c3_chart_internal_fn.initText = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartTexts]); + $$.mainText = $$.d3.selectAll([]); +}; +c3_chart_internal_fn.updateTargetsForText = function (targets) { + var $$ = this, CLASS = $$.CLASS, mainTextUpdate, mainTextEnter, + classChartText = $$.classChartText.bind($$), + classTexts = $$.classTexts.bind($$); + mainTextUpdate = $$.main.select('.' + CLASS[_chartTexts]).selectAll('.' + CLASS[_chartText]) + .data(targets) + .attr('class', classChartText); + mainTextEnter = mainTextUpdate.enter().append('g') + .attr('class', classChartText) + .style('opacity', 0) + .style("pointer-events", "none"); + mainTextEnter.append('g') + .attr('class', classTexts); +}; +c3_chart_internal_fn.redrawText = function (durationForExit) { + var $$ = this, config = $$.config, CLASS = $$.CLASS; + $$.mainText = $$.main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) + .data(generateCall($$.barOrLineData, $$)); + $$.mainText.enter().append('text') + .attr("class", generateCall($$.classText, $$)) + .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) + .style("stroke", 'none') + .style("fill", function (d) { return $$.color(d); }) + .style("fill-opacity", 0); + $$.mainText + .text(function (d) { return $$.formatByAxisId($$.getAxisId(d.id))(d.value, d.id); }); + $$.mainText.exit() + .transition().duration(durationForExit) + .style('fill-opacity', 0) + .remove(); +}; +c3_chart_internal_fn.addTransitionForText = function (transitions, xForText, yForText, forFlow) { + var $$ = this; + transitions.push($$.mainText.transition() + .attr('x', xForText) + .attr('y', yForText) + .style("fill", $$.color) + .style("fill-opacity", forFlow ? 0 : generateCall($$.opacityForText, $$))); +}; c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; this.d3.select('body').selectAll('.dummy') From 5ef894aacf9ed7015540c9027197bd481080944e Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 21:59:18 +0900 Subject: [PATCH 36/44] Modularize bar --- Gruntfile.coffee | 1 + c3.js | 224 ++++++++++++++++++++++++++--------------------- c3.min.js | 8 +- src/core.js | 41 ++------- src/shape.bar.js | 114 ++++++++++++++++++++++++ src/shape.js | 70 --------------- 6 files changed, 251 insertions(+), 207 deletions(-) create mode 100644 src/shape.bar.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index b48e006..350f035 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -29,6 +29,7 @@ module.exports = (grunt) -> 'src/category.js', 'src/size.js', 'src/shape.js', + 'src/shape.bar.js', 'src/text.js', 'src/type.js', 'src/grid.js', diff --git a/c3.js b/c3.js index 8b6a4c9..44bd6e2 100644 --- a/c3.js +++ b/c3.js @@ -230,8 +230,7 @@ .style('fill-opacity', 0); // Define g for bar chart area - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartBars]); + if ($$.initBar) { $$.initBar(); } // Define g for line chart area main.select('.' + CLASS[_chart]).append("g") @@ -380,7 +379,7 @@ }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate; + var mainLineEnter, mainLineUpdate; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ @@ -389,17 +388,7 @@ $$.updateTargetsForText(targets); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) - .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); - mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', generateCall($$.classChartBar, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - // Bars for each data - mainBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)) - .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + $$.updateTargetsForBar(targets); //-- Line --// mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) @@ -443,7 +432,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -533,7 +522,7 @@ // setup drawer - MEMO: these must be called after axis updated drawArea = $$.generateDrawArea(areaIndices, false); - drawBar = $$.generateDrawBar(barIndices); + drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined; drawLine = $$.generateDrawLine(lineIndices, false); xForText = $$.generateXYForText(barIndices, true); yForText = $$.generateXYForText(barIndices, false); @@ -563,17 +552,7 @@ $$.redrawRegion(duration); // bars - mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); - mainBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) - .style("stroke", function (d) { return $$.color(d.id); }) - .style("fill", function (d) { return $$.color(d.id); }); - mainBar - .style("opacity", generateCall($$.initialOpacity, $$)); - mainBar.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); + $$.redrawBar(durationForExit); // lines, areas and cricles mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) @@ -700,10 +679,7 @@ d3.transition().duration(duration).each(function () { var transitions = []; - transitions.push(mainBar.transition() - .attr('d', drawBar) - .style("fill", $$.color) - .style("opacity", 1)); + $$.addTransitionForBar(transitions, drawBar); transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) @@ -746,7 +722,8 @@ var xgrid = $$.xgrid || d3.selectAll([]), xgridLines = $$.xgridLines || d3.selectAll([]), mainRegion = $$.mainRegion || d3.selectAll([]), - mainText = $$.mainText || d3.selectAll([]); + mainText = $$.mainText || d3.selectAll([]), + mainBar = $$.mainBar || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -2785,68 +2762,6 @@ - c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { - var $$ = this, config = $$.config, - w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; - return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; - }; - c3_chart_internal_fn.getBars = function (i) { - var $$ = this; - return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); - }; - c3_chart_internal_fn.expandBars = function (i) { - var $$ = this; - $$.getBars(i).classed(CLASS[_EXPANDED], true); - }; - c3_chart_internal_fn.unexpandBars = function (i) { - var $$ = this; - $$.getBars(i).classed(CLASS[_EXPANDED], false); - }; - c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { - var $$ = this, config = $$.config, - getPoints = $$.generateGetBarPoints(barIndices, isSub); - return function (d, i) { - // 4 points that make a bar - var points = getPoints(d, i); - - // switch points if axis is rotated, not applicable for sub chart - var indexX = config[__axis_rotated] ? 1 : 0; - var indexY = config[__axis_rotated] ? 0 : 1; - - var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + - 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + - 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + - 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + - 'z'; - - return path; - }; - }; - c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { - var $$ = this, - barTargetsNum = barIndices.__max__ + 1, - barW = $$.getBarW($$.xAxis, barTargetsNum), - barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), - barY = $$.getShapeY(!!isSub), - barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), - yScale = isSub ? $$.getSubYScale : $$.getYScale; - return function (d, i) { - var y0 = yScale.call($$, d.id)(0), - offset = barOffset(d, i) || y0, // offset is for stacked bar chart - posX = barX(d), posY = barY(d); - // fix posY not to overflow opposite quadrant - if ($$.config[__axis_rotated]) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } - } - // 4 points that make a bar - return [ - [posX, offset], - [posX, posY - (y0 - offset)], - [posX + barW, posY - (y0 - offset)], - [posX + barW, offset] - ]; - }; - }; c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { var $$ = this, config = $$.config, area = $$.d3.svg.area(), @@ -3064,6 +2979,120 @@ cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; + c3_chart_internal_fn.isWithinRegions = function (x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; + }; + + c3_chart_internal_fn.initBar = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); + }; + c3_chart_internal_fn.updateTargetsForBar = function (targets) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + mainBarUpdate, mainBarEnter, + classChartBar = $$.classChartBar.bind($$), + classBars = $$.classBars.bind($$); + mainBarUpdate = $$.main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) + .data(targets) + .attr('class', classChartBar); + mainBarEnter = mainBarUpdate.enter().append('g') + .attr('class', classChartBar) + .style('opacity', 0) + .style("pointer-events", "none"); + // Bars for each data + mainBarEnter.append('g') + .attr("class", classBars) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + + }; + c3_chart_internal_fn.redrawBar = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS; + $$.mainBar = $$.main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) + .data(generateCall($$.barData, $$)); + $$.mainBar.enter().append('path') + .attr("class", generateCall($$.classBar, $$)) + .style("stroke", function (d) { return $$.color(d.id); }) + .style("fill", function (d) { return $$.color(d.id); }); + $$.mainBar + .style("opacity", generateCall($$.initialOpacity, $$)); + $$.mainBar.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + }; + c3_chart_internal_fn.addTransitionForBar = function (transitions, drawBar) { + var $$ = this; + transitions.push($$.mainBar.transition() + .attr('d', drawBar) + .style("fill", $$.color) + .style("opacity", 1)); + }; + c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { + var $$ = this, config = $$.config, + w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; + return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; + }; + c3_chart_internal_fn.getBars = function (i) { + var $$ = this; + return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); + }; + c3_chart_internal_fn.expandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], true); + }; + c3_chart_internal_fn.unexpandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], false); + }; + c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { + var $$ = this, config = $$.config, + getPoints = $$.generateGetBarPoints(barIndices, isSub); + return function (d, i) { + // 4 points that make a bar + var points = getPoints(d, i); + + // switch points if axis is rotated, not applicable for sub chart + var indexX = config[__axis_rotated] ? 1 : 0; + var indexY = config[__axis_rotated] ? 0 : 1; + + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + + 'z'; + + return path; + }; + }; + c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { + var $$ = this, + barTargetsNum = barIndices.__max__ + 1, + barW = $$.getBarW($$.xAxis, barTargetsNum), + barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = $$.getShapeY(!!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = barOffset(d, i) || y0, // offset is for stacked bar chart + posX = barX(d), posY = barY(d); + // fix posY not to overflow opposite quadrant + if ($$.config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 4 points that make a bar + return [ + [posX, offset], + [posX, posY - (y0 - offset)], + [posX + barW, posY - (y0 - offset)], + [posX + barW, offset] + ]; + }; + }; c3_chart_internal_fn.isWithinBar = function (_this) { var d3 = this.d3, mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), @@ -3072,13 +3101,6 @@ sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; }; - c3_chart_internal_fn.isWithinRegions = function (x, regions) { - var i; - for (i = 0; i < regions.length; i++) { - if (regions[i].start < x && x <= regions[i].end) { return true; } - } - return false; - }; c3_chart_internal_fn.initText = function () { var $$ = this, CLASS = $$.CLASS; diff --git a/c3.min.js b/c3.min.js index fee4f47..b9e6597 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&M.select(this).style("display",b%J?"none":"block")})}else K.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!N[vb]&&N[Hb]&&K.rotateTickText(K.axes.x,b.axisX,N[Hb]),w=K.generateDrawArea(O,!1),y=K.generateDrawBar(P),A=K.generateDrawLine(Q,!1),B=K.generateXYForText(P,!0),C=K.generateXYForText(P,!1),K.subY.domain(K.y.domain()),K.subY2.domain(K.y2.domain()),K.tooltip.style("display","none"),K.updateXgridFocus(),L.select("text."+pe[Nd]+"."+pe[Md]).attr("x",K.width/2).attr("y",K.height/2).text(N[fb]).transition().style("opacity",S.length?0:1),K.redrawGrid(D,l),K.redrawRegion(D),f=L.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(K.barData,K)),f.enter().append("path").attr("class",De(K.classBar,K)).style("stroke",function(a){return K.color(a.id)}).style("fill",function(a){return K.color(a.id)}),f.style("opacity",De(K.initialOpacity,K)),f.exit().transition().duration(E).style("opacity",0).remove(),c=L.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(K.lineData,K)),c.enter().append("path").attr("class",De(K.classLine,K)).style("stroke",K.color),c.style("opacity",De(K.initialOpacity,K)).attr("transform",null),c.exit().transition().duration(E).style("opacity",0).remove(),d=L.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(K.lineData,K)),d.enter().append("path").attr("class",De(K.classArea,K)).style("fill",K.color).style("opacity",function(){return K.orgAreaOpacity=+M.select(this).style("opacity"),0}),d.style("opacity",K.orgAreaOpacity),d.exit().transition().duration(E).style("opacity",0).remove(),N[mc]&&(e=L.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(K.lineOrScatterData,K)),e.enter().append("circle").attr("class",De(K.classCircle,K)).attr("r",De(K.pointR,K)).style("fill",K.color),e.style("opacity",De(K.initialOpacity,K)),e.exit().remove()),K.hasDataLabel()&&K.redrawText(E),K.redrawArc&&K.redrawArc(D,E,r),K.redrawSubchart&&K.redrawSubchart(m,b,D,E,O,P,Q),L.selectAll("."+pe[od]).filter(De(K.isBarType,K)).selectAll("circle").remove(),N[s]&&(g=L.select("."+pe[qd]).style("cursor",N[o]?N[vb]?"ns-resize":"ew-resize":null),ze(N[z])&&!K.isSingleX(N[z])?(g.classed(pe[sd])||g.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),h=L.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),K.generateEventRectsForMultipleXs(h.enter()),h.attr("x",0).attr("y",0).attr("width",K.width).attr("height",K.height)):(g.classed(pe[rd])||g.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!K.isCustomX()&&!K.isTimeSeries()||K.isCategorized()?(k=K.getEventRectWidth(),j=function(a){return K.x(a.x)-k/2}):(k=function(a){var b=K.getPrevX(a.index),c=K.getNextX(a.index),d=K.data.xs[a.id][a.index],e=(K.x(c?c:d)-K.x(b?b:d))/2;return 0>e?0:e},j=function(a){var b=K.getPrevX(a.index),c=K.data.xs[a.id][a.index];return(K.x(c)+K.x(b?b:c))/2}),i=K.getMaxDataCountTarget(K.data.targets),L.select("."+pe[qd]).datum(i?i.values:[]),h=L.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),K.generateEventRectsForSingleX(h.enter()),h.attr("class",De(K.classEvent,K)).attr("x",N[vb]?0:j).attr("y",N[vb]?j:0).attr("width",N[vb]?K.width:k).attr("height",N[vb]?k:K.height),h.exit().remove())),M.transition().duration(D).each(function(){var b=[];b.push(f.transition().attr("d",y).style("fill",K.color).style("opacity",1)),b.push(c.transition().attr("d",A).style("stroke",K.color).style("opacity",1)),b.push(d.transition().attr("d",w).style("fill",K.color).style("opacity",K.orgAreaOpacity)),b.push(e.transition().style("opacity",De(K.opacityForCircle,K)).style("fill",K.color).attr("cx",U).attr("cy",V)),b.push(L.selectAll("."+pe[nd]).transition().attr("cx",U).attr("cy",V)),K.addTransitionForText(b,B,C,a.flow),K.addTransitionForRegion(b),K.addTransitionForGrid(b),a.flow&&(G=K.generateWait(),b.forEach(function(a){G.add(a)}))}).call(G?G:function(){},function(){var b,g,i,l=1,m=a.flow.index,n=a.flow.length,o=K.getValueOnIndex(K.data.targets[0].values,m),p=K.getValueOnIndex(K.data.targets[0].values,m+n),q=K.x.domain(),r=a.flow.duration||D,s=a.flow.done||function(){},t=K.generateWait(),u=K.xgrid||M.selectAll([]),v=K.xgridLines||M.selectAll([]),x=K.mainRegion||M.selectAll([]),z=K.mainText||M.selectAll([]);K.data.targets.forEach(function(a){a.values.splice(0,n)}),i=K.updateXDomain(S,!0,!0),K.updateXGrid&&K.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||o.x===p.x?K.x(q[0])-K.x(i[0]):K.isTimeSeries()?K.x(q[0])-K.x(i[0]):K.x(o.x)-K.x(p.x):1!==K.data.targets[0].values.length?b=K.x(q[0])-K.x(i[0]):K.isTimeSeries()?(o=K.getValueOnIndex(K.data.targets[0].values,0),p=K.getValueOnIndex(K.data.targets[0].values,K.data.targets[0].values.length-1),b=K.x(o.x)-K.x(p.x)):b=xe(i)/2,l=xe(q)/xe(i),g="translate("+b+",0) scale("+l+",1)",M.transition().ease("linear").duration(r).each(function(){t.add(K.axes.x.transition().call(K.xAxis)),t.add(f.transition().attr("transform",g)),t.add(c.transition().attr("transform",g)),t.add(d.transition().attr("transform",g)),t.add(e.transition().attr("transform",g)),t.add(z.transition().attr("transform",g)),t.add(x.filter(K.isRegionOnX).transition().attr("transform",g)),t.add(u.transition().attr("transform",g)),t.add(v.transition().attr("transform",g))}).call(t,function(){var a,b=[],g=[],i=[];if(n){for(a=0;n>a;a++)b.push("."+pe[Ad]+"-"+(m+a)),g.push("."+pe[Nd]+"-"+(m+a)),i.push("."+pe[pd]+"-"+(m+a));K.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),K.svg.selectAll("."+pe[Od]).selectAll(g).remove(),K.svg.selectAll("."+pe[qd]).selectAll(i).remove(),K.svg.select("."+pe[Rd]).remove()}u.attr("transform",null).attr(K.xgridAttr),v.attr("transform",null),v.select("line").attr("x1",N[vb]?0:T).attr("x2",N[vb]?K.width:T),v.select("text").attr("x",N[vb]?K.width:0).attr("y",T),f.attr("transform",null).attr("d",y),c.attr("transform",null).attr("d",A),d.attr("transform",null).attr("d",w),e.attr("transform",null).attr("cx",U).attr("cy",V),z.attr("transform",null).attr("x",B).attr("y",C).style("fill-opacity",De(K.opacityForText,K)),x.attr("transform",null),x.select("rect").filter(K.isRegionOnX).attr("x",De(K.regionX,K)).attr("width",De(K.regionWidth,K)),h.attr("x",N[vb]?0:j).attr("y",N[vb]?j:0).attr("width",N[vb]?K.width:k).attr("height",N[vb]?k:K.height),s()})}),K.mapToIds(K.data.targets).forEach(function(a){K.withoutFadeIn[a]=!0}),K.updateZoom&&K.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a); -return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.getBarW=function(a,b){var c=this,d=c.config,e="number"==typeof d[sc]?d[sc]:b?2*a.tickOffset()*d[tc]/b:0;return d[uc]&&e>d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a) -},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&L.select(this).style("display",b%I?"none":"block")})}else J.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!M[vb]&&M[Hb]&&J.rotateTickText(J.axes.x,b.axisX,M[Hb]),v=J.generateDrawArea(N,!1),w=J.generateDrawBar?J.generateDrawBar(O):void 0,y=J.generateDrawLine(P,!1),A=J.generateXYForText(O,!0),B=J.generateXYForText(O,!1),J.subY.domain(J.y.domain()),J.subY2.domain(J.y2.domain()),J.tooltip.style("display","none"),J.updateXgridFocus(),K.select("text."+pe[Nd]+"."+pe[Md]).attr("x",J.width/2).attr("y",J.height/2).text(M[fb]).transition().style("opacity",R.length?0:1),J.redrawGrid(C,k),J.redrawRegion(C),J.redrawBar(D),c=K.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(J.lineData,J)),c.enter().append("path").attr("class",De(J.classLine,J)).style("stroke",J.color),c.style("opacity",De(J.initialOpacity,J)).attr("transform",null),c.exit().transition().duration(D).style("opacity",0).remove(),d=K.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(J.lineData,J)),d.enter().append("path").attr("class",De(J.classArea,J)).style("fill",J.color).style("opacity",function(){return J.orgAreaOpacity=+L.select(this).style("opacity"),0}),d.style("opacity",J.orgAreaOpacity),d.exit().transition().duration(D).style("opacity",0).remove(),M[mc]&&(e=K.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(J.lineOrScatterData,J)),e.enter().append("circle").attr("class",De(J.classCircle,J)).attr("r",De(J.pointR,J)).style("fill",J.color),e.style("opacity",De(J.initialOpacity,J)),e.exit().remove()),J.hasDataLabel()&&J.redrawText(D),J.redrawArc&&J.redrawArc(C,D,q),J.redrawSubchart&&J.redrawSubchart(l,b,C,D,N,O,P),K.selectAll("."+pe[od]).filter(De(J.isBarType,J)).selectAll("circle").remove(),M[s]&&(f=K.select("."+pe[qd]).style("cursor",M[o]?M[vb]?"ns-resize":"ew-resize":null),ze(M[z])&&!J.isSingleX(M[z])?(f.classed(pe[sd])||f.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),J.generateEventRectsForMultipleXs(g.enter()),g.attr("x",0).attr("y",0).attr("width",J.width).attr("height",J.height)):(f.classed(pe[rd])||f.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!J.isCustomX()&&!J.isTimeSeries()||J.isCategorized()?(j=J.getEventRectWidth(),i=function(a){return J.x(a.x)-j/2}):(j=function(a){var b=J.getPrevX(a.index),c=J.getNextX(a.index),d=J.data.xs[a.id][a.index],e=(J.x(c?c:d)-J.x(b?b:d))/2;return 0>e?0:e},i=function(a){var b=J.getPrevX(a.index),c=J.data.xs[a.id][a.index];return(J.x(c)+J.x(b?b:c))/2}),h=J.getMaxDataCountTarget(J.data.targets),K.select("."+pe[qd]).datum(h?h.values:[]),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),J.generateEventRectsForSingleX(g.enter()),g.attr("class",De(J.classEvent,J)).attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),g.exit().remove())),L.transition().duration(C).each(function(){var b=[];J.addTransitionForBar(b,w),b.push(c.transition().attr("d",y).style("stroke",J.color).style("opacity",1)),b.push(d.transition().attr("d",v).style("fill",J.color).style("opacity",J.orgAreaOpacity)),b.push(e.transition().style("opacity",De(J.opacityForCircle,J)).style("fill",J.color).attr("cx",T).attr("cy",U)),b.push(K.selectAll("."+pe[nd]).transition().attr("cx",T).attr("cy",U)),J.addTransitionForText(b,A,B,a.flow),J.addTransitionForRegion(b),J.addTransitionForGrid(b),a.flow&&(F=J.generateWait(),b.forEach(function(a){F.add(a)}))}).call(F?F:function(){},function(){var b,f,h,k=1,l=a.flow.index,m=a.flow.length,n=J.getValueOnIndex(J.data.targets[0].values,l),o=J.getValueOnIndex(J.data.targets[0].values,l+m),p=J.x.domain(),q=a.flow.duration||C,r=a.flow.done||function(){},s=J.generateWait(),t=J.xgrid||L.selectAll([]),u=J.xgridLines||L.selectAll([]),x=J.mainRegion||L.selectAll([]),z=J.mainText||L.selectAll([]),D=J.mainBar||L.selectAll([]);J.data.targets.forEach(function(a){a.values.splice(0,m)}),h=J.updateXDomain(R,!0,!0),J.updateXGrid&&J.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||n.x===o.x?J.x(p[0])-J.x(h[0]):J.isTimeSeries()?J.x(p[0])-J.x(h[0]):J.x(n.x)-J.x(o.x):1!==J.data.targets[0].values.length?b=J.x(p[0])-J.x(h[0]):J.isTimeSeries()?(n=J.getValueOnIndex(J.data.targets[0].values,0),o=J.getValueOnIndex(J.data.targets[0].values,J.data.targets[0].values.length-1),b=J.x(n.x)-J.x(o.x)):b=xe(h)/2,k=xe(p)/xe(h),f="translate("+b+",0) scale("+k+",1)",L.transition().ease("linear").duration(q).each(function(){s.add(J.axes.x.transition().call(J.xAxis)),s.add(D.transition().attr("transform",f)),s.add(c.transition().attr("transform",f)),s.add(d.transition().attr("transform",f)),s.add(e.transition().attr("transform",f)),s.add(z.transition().attr("transform",f)),s.add(x.filter(J.isRegionOnX).transition().attr("transform",f)),s.add(t.transition().attr("transform",f)),s.add(u.transition().attr("transform",f))}).call(s,function(){var a,b=[],f=[],h=[];if(m){for(a=0;m>a;a++)b.push("."+pe[Ad]+"-"+(l+a)),f.push("."+pe[Nd]+"-"+(l+a)),h.push("."+pe[pd]+"-"+(l+a));J.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),J.svg.selectAll("."+pe[Od]).selectAll(f).remove(),J.svg.selectAll("."+pe[qd]).selectAll(h).remove(),J.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(J.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",M[vb]?0:S).attr("x2",M[vb]?J.width:S),u.select("text").attr("x",M[vb]?J.width:0).attr("y",S),D.attr("transform",null).attr("d",w),c.attr("transform",null).attr("d",y),d.attr("transform",null).attr("d",v),e.attr("transform",null).attr("cx",T).attr("cy",U),z.attr("transform",null).attr("x",A).attr("y",B).style("fill-opacity",De(J.opacityForText,J)),x.attr("transform",null),x.select("rect").filter(J.isRegionOnX).attr("x",De(J.regionX,J)).attr("width",De(J.regionWidth,J)),g.attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),r()})}),J.mapToIds(J.data.targets).forEach(function(a){J.withoutFadeIn[a]=!0}),J.updateZoom&&J.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset() +}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return l=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f) +},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx")) +},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 57a002d..a1e4d32 100644 --- a/src/core.js +++ b/src/core.js @@ -225,8 +225,7 @@ c3_chart_internal_fn.initWithData = function (data) { .style('fill-opacity', 0); // Define g for bar chart area - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartBars]); + if ($$.initBar) { $$.initBar(); } // Define g for line chart area main.select('.' + CLASS[_chart]).append("g") @@ -375,7 +374,7 @@ c3_chart_internal_fn.updateSizes = function () { }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate, mainBarEnter, mainBarUpdate; + var mainLineEnter, mainLineUpdate; var $$ = this, config = $$.config, main = $$.main; /*-- Main --*/ @@ -384,17 +383,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { $$.updateTargetsForText(targets); //-- Bar --// - mainBarUpdate = main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) - .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); - mainBarEnter = mainBarUpdate.enter().append('g') - .attr('class', generateCall($$.classChartBar, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - // Bars for each data - mainBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)) - .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + $$.updateTargetsForBar(targets); //-- Line --// mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) @@ -438,7 +427,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, mainBar, eventRect, eventRectUpdate; + var mainLine, mainArea, mainCircle, eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -528,7 +517,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { // setup drawer - MEMO: these must be called after axis updated drawArea = $$.generateDrawArea(areaIndices, false); - drawBar = $$.generateDrawBar(barIndices); + drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined; drawLine = $$.generateDrawLine(lineIndices, false); xForText = $$.generateXYForText(barIndices, true); yForText = $$.generateXYForText(barIndices, false); @@ -558,17 +547,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.redrawRegion(duration); // bars - mainBar = main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); - mainBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) - .style("stroke", function (d) { return $$.color(d.id); }) - .style("fill", function (d) { return $$.color(d.id); }); - mainBar - .style("opacity", generateCall($$.initialOpacity, $$)); - mainBar.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); + $$.redrawBar(durationForExit); // lines, areas and cricles mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) @@ -695,10 +674,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { d3.transition().duration(duration).each(function () { var transitions = []; - transitions.push(mainBar.transition() - .attr('d', drawBar) - .style("fill", $$.color) - .style("opacity", 1)); + $$.addTransitionForBar(transitions, drawBar); transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) @@ -741,7 +717,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var xgrid = $$.xgrid || d3.selectAll([]), xgridLines = $$.xgridLines || d3.selectAll([]), mainRegion = $$.mainRegion || d3.selectAll([]), - mainText = $$.mainText || d3.selectAll([]); + mainText = $$.mainText || d3.selectAll([]), + mainBar = $$.mainBar || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { diff --git a/src/shape.bar.js b/src/shape.bar.js new file mode 100644 index 0000000..24cd3e6 --- /dev/null +++ b/src/shape.bar.js @@ -0,0 +1,114 @@ +c3_chart_internal_fn.initBar = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartBars]); +}; +c3_chart_internal_fn.updateTargetsForBar = function (targets) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + mainBarUpdate, mainBarEnter, + classChartBar = $$.classChartBar.bind($$), + classBars = $$.classBars.bind($$); + mainBarUpdate = $$.main.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) + .data(targets) + .attr('class', classChartBar); + mainBarEnter = mainBarUpdate.enter().append('g') + .attr('class', classChartBar) + .style('opacity', 0) + .style("pointer-events", "none"); + // Bars for each data + mainBarEnter.append('g') + .attr("class", classBars) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + +}; +c3_chart_internal_fn.redrawBar = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS; + $$.mainBar = $$.main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) + .data(generateCall($$.barData, $$)); + $$.mainBar.enter().append('path') + .attr("class", generateCall($$.classBar, $$)) + .style("stroke", function (d) { return $$.color(d.id); }) + .style("fill", function (d) { return $$.color(d.id); }); + $$.mainBar + .style("opacity", generateCall($$.initialOpacity, $$)); + $$.mainBar.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); +}; +c3_chart_internal_fn.addTransitionForBar = function (transitions, drawBar) { + var $$ = this; + transitions.push($$.mainBar.transition() + .attr('d', drawBar) + .style("fill", $$.color) + .style("opacity", 1)); +}; +c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { + var $$ = this, config = $$.config, + w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; + return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; +}; +c3_chart_internal_fn.getBars = function (i) { + var $$ = this; + return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); +}; +c3_chart_internal_fn.expandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], true); +}; +c3_chart_internal_fn.unexpandBars = function (i) { + var $$ = this; + $$.getBars(i).classed(CLASS[_EXPANDED], false); +}; +c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { + var $$ = this, config = $$.config, + getPoints = $$.generateGetBarPoints(barIndices, isSub); + return function (d, i) { + // 4 points that make a bar + var points = getPoints(d, i); + + // switch points if axis is rotated, not applicable for sub chart + var indexX = config[__axis_rotated] ? 1 : 0; + var indexY = config[__axis_rotated] ? 0 : 1; + + var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + + 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + + 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + + 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + + 'z'; + + return path; + }; +}; +c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { + var $$ = this, + barTargetsNum = barIndices.__max__ + 1, + barW = $$.getBarW($$.xAxis, barTargetsNum), + barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), + barY = $$.getShapeY(!!isSub), + barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = barOffset(d, i) || y0, // offset is for stacked bar chart + posX = barX(d), posY = barY(d); + // fix posY not to overflow opposite quadrant + if ($$.config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 4 points that make a bar + return [ + [posX, offset], + [posX, posY - (y0 - offset)], + [posX + barW, posY - (y0 - offset)], + [posX + barW, offset] + ]; + }; +}; +c3_chart_internal_fn.isWithinBar = function (_this) { + var d3 = this.d3, + mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), + seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), + x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, + sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; + return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; +}; diff --git a/src/shape.js b/src/shape.js index 21dbffb..d0ec88c 100644 --- a/src/shape.js +++ b/src/shape.js @@ -93,68 +93,6 @@ c3_chart_internal_fn.pointSelectR = function (d) { -c3_chart_internal_fn.getBarW = function (axis, barTargetsNum) { - var $$ = this, config = $$.config, - w = typeof config[__bar_width] === 'number' ? config[__bar_width] : barTargetsNum ? (axis.tickOffset() * 2 * config[__bar_width_ratio]) / barTargetsNum : 0; - return config[__bar_width_max] && w > config[__bar_width_max] ? config[__bar_width_max] : w; -}; -c3_chart_internal_fn.getBars = function (i) { - var $$ = this; - return $$.main.selectAll('.' + CLASS[_bar] + (isValue(i) ? '-' + i : '')); -}; -c3_chart_internal_fn.expandBars = function (i) { - var $$ = this; - $$.getBars(i).classed(CLASS[_EXPANDED], true); -}; -c3_chart_internal_fn.unexpandBars = function (i) { - var $$ = this; - $$.getBars(i).classed(CLASS[_EXPANDED], false); -}; -c3_chart_internal_fn.generateDrawBar = function (barIndices, isSub) { - var $$ = this, config = $$.config, - getPoints = $$.generateGetBarPoints(barIndices, isSub); - return function (d, i) { - // 4 points that make a bar - var points = getPoints(d, i); - - // switch points if axis is rotated, not applicable for sub chart - var indexX = config[__axis_rotated] ? 1 : 0; - var indexY = config[__axis_rotated] ? 0 : 1; - - var path = 'M ' + points[0][indexX] + ',' + points[0][indexY] + ' ' + - 'L' + points[1][indexX] + ',' + points[1][indexY] + ' ' + - 'L' + points[2][indexX] + ',' + points[2][indexY] + ' ' + - 'L' + points[3][indexX] + ',' + points[3][indexY] + ' ' + - 'z'; - - return path; - }; -}; -c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) { - var $$ = this, - barTargetsNum = barIndices.__max__ + 1, - barW = $$.getBarW($$.xAxis, barTargetsNum), - barX = $$.getShapeX(barW, barTargetsNum, barIndices, !!isSub), - barY = $$.getShapeY(!!isSub), - barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub), - yScale = isSub ? $$.getSubYScale : $$.getYScale; - return function (d, i) { - var y0 = yScale.call($$, d.id)(0), - offset = barOffset(d, i) || y0, // offset is for stacked bar chart - posX = barX(d), posY = barY(d); - // fix posY not to overflow opposite quadrant - if ($$.config[__axis_rotated]) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } - } - // 4 points that make a bar - return [ - [posX, offset], - [posX, posY - (y0 - offset)], - [posX + barW, posY - (y0 - offset)], - [posX + barW, offset] - ]; - }; -}; c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { var $$ = this, config = $$.config, area = $$.d3.svg.area(), @@ -372,14 +310,6 @@ c3_chart_internal_fn.isWithinCircle = function (_this, _r) { cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; -c3_chart_internal_fn.isWithinBar = function (_this) { - var d3 = this.d3, - mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), - seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), - x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, - sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; - return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; -}; c3_chart_internal_fn.isWithinRegions = function (x, regions) { var i; for (i = 0; i < regions.length; i++) { From 1669ec46e0a2321309a491fc4ecf2d9806bb4d26 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 22:09:14 +0900 Subject: [PATCH 37/44] Fix tick format for timeseries --- c3.js | 4 ++-- c3.min.js | 2 +- src/axis.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/c3.js b/c3.js index 44bd6e2..f294b11 100644 --- a/c3.js +++ b/c3.js @@ -3916,7 +3916,7 @@ var $$ = this, config = $$.config, format = $$.isTimeSeries() ? $$.defaultAxisTimeFormat : $$.isCategorized() ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; if (config[__axis_x_tick_format]) { - if (config[__axis_x_tick_format]) { + if (isFunction(config[__axis_x_tick_format])) { format = config[__axis_x_tick_format]; } else if ($$.isTimeSeries()) { format = function (date) { @@ -3924,7 +3924,7 @@ }; } } - return function (v) { return format.call($$, v); }; + return isFunction(format) ? function (v) { return format.call($$, v); } : format; }; c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { var $$ = this, config = $$.config, option; diff --git a/c3.min.js b/c3.min.js index b9e6597..b90b57d 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ !function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&L.select(this).style("display",b%I?"none":"block")})}else J.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!M[vb]&&M[Hb]&&J.rotateTickText(J.axes.x,b.axisX,M[Hb]),v=J.generateDrawArea(N,!1),w=J.generateDrawBar?J.generateDrawBar(O):void 0,y=J.generateDrawLine(P,!1),A=J.generateXYForText(O,!0),B=J.generateXYForText(O,!1),J.subY.domain(J.y.domain()),J.subY2.domain(J.y2.domain()),J.tooltip.style("display","none"),J.updateXgridFocus(),K.select("text."+pe[Nd]+"."+pe[Md]).attr("x",J.width/2).attr("y",J.height/2).text(M[fb]).transition().style("opacity",R.length?0:1),J.redrawGrid(C,k),J.redrawRegion(C),J.redrawBar(D),c=K.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(J.lineData,J)),c.enter().append("path").attr("class",De(J.classLine,J)).style("stroke",J.color),c.style("opacity",De(J.initialOpacity,J)).attr("transform",null),c.exit().transition().duration(D).style("opacity",0).remove(),d=K.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(J.lineData,J)),d.enter().append("path").attr("class",De(J.classArea,J)).style("fill",J.color).style("opacity",function(){return J.orgAreaOpacity=+L.select(this).style("opacity"),0}),d.style("opacity",J.orgAreaOpacity),d.exit().transition().duration(D).style("opacity",0).remove(),M[mc]&&(e=K.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(J.lineOrScatterData,J)),e.enter().append("circle").attr("class",De(J.classCircle,J)).attr("r",De(J.pointR,J)).style("fill",J.color),e.style("opacity",De(J.initialOpacity,J)),e.exit().remove()),J.hasDataLabel()&&J.redrawText(D),J.redrawArc&&J.redrawArc(C,D,q),J.redrawSubchart&&J.redrawSubchart(l,b,C,D,N,O,P),K.selectAll("."+pe[od]).filter(De(J.isBarType,J)).selectAll("circle").remove(),M[s]&&(f=K.select("."+pe[qd]).style("cursor",M[o]?M[vb]?"ns-resize":"ew-resize":null),ze(M[z])&&!J.isSingleX(M[z])?(f.classed(pe[sd])||f.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),J.generateEventRectsForMultipleXs(g.enter()),g.attr("x",0).attr("y",0).attr("width",J.width).attr("height",J.height)):(f.classed(pe[rd])||f.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!J.isCustomX()&&!J.isTimeSeries()||J.isCategorized()?(j=J.getEventRectWidth(),i=function(a){return J.x(a.x)-j/2}):(j=function(a){var b=J.getPrevX(a.index),c=J.getNextX(a.index),d=J.data.xs[a.id][a.index],e=(J.x(c?c:d)-J.x(b?b:d))/2;return 0>e?0:e},i=function(a){var b=J.getPrevX(a.index),c=J.data.xs[a.id][a.index];return(J.x(c)+J.x(b?b:c))/2}),h=J.getMaxDataCountTarget(J.data.targets),K.select("."+pe[qd]).datum(h?h.values:[]),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),J.generateEventRectsForSingleX(g.enter()),g.attr("class",De(J.classEvent,J)).attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),g.exit().remove())),L.transition().duration(C).each(function(){var b=[];J.addTransitionForBar(b,w),b.push(c.transition().attr("d",y).style("stroke",J.color).style("opacity",1)),b.push(d.transition().attr("d",v).style("fill",J.color).style("opacity",J.orgAreaOpacity)),b.push(e.transition().style("opacity",De(J.opacityForCircle,J)).style("fill",J.color).attr("cx",T).attr("cy",U)),b.push(K.selectAll("."+pe[nd]).transition().attr("cx",T).attr("cy",U)),J.addTransitionForText(b,A,B,a.flow),J.addTransitionForRegion(b),J.addTransitionForGrid(b),a.flow&&(F=J.generateWait(),b.forEach(function(a){F.add(a)}))}).call(F?F:function(){},function(){var b,f,h,k=1,l=a.flow.index,m=a.flow.length,n=J.getValueOnIndex(J.data.targets[0].values,l),o=J.getValueOnIndex(J.data.targets[0].values,l+m),p=J.x.domain(),q=a.flow.duration||C,r=a.flow.done||function(){},s=J.generateWait(),t=J.xgrid||L.selectAll([]),u=J.xgridLines||L.selectAll([]),x=J.mainRegion||L.selectAll([]),z=J.mainText||L.selectAll([]),D=J.mainBar||L.selectAll([]);J.data.targets.forEach(function(a){a.values.splice(0,m)}),h=J.updateXDomain(R,!0,!0),J.updateXGrid&&J.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||n.x===o.x?J.x(p[0])-J.x(h[0]):J.isTimeSeries()?J.x(p[0])-J.x(h[0]):J.x(n.x)-J.x(o.x):1!==J.data.targets[0].values.length?b=J.x(p[0])-J.x(h[0]):J.isTimeSeries()?(n=J.getValueOnIndex(J.data.targets[0].values,0),o=J.getValueOnIndex(J.data.targets[0].values,J.data.targets[0].values.length-1),b=J.x(n.x)-J.x(o.x)):b=xe(h)/2,k=xe(p)/xe(h),f="translate("+b+",0) scale("+k+",1)",L.transition().ease("linear").duration(q).each(function(){s.add(J.axes.x.transition().call(J.xAxis)),s.add(D.transition().attr("transform",f)),s.add(c.transition().attr("transform",f)),s.add(d.transition().attr("transform",f)),s.add(e.transition().attr("transform",f)),s.add(z.transition().attr("transform",f)),s.add(x.filter(J.isRegionOnX).transition().attr("transform",f)),s.add(t.transition().attr("transform",f)),s.add(u.transition().attr("transform",f))}).call(s,function(){var a,b=[],f=[],h=[];if(m){for(a=0;m>a;a++)b.push("."+pe[Ad]+"-"+(l+a)),f.push("."+pe[Nd]+"-"+(l+a)),h.push("."+pe[pd]+"-"+(l+a));J.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),J.svg.selectAll("."+pe[Od]).selectAll(f).remove(),J.svg.selectAll("."+pe[qd]).selectAll(h).remove(),J.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(J.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",M[vb]?0:S).attr("x2",M[vb]?J.width:S),u.select("text").attr("x",M[vb]?J.width:0).attr("y",S),D.attr("transform",null).attr("d",w),c.attr("transform",null).attr("d",y),d.attr("transform",null).attr("d",v),e.attr("transform",null).attr("cx",T).attr("cy",U),z.attr("transform",null).attr("x",A).attr("y",B).style("fill-opacity",De(J.opacityForText,J)),x.attr("transform",null),x.select("rect").filter(J.isRegionOnX).attr("x",De(J.regionX,J)).attr("width",De(J.regionWidth,J)),g.attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),r()})}),J.mapToIds(J.data.targets).forEach(function(a){J.withoutFadeIn[a]=!0}),J.updateZoom&&J.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset() }),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return l=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f) -},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(b[Bb]?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),function(b){return c.call(a,b)}},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx")) +},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx")) },f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/axis.js b/src/axis.js index 200807f..075cd36 100644 --- a/src/axis.js +++ b/src/axis.js @@ -63,7 +63,7 @@ c3_chart_internal_fn.getXAxisTickFormat = function () { var $$ = this, config = $$.config, format = $$.isTimeSeries() ? $$.defaultAxisTimeFormat : $$.isCategorized() ? $$.categoryName : function (v) { return v < 0 ? v.toFixed(0) : v; }; if (config[__axis_x_tick_format]) { - if (config[__axis_x_tick_format]) { + if (isFunction(config[__axis_x_tick_format])) { format = config[__axis_x_tick_format]; } else if ($$.isTimeSeries()) { format = function (date) { @@ -71,7 +71,7 @@ c3_chart_internal_fn.getXAxisTickFormat = function () { }; } } - return function (v) { return format.call($$, v); }; + return isFunction(format) ? function (v) { return format.call($$, v); } : format; }; c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { var $$ = this, config = $$.config, option; From f2f75452db2762723cbe2cac42e9a5dc1d157722 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sat, 16 Aug 2014 23:03:20 +0900 Subject: [PATCH 38/44] Modularize line, area and circle --- Gruntfile.coffee | 1 + c3.js | 460 ++++++++++++++++++++++++++-------------------- c3.min.js | 8 +- src/core.js | 96 +++------- src/shape.js | 266 --------------------------- src/shape.line.js | 338 ++++++++++++++++++++++++++++++++++ src/text.js | 29 +++ 7 files changed, 653 insertions(+), 545 deletions(-) create mode 100644 src/shape.line.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 350f035..88c3855 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -29,6 +29,7 @@ module.exports = (grunt) -> 'src/category.js', 'src/size.js', 'src/shape.js', + 'src/shape.line.js', 'src/shape.bar.js', 'src/text.js', 'src/type.js', diff --git a/c3.js b/c3.js index f294b11..87a5e1f 100644 --- a/c3.js +++ b/c3.js @@ -233,8 +233,7 @@ if ($$.initBar) { $$.initBar(); } // Define g for line chart area - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartLines]); + if ($$.initLine) { $$.initLine(); } // Define g for arc chart area if ($$.initArc) { $$.initArc(); } @@ -379,8 +378,7 @@ }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate; - var $$ = this, config = $$.config, main = $$.main; + var $$ = this, config = $$.config; /*-- Main --*/ @@ -391,34 +389,9 @@ $$.updateTargetsForBar(targets); //-- Line --// - mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) - .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); - mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', generateCall($$.classChartLine, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - // Lines for each data - mainLineEnter.append('g') - .attr("class", generateCall($$.classLines, $$)); - // Areas - mainLineEnter.append('g') - .attr('class', generateCall($$.classAreas, $$)); - // Circles for each data point on lines - mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); - mainLineEnter.append('g') - .attr("class", generateCall($$.classCircles, $$)) - .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); - // Update date for selected circles - targets.forEach(function (t) { - main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { - d.value = t.values[d.index].value; - }); - }); - // MEMO: can not keep same color... - //mainLineUpdate.exit().remove(); + $$.updateTargetsForLine(targets); + //-- Arc --// if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); } if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); } @@ -432,7 +405,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, eventRect, eventRectUpdate; + var eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -444,8 +417,6 @@ cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - mainCircle = d3.selectAll([]); - options = options || {}; withY = getOption(options, "withY", true); withSubchart = getOption(options, "withSubchart", true); @@ -521,9 +492,9 @@ } // setup drawer - MEMO: these must be called after axis updated - drawArea = $$.generateDrawArea(areaIndices, false); + drawArea = $$.generateDrawArea ? $$.generateDrawArea(areaIndices, false) : undefined; drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined; - drawLine = $$.generateDrawLine(lineIndices, false); + drawLine = $$.generateDrawLine ? $$.generateDrawLine(lineIndices, false) : undefined; xForText = $$.generateXYForText(barIndices, true); yForText = $$.generateXYForText(barIndices, false); @@ -555,42 +526,11 @@ $$.redrawBar(durationForExit); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) - .data(generateCall($$.lineData, $$)); - mainLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) - .style("stroke", $$.color); - mainLine - .style("opacity", generateCall($$.initialOpacity, $$)) - .attr('transform', null); - mainLine.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - - mainArea = main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) - .data(generateCall($$.lineData, $$)); - mainArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) - .style("fill", $$.color) - .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); - mainArea - .style("opacity", $$.orgAreaOpacity); - mainArea.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - - if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) - .data(generateCall($$.lineOrScatterData, $$)); - mainCircle.enter().append("circle") - .attr("class", generateCall($$.classCircle, $$)) - .attr("r", generateCall($$.pointR, $$)) - .style("fill", $$.color); - mainCircle - .style("opacity", generateCall($$.initialOpacity, $$)); - mainCircle.exit().remove(); - } + $$.redrawLine(durationForExit); + $$.redrawArea(durationForExit); + if (config[__point_show]) { $$.redrawCircle(); } + // text if ($$.hasDataLabel()) { $$.redrawText(durationForExit); } @@ -680,14 +620,22 @@ var transitions = []; $$.addTransitionForBar(transitions, drawBar); + $$.addTransitionForLine(transitions, drawLine); + /* transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) .style("opacity", 1)); + */ + $$.addTransitionForArea(transitions, drawArea); + /* transitions.push(mainArea.transition() .attr("d", drawArea) .style("fill", $$.color) .style("opacity", $$.orgAreaOpacity)); + */ + $$.addTransitionForCircle(transitions, cx, cy); + /* transitions.push(mainCircle.transition() .style('opacity', generateCall($$.opacityForCircle, $$)) .style("fill", $$.color) @@ -696,6 +644,7 @@ transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); + */ $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -723,7 +672,10 @@ xgridLines = $$.xgridLines || d3.selectAll([]), mainRegion = $$.mainRegion || d3.selectAll([]), mainText = $$.mainText || d3.selectAll([]), - mainBar = $$.mainBar || d3.selectAll([]); + mainBar = $$.mainBar || d3.selectAll([]), + mainLine = $$.mainLine || d3.selectAll([]), + mainArea = $$.mainArea || d3.selectAll([]), + mainCircle = $$.mainCircle || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { @@ -2721,80 +2673,67 @@ return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; - - c3_chart_internal_fn.circleX = function (d) { - return d.x || d.x === 0 ? this.x(d.x) : null; - }; - c3_chart_internal_fn.circleY = function (d, i) { - var $$ = this, - lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); - return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + c3_chart_internal_fn.initLine = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); }; - c3_chart_internal_fn.getCircles = function (i, id) { - var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); + c3_chart_internal_fn.updateTargetsForLine = function (targets) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + mainLineUpdate, mainLineEnter, + classChartLine = $$.classChartLine.bind($$), + classLines = $$.classLines.bind($$), + classAreas = $$.classAreas.bind($$), + classCircles = $$.classCircles.bind($$); + mainLineUpdate = $$.main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) + .data(targets) + .attr('class', classChartLine); + mainLineEnter = mainLineUpdate.enter().append('g') + .attr('class', classChartLine) + .style('opacity', 0) + .style("pointer-events", "none"); + // Lines for each data + mainLineEnter.append('g') + .attr("class", classLines); + // Areas + mainLineEnter.append('g') + .attr('class', classAreas); + // Circles for each data point on lines + mainLineEnter.append('g') + .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); + mainLineEnter.append('g') + .attr("class", classCircles) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + // Update date for selected circles + targets.forEach(function (t) { + $$.main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { + d.value = t.values[d.index].value; + }); + }); + // MEMO: can not keep same color... + //mainLineUpdate.exit().remove(); }; - c3_chart_internal_fn.expandCircles = function (i, id) { - var $$ = this; - $$.getCircles(i, id) - .classed(CLASS[_EXPANDED], true) - .attr('r', generateCall($$.pointExpandedR, $$)); + c3_chart_internal_fn.redrawLine = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS; + $$.mainLine = $$.main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) + .data($$.lineData.bind($$)); + $$.mainLine.enter().append('path') + .attr('class', $$.classLine.bind($$)) + .style("stroke", $$.color); + $$.mainLine + .style("opacity", $$.initialOpacity.bind($$)) + .attr('transform', null); + $$.mainLine.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); }; - c3_chart_internal_fn.unexpandCircles = function (i) { + c3_chart_internal_fn.addTransitionForLine = function (transitions, drawLine) { var $$ = this; - $$.getCircles(i) - .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) - .classed(CLASS[_EXPANDED], false) - .attr('r', generateCall($$.pointR, $$)); - }; - c3_chart_internal_fn.pointR = function (d) { - var $$ = this, config = $$.config; - return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; - }; - c3_chart_internal_fn.pointExpandedR = function (d) { - var $$ = this, config = $$.config; - return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); - }; - c3_chart_internal_fn.pointSelectR = function (d) { - var $$ = this, config = $$.config; - return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; - }; - - - - - c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { - var $$ = this, config = $$.config, area = $$.d3.svg.area(), - getPoint = $$.generateGetAreaPoint(areaIndices, isSub), - yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, - xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, - value0 = function (d, i) { - return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); - }, - value1 = function (d, i) { - return config[__data_groups].length > 0 ? getPoint(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); - if (!config[__line_connect_null]) { - area = area.defined(function (d) { return d.value !== null; }); - } - - return function (d) { - var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; - if ($$.isAreaType(d)) { - path = area.interpolate($$.getInterpolate(d))(data); - } else { - if (data[0]) { - x0 = $$.x(data[0].x); - y0 = $$.getYScale(d.id)(data[0].value); - } - path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; - } - return path ? path : "M 0 0"; - }; + transitions.push($$.mainLine.transition() + .attr("d", drawLine) + .style("stroke", $$.color) + .style("opacity", 1)); }; - c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { var $$ = this, config = $$.config, line = $$.d3.svg.line(), @@ -2826,60 +2765,6 @@ return path ? path : "M 0 0"; }; }; - - c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { - var $$ = this, - getPoints = $$.generateGetBarPoints(barIndices, false), - getter = forX ? $$.getXForText : $$.getYForText; - return function (d, i) { - return getter.call($$, getPoints(d, i), d, this); - }; - }; - c3_chart_internal_fn.getXForText = function (points, d, textElement) { - var $$ = this, - box = textElement.getBoundingClientRect(), xPos, padding; - if ($$.config[__axis_rotated]) { - padding = $$.isBarType(d) ? 4 : 6; - xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); - } else { - xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; - } - return xPos > $$.width ? $$.width - box.width : xPos; - }; - c3_chart_internal_fn.getYForText = function (points, d, textElement) { - var $$ = this, - box = textElement.getBoundingClientRect(), yPos; - if ($$.config[__axis_rotated]) { - yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; - } else { - yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); - } - return yPos < box.height ? box.height : yPos; - }; - - c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints - var $$ = this, config = $$.config, - areaTargetsNum = areaIndices.__max__ + 1, - x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), - y = $$.getShapeY(!!isSub), - areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), - yScale = isSub ? $$.getSubYScale : $$.getYScale; - return function (d, i) { - var y0 = yScale.call($$, d.id)(0), - offset = areaOffset(d, i) || y0, // offset is for stacked area chart - posX = x(d), posY = y(d); - // fix posY not to overflow opposite quadrant - if (config[__axis_rotated]) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } - } - // 1 point that marks the area position - return [ - [posX, offset], - [posX, posY - (y0 - offset)] - ]; - }; - }; - c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints var $$ = this, config = $$.config, lineTargetsNum = lineIndices.__max__ + 1, @@ -2911,6 +2796,14 @@ xValue, yValue, regions = []; + function isWithinRegions(x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; + } + // Check start/end of regions if (isDefined(_regions)) { for (i = 0; i < _regions.length; i++) { @@ -2950,7 +2843,7 @@ for (i = 0; i < d.length; i++) { // 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]); } // Draw with region // TODO: Fix for horizotal charts @@ -2973,19 +2866,151 @@ return s; }; + + + c3_chart_internal_fn.redrawArea = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; + $$.mainArea = $$.main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) + .data($$.lineData.bind($$)); + $$.mainArea.enter().append('path') + .attr("class", $$.classArea.bind($$)) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + $$.mainArea + .style("opacity", $$.orgAreaOpacity); + $$.mainArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); + }; + c3_chart_internal_fn.addTransitionForArea = function (transitions, drawArea) { + var $$ = this; + transitions.push($$.mainArea.transition() + .attr("d", drawArea) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity)); + }; + c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { + var $$ = this, config = $$.config, area = $$.d3.svg.area(), + getPoint = $$.generateGetAreaPoint(areaIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + value0 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + }, + value1 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(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); + if (!config[__line_connect_null]) { + area = area.defined(function (d) { return d.value !== null; }); + } + + return function (d) { + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; + if ($$.isAreaType(d)) { + path = area.interpolate($$.getInterpolate(d))(data); + } else { + if (data[0]) { + x0 = $$.x(data[0].x); + y0 = $$.getYScale(d.id)(data[0].value); + } + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; + }; + + c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, config = $$.config, + areaTargetsNum = areaIndices.__max__ + 1, + x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = $$.getShapeY(!!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = areaOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the area position + return [ + [posX, offset], + [posX, posY - (y0 - offset)] + ]; + }; + }; + + + c3_chart_internal_fn.redrawCircle = function () { + var $$ = this, CLASS = $$.CLASS; + $$.mainCircle = $$.main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) + .data($$.lineOrScatterData.bind($$)); + $$.mainCircle.enter().append("circle") + .attr("class", $$.classCircle.bind($$)) + .attr("r", $$.pointR.bind($$)) + .style("fill", $$.color); + $$.mainCircle + .style("opacity", $$.initialOpacity.bind($$)); + $$.mainCircle.exit().remove(); + }; + c3_chart_internal_fn.addTransitionForCircle = function (transitions, cx, cy) { + var $$ = this; + transitions.push($$.mainCircle.transition() + .style('opacity', $$.opacityForCircle.bind($$)) + .style("fill", $$.color) + .attr("cx", cx) + .attr("cy", cy)); + transitions.push($$.main.selectAll('.' + CLASS[_selectedCircle]).transition() + .attr("cx", cx) + .attr("cy", cy)); + }; + c3_chart_internal_fn.circleX = function (d) { + return d.x || d.x === 0 ? this.x(d.x) : null; + }; + c3_chart_internal_fn.circleY = function (d, i) { + var $$ = this, + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); + }; + c3_chart_internal_fn.getCircles = function (i, id) { + var $$ = this; + return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); + }; + c3_chart_internal_fn.expandCircles = function (i, id) { + var $$ = this; + $$.getCircles(i, id) + .classed(CLASS[_EXPANDED], true) + .attr('r', generateCall($$.pointExpandedR, $$)); + }; + c3_chart_internal_fn.unexpandCircles = function (i) { + var $$ = this; + $$.getCircles(i) + .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) + .classed(CLASS[_EXPANDED], false) + .attr('r', generateCall($$.pointR, $$)); + }; + c3_chart_internal_fn.pointR = function (d) { + var $$ = this, config = $$.config; + return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; + }; + c3_chart_internal_fn.pointExpandedR = function (d) { + var $$ = this, config = $$.config; + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); + }; + c3_chart_internal_fn.pointSelectR = function (d) { + var $$ = this, config = $$.config; + return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; + }; c3_chart_internal_fn.isWithinCircle = function (_this, _r) { var d3 = this.d3, mouse = d3.mouse(_this), d3_this = d3.select(_this), cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; }; - c3_chart_internal_fn.isWithinRegions = function (x, regions) { - var i; - for (i = 0; i < regions.length; i++) { - if (regions[i].start < x && x <= regions[i].end) { return true; } - } - return false; - }; c3_chart_internal_fn.initBar = function () { var $$ = this, CLASS = $$.CLASS; @@ -3158,6 +3183,35 @@ .remove(); return rect; }; + c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { + var $$ = this, + getPoints = $$.generateGetBarPoints(barIndices, false), + getter = forX ? $$.getXForText : $$.getYForText; + return function (d, i) { + return getter.call($$, getPoints(d, i), d, this); + }; + }; + c3_chart_internal_fn.getXForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), xPos, padding; + if ($$.config[__axis_rotated]) { + padding = $$.isBarType(d) ? 4 : 6; + xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); + } else { + xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; + } + return xPos > $$.width ? $$.width - box.width : xPos; + }; + c3_chart_internal_fn.getYForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), yPos; + if ($$.config[__axis_rotated]) { + yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; + } else { + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); + } + return yPos < box.height ? box.height : yPos; + }; c3_chart_internal_fn.setTargetType = function (targetIds, type) { var $$ = this, config = $$.config; diff --git a/c3.min.js b/c3.min.js index b90b57d..30ebbf7 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&L.select(this).style("display",b%I?"none":"block")})}else J.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!M[vb]&&M[Hb]&&J.rotateTickText(J.axes.x,b.axisX,M[Hb]),v=J.generateDrawArea(N,!1),w=J.generateDrawBar?J.generateDrawBar(O):void 0,y=J.generateDrawLine(P,!1),A=J.generateXYForText(O,!0),B=J.generateXYForText(O,!1),J.subY.domain(J.y.domain()),J.subY2.domain(J.y2.domain()),J.tooltip.style("display","none"),J.updateXgridFocus(),K.select("text."+pe[Nd]+"."+pe[Md]).attr("x",J.width/2).attr("y",J.height/2).text(M[fb]).transition().style("opacity",R.length?0:1),J.redrawGrid(C,k),J.redrawRegion(C),J.redrawBar(D),c=K.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(J.lineData,J)),c.enter().append("path").attr("class",De(J.classLine,J)).style("stroke",J.color),c.style("opacity",De(J.initialOpacity,J)).attr("transform",null),c.exit().transition().duration(D).style("opacity",0).remove(),d=K.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(J.lineData,J)),d.enter().append("path").attr("class",De(J.classArea,J)).style("fill",J.color).style("opacity",function(){return J.orgAreaOpacity=+L.select(this).style("opacity"),0}),d.style("opacity",J.orgAreaOpacity),d.exit().transition().duration(D).style("opacity",0).remove(),M[mc]&&(e=K.selectAll("."+pe[Hd]).selectAll("."+pe[Gd]).data(De(J.lineOrScatterData,J)),e.enter().append("circle").attr("class",De(J.classCircle,J)).attr("r",De(J.pointR,J)).style("fill",J.color),e.style("opacity",De(J.initialOpacity,J)),e.exit().remove()),J.hasDataLabel()&&J.redrawText(D),J.redrawArc&&J.redrawArc(C,D,q),J.redrawSubchart&&J.redrawSubchart(l,b,C,D,N,O,P),K.selectAll("."+pe[od]).filter(De(J.isBarType,J)).selectAll("circle").remove(),M[s]&&(f=K.select("."+pe[qd]).style("cursor",M[o]?M[vb]?"ns-resize":"ew-resize":null),ze(M[z])&&!J.isSingleX(M[z])?(f.classed(pe[sd])||f.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),J.generateEventRectsForMultipleXs(g.enter()),g.attr("x",0).attr("y",0).attr("width",J.width).attr("height",J.height)):(f.classed(pe[rd])||f.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!J.isCustomX()&&!J.isTimeSeries()||J.isCategorized()?(j=J.getEventRectWidth(),i=function(a){return J.x(a.x)-j/2}):(j=function(a){var b=J.getPrevX(a.index),c=J.getNextX(a.index),d=J.data.xs[a.id][a.index],e=(J.x(c?c:d)-J.x(b?b:d))/2;return 0>e?0:e},i=function(a){var b=J.getPrevX(a.index),c=J.data.xs[a.id][a.index];return(J.x(c)+J.x(b?b:c))/2}),h=J.getMaxDataCountTarget(J.data.targets),K.select("."+pe[qd]).datum(h?h.values:[]),g=K.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),J.generateEventRectsForSingleX(g.enter()),g.attr("class",De(J.classEvent,J)).attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),g.exit().remove())),L.transition().duration(C).each(function(){var b=[];J.addTransitionForBar(b,w),b.push(c.transition().attr("d",y).style("stroke",J.color).style("opacity",1)),b.push(d.transition().attr("d",v).style("fill",J.color).style("opacity",J.orgAreaOpacity)),b.push(e.transition().style("opacity",De(J.opacityForCircle,J)).style("fill",J.color).attr("cx",T).attr("cy",U)),b.push(K.selectAll("."+pe[nd]).transition().attr("cx",T).attr("cy",U)),J.addTransitionForText(b,A,B,a.flow),J.addTransitionForRegion(b),J.addTransitionForGrid(b),a.flow&&(F=J.generateWait(),b.forEach(function(a){F.add(a)}))}).call(F?F:function(){},function(){var b,f,h,k=1,l=a.flow.index,m=a.flow.length,n=J.getValueOnIndex(J.data.targets[0].values,l),o=J.getValueOnIndex(J.data.targets[0].values,l+m),p=J.x.domain(),q=a.flow.duration||C,r=a.flow.done||function(){},s=J.generateWait(),t=J.xgrid||L.selectAll([]),u=J.xgridLines||L.selectAll([]),x=J.mainRegion||L.selectAll([]),z=J.mainText||L.selectAll([]),D=J.mainBar||L.selectAll([]);J.data.targets.forEach(function(a){a.values.splice(0,m)}),h=J.updateXDomain(R,!0,!0),J.updateXGrid&&J.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||n.x===o.x?J.x(p[0])-J.x(h[0]):J.isTimeSeries()?J.x(p[0])-J.x(h[0]):J.x(n.x)-J.x(o.x):1!==J.data.targets[0].values.length?b=J.x(p[0])-J.x(h[0]):J.isTimeSeries()?(n=J.getValueOnIndex(J.data.targets[0].values,0),o=J.getValueOnIndex(J.data.targets[0].values,J.data.targets[0].values.length-1),b=J.x(n.x)-J.x(o.x)):b=xe(h)/2,k=xe(p)/xe(h),f="translate("+b+",0) scale("+k+",1)",L.transition().ease("linear").duration(q).each(function(){s.add(J.axes.x.transition().call(J.xAxis)),s.add(D.transition().attr("transform",f)),s.add(c.transition().attr("transform",f)),s.add(d.transition().attr("transform",f)),s.add(e.transition().attr("transform",f)),s.add(z.transition().attr("transform",f)),s.add(x.filter(J.isRegionOnX).transition().attr("transform",f)),s.add(t.transition().attr("transform",f)),s.add(u.transition().attr("transform",f))}).call(s,function(){var a,b=[],f=[],h=[];if(m){for(a=0;m>a;a++)b.push("."+pe[Ad]+"-"+(l+a)),f.push("."+pe[Nd]+"-"+(l+a)),h.push("."+pe[pd]+"-"+(l+a));J.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),J.svg.selectAll("."+pe[Od]).selectAll(f).remove(),J.svg.selectAll("."+pe[qd]).selectAll(h).remove(),J.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(J.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",M[vb]?0:S).attr("x2",M[vb]?J.width:S),u.select("text").attr("x",M[vb]?J.width:0).attr("y",S),D.attr("transform",null).attr("d",w),c.attr("transform",null).attr("d",y),d.attr("transform",null).attr("d",v),e.attr("transform",null).attr("cx",T).attr("cy",U),z.attr("transform",null).attr("x",A).attr("y",B).style("fill-opacity",De(J.opacityForText,J)),x.attr("transform",null),x.select("rect").filter(J.isRegionOnX).attr("x",De(J.regionX,J)).attr("width",De(J.regionWidth,J)),g.attr("x",M[vb]?0:i).attr("y",M[vb]?i:0).attr("width",M[vb]?J.width:j).attr("height",M[vb]?j:J.height),r()})}),J.mapToIds(J.data.targets).forEach(function(a){J.withoutFadeIn[a]=!0}),J.updateZoom&&J.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset() -}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateXYForText=function(a,b){var c=this,d=c.generateGetBarPoints(a,!1),e=b?c.getXForText:c.getYForText;return function(a,b){return e.call(c,d(a,b),a,this)}},f.getXForText=function(a,b,c){var d,e,f=this,g=c.getBoundingClientRect();return f.config[vb]?(e=f.isBarType(b)?4:6,d=a[2][1]+e*(b.value<0?-1:1)):d=f.hasType("bar")?(a[2][0]+a[0][0])/2:a[0][0],d>f.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),dl||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=-1,t="M",u=[];if(ue(d))for(e=0;e=f;f+=n)t+=g(a[e-1],a[e],f,m);s=a[e].x}return t},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return l=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f) -},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx")) -},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&I.select(this).style("display",b%F?"none":"block")})}else G.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!J[vb]&&J[Hb]&&G.rotateTickText(G.axes.x,b.axisX,J[Hb]),r=G.generateDrawArea?G.generateDrawArea(K,!1):void 0,t=G.generateDrawBar?G.generateDrawBar(L):void 0,u=G.generateDrawLine?G.generateDrawLine(M,!1):void 0,v=G.generateXYForText(L,!0),w=G.generateXYForText(L,!1),G.subY.domain(G.y.domain()),G.subY2.domain(G.y2.domain()),G.tooltip.style("display","none"),G.updateXgridFocus(),H.select("text."+pe[Nd]+"."+pe[Md]).attr("x",G.width/2).attr("y",G.height/2).text(J[fb]).transition().style("opacity",O.length?0:1),G.redrawGrid(y,h),G.redrawRegion(y),G.redrawBar(A),G.redrawLine(A),G.redrawArea(A),J[mc]&&G.redrawCircle(),G.hasDataLabel()&&G.redrawText(A),G.redrawArc&&G.redrawArc(y,A,m),G.redrawSubchart&&G.redrawSubchart(i,b,y,A,K,L,M),H.selectAll("."+pe[od]).filter(De(G.isBarType,G)).selectAll("circle").remove(),J[s]&&(c=H.select("."+pe[qd]).style("cursor",J[o]?J[vb]?"ns-resize":"ew-resize":null),ze(J[z])&&!G.isSingleX(J[z])?(c.classed(pe[sd])||c.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),d=H.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),G.generateEventRectsForMultipleXs(d.enter()),d.attr("x",0).attr("y",0).attr("width",G.width).attr("height",G.height)):(c.classed(pe[rd])||c.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!G.isCustomX()&&!G.isTimeSeries()||G.isCategorized()?(g=G.getEventRectWidth(),f=function(a){return G.x(a.x)-g/2}):(g=function(a){var b=G.getPrevX(a.index),c=G.getNextX(a.index),d=G.data.xs[a.id][a.index],e=(G.x(c?c:d)-G.x(b?b:d))/2;return 0>e?0:e},f=function(a){var b=G.getPrevX(a.index),c=G.data.xs[a.id][a.index];return(G.x(c)+G.x(b?b:c))/2}),e=G.getMaxDataCountTarget(G.data.targets),H.select("."+pe[qd]).datum(e?e.values:[]),d=H.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),G.generateEventRectsForSingleX(d.enter()),d.attr("class",De(G.classEvent,G)).attr("x",J[vb]?0:f).attr("y",J[vb]?f:0).attr("width",J[vb]?G.width:g).attr("height",J[vb]?g:G.height),d.exit().remove())),I.transition().duration(y).each(function(){var b=[];G.addTransitionForBar(b,t),G.addTransitionForLine(b,u),G.addTransitionForArea(b,r),G.addTransitionForCircle(b,Q,R),G.addTransitionForText(b,v,w,a.flow),G.addTransitionForRegion(b),G.addTransitionForGrid(b),a.flow&&(C=G.generateWait(),b.forEach(function(a){C.add(a)}))}).call(C?C:function(){},function(){var b,c,e,h=1,i=a.flow.index,j=a.flow.length,k=G.getValueOnIndex(G.data.targets[0].values,i),l=G.getValueOnIndex(G.data.targets[0].values,i+j),m=G.x.domain(),n=a.flow.duration||y,o=a.flow.done||function(){},p=G.generateWait(),q=G.xgrid||I.selectAll([]),s=G.xgridLines||I.selectAll([]),x=G.mainRegion||I.selectAll([]),z=G.mainText||I.selectAll([]),A=G.mainBar||I.selectAll([]),B=G.mainLine||I.selectAll([]),C=G.mainArea||I.selectAll([]),D=G.mainCircle||I.selectAll([]);G.data.targets.forEach(function(a){a.values.splice(0,j)}),e=G.updateXDomain(O,!0,!0),G.updateXGrid&&G.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||k.x===l.x?G.x(m[0])-G.x(e[0]):G.isTimeSeries()?G.x(m[0])-G.x(e[0]):G.x(k.x)-G.x(l.x):1!==G.data.targets[0].values.length?b=G.x(m[0])-G.x(e[0]):G.isTimeSeries()?(k=G.getValueOnIndex(G.data.targets[0].values,0),l=G.getValueOnIndex(G.data.targets[0].values,G.data.targets[0].values.length-1),b=G.x(k.x)-G.x(l.x)):b=xe(e)/2,h=xe(m)/xe(e),c="translate("+b+",0) scale("+h+",1)",I.transition().ease("linear").duration(n).each(function(){p.add(G.axes.x.transition().call(G.xAxis)),p.add(A.transition().attr("transform",c)),p.add(B.transition().attr("transform",c)),p.add(C.transition().attr("transform",c)),p.add(D.transition().attr("transform",c)),p.add(z.transition().attr("transform",c)),p.add(x.filter(G.isRegionOnX).transition().attr("transform",c)),p.add(q.transition().attr("transform",c)),p.add(s.transition().attr("transform",c))}).call(p,function(){var a,b=[],c=[],e=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),c.push("."+pe[Nd]+"-"+(i+a)),e.push("."+pe[pd]+"-"+(i+a));G.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),G.svg.selectAll("."+pe[Od]).selectAll(c).remove(),G.svg.selectAll("."+pe[qd]).selectAll(e).remove(),G.svg.select("."+pe[Rd]).remove()}q.attr("transform",null).attr(G.xgridAttr),s.attr("transform",null),s.select("line").attr("x1",J[vb]?0:P).attr("x2",J[vb]?G.width:P),s.select("text").attr("x",J[vb]?G.width:0).attr("y",P),A.attr("transform",null).attr("d",t),B.attr("transform",null).attr("d",u),C.attr("transform",null).attr("d",r),D.attr("transform",null).attr("cx",Q).attr("cy",R),z.attr("transform",null).attr("x",v).attr("y",w).style("fill-opacity",De(G.opacityForText,G)),x.attr("transform",null),x.select("rect").filter(G.isRegionOnX).attr("x",De(G.regionX,G)).attr("width",De(G.regionWidth,G)),d.attr("x",J[vb]?0:f).attr("y",J[vb]?f:0).attr("width",J[vb]?G.width:g).attr("height",J[vb]?g:G.height),o()})}),G.mapToIds(G.data.targets).forEach(function(a){G.withoutFadeIn[a]=!0}),G.updateZoom&&G.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0 +}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config; +a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 +}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index a1e4d32..590c78c 100644 --- a/src/core.js +++ b/src/core.js @@ -228,8 +228,7 @@ c3_chart_internal_fn.initWithData = function (data) { if ($$.initBar) { $$.initBar(); } // Define g for line chart area - main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_chartLines]); + if ($$.initLine) { $$.initLine(); } // Define g for arc chart area if ($$.initArc) { $$.initArc(); } @@ -374,8 +373,7 @@ c3_chart_internal_fn.updateSizes = function () { }; c3_chart_internal_fn.updateTargets = function (targets) { - var mainLineEnter, mainLineUpdate; - var $$ = this, config = $$.config, main = $$.main; + var $$ = this, config = $$.config; /*-- Main --*/ @@ -386,34 +384,9 @@ c3_chart_internal_fn.updateTargets = function (targets) { $$.updateTargetsForBar(targets); //-- Line --// - mainLineUpdate = main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) - .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); - mainLineEnter = mainLineUpdate.enter().append('g') - .attr('class', generateCall($$.classChartLine, $$)) - .style('opacity', 0) - .style("pointer-events", "none"); - // Lines for each data - mainLineEnter.append('g') - .attr("class", generateCall($$.classLines, $$)); - // Areas - mainLineEnter.append('g') - .attr('class', generateCall($$.classAreas, $$)); - // Circles for each data point on lines - mainLineEnter.append('g') - .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); - mainLineEnter.append('g') - .attr("class", generateCall($$.classCircles, $$)) - .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); - // Update date for selected circles - targets.forEach(function (t) { - main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { - d.value = t.values[d.index].value; - }); - }); - // MEMO: can not keep same color... - //mainLineUpdate.exit().remove(); + $$.updateTargetsForLine(targets); + //-- Arc --// if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); } if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); } @@ -427,7 +400,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var mainLine, mainArea, mainCircle, eventRect, eventRectUpdate; + var eventRect, eventRectUpdate; var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; var rectX, rectW; var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; @@ -439,8 +412,6 @@ c3_chart_internal_fn.redraw = function (options, transitions) { cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - mainCircle = d3.selectAll([]); - options = options || {}; withY = getOption(options, "withY", true); withSubchart = getOption(options, "withSubchart", true); @@ -516,9 +487,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) { } // setup drawer - MEMO: these must be called after axis updated - drawArea = $$.generateDrawArea(areaIndices, false); + drawArea = $$.generateDrawArea ? $$.generateDrawArea(areaIndices, false) : undefined; drawBar = $$.generateDrawBar ? $$.generateDrawBar(barIndices) : undefined; - drawLine = $$.generateDrawLine(lineIndices, false); + drawLine = $$.generateDrawLine ? $$.generateDrawLine(lineIndices, false) : undefined; xForText = $$.generateXYForText(barIndices, true); yForText = $$.generateXYForText(barIndices, false); @@ -550,42 +521,11 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.redrawBar(durationForExit); // lines, areas and cricles - mainLine = main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) - .data(generateCall($$.lineData, $$)); - mainLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) - .style("stroke", $$.color); - mainLine - .style("opacity", generateCall($$.initialOpacity, $$)) - .attr('transform', null); - mainLine.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - - mainArea = main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) - .data(generateCall($$.lineData, $$)); - mainArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) - .style("fill", $$.color) - .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); - mainArea - .style("opacity", $$.orgAreaOpacity); - mainArea.exit().transition().duration(durationForExit) - .style('opacity', 0) - .remove(); - - if (config[__point_show]) { - mainCircle = main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) - .data(generateCall($$.lineOrScatterData, $$)); - mainCircle.enter().append("circle") - .attr("class", generateCall($$.classCircle, $$)) - .attr("r", generateCall($$.pointR, $$)) - .style("fill", $$.color); - mainCircle - .style("opacity", generateCall($$.initialOpacity, $$)); - mainCircle.exit().remove(); - } + $$.redrawLine(durationForExit); + $$.redrawArea(durationForExit); + if (config[__point_show]) { $$.redrawCircle(); } + // text if ($$.hasDataLabel()) { $$.redrawText(durationForExit); } @@ -675,14 +615,22 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var transitions = []; $$.addTransitionForBar(transitions, drawBar); + $$.addTransitionForLine(transitions, drawLine); +/* transitions.push(mainLine.transition() .attr("d", drawLine) .style("stroke", $$.color) .style("opacity", 1)); +*/ + $$.addTransitionForArea(transitions, drawArea); +/* transitions.push(mainArea.transition() .attr("d", drawArea) .style("fill", $$.color) .style("opacity", $$.orgAreaOpacity)); +*/ + $$.addTransitionForCircle(transitions, cx, cy); +/* transitions.push(mainCircle.transition() .style('opacity', generateCall($$.opacityForCircle, $$)) .style("fill", $$.color) @@ -691,6 +639,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() .attr("cx", cx) .attr("cy", cy)); +*/ $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -718,7 +667,10 @@ c3_chart_internal_fn.redraw = function (options, transitions) { xgridLines = $$.xgridLines || d3.selectAll([]), mainRegion = $$.mainRegion || d3.selectAll([]), mainText = $$.mainText || d3.selectAll([]), - mainBar = $$.mainBar || d3.selectAll([]); + mainBar = $$.mainBar || d3.selectAll([]), + mainLine = $$.mainLine || d3.selectAll([]), + mainArea = $$.mainArea || d3.selectAll([]), + mainCircle = $$.mainCircle || d3.selectAll([]); // remove head data after rendered $$.data.targets.forEach(function (d) { diff --git a/src/shape.js b/src/shape.js index d0ec88c..d6b7fd7 100644 --- a/src/shape.js +++ b/src/shape.js @@ -51,269 +51,3 @@ c3_chart_internal_fn.getInterpolate = function (d) { var $$ = this; return $$.isSplineType(d) ? "cardinal" : $$.isStepType(d) ? "step-after" : "linear"; }; - - -c3_chart_internal_fn.circleX = function (d) { - return d.x || d.x === 0 ? this.x(d.x) : null; -}; -c3_chart_internal_fn.circleY = function (d, i) { - var $$ = this, - lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); - return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); -}; -c3_chart_internal_fn.getCircles = function (i, id) { - var $$ = this; - return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); -}; -c3_chart_internal_fn.expandCircles = function (i, id) { - var $$ = this; - $$.getCircles(i, id) - .classed(CLASS[_EXPANDED], true) - .attr('r', generateCall($$.pointExpandedR, $$)); -}; -c3_chart_internal_fn.unexpandCircles = function (i) { - var $$ = this; - $$.getCircles(i) - .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) - .classed(CLASS[_EXPANDED], false) - .attr('r', generateCall($$.pointR, $$)); -}; -c3_chart_internal_fn.pointR = function (d) { - var $$ = this, config = $$.config; - return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; -}; -c3_chart_internal_fn.pointExpandedR = function (d) { - var $$ = this, config = $$.config; - return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); -}; -c3_chart_internal_fn.pointSelectR = function (d) { - var $$ = this, config = $$.config; - return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; -}; - - - - -c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { - var $$ = this, config = $$.config, area = $$.d3.svg.area(), - getPoint = $$.generateGetAreaPoint(areaIndices, isSub), - yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, - xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, - value0 = function (d, i) { - return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); - }, - value1 = function (d, i) { - return config[__data_groups].length > 0 ? getPoint(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); - if (!config[__line_connect_null]) { - area = area.defined(function (d) { return d.value !== null; }); - } - - return function (d) { - var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; - if ($$.isAreaType(d)) { - path = area.interpolate($$.getInterpolate(d))(data); - } else { - if (data[0]) { - x0 = $$.x(data[0].x); - y0 = $$.getYScale(d.id)(data[0].value); - } - path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; - } - return path ? path : "M 0 0"; - }; -}; - -c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { - var $$ = this, config = $$.config, - line = $$.d3.svg.line(), - getPoint = $$.generateGetLinePoint(lineIndices, isSub), - yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, - xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, - yValue = function (d, i) { - return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); - }; - - line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); - if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } - return function (d) { - var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, - x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; - if ($$.isLineType(d)) { - if (config[__data_regions][d.id]) { - path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); - } else { - path = line.interpolate($$.getInterpolate(d))(data); - } - } else { - if (data[0]) { - x0 = x(data[0].x); - y0 = y(data[0].value); - } - path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; - } - return path ? path : "M 0 0"; - }; -}; - -c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { - var $$ = this, - getPoints = $$.generateGetBarPoints(barIndices, false), - getter = forX ? $$.getXForText : $$.getYForText; - return function (d, i) { - return getter.call($$, getPoints(d, i), d, this); - }; -}; -c3_chart_internal_fn.getXForText = function (points, d, textElement) { - var $$ = this, - box = textElement.getBoundingClientRect(), xPos, padding; - if ($$.config[__axis_rotated]) { - padding = $$.isBarType(d) ? 4 : 6; - xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); - } else { - xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; - } - return xPos > $$.width ? $$.width - box.width : xPos; -}; -c3_chart_internal_fn.getYForText = function (points, d, textElement) { - var $$ = this, - box = textElement.getBoundingClientRect(), yPos; - if ($$.config[__axis_rotated]) { - yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; - } else { - yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); - } - return yPos < box.height ? box.height : yPos; -}; - -c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints - var $$ = this, config = $$.config, - areaTargetsNum = areaIndices.__max__ + 1, - x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), - y = $$.getShapeY(!!isSub), - areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), - yScale = isSub ? $$.getSubYScale : $$.getYScale; - return function (d, i) { - var y0 = yScale.call($$, d.id)(0), - offset = areaOffset(d, i) || y0, // offset is for stacked area chart - posX = x(d), posY = y(d); - // fix posY not to overflow opposite quadrant - if (config[__axis_rotated]) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } - } - // 1 point that marks the area position - return [ - [posX, offset], - [posX, posY - (y0 - offset)] - ]; - }; -}; - -c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints - var $$ = this, config = $$.config, - lineTargetsNum = lineIndices.__max__ + 1, - x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), - y = $$.getShapeY(!!isSub), - lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), - yScale = isSub ? $$.getSubYScale : $$.getYScale; - return function (d, i) { - var y0 = yScale.call($$, d.id)(0), - offset = lineOffset(d, i) || y0, // offset is for stacked area chart - posX = x(d), posY = y(d); - // fix posY not to overflow opposite quadrant - if (config[__axis_rotated]) { - if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } - } - // 1 point that marks the line position - return [ - [posX, posY - (y0 - offset)] - ]; - }; -}; - - -c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { - var $$ = this, config = $$.config, - prev = -1, i, j, - s = "M", sWithRegion, - xp, yp, dx, dy, dd, diff, diffx2, - xValue, yValue, - regions = []; - - // Check start/end of regions - if (isDefined(_regions)) { - for (i = 0; i < _regions.length; i++) { - regions[i] = {}; - if (isUndefined(_regions[i].start)) { - regions[i].start = d[0].x; - } else { - regions[i].start = $$.isTimeSeries() ? $$.parseDate(_regions[i].start) : _regions[i].start; - } - if (isUndefined(_regions[i].end)) { - regions[i].end = d[d.length - 1].x; - } else { - regions[i].end = $$.isTimeSeries() ? $$.parseDate(_regions[i].end) : _regions[i].end; - } - } - } - - // Set scales - 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); }; - - // Define svg generator function for region - if ($$.isTimeSeries()) { - sWithRegion = function (d0, d1, j, diff) { - var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, - xv0 = new Date(x0 + x_diff * j), - xv1 = new Date(x0 + x_diff * (j + diff)); - return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); - }; - } else { - sWithRegion = function (d0, d1, j, diff) { - return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); - }; - } - - // Generate - for (i = 0; i < d.length; i++) { - - // Draw as normal - if (isUndefined(regions) || ! $$.isWithinRegions(d[i].x, regions)) { - s += " " + xValue(d[i]) + " " + yValue(d[i]); - } - // Draw with region // TODO: Fix for horizotal charts - else { - xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries()); - yp = $$.getScale(d[i - 1].value, d[i].value); - - dx = x(d[i].x) - x(d[i - 1].x); - dy = y(d[i].value) - y(d[i - 1].value); - dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); - diff = 2 / dd; - diffx2 = diff * 2; - - for (j = diff; j <= 1; j += diffx2) { - s += sWithRegion(d[i - 1], d[i], j, diff); - } - } - prev = d[i].x; - } - - return s; -}; -c3_chart_internal_fn.isWithinCircle = function (_this, _r) { - var d3 = this.d3, - mouse = d3.mouse(_this), d3_this = d3.select(_this), - cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; - return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; -}; -c3_chart_internal_fn.isWithinRegions = function (x, regions) { - var i; - for (i = 0; i < regions.length; i++) { - if (regions[i].start < x && x <= regions[i].end) { return true; } - } - return false; -}; diff --git a/src/shape.line.js b/src/shape.line.js new file mode 100644 index 0000000..b84129f --- /dev/null +++ b/src/shape.line.js @@ -0,0 +1,338 @@ +c3_chart_internal_fn.initLine = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_chartLines]); +}; +c3_chart_internal_fn.updateTargetsForLine = function (targets) { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + mainLineUpdate, mainLineEnter, + classChartLine = $$.classChartLine.bind($$), + classLines = $$.classLines.bind($$), + classAreas = $$.classAreas.bind($$), + classCircles = $$.classCircles.bind($$); + mainLineUpdate = $$.main.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) + .data(targets) + .attr('class', classChartLine); + mainLineEnter = mainLineUpdate.enter().append('g') + .attr('class', classChartLine) + .style('opacity', 0) + .style("pointer-events", "none"); + // Lines for each data + mainLineEnter.append('g') + .attr("class", classLines); + // Areas + mainLineEnter.append('g') + .attr('class', classAreas); + // Circles for each data point on lines + mainLineEnter.append('g') + .attr("class", function (d) { return $$.generateClass(CLASS[_selectedCircles], d.id); }); + mainLineEnter.append('g') + .attr("class", classCircles) + .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }); + // Update date for selected circles + targets.forEach(function (t) { + $$.main.selectAll('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(t.id)).selectAll('.' + CLASS[_selectedCircle]).each(function (d) { + d.value = t.values[d.index].value; + }); + }); + // MEMO: can not keep same color... + //mainLineUpdate.exit().remove(); +}; +c3_chart_internal_fn.redrawLine = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS; + $$.mainLine = $$.main.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) + .data($$.lineData.bind($$)); + $$.mainLine.enter().append('path') + .attr('class', $$.classLine.bind($$)) + .style("stroke", $$.color); + $$.mainLine + .style("opacity", $$.initialOpacity.bind($$)) + .attr('transform', null); + $$.mainLine.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); +}; +c3_chart_internal_fn.addTransitionForLine = function (transitions, drawLine) { + var $$ = this; + transitions.push($$.mainLine.transition() + .attr("d", drawLine) + .style("stroke", $$.color) + .style("opacity", 1)); +}; +c3_chart_internal_fn.generateDrawLine = function (lineIndices, isSub) { + var $$ = this, config = $$.config, + line = $$.d3.svg.line(), + getPoint = $$.generateGetLinePoint(lineIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + yValue = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(d.value); + }; + + line = config[__axis_rotated] ? line.x(yValue).y(xValue) : line.x(xValue).y(yValue); + if (!config[__line_connect_null]) { line = line.defined(function (d) { return d.value != null; }); } + return function (d) { + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, + x = isSub ? $$.x : $$.subX, y = yScaleGetter.call($$, d.id), x0 = 0, y0 = 0, path; + if ($$.isLineType(d)) { + if (config[__data_regions][d.id]) { + path = $$.lineWithRegions(data, x, y, config[__data_regions][d.id]); + } else { + path = line.interpolate($$.getInterpolate(d))(data); + } + } else { + if (data[0]) { + x0 = x(data[0].x); + y0 = y(data[0].value); + } + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; +}; +c3_chart_internal_fn.generateGetLinePoint = function (lineIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, config = $$.config, + lineTargetsNum = lineIndices.__max__ + 1, + x = $$.getShapeX(0, lineTargetsNum, lineIndices, !!isSub), + y = $$.getShapeY(!!isSub), + lineOffset = $$.getShapeOffset($$.isLineType, lineIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = lineOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the line position + return [ + [posX, posY - (y0 - offset)] + ]; + }; +}; + + +c3_chart_internal_fn.lineWithRegions = function (d, x, y, _regions) { + var $$ = this, config = $$.config, + prev = -1, i, j, + s = "M", sWithRegion, + xp, yp, dx, dy, dd, diff, diffx2, + xValue, yValue, + regions = []; + + function isWithinRegions(x, regions) { + var i; + for (i = 0; i < regions.length; i++) { + if (regions[i].start < x && x <= regions[i].end) { return true; } + } + return false; + } + + // Check start/end of regions + if (isDefined(_regions)) { + for (i = 0; i < _regions.length; i++) { + regions[i] = {}; + if (isUndefined(_regions[i].start)) { + regions[i].start = d[0].x; + } else { + regions[i].start = $$.isTimeSeries() ? $$.parseDate(_regions[i].start) : _regions[i].start; + } + if (isUndefined(_regions[i].end)) { + regions[i].end = d[d.length - 1].x; + } else { + regions[i].end = $$.isTimeSeries() ? $$.parseDate(_regions[i].end) : _regions[i].end; + } + } + } + + // Set scales + 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); }; + + // Define svg generator function for region + if ($$.isTimeSeries()) { + sWithRegion = function (d0, d1, j, diff) { + var x0 = d0.x.getTime(), x_diff = d1.x - d0.x, + xv0 = new Date(x0 + x_diff * j), + xv1 = new Date(x0 + x_diff * (j + diff)); + return "M" + x(xv0) + " " + y(yp(j)) + " " + x(xv1) + " " + y(yp(j + diff)); + }; + } else { + sWithRegion = function (d0, d1, j, diff) { + return "M" + x(xp(j), true) + " " + y(yp(j)) + " " + x(xp(j + diff), true) + " " + y(yp(j + diff)); + }; + } + + // Generate + for (i = 0; i < d.length; i++) { + + // Draw as normal + if (isUndefined(regions) || ! isWithinRegions(d[i].x, regions)) { + s += " " + xValue(d[i]) + " " + yValue(d[i]); + } + // Draw with region // TODO: Fix for horizotal charts + else { + xp = $$.getScale(d[i - 1].x, d[i].x, $$.isTimeSeries()); + yp = $$.getScale(d[i - 1].value, d[i].value); + + dx = x(d[i].x) - x(d[i - 1].x); + dy = y(d[i].value) - y(d[i - 1].value); + dd = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); + diff = 2 / dd; + diffx2 = diff * 2; + + for (j = diff; j <= 1; j += diffx2) { + s += sWithRegion(d[i - 1], d[i], j, diff); + } + } + prev = d[i].x; + } + + return s; +}; + + +c3_chart_internal_fn.redrawArea = function (durationForExit) { + var $$ = this, CLASS = $$.CLASS, d3 = $$.d3; + $$.mainArea = $$.main.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) + .data($$.lineData.bind($$)); + $$.mainArea.enter().append('path') + .attr("class", $$.classArea.bind($$)) + .style("fill", $$.color) + .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); + $$.mainArea + .style("opacity", $$.orgAreaOpacity); + $$.mainArea.exit().transition().duration(durationForExit) + .style('opacity', 0) + .remove(); +}; +c3_chart_internal_fn.addTransitionForArea = function (transitions, drawArea) { + var $$ = this; + transitions.push($$.mainArea.transition() + .attr("d", drawArea) + .style("fill", $$.color) + .style("opacity", $$.orgAreaOpacity)); +}; +c3_chart_internal_fn.generateDrawArea = function (areaIndices, isSub) { + var $$ = this, config = $$.config, area = $$.d3.svg.area(), + getPoint = $$.generateGetAreaPoint(areaIndices, isSub), + yScaleGetter = isSub ? $$.getSubYScale : $$.getYScale, + xValue = function (d) { return (isSub ? $$.subxx : $$.xx).call($$, d); }, + value0 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : yScaleGetter.call($$, d.id)(0); + }, + value1 = function (d, i) { + return config[__data_groups].length > 0 ? getPoint(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); + if (!config[__line_connect_null]) { + area = area.defined(function (d) { return d.value !== null; }); + } + + return function (d) { + var data = config[__line_connect_null] ? $$.filterRemoveNull(d.values) : d.values, x0 = 0, y0 = 0, path; + if ($$.isAreaType(d)) { + path = area.interpolate($$.getInterpolate(d))(data); + } else { + if (data[0]) { + x0 = $$.x(data[0].x); + y0 = $$.getYScale(d.id)(data[0].value); + } + path = config[__axis_rotated] ? "M " + y0 + " " + x0 : "M " + x0 + " " + y0; + } + return path ? path : "M 0 0"; + }; +}; + +c3_chart_internal_fn.generateGetAreaPoint = function (areaIndices, isSub) { // partial duplication of generateGetBarPoints + var $$ = this, config = $$.config, + areaTargetsNum = areaIndices.__max__ + 1, + x = $$.getShapeX(0, areaTargetsNum, areaIndices, !!isSub), + y = $$.getShapeY(!!isSub), + areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, !!isSub), + yScale = isSub ? $$.getSubYScale : $$.getYScale; + return function (d, i) { + var y0 = yScale.call($$, d.id)(0), + offset = areaOffset(d, i) || y0, // offset is for stacked area chart + posX = x(d), posY = y(d); + // fix posY not to overflow opposite quadrant + if (config[__axis_rotated]) { + if ((0 < d.value && posY < y0) || (d.value < 0 && y0 < posY)) { posY = y0; } + } + // 1 point that marks the area position + return [ + [posX, offset], + [posX, posY - (y0 - offset)] + ]; + }; +}; + + +c3_chart_internal_fn.redrawCircle = function () { + var $$ = this, CLASS = $$.CLASS; + $$.mainCircle = $$.main.selectAll('.' + CLASS[_circles]).selectAll('.' + CLASS[_circle]) + .data($$.lineOrScatterData.bind($$)); + $$.mainCircle.enter().append("circle") + .attr("class", $$.classCircle.bind($$)) + .attr("r", $$.pointR.bind($$)) + .style("fill", $$.color); + $$.mainCircle + .style("opacity", $$.initialOpacity.bind($$)); + $$.mainCircle.exit().remove(); +}; +c3_chart_internal_fn.addTransitionForCircle = function (transitions, cx, cy) { + var $$ = this; + transitions.push($$.mainCircle.transition() + .style('opacity', $$.opacityForCircle.bind($$)) + .style("fill", $$.color) + .attr("cx", cx) + .attr("cy", cy)); + transitions.push($$.main.selectAll('.' + CLASS[_selectedCircle]).transition() + .attr("cx", cx) + .attr("cy", cy)); +}; +c3_chart_internal_fn.circleX = function (d) { + return d.x || d.x === 0 ? this.x(d.x) : null; +}; +c3_chart_internal_fn.circleY = function (d, i) { + var $$ = this, + lineIndices = $$.getShapeIndices($$.isLineType), getPoint = $$.generateGetLinePoint(lineIndices); + return $$.config[__data_groups].length > 0 ? getPoint(d, i)[0][1] : $$.getYScale(d.id)(d.value); +}; +c3_chart_internal_fn.getCircles = function (i, id) { + var $$ = this; + return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); +}; +c3_chart_internal_fn.expandCircles = function (i, id) { + var $$ = this; + $$.getCircles(i, id) + .classed(CLASS[_EXPANDED], true) + .attr('r', generateCall($$.pointExpandedR, $$)); +}; +c3_chart_internal_fn.unexpandCircles = function (i) { + var $$ = this; + $$.getCircles(i) + .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) + .classed(CLASS[_EXPANDED], false) + .attr('r', generateCall($$.pointR, $$)); +}; +c3_chart_internal_fn.pointR = function (d) { + var $$ = this, config = $$.config; + return config[__point_show] && !$$.isStepType(d) ? (isFunction(config[__point_r]) ? config[__point_r](d) : config[__point_r]) : 0; +}; +c3_chart_internal_fn.pointExpandedR = function (d) { + var $$ = this, config = $$.config; + return config[__point_focus_expand_enabled] ? (config[__point_focus_expand_r] ? config[__point_focus_expand_r] : $$.pointR(d) * 1.75) : $$.pointR(d); +}; +c3_chart_internal_fn.pointSelectR = function (d) { + var $$ = this, config = $$.config; + return config[__point_select_r] ? config[__point_select_r] : $$.pointR(d) * 4; +}; +c3_chart_internal_fn.isWithinCircle = function (_this, _r) { + var d3 = this.d3, + mouse = d3.mouse(_this), d3_this = d3.select(_this), + cx = d3_this.attr("cx") * 1, cy = d3_this.attr("cy") * 1; + return Math.sqrt(Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)) < _r; +}; diff --git a/src/text.js b/src/text.js index 45ec347..a61fc8d 100644 --- a/src/text.js +++ b/src/text.js @@ -54,3 +54,32 @@ c3_chart_internal_fn.getTextRect = function (text, cls) { .remove(); return rect; }; +c3_chart_internal_fn.generateXYForText = function (barIndices, forX) { + var $$ = this, + getPoints = $$.generateGetBarPoints(barIndices, false), + getter = forX ? $$.getXForText : $$.getYForText; + return function (d, i) { + return getter.call($$, getPoints(d, i), d, this); + }; +}; +c3_chart_internal_fn.getXForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), xPos, padding; + if ($$.config[__axis_rotated]) { + padding = $$.isBarType(d) ? 4 : 6; + xPos = points[2][1] + padding * (d.value < 0 ? -1 : 1); + } else { + xPos = $$.hasType('bar') ? (points[2][0] + points[0][0]) / 2 : points[0][0]; + } + return xPos > $$.width ? $$.width - box.width : xPos; +}; +c3_chart_internal_fn.getYForText = function (points, d, textElement) { + var $$ = this, + box = textElement.getBoundingClientRect(), yPos; + if ($$.config[__axis_rotated]) { + yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2; + } else { + yPos = points[2][1] + (d.value < 0 ? box.height : $$.isBarType(d) ? -3 : -6); + } + return yPos < box.height ? box.height : yPos; +}; From 0516616d41de436653c592798b0ae780b9304093 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 17 Aug 2014 11:48:21 +0900 Subject: [PATCH 39/44] Modularize event rect --- Gruntfile.coffee | 1 + c3.js | 626 +++++++++++++++++++++++---------------------- c3.min.js | 6 +- src/core.js | 316 +---------------------- src/data.js | 8 +- src/interaction.js | 301 ++++++++++++++++++++++ 6 files changed, 631 insertions(+), 627 deletions(-) create mode 100644 src/interaction.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 88c3855..3118abf 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -27,6 +27,7 @@ module.exports = (grunt) -> 'src/data.convert.js', 'src/data.load.js', 'src/category.js', + 'src/interaction.js', 'src/size.js', 'src/shape.js', 'src/shape.line.js', diff --git a/c3.js b/c3.js index 87a5e1f..993eda0 100644 --- a/c3.js +++ b/c3.js @@ -132,7 +132,7 @@ c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; - var main, eventRect, binding = true; + var main, binding = true; if ($$.initPie) { $$.initPie(); } if ($$.initBrush) { $$.initBrush(); } @@ -225,9 +225,7 @@ .attr('class', CLASS[_chart]); // Cover whole with rects for events - eventRect = main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_eventRects]) - .style('fill-opacity', 0); + $$.initEventRect(); // Define g for bar chart area if ($$.initBar) { $$.initBar(); } @@ -405,9 +403,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; - var rectX, rectW; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType); var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; @@ -549,70 +545,9 @@ .selectAll('circle') .remove(); + // event rect if (config[__interaction_enabled]) { - // rect for mouseover - eventRect = main.select('.' + CLASS[_eventRects]) - .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { - - if (!eventRect.classed(CLASS[_eventRectsMultiple])) { - eventRect.classed(CLASS[_eventRectsMultiple], true).classed(CLASS[_eventRectsSingle], false) - .selectAll('.' + CLASS[_eventRect]).remove(); - } - - eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) - .data([0]); - // enter : only one rect will be added - $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('x', 0) - .attr('y', 0) - .attr('width', $$.width) - .attr('height', $$.height); - // exit : not needed because always only one rect exists - } else { - - if (!eventRect.classed(CLASS[_eventRectsSingle])) { - eventRect.classed(CLASS[_eventRectsMultiple], false).classed(CLASS[_eventRectsSingle], true) - .selectAll('.' + CLASS[_eventRect]).remove(); - } - - if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { - rectW = function (d) { - var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], - w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; - return w < 0 ? 0 : w; - }; - rectX = function (d) { - var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; - return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; - }; - } else { - rectW = $$.getEventRectWidth(); - rectX = function (d) { - return $$.x(d.x) - (rectW / 2); - }; - } - // Set data - maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); - main.select('.' + CLASS[_eventRects]) - .datum(maxDataCountTarget ? maxDataCountTarget.values : []); - // Update rects - eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) - .data(function (d) { return d; }); - // enter - $$.generateEventRectsForSingleX(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('class', generateCall($$.classEvent, $$)) - .attr("x", config[__axis_rotated] ? 0 : rectX) - .attr("y", config[__axis_rotated] ? rectX : 0) - .attr("width", config[__axis_rotated] ? $$.width : rectW) - .attr("height", config[__axis_rotated] ? rectW : $$.height); - // exit - eventRectUpdate.exit().remove(); - } + $$.redrawEventRect(); } // transition should be derived from one transition @@ -621,30 +556,8 @@ $$.addTransitionForBar(transitions, drawBar); $$.addTransitionForLine(transitions, drawLine); - /* - transitions.push(mainLine.transition() - .attr("d", drawLine) - .style("stroke", $$.color) - .style("opacity", 1)); - */ $$.addTransitionForArea(transitions, drawArea); - /* - transitions.push(mainArea.transition() - .attr("d", drawArea) - .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity)); - */ $$.addTransitionForCircle(transitions, cx, cy); - /* - transitions.push(mainCircle.transition() - .style('opacity', generateCall($$.opacityForCircle, $$)) - .style("fill", $$.color) - .attr("cx", cx) - .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() - .attr("cx", cx) - .attr("cy", cy)); - */ $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -774,11 +687,7 @@ mainRegion.select('rect').filter($$.isRegionOnX) .attr("x", generateCall($$.regionX, $$)) .attr("width", generateCall($$.regionWidth, $$)); - eventRectUpdate - .attr("x", config[__axis_rotated] ? 0 : rectX) - .attr("y", config[__axis_rotated] ? rectX : 0) - .attr("width", config[__axis_rotated] ? $$.width : rectW) - .attr("height", config[__axis_rotated] ? rectW : $$.height); + $$.updateEventRect(); // callback for end of flow done(); @@ -820,219 +729,6 @@ $$.redraw(options, transitions); }; - c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { - var $$ = this, d3 = $$.d3, config = $$.config; - eventRectEnter.append("rect") - .attr("class", generateCall($$.classEvent, $$)) - .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) - .on('mouseover', function (d) { - var index = d.index, selectedData, newData; - - if ($$.dragging) { return; } // do nothing if dragging - if ($$.hasArcType()) { return; } - - selectedData = $$.data.targets.map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); - }); - - // Sort selectedData as names order - newData = []; - Object.keys(config[__data_names]).forEach(function (id) { - for (var j = 0; j < selectedData.length; j++) { - if (selectedData[j] && selectedData[j].id === id) { - newData.push(selectedData[j]); - selectedData.shift(j); - break; - } - } - }); - selectedData = newData.concat(selectedData); // Add remained - - // Expand shapes for selection - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } - $$.expandBars(index); - - // Call event handler - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - config[__data_onmouseover].call(c3, d); - }); - }) - .on('mouseout', function (d) { - var index = d.index; - if ($$.hasArcType()) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); - // Undo expanded shapes - $$.unexpandCircles(index); - $$.unexpandBars(); - // Call event handler - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - config[__data_onmouseout].call($$, d); - }); - }) - .on('mousemove', function (d) { - var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); - - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType()) { return; } - - // Show tooltip - selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); - }); - - if (config[__tooltip_grouped]) { - $$.showTooltip(selectedData, d3.mouse(this)); - $$.showXGridFocus(selectedData); - } - - if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { - return; - } - - $$.main.selectAll('.' + CLASS[_shape] + '-' + index) - .each(function () { - d3.select(this).classed(CLASS[_EXPANDED], true); - if (config[__data_selection_enabled]) { - eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); - } - if (!config[__tooltip_grouped]) { - $$.hideXGridFocus(); - $$.hideTooltip(); - if (!config[__data_selection_grouped]) { - $$.unexpandCircles(index); - $$.unexpandBars(); - } - } - }) - .filter(function (d) { - if (this.nodeName === 'circle') { - return $$.isWithinCircle(this, $$.pointSelectR(d)); - } - else if (this.nodeName === 'path') { - return $$.isWithinBar(this); - } - }) - .each(function (d) { - if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { - eventRect.style('cursor', 'pointer'); - } - if (!config[__tooltip_grouped]) { - $$.showTooltip([d], d3.mouse(this)); - $$.showXGridFocus([d]); - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } - $$.expandBars(index, d.id); - } - }); - }) - .on('click', function (d) { - var index = d.index; - if ($$.hasArcType() || !$$.toggleShape) { return; } - if ($$.cancelClick) { - $$.cancelClick = false; - return; - } - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - $$.toggleShape(this, d, index); - }); - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) - ) - .on("dblclick.zoom", null); - }; - - c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { - var $$ = this, d3 = $$.d3, config = $$.config; - eventRectEnter.append('rect') - .attr('x', 0) - .attr('y', 0) - .attr('width', $$.width) - .attr('height', $$.height) - .attr('class', CLASS[_eventRect]) - .on('mouseout', function () { - if ($$.hasArcType()) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); - $$.unexpandCircles(); - }) - .on('mousemove', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); - var mouse, closest, sameXData, selectedData; - - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType(targetsToShow)) { return; } - - mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); - - if (! closest) { return; } - - if ($$.isScatterType(closest)) { - sameXData = [closest]; - } else { - sameXData = $$.filterSameX(targetsToShow, closest.x); - } - - // show tooltip when cursor is close to some point - selectedData = sameXData.map(function (d) { - return $$.addName(d); - }); - $$.showTooltip(selectedData, mouse); - - // expand points - if (config[__point_focus_expand_enabled]) { - $$.unexpandCircles(); - $$.expandCircles(closest.index, closest.id); - } - - // Show xgrid focus line - $$.showXGridFocus(selectedData); - - // Show cursor as pointer if point is close to mouse position - if ($$.dist(closest, mouse) < 100) { - $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); - if (!$$.mouseover) { - config[__data_onmouseover].call($$, closest); - $$.mouseover = true; - } - } else if ($$.mouseover) { - $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); - config[__data_onmouseout].call($$, closest); - $$.mouseover = false; - } - }) - .on('click', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); - var mouse, closest; - - if ($$.hasArcType(targetsToShow)) { return; } - - mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); - - if (! closest) { return; } - - // select if selection enabled - if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { - $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { - $$.toggleShape(this, closest, closest.index); - }); - } - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) - ) - .on("dblclick.zoom", null); - }; - c3_chart_internal_fn.isTimeSeries = function () { return this.config[__axis_x_type] === 'timeseries'; }; @@ -1958,8 +1654,12 @@ $$.config[__data_xs][id] = xs[id]; }); }; - c3_chart_internal_fn.isSingleX = function (xs) { - return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; + c3_chart_internal_fn.hasMultipleX = function (xs) { + return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() > 1; + }; + c3_chart_internal_fn.isMultipleX = function () { + var $$ = this, config = $$.config; + return notEmpty(config[__data_xs]) && $$.hasMultipleX(config[__data_xs]); }; c3_chart_internal_fn.addName = function (data) { var $$ = this, name; @@ -2517,6 +2217,308 @@ return i < config[__axis_x_categories].length ? config[__axis_x_categories][i] : i; }; + c3_chart_internal_fn.initEventRect = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_eventRects]) + .style('fill-opacity', 0); + }; + c3_chart_internal_fn.redrawEventRect = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + eventRectUpdate, maxDataCountTarget, + isMultipleX = $$.isMultipleX(); + + // rects for mouseover + var eventRects = $$.main.select('.' + CLASS[_eventRects]) + .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null) + .classed(CLASS[_eventRectsMultiple], isMultipleX) + .classed(CLASS[_eventRectsSingle], !isMultipleX); + + // clear old rects + eventRects.selectAll('.' + CLASS[_eventRect]).remove(); + + // open as public variable + $$.eventRect = eventRects.selectAll('.' + CLASS[_eventRect]); + + if (isMultipleX) { + eventRectUpdate = $$.eventRect.data([0]); + // enter : only one rect will be added + $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); + // update + $$.updateEventRect(eventRectUpdate); + // exit : not needed because always only one rect exists + } + else { + // Set data and update $$.eventRect + maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); + eventRects.datum(maxDataCountTarget ? maxDataCountTarget.values : []); + $$.eventRect = eventRects.selectAll('.' + CLASS[_eventRect]); + eventRectUpdate = $$.eventRect.data(function (d) { return d; }); + // enter + $$.generateEventRectsForSingleX(eventRectUpdate.enter()); + // update + $$.updateEventRect(eventRectUpdate); + // exit + eventRectUpdate.exit().remove(); + } + }; + c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) { + var $$ = this, config = $$.config, + x, y, w, h, rectW, rectX; + + // set update selection if null + eventRectUpdate = eventRectUpdate || $$.eventRect.data(function (d) { return d; }); + + if ($$.isMultipleX()) { + // TODO: rotated not supported yet + x = 0; + y = 0; + w = $$.width; + h = $$.height; + } + else { + if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { + rectW = function (d) { + var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], + w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; + return w < 0 ? 0 : w; + }; + rectX = function (d) { + var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; + return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; + }; + } else { + rectW = $$.getEventRectWidth(); + rectX = function (d) { + return $$.x(d.x) - (rectW / 2); + }; + } + x = config[__axis_rotated] ? 0 : rectX; + y = config[__axis_rotated] ? rectX : 0; + w = config[__axis_rotated] ? $$.width : rectW; + h = config[__axis_rotated] ? rectW : $$.height; + } + + eventRectUpdate + .attr('class', $$.classEvent.bind($$)) + .attr("x", x) + .attr("y", y) + .attr("width", w) + .attr("height", h); + }; + c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append("rect") + .attr("class", generateCall($$.classEvent, $$)) + .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) + .on('mouseover', function (d) { + var index = d.index, selectedData, newData; + + if ($$.dragging) { return; } // do nothing if dragging + if ($$.hasArcType()) { return; } + + selectedData = $$.data.targets.map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + // Sort selectedData as names order + newData = []; + Object.keys(config[__data_names]).forEach(function (id) { + for (var j = 0; j < selectedData.length; j++) { + if (selectedData[j] && selectedData[j].id === id) { + newData.push(selectedData[j]); + selectedData.shift(j); + break; + } + } + }); + selectedData = newData.concat(selectedData); // Add remained + + // Expand shapes for selection + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } + $$.expandBars(index); + + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseover].call(c3, d); + }); + }) + .on('mouseout', function (d) { + var index = d.index; + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + // Undo expanded shapes + $$.unexpandCircles(index); + $$.unexpandBars(); + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseout].call($$, d); + }); + }) + .on('mousemove', function (d) { + var selectedData, index = d.index, + eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType()) { return; } + + // Show tooltip + selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + if (config[__tooltip_grouped]) { + $$.showTooltip(selectedData, d3.mouse(this)); + $$.showXGridFocus(selectedData); + } + + if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { + return; + } + + $$.main.selectAll('.' + CLASS[_shape] + '-' + index) + .each(function () { + d3.select(this).classed(CLASS[_EXPANDED], true); + if (config[__data_selection_enabled]) { + eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); + } + if (!config[__tooltip_grouped]) { + $$.hideXGridFocus(); + $$.hideTooltip(); + if (!config[__data_selection_grouped]) { + $$.unexpandCircles(index); + $$.unexpandBars(); + } + } + }) + .filter(function (d) { + if (this.nodeName === 'circle') { + return $$.isWithinCircle(this, $$.pointSelectR(d)); + } + else if (this.nodeName === 'path') { + return $$.isWithinBar(this); + } + }) + .each(function (d) { + if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { + eventRect.style('cursor', 'pointer'); + } + if (!config[__tooltip_grouped]) { + $$.showTooltip([d], d3.mouse(this)); + $$.showXGridFocus([d]); + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } + $$.expandBars(index, d.id); + } + }); + }) + .on('click', function (d) { + var index = d.index; + if ($$.hasArcType() || !$$.toggleShape) { return; } + if ($$.cancelClick) { + $$.cancelClick = false; + return; + } + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + $$.toggleShape(this, d, index); + }); + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); + }; + + c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height) + .attr('class', CLASS[_eventRect]) + .on('mouseout', function () { + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + $$.unexpandCircles(); + }) + .on('mousemove', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest, sameXData, selectedData; + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + if ($$.isScatterType(closest)) { + sameXData = [closest]; + } else { + sameXData = $$.filterSameX(targetsToShow, closest.x); + } + + // show tooltip when cursor is close to some point + selectedData = sameXData.map(function (d) { + return $$.addName(d); + }); + $$.showTooltip(selectedData, mouse); + + // expand points + if (config[__point_focus_expand_enabled]) { + $$.unexpandCircles(); + $$.expandCircles(closest.index, closest.id); + } + + // Show xgrid focus line + $$.showXGridFocus(selectedData); + + // Show cursor as pointer if point is close to mouse position + if ($$.dist(closest, mouse) < 100) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); + if (!$$.mouseover) { + config[__data_onmouseover].call($$, closest); + $$.mouseover = true; + } + } else if ($$.mouseover) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); + config[__data_onmouseout].call($$, closest); + $$.mouseover = false; + } + }) + .on('click', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest; + + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + // select if selection enabled + if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { + $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { + $$.toggleShape(this, closest, closest.index); + }); + } + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); + }; + c3_chart_internal_fn.getCurrentWidth = function () { var $$ = this, config = $$.config; return config[__size_width] ? config[__size_width] : $$.getParentWidth(); diff --git a/c3.min.js b/c3.min.js index 30ebbf7..546f720 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&I.select(this).style("display",b%F?"none":"block")})}else G.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!J[vb]&&J[Hb]&&G.rotateTickText(G.axes.x,b.axisX,J[Hb]),r=G.generateDrawArea?G.generateDrawArea(K,!1):void 0,t=G.generateDrawBar?G.generateDrawBar(L):void 0,u=G.generateDrawLine?G.generateDrawLine(M,!1):void 0,v=G.generateXYForText(L,!0),w=G.generateXYForText(L,!1),G.subY.domain(G.y.domain()),G.subY2.domain(G.y2.domain()),G.tooltip.style("display","none"),G.updateXgridFocus(),H.select("text."+pe[Nd]+"."+pe[Md]).attr("x",G.width/2).attr("y",G.height/2).text(J[fb]).transition().style("opacity",O.length?0:1),G.redrawGrid(y,h),G.redrawRegion(y),G.redrawBar(A),G.redrawLine(A),G.redrawArea(A),J[mc]&&G.redrawCircle(),G.hasDataLabel()&&G.redrawText(A),G.redrawArc&&G.redrawArc(y,A,m),G.redrawSubchart&&G.redrawSubchart(i,b,y,A,K,L,M),H.selectAll("."+pe[od]).filter(De(G.isBarType,G)).selectAll("circle").remove(),J[s]&&(c=H.select("."+pe[qd]).style("cursor",J[o]?J[vb]?"ns-resize":"ew-resize":null),ze(J[z])&&!G.isSingleX(J[z])?(c.classed(pe[sd])||c.classed(pe[sd],!0).classed(pe[rd],!1).selectAll("."+pe[pd]).remove(),d=H.select("."+pe[qd]).selectAll("."+pe[pd]).data([0]),G.generateEventRectsForMultipleXs(d.enter()),d.attr("x",0).attr("y",0).attr("width",G.width).attr("height",G.height)):(c.classed(pe[rd])||c.classed(pe[sd],!1).classed(pe[rd],!0).selectAll("."+pe[pd]).remove(),!G.isCustomX()&&!G.isTimeSeries()||G.isCategorized()?(g=G.getEventRectWidth(),f=function(a){return G.x(a.x)-g/2}):(g=function(a){var b=G.getPrevX(a.index),c=G.getNextX(a.index),d=G.data.xs[a.id][a.index],e=(G.x(c?c:d)-G.x(b?b:d))/2;return 0>e?0:e},f=function(a){var b=G.getPrevX(a.index),c=G.data.xs[a.id][a.index];return(G.x(c)+G.x(b?b:c))/2}),e=G.getMaxDataCountTarget(G.data.targets),H.select("."+pe[qd]).datum(e?e.values:[]),d=H.select("."+pe[qd]).selectAll("."+pe[pd]).data(function(a){return a}),G.generateEventRectsForSingleX(d.enter()),d.attr("class",De(G.classEvent,G)).attr("x",J[vb]?0:f).attr("y",J[vb]?f:0).attr("width",J[vb]?G.width:g).attr("height",J[vb]?g:G.height),d.exit().remove())),I.transition().duration(y).each(function(){var b=[];G.addTransitionForBar(b,t),G.addTransitionForLine(b,u),G.addTransitionForArea(b,r),G.addTransitionForCircle(b,Q,R),G.addTransitionForText(b,v,w,a.flow),G.addTransitionForRegion(b),G.addTransitionForGrid(b),a.flow&&(C=G.generateWait(),b.forEach(function(a){C.add(a)}))}).call(C?C:function(){},function(){var b,c,e,h=1,i=a.flow.index,j=a.flow.length,k=G.getValueOnIndex(G.data.targets[0].values,i),l=G.getValueOnIndex(G.data.targets[0].values,i+j),m=G.x.domain(),n=a.flow.duration||y,o=a.flow.done||function(){},p=G.generateWait(),q=G.xgrid||I.selectAll([]),s=G.xgridLines||I.selectAll([]),x=G.mainRegion||I.selectAll([]),z=G.mainText||I.selectAll([]),A=G.mainBar||I.selectAll([]),B=G.mainLine||I.selectAll([]),C=G.mainArea||I.selectAll([]),D=G.mainCircle||I.selectAll([]);G.data.targets.forEach(function(a){a.values.splice(0,j)}),e=G.updateXDomain(O,!0,!0),G.updateXGrid&&G.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||k.x===l.x?G.x(m[0])-G.x(e[0]):G.isTimeSeries()?G.x(m[0])-G.x(e[0]):G.x(k.x)-G.x(l.x):1!==G.data.targets[0].values.length?b=G.x(m[0])-G.x(e[0]):G.isTimeSeries()?(k=G.getValueOnIndex(G.data.targets[0].values,0),l=G.getValueOnIndex(G.data.targets[0].values,G.data.targets[0].values.length-1),b=G.x(k.x)-G.x(l.x)):b=xe(e)/2,h=xe(m)/xe(e),c="translate("+b+",0) scale("+h+",1)",I.transition().ease("linear").duration(n).each(function(){p.add(G.axes.x.transition().call(G.xAxis)),p.add(A.transition().attr("transform",c)),p.add(B.transition().attr("transform",c)),p.add(C.transition().attr("transform",c)),p.add(D.transition().attr("transform",c)),p.add(z.transition().attr("transform",c)),p.add(x.filter(G.isRegionOnX).transition().attr("transform",c)),p.add(q.transition().attr("transform",c)),p.add(s.transition().attr("transform",c))}).call(p,function(){var a,b=[],c=[],e=[];if(j){for(a=0;j>a;a++)b.push("."+pe[Ad]+"-"+(i+a)),c.push("."+pe[Nd]+"-"+(i+a)),e.push("."+pe[pd]+"-"+(i+a));G.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),G.svg.selectAll("."+pe[Od]).selectAll(c).remove(),G.svg.selectAll("."+pe[qd]).selectAll(e).remove(),G.svg.select("."+pe[Rd]).remove()}q.attr("transform",null).attr(G.xgridAttr),s.attr("transform",null),s.select("line").attr("x1",J[vb]?0:P).attr("x2",J[vb]?G.width:P),s.select("text").attr("x",J[vb]?G.width:0).attr("y",P),A.attr("transform",null).attr("d",t),B.attr("transform",null).attr("d",u),C.attr("transform",null).attr("d",r),D.attr("transform",null).attr("cx",Q).attr("cy",R),z.attr("transform",null).attr("x",v).attr("y",w).style("fill-opacity",De(G.opacityForText,G)),x.attr("transform",null),x.select("rect").filter(G.isRegionOnX).attr("x",De(G.regionX,G)).attr("width",De(G.regionWidth,G)),d.attr("x",J[vb]?0:f).attr("y",J[vb]?f:0).attr("width",J[vb]?G.width:g).attr("height",J[vb]?g:G.height),o()})}),G.mapToIds(G.data.targets).forEach(function(a){G.withoutFadeIn[a]=!0}),G.updateZoom&&G.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0 -}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;c0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid")}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config; -a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&B.select(this).style("display",b%y?"none":"block")})}else z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!C[vb]&&C[Hb]&&z.rotateTickText(z.axes.x,b.axisX,C[Hb]),l=z.generateDrawArea?z.generateDrawArea(D,!1):void 0,m=z.generateDrawBar?z.generateDrawBar(E):void 0,n=z.generateDrawLine?z.generateDrawLine(F,!1):void 0,o=z.generateXYForText(E,!0),p=z.generateXYForText(E,!1),z.subY.domain(z.y.domain()),z.subY2.domain(z.y2.domain()),z.tooltip.style("display","none"),z.updateXgridFocus(),A.select("text."+pe[Nd]+"."+pe[Md]).attr("x",z.width/2).attr("y",z.height/2).text(C[fb]).transition().style("opacity",H.length?0:1),z.redrawGrid(q,c),z.redrawRegion(q),z.redrawBar(r),z.redrawLine(r),z.redrawArea(r),C[mc]&&z.redrawCircle(),z.hasDataLabel()&&z.redrawText(r),z.redrawArc&&z.redrawArc(q,r,h),z.redrawSubchart&&z.redrawSubchart(d,b,q,r,D,E,F),A.selectAll("."+pe[od]).filter(De(z.isBarType,z)).selectAll("circle").remove(),C[s]&&z.redrawEventRect(),B.transition().duration(q).each(function(){var b=[];z.addTransitionForBar(b,m),z.addTransitionForLine(b,n),z.addTransitionForArea(b,l),z.addTransitionForCircle(b,J,K),z.addTransitionForText(b,o,p,a.flow),z.addTransitionForRegion(b),z.addTransitionForGrid(b),a.flow&&(u=z.generateWait(),b.forEach(function(a){u.add(a)}))}).call(u?u:function(){},function(){var b,c,d,e=1,f=a.flow.index,g=a.flow.length,h=z.getValueOnIndex(z.data.targets[0].values,f),i=z.getValueOnIndex(z.data.targets[0].values,f+g),j=z.x.domain(),k=a.flow.duration||q,r=a.flow.done||function(){},s=z.generateWait(),t=z.xgrid||B.selectAll([]),u=z.xgridLines||B.selectAll([]),v=z.mainRegion||B.selectAll([]),w=z.mainText||B.selectAll([]),x=z.mainBar||B.selectAll([]),y=z.mainLine||B.selectAll([]),A=z.mainArea||B.selectAll([]),D=z.mainCircle||B.selectAll([]);z.data.targets.forEach(function(a){a.values.splice(0,g)}),d=z.updateXDomain(H,!0,!0),z.updateXGrid&&z.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||h.x===i.x?z.x(j[0])-z.x(d[0]):z.isTimeSeries()?z.x(j[0])-z.x(d[0]):z.x(h.x)-z.x(i.x):1!==z.data.targets[0].values.length?b=z.x(j[0])-z.x(d[0]):z.isTimeSeries()?(h=z.getValueOnIndex(z.data.targets[0].values,0),i=z.getValueOnIndex(z.data.targets[0].values,z.data.targets[0].values.length-1),b=z.x(h.x)-z.x(i.x)):b=xe(d)/2,e=xe(j)/xe(d),c="translate("+b+",0) scale("+e+",1)",B.transition().ease("linear").duration(k).each(function(){s.add(z.axes.x.transition().call(z.xAxis)),s.add(x.transition().attr("transform",c)),s.add(y.transition().attr("transform",c)),s.add(A.transition().attr("transform",c)),s.add(D.transition().attr("transform",c)),s.add(w.transition().attr("transform",c)),s.add(v.filter(z.isRegionOnX).transition().attr("transform",c)),s.add(t.transition().attr("transform",c)),s.add(u.transition().attr("transform",c))}).call(s,function(){var a,b=[],c=[],d=[];if(g){for(a=0;g>a;a++)b.push("."+pe[Ad]+"-"+(f+a)),c.push("."+pe[Nd]+"-"+(f+a)),d.push("."+pe[pd]+"-"+(f+a));z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),z.svg.selectAll("."+pe[Od]).selectAll(c).remove(),z.svg.selectAll("."+pe[qd]).selectAll(d).remove(),z.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(z.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",C[vb]?0:I).attr("x2",C[vb]?z.width:I),u.select("text").attr("x",C[vb]?z.width:0).attr("y",I),x.attr("transform",null).attr("d",m),y.attr("transform",null).attr("d",n),A.attr("transform",null).attr("d",l),D.attr("transform",null).attr("cx",J).attr("cy",K),w.attr("transform",null).attr("x",o).attr("y",p).style("fill-opacity",De(z.opacityForText,z)),v.attr("transform",null),v.select("rect").filter(z.isRegionOnX).attr("x",De(z.regionX,z)).attr("width",De(z.regionWidth,z)),z.updateEventRect(),r()})}),z.mapToIds(z.data.targets).forEach(function(a){z.withoutFadeIn[a]=!0}),z.updateZoom&&z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1); +return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid") +}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 }),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index 590c78c..9794fb8 100644 --- a/src/core.js +++ b/src/core.js @@ -127,7 +127,7 @@ c3_chart_internal_fn.initParams = function () { c3_chart_internal_fn.initWithData = function (data) { var $$ = this, d3 = $$.d3, config = $$.config; - var main, eventRect, binding = true; + var main, binding = true; if ($$.initPie) { $$.initPie(); } if ($$.initBrush) { $$.initBrush(); } @@ -220,9 +220,7 @@ c3_chart_internal_fn.initWithData = function (data) { .attr('class', CLASS[_chart]); // Cover whole with rects for events - eventRect = main.select('.' + CLASS[_chart]).append("g") - .attr("class", CLASS[_eventRects]) - .style('fill-opacity', 0); + $$.initEventRect(); // Define g for bar chart area if ($$.initBar) { $$.initBar(); } @@ -400,9 +398,7 @@ c3_chart_internal_fn.updateTargets = function (targets) { c3_chart_internal_fn.redraw = function (options, transitions) { var $$ = this, main = $$.main, d3 = $$.d3, config = $$.config; - var eventRect, eventRectUpdate; - var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType), maxDataCountTarget; - var rectX, rectW; + var areaIndices = $$.getShapeIndices($$.isAreaType), barIndices = $$.getShapeIndices($$.isBarType), lineIndices = $$.getShapeIndices($$.isLineType); var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; @@ -544,70 +540,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .selectAll('circle') .remove(); + // event rect if (config[__interaction_enabled]) { - // rect for mouseover - eventRect = main.select('.' + CLASS[_eventRects]) - .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null); - if (notEmpty(config[__data_xs]) && !$$.isSingleX(config[__data_xs])) { - - if (!eventRect.classed(CLASS[_eventRectsMultiple])) { - eventRect.classed(CLASS[_eventRectsMultiple], true).classed(CLASS[_eventRectsSingle], false) - .selectAll('.' + CLASS[_eventRect]).remove(); - } - - eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) - .data([0]); - // enter : only one rect will be added - $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('x', 0) - .attr('y', 0) - .attr('width', $$.width) - .attr('height', $$.height); - // exit : not needed because always only one rect exists - } else { - - if (!eventRect.classed(CLASS[_eventRectsSingle])) { - eventRect.classed(CLASS[_eventRectsMultiple], false).classed(CLASS[_eventRectsSingle], true) - .selectAll('.' + CLASS[_eventRect]).remove(); - } - - if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { - rectW = function (d) { - var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], - w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; - return w < 0 ? 0 : w; - }; - rectX = function (d) { - var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; - return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; - }; - } else { - rectW = $$.getEventRectWidth(); - rectX = function (d) { - return $$.x(d.x) - (rectW / 2); - }; - } - // Set data - maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); - main.select('.' + CLASS[_eventRects]) - .datum(maxDataCountTarget ? maxDataCountTarget.values : []); - // Update rects - eventRectUpdate = main.select('.' + CLASS[_eventRects]).selectAll('.' + CLASS[_eventRect]) - .data(function (d) { return d; }); - // enter - $$.generateEventRectsForSingleX(eventRectUpdate.enter()); - // update - eventRectUpdate - .attr('class', generateCall($$.classEvent, $$)) - .attr("x", config[__axis_rotated] ? 0 : rectX) - .attr("y", config[__axis_rotated] ? rectX : 0) - .attr("width", config[__axis_rotated] ? $$.width : rectW) - .attr("height", config[__axis_rotated] ? rectW : $$.height); - // exit - eventRectUpdate.exit().remove(); - } + $$.redrawEventRect(); } // transition should be derived from one transition @@ -616,30 +551,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { $$.addTransitionForBar(transitions, drawBar); $$.addTransitionForLine(transitions, drawLine); -/* - transitions.push(mainLine.transition() - .attr("d", drawLine) - .style("stroke", $$.color) - .style("opacity", 1)); -*/ $$.addTransitionForArea(transitions, drawArea); -/* - transitions.push(mainArea.transition() - .attr("d", drawArea) - .style("fill", $$.color) - .style("opacity", $$.orgAreaOpacity)); -*/ $$.addTransitionForCircle(transitions, cx, cy); -/* - transitions.push(mainCircle.transition() - .style('opacity', generateCall($$.opacityForCircle, $$)) - .style("fill", $$.color) - .attr("cx", cx) - .attr("cy", cy)); - transitions.push(main.selectAll('.' + CLASS[_selectedCircle]).transition() - .attr("cx", cx) - .attr("cy", cy)); -*/ $$.addTransitionForText(transitions, xForText, yForText, options.flow); $$.addTransitionForRegion(transitions); $$.addTransitionForGrid(transitions); @@ -769,11 +682,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { mainRegion.select('rect').filter($$.isRegionOnX) .attr("x", generateCall($$.regionX, $$)) .attr("width", generateCall($$.regionWidth, $$)); - eventRectUpdate - .attr("x", config[__axis_rotated] ? 0 : rectX) - .attr("y", config[__axis_rotated] ? rectX : 0) - .attr("width", config[__axis_rotated] ? $$.width : rectW) - .attr("height", config[__axis_rotated] ? rectW : $$.height); + $$.updateEventRect(); // callback for end of flow done(); @@ -815,219 +724,6 @@ c3_chart_internal_fn.updateAndRedraw = function (options) { $$.redraw(options, transitions); }; -c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { - var $$ = this, d3 = $$.d3, config = $$.config; - eventRectEnter.append("rect") - .attr("class", generateCall($$.classEvent, $$)) - .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) - .on('mouseover', function (d) { - var index = d.index, selectedData, newData; - - if ($$.dragging) { return; } // do nothing if dragging - if ($$.hasArcType()) { return; } - - selectedData = $$.data.targets.map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); - }); - - // Sort selectedData as names order - newData = []; - Object.keys(config[__data_names]).forEach(function (id) { - for (var j = 0; j < selectedData.length; j++) { - if (selectedData[j] && selectedData[j].id === id) { - newData.push(selectedData[j]); - selectedData.shift(j); - break; - } - } - }); - selectedData = newData.concat(selectedData); // Add remained - - // Expand shapes for selection - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } - $$.expandBars(index); - - // Call event handler - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - config[__data_onmouseover].call(c3, d); - }); - }) - .on('mouseout', function (d) { - var index = d.index; - if ($$.hasArcType()) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); - // Undo expanded shapes - $$.unexpandCircles(index); - $$.unexpandBars(); - // Call event handler - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - config[__data_onmouseout].call($$, d); - }); - }) - .on('mousemove', function (d) { - var selectedData, index = d.index, - eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); - - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType()) { return; } - - // Show tooltip - selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { - return $$.addName($$.getValueOnIndex(t.values, index)); - }); - - if (config[__tooltip_grouped]) { - $$.showTooltip(selectedData, d3.mouse(this)); - $$.showXGridFocus(selectedData); - } - - if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { - return; - } - - $$.main.selectAll('.' + CLASS[_shape] + '-' + index) - .each(function () { - d3.select(this).classed(CLASS[_EXPANDED], true); - if (config[__data_selection_enabled]) { - eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); - } - if (!config[__tooltip_grouped]) { - $$.hideXGridFocus(); - $$.hideTooltip(); - if (!config[__data_selection_grouped]) { - $$.unexpandCircles(index); - $$.unexpandBars(); - } - } - }) - .filter(function (d) { - if (this.nodeName === 'circle') { - return $$.isWithinCircle(this, $$.pointSelectR(d)); - } - else if (this.nodeName === 'path') { - return $$.isWithinBar(this); - } - }) - .each(function (d) { - if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { - eventRect.style('cursor', 'pointer'); - } - if (!config[__tooltip_grouped]) { - $$.showTooltip([d], d3.mouse(this)); - $$.showXGridFocus([d]); - if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } - $$.expandBars(index, d.id); - } - }); - }) - .on('click', function (d) { - var index = d.index; - if ($$.hasArcType() || !$$.toggleShape) { return; } - if ($$.cancelClick) { - $$.cancelClick = false; - return; - } - $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { - $$.toggleShape(this, d, index); - }); - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) - ) - .on("dblclick.zoom", null); -}; - -c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { - var $$ = this, d3 = $$.d3, config = $$.config; - eventRectEnter.append('rect') - .attr('x', 0) - .attr('y', 0) - .attr('width', $$.width) - .attr('height', $$.height) - .attr('class', CLASS[_eventRect]) - .on('mouseout', function () { - if ($$.hasArcType()) { return; } - $$.hideXGridFocus(); - $$.hideTooltip(); - $$.unexpandCircles(); - }) - .on('mousemove', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); - var mouse, closest, sameXData, selectedData; - - if ($$.dragging) { return; } // do nothing when dragging - if ($$.hasArcType(targetsToShow)) { return; } - - mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); - - if (! closest) { return; } - - if ($$.isScatterType(closest)) { - sameXData = [closest]; - } else { - sameXData = $$.filterSameX(targetsToShow, closest.x); - } - - // show tooltip when cursor is close to some point - selectedData = sameXData.map(function (d) { - return $$.addName(d); - }); - $$.showTooltip(selectedData, mouse); - - // expand points - if (config[__point_focus_expand_enabled]) { - $$.unexpandCircles(); - $$.expandCircles(closest.index, closest.id); - } - - // Show xgrid focus line - $$.showXGridFocus(selectedData); - - // Show cursor as pointer if point is close to mouse position - if ($$.dist(closest, mouse) < 100) { - $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); - if (!$$.mouseover) { - config[__data_onmouseover].call($$, closest); - $$.mouseover = true; - } - } else if ($$.mouseover) { - $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); - config[__data_onmouseout].call($$, closest); - $$.mouseover = false; - } - }) - .on('click', function () { - var targetsToShow = $$.filterTargetsToShow($$.data.targets); - var mouse, closest; - - if ($$.hasArcType(targetsToShow)) { return; } - - mouse = d3.mouse(this); - closest = $$.findClosestFromTargets(targetsToShow, mouse); - - if (! closest) { return; } - - // select if selection enabled - if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { - $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { - $$.toggleShape(this, closest, closest.index); - }); - } - }) - .call( - d3.behavior.drag().origin(Object) - .on('drag', function () { $$.drag(d3.mouse(this)); }) - .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) - .on('dragend', function () { $$.dragend(); }) - ) - .on("dblclick.zoom", null); -}; - c3_chart_internal_fn.isTimeSeries = function () { return this.config[__axis_x_type] === 'timeseries'; }; diff --git a/src/data.js b/src/data.js index 483ecf7..8313506 100644 --- a/src/data.js +++ b/src/data.js @@ -38,8 +38,12 @@ c3_chart_internal_fn.addXs = function (xs) { $$.config[__data_xs][id] = xs[id]; }); }; -c3_chart_internal_fn.isSingleX = function (xs) { - return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() === 1; +c3_chart_internal_fn.hasMultipleX = function (xs) { + return this.d3.set(Object.keys(xs).map(function (id) { return xs[id]; })).size() > 1; +}; +c3_chart_internal_fn.isMultipleX = function () { + var $$ = this, config = $$.config; + return notEmpty(config[__data_xs]) && $$.hasMultipleX(config[__data_xs]); }; c3_chart_internal_fn.addName = function (data) { var $$ = this, name; diff --git a/src/interaction.js b/src/interaction.js new file mode 100644 index 0000000..720e1b9 --- /dev/null +++ b/src/interaction.js @@ -0,0 +1,301 @@ +c3_chart_internal_fn.initEventRect = function () { + var $$ = this, CLASS = $$.CLASS; + $$.main.select('.' + CLASS[_chart]).append("g") + .attr("class", CLASS[_eventRects]) + .style('fill-opacity', 0); +}; +c3_chart_internal_fn.redrawEventRect = function () { + var $$ = this, config = $$.config, CLASS = $$.CLASS, + eventRectUpdate, maxDataCountTarget, + isMultipleX = $$.isMultipleX(); + + // rects for mouseover + var eventRects = $$.main.select('.' + CLASS[_eventRects]) + .style('cursor', config[__zoom_enabled] ? config[__axis_rotated] ? 'ns-resize' : 'ew-resize' : null) + .classed(CLASS[_eventRectsMultiple], isMultipleX) + .classed(CLASS[_eventRectsSingle], !isMultipleX); + + // clear old rects + eventRects.selectAll('.' + CLASS[_eventRect]).remove(); + + // open as public variable + $$.eventRect = eventRects.selectAll('.' + CLASS[_eventRect]); + + if (isMultipleX) { + eventRectUpdate = $$.eventRect.data([0]); + // enter : only one rect will be added + $$.generateEventRectsForMultipleXs(eventRectUpdate.enter()); + // update + $$.updateEventRect(eventRectUpdate); + // exit : not needed because always only one rect exists + } + else { + // Set data and update $$.eventRect + maxDataCountTarget = $$.getMaxDataCountTarget($$.data.targets); + eventRects.datum(maxDataCountTarget ? maxDataCountTarget.values : []); + $$.eventRect = eventRects.selectAll('.' + CLASS[_eventRect]); + eventRectUpdate = $$.eventRect.data(function (d) { return d; }); + // enter + $$.generateEventRectsForSingleX(eventRectUpdate.enter()); + // update + $$.updateEventRect(eventRectUpdate); + // exit + eventRectUpdate.exit().remove(); + } +}; +c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) { + var $$ = this, config = $$.config, + x, y, w, h, rectW, rectX; + + // set update selection if null + eventRectUpdate = eventRectUpdate || $$.eventRect.data(function (d) { return d; }); + + if ($$.isMultipleX()) { + // TODO: rotated not supported yet + x = 0; + y = 0; + w = $$.width; + h = $$.height; + } + else { + if (($$.isCustomX() || $$.isTimeSeries()) && !$$.isCategorized()) { + rectW = function (d) { + var prevX = $$.getPrevX(d.index), nextX = $$.getNextX(d.index), dx = $$.data.xs[d.id][d.index], + w = ($$.x(nextX ? nextX : dx) - $$.x(prevX ? prevX : dx)) / 2; + return w < 0 ? 0 : w; + }; + rectX = function (d) { + var prevX = $$.getPrevX(d.index), dx = $$.data.xs[d.id][d.index]; + return ($$.x(dx) + $$.x(prevX ? prevX : dx)) / 2; + }; + } else { + rectW = $$.getEventRectWidth(); + rectX = function (d) { + return $$.x(d.x) - (rectW / 2); + }; + } + x = config[__axis_rotated] ? 0 : rectX; + y = config[__axis_rotated] ? rectX : 0; + w = config[__axis_rotated] ? $$.width : rectW; + h = config[__axis_rotated] ? rectW : $$.height; + } + + eventRectUpdate + .attr('class', $$.classEvent.bind($$)) + .attr("x", x) + .attr("y", y) + .attr("width", w) + .attr("height", h); +}; +c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append("rect") + .attr("class", generateCall($$.classEvent, $$)) + .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) + .on('mouseover', function (d) { + var index = d.index, selectedData, newData; + + if ($$.dragging) { return; } // do nothing if dragging + if ($$.hasArcType()) { return; } + + selectedData = $$.data.targets.map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + // Sort selectedData as names order + newData = []; + Object.keys(config[__data_names]).forEach(function (id) { + for (var j = 0; j < selectedData.length; j++) { + if (selectedData[j] && selectedData[j].id === id) { + newData.push(selectedData[j]); + selectedData.shift(j); + break; + } + } + }); + selectedData = newData.concat(selectedData); // Add remained + + // Expand shapes for selection + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index); } + $$.expandBars(index); + + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseover].call(c3, d); + }); + }) + .on('mouseout', function (d) { + var index = d.index; + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + // Undo expanded shapes + $$.unexpandCircles(index); + $$.unexpandBars(); + // Call event handler + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + config[__data_onmouseout].call($$, d); + }); + }) + .on('mousemove', function (d) { + var selectedData, index = d.index, + eventRect = $$.svg.select('.' + CLASS[_eventRect] + '-' + index); + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType()) { return; } + + // Show tooltip + selectedData = $$.filterTargetsToShow($$.data.targets).map(function (t) { + return $$.addName($$.getValueOnIndex(t.values, index)); + }); + + if (config[__tooltip_grouped]) { + $$.showTooltip(selectedData, d3.mouse(this)); + $$.showXGridFocus(selectedData); + } + + if (config[__tooltip_grouped] && (!config[__data_selection_enabled] || config[__data_selection_grouped])) { + return; + } + + $$.main.selectAll('.' + CLASS[_shape] + '-' + index) + .each(function () { + d3.select(this).classed(CLASS[_EXPANDED], true); + if (config[__data_selection_enabled]) { + eventRect.style('cursor', config[__data_selection_grouped] ? 'pointer' : null); + } + if (!config[__tooltip_grouped]) { + $$.hideXGridFocus(); + $$.hideTooltip(); + if (!config[__data_selection_grouped]) { + $$.unexpandCircles(index); + $$.unexpandBars(); + } + } + }) + .filter(function (d) { + if (this.nodeName === 'circle') { + return $$.isWithinCircle(this, $$.pointSelectR(d)); + } + else if (this.nodeName === 'path') { + return $$.isWithinBar(this); + } + }) + .each(function (d) { + if (config[__data_selection_enabled] && (config[__data_selection_grouped] || config[__data_selection_isselectable](d))) { + eventRect.style('cursor', 'pointer'); + } + if (!config[__tooltip_grouped]) { + $$.showTooltip([d], d3.mouse(this)); + $$.showXGridFocus([d]); + if (config[__point_focus_expand_enabled]) { $$.expandCircles(index, d.id); } + $$.expandBars(index, d.id); + } + }); + }) + .on('click', function (d) { + var index = d.index; + if ($$.hasArcType() || !$$.toggleShape) { return; } + if ($$.cancelClick) { + $$.cancelClick = false; + return; + } + $$.main.selectAll('.' + CLASS[_shape] + '-' + index).each(function (d) { + $$.toggleShape(this, d, index); + }); + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); +}; + +c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) { + var $$ = this, d3 = $$.d3, config = $$.config; + eventRectEnter.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', $$.width) + .attr('height', $$.height) + .attr('class', CLASS[_eventRect]) + .on('mouseout', function () { + if ($$.hasArcType()) { return; } + $$.hideXGridFocus(); + $$.hideTooltip(); + $$.unexpandCircles(); + }) + .on('mousemove', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest, sameXData, selectedData; + + if ($$.dragging) { return; } // do nothing when dragging + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + if ($$.isScatterType(closest)) { + sameXData = [closest]; + } else { + sameXData = $$.filterSameX(targetsToShow, closest.x); + } + + // show tooltip when cursor is close to some point + selectedData = sameXData.map(function (d) { + return $$.addName(d); + }); + $$.showTooltip(selectedData, mouse); + + // expand points + if (config[__point_focus_expand_enabled]) { + $$.unexpandCircles(); + $$.expandCircles(closest.index, closest.id); + } + + // Show xgrid focus line + $$.showXGridFocus(selectedData); + + // Show cursor as pointer if point is close to mouse position + if ($$.dist(closest, mouse) < 100) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', 'pointer'); + if (!$$.mouseover) { + config[__data_onmouseover].call($$, closest); + $$.mouseover = true; + } + } else if ($$.mouseover) { + $$.svg.select('.' + CLASS[_eventRect]).style('cursor', null); + config[__data_onmouseout].call($$, closest); + $$.mouseover = false; + } + }) + .on('click', function () { + var targetsToShow = $$.filterTargetsToShow($$.data.targets); + var mouse, closest; + + if ($$.hasArcType(targetsToShow)) { return; } + + mouse = d3.mouse(this); + closest = $$.findClosestFromTargets(targetsToShow, mouse); + + if (! closest) { return; } + + // select if selection enabled + if ($$.dist(closest, mouse) < 100 && $$.toggleShape) { + $$.main.select('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(closest.id)).select('.' + CLASS[_circle] + '-' + closest.index).each(function () { + $$.toggleShape(this, closest, closest.index); + }); + } + }) + .call( + d3.behavior.drag().origin(Object) + .on('drag', function () { $$.drag(d3.mouse(this)); }) + .on('dragstart', function () { $$.dragstart(d3.mouse(this)); }) + .on('dragend', function () { $$.dragend(); }) + ) + .on("dblclick.zoom", null); +}; From 0b4a32408ea851e4b812f701bb017b4d2c8dafda Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 17 Aug 2014 17:39:53 +0900 Subject: [PATCH 40/44] Use bind instead of my function --- c3.js | 218 +++++++++++++++++++++++++-------------------- c3.min.js | 8 +- src/api.js | 12 +-- src/arc.js | 19 ++-- src/axis.js | 30 +++---- src/core.js | 30 +++---- src/grid.js | 13 +-- src/interaction.js | 2 +- src/region.js | 16 ++-- src/selection.js | 8 +- src/shape.bar.js | 16 ++-- src/shape.line.js | 10 ++- src/subchart.js | 46 ++++++---- src/text.js | 13 +-- src/util.js | 3 - 15 files changed, 246 insertions(+), 198 deletions(-) diff --git a/c3.js b/c3.js index 993eda0..a42348b 100644 --- a/c3.js +++ b/c3.js @@ -409,9 +409,9 @@ var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var xv = generateCall($$.xv, $$), - cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), - cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); + var xv = $$.xv.bind($$), + cx = ($$.config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), + cy = ($$.config[__axis_rotated] ? $$.circleX : $$.circleY).bind($$); options = options || {}; withY = getOption(options, "withY", true); @@ -541,7 +541,7 @@ // circles for select main.selectAll('.' + CLASS[_selectedCircles]) - .filter(generateCall($$.isBarType, $$)) + .filter($$.isBarType.bind($$)) .selectAll('circle') .remove(); @@ -681,12 +681,12 @@ .attr('transform', null) .attr('x', xForText) .attr('y', yForText) - .style('fill-opacity', generateCall($$.opacityForText, $$)); + .style('fill-opacity', $$.opacityForText.bind($$)); mainRegion .attr('transform', null); mainRegion.select('rect').filter($$.isRegionOnX) - .attr("x", generateCall($$.regionX, $$)) - .attr("width", generateCall($$.regionWidth, $$)); + .attr("x", $$.regionX.bind($$)) + .attr("width", $$.regionWidth.bind($$)); $$.updateEventRect(); // callback for end of flow @@ -836,15 +836,15 @@ .attr('width', $$.width) .attr('height', $$.height); $$.svg.select('#' + $$.clipIdForXAxis).select('rect') - .attr('x', generateCall($$.getXAxisClipX, $$)) - .attr('y', generateCall($$.getXAxisClipY, $$)) - .attr('width', generateCall($$.getXAxisClipWidth, $$)) - .attr('height', generateCall($$.getXAxisClipHeight, $$)); + .attr('x', $$.getXAxisClipX.bind($$)) + .attr('y', $$.getXAxisClipY.bind($$)) + .attr('width', $$.getXAxisClipWidth.bind($$)) + .attr('height', $$.getXAxisClipHeight.bind($$)); $$.svg.select('#' + $$.clipIdForYAxis).select('rect') - .attr('x', generateCall($$.getYAxisClipX, $$)) - .attr('y', generateCall($$.getYAxisClipY, $$)) - .attr('width', generateCall($$.getYAxisClipWidth, $$)) - .attr('height', generateCall($$.getYAxisClipHeight, $$)); + .attr('x', $$.getYAxisClipX.bind($$)) + .attr('y', $$.getYAxisClipY.bind($$)) + .attr('width', $$.getYAxisClipWidth.bind($$)) + .attr('height', $$.getYAxisClipHeight.bind($$)); $$.svg.select('.' + CLASS[_zoomRect]) .attr('width', $$.width) .attr('height', $$.height); @@ -2309,7 +2309,7 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append("rect") - .attr("class", generateCall($$.classEvent, $$)) + .attr("class", $$.classEvent.bind($$)) .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; @@ -2983,17 +2983,19 @@ return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { - var $$ = this; + var $$ = this, + r = $$.pointExpandedR.bind($$); $$.getCircles(i, id) .classed(CLASS[_EXPANDED], true) - .attr('r', generateCall($$.pointExpandedR, $$)); + .attr('r', r); }; c3_chart_internal_fn.unexpandCircles = function (i) { - var $$ = this; + var $$ = this, + r = $$.pointR.bind($$); $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) .classed(CLASS[_EXPANDED], false) - .attr('r', generateCall($$.pointR, $$)); + .attr('r', r); }; c3_chart_internal_fn.pointR = function (d) { var $$ = this, config = $$.config; @@ -3038,15 +3040,19 @@ }; c3_chart_internal_fn.redrawBar = function (durationForExit) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this, CLASS = $$.CLASS, + barData = $$.barData.bind($$), + classBar = $$.classBar.bind($$), + initialOpacity = $$.initialOpacity.bind($$), + color = function (d) { return $$.color(d.id); }; $$.mainBar = $$.main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); + .data(barData); $$.mainBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) - .style("stroke", function (d) { return $$.color(d.id); }) - .style("fill", function (d) { return $$.color(d.id); }); + .attr("class", classBar) + .style("stroke", color) + .style("fill", color); $$.mainBar - .style("opacity", generateCall($$.initialOpacity, $$)); + .style("opacity", initialOpacity); $$.mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); @@ -3150,11 +3156,13 @@ .attr('class', classTexts); }; c3_chart_internal_fn.redrawText = function (durationForExit) { - var $$ = this, config = $$.config, CLASS = $$.CLASS; + var $$ = this, config = $$.config, CLASS = $$.CLASS, + barOrLineData = $$.barOrLineData.bind($$), + classText = $$.classText.bind($$); $$.mainText = $$.main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) - .data(generateCall($$.barOrLineData, $$)); + .data(barOrLineData); $$.mainText.enter().append('text') - .attr("class", generateCall($$.classText, $$)) + .attr("class", classText) .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) @@ -3167,12 +3175,13 @@ .remove(); }; c3_chart_internal_fn.addTransitionForText = function (transitions, xForText, yForText, forFlow) { - var $$ = this; + var $$ = this, + opacityForText = forFlow ? 0 : $$.opacityForText.bind($$); transitions.push($$.mainText.transition() .attr('x', xForText) .attr('y', yForText) .style("fill", $$.color) - .style("fill-opacity", forFlow ? 0 : generateCall($$.opacityForText, $$))); + .style("fill-opacity", opacityForText)); }; c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; @@ -3408,7 +3417,7 @@ .attr('dy', -5) .style("opacity", 0); // update - yv = generateCall($$.yv, $$); + yv = $$.yv.bind($$); $$.ygridLines.select('line') .transition().duration(duration) .attr("x1", config[__axis_rotated] ? yv : 0) @@ -3429,7 +3438,7 @@ } }; c3_chart_internal_fn.addTransitionForGrid = function (transitions) { - var $$ = this, config = $$.config, xv = generateCall($$.xv, $$); + var $$ = this, config = $$.config, xv = $$.xv.bind($$); transitions.push($$.xgridLines.select('line').transition() .attr("x1", config[__axis_rotated] ? 0 : xv) .attr("x2", config[__axis_rotated] ? $$.width : xv) @@ -3444,16 +3453,17 @@ }; c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, config = $$.config, - dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }), + focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]), + xx = $$.xx.bind($$); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists if ($$.hasType('scatter') || $$.hasArcType()) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); focusEl .style("visibility", "visible") .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + .attr(config[__axis_rotated] ? 'y1' : 'x1', xx) + .attr(config[__axis_rotated] ? 'y2' : 'x2', xx); $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { @@ -3917,7 +3927,7 @@ $$.axes.x.append("text") .attr("class", CLASS[_axisXLabel]) .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") - .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); + .style("text-anchor", $$.textAnchorForXAxisLabel.bind($$)); $$.axes.y = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) @@ -3927,7 +3937,7 @@ $$.axes.y.append("text") .attr("class", CLASS[_axisYLabel]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); + .style("text-anchor", $$.textAnchorForYAxisLabel.bind($$)); $$.axes.y2 = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY2]) @@ -3937,7 +3947,7 @@ $$.axes.y2.append("text") .attr("class", CLASS[_axisY2Label]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); + .style("text-anchor", $$.textAnchorForY2AxisLabel.bind($$)); }; c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, @@ -4174,20 +4184,20 @@ axisYLabel = $$.main.select('.' + CLASS[_axisY] + ' .' + CLASS[_axisYLabel]), axisY2Label = $$.main.select('.' + CLASS[_axisY2] + ' .' + CLASS[_axisY2Label]); (withTransition ? axisXLabel.transition() : axisXLabel) - .attr("x", generateCall($$.xForXAxisLabel, $$)) - .attr("dx", generateCall($$.dxForXAxisLabel, $$)) - .attr("dy", generateCall($$.dyForXAxisLabel, $$)) - .text(generateCall($$.textForXAxisLabel, $$)); + .attr("x", $$.xForXAxisLabel.bind($$)) + .attr("dx", $$.dxForXAxisLabel.bind($$)) + .attr("dy", $$.dyForXAxisLabel.bind($$)) + .text($$.textForXAxisLabel.bind($$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", generateCall($$.xForYAxisLabel, $$)) - .attr("dx", generateCall($$.dxForYAxisLabel, $$)) - .attr("dy", generateCall($$.dyForYAxisLabel, $$)) - .text(generateCall($$.textForYAxisLabel, $$)); + .attr("x", $$.xForYAxisLabel.bind($$)) + .attr("dx", $$.dxForYAxisLabel.bind($$)) + .attr("dy", $$.dyForYAxisLabel.bind($$)) + .text($$.textForYAxisLabel.bind($$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", generateCall($$.xForY2AxisLabel, $$)) - .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) - .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) - .text(generateCall($$.textForY2AxisLabel, $$)); + .attr("x", $$.xForY2AxisLabel.bind($$)) + .attr("dx", $$.dxForY2AxisLabel.bind($$)) + .attr("dy", $$.dyForY2AxisLabel.bind($$)) + .text($$.textForY2AxisLabel.bind($$)); }; c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { @@ -4491,14 +4501,17 @@ }; c3_chart_internal_fn.updateTargetsForArc = function (targets) { - var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; + var $$ = this, main = $$.main, + mainPieUpdate, mainPieEnter, + classChartArc = $$.classChartArc.bind($$), + classArcs = $$.classArcs.bind($$); mainPieUpdate = main.select('.' + CLASS[_chartArcs]).selectAll('.' + CLASS[_chartArc]) .data($$.pie(targets)) - .attr("class", generateCall($$.classChartArc, $$)); + .attr("class", classChartArc); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", generateCall($$.classChartArc, $$)); + .attr("class", classChartArc); mainPieEnter.append('g') - .attr('class', generateCall($$.classArcs, $$)); + .attr('class', classArcs); mainPieEnter.append("text") .attr("dy", $$.hasType('gauge') ? "-0.35em" : ".35em") .style("opacity", 0) @@ -4523,9 +4536,9 @@ var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; mainArc = main.selectAll('.' + CLASS[_arcs]).selectAll('.' + CLASS[_arc]) - .data(generateCall($$.arcData, $$)); + .data($$.arcData.bind($$)); mainArc.enter().append('path') - .attr("class", generateCall($$.classArc, $$)) + .attr("class", $$.classArc.bind($$)) .style("fill", function (d) { return $$.color(d.data); }) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) .style("opacity", 0) @@ -4612,8 +4625,8 @@ main.selectAll('.' + CLASS[_chartArc]).select('text') .style("opacity", 0) .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[_gaugeValue] : ''; }) - .text(generateCall($$.textForArcLabel, $$)) - .attr("transform", generateCall($$.transformForArcLabel, $$)) + .text($$.textForArcLabel.bind($$)) + .attr("transform", $$.transformForArcLabel.bind($$)) .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS[_chartArcsTitle]) @@ -4667,7 +4680,7 @@ $$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) .data(config[__regions]); $$.mainRegion.enter().append('g') - .attr('class', generateCall($$.classRegion, $$)) + .attr('class', $$.classRegion.bind($$)) .append('rect') .style("fill-opacity", 0); $$.mainRegion.exit().transition().duration(duration) @@ -4675,12 +4688,16 @@ .remove(); }; c3_chart_internal_fn.addTransitionForRegion = function (transitions) { - var $$ = this; + var $$ = this, + x = $$.regionX.bind($$), + y = $$.regionY.bind($$), + w = $$.regionWidth.bind($$), + h = $$.regionHeight.bind($$); transitions.push($$.mainRegion.selectAll('rect').transition() - .attr("x", generateCall($$.regionX, $$)) - .attr("y", generateCall($$.regionY, $$)) - .attr("width", generateCall($$.regionWidth, $$)) - .attr("height", generateCall($$.regionHeight, $$)) + .attr("x", x) + .attr("y", y) + .attr("width", w) + .attr("height", h) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); }; c3_chart_internal_fn.regionX = function (d) { @@ -4814,9 +4831,9 @@ c3_chart_internal_fn.selectPoint = function (target, d, i) { var $$ = this, config = $$.config, - cx = generateCall(config[__axis_rotated] ? $$.circleY : $$.circleX, $$), - cy = generateCall(config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - + cx = (config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), + cy = (config[__axis_rotated] ? $$.circleX : $$.circleY).bind($$), + r = $$.pointSelectR.bind($$); config[__data_onselected].call($$.api, d, target.node()); // add selected-circle on low layer g $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) @@ -4828,7 +4845,7 @@ .attr("stroke", function () { return $$.color(d); }) .attr("r", function (d) { return $$.pointSelectR(d) * 1.4; }) .transition().duration(100) - .attr("r", generateCall($$.pointSelectR, $$)); + .attr("r", r); }; c3_chart_internal_fn.unselectPoint = function (target, d, i) { var $$ = this; @@ -4944,38 +4961,48 @@ }; c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { var $$ = this, context = $$.context, config = $$.config, - contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate, + classChartBar = $$.classChartBar.bind($$), + classBars = $$.classBars.bind($$), + classChartLine = $$.classChartLine.bind($$), + classLines = $$.classLines.bind($$), + classAreas = $$.classAreas.bind($$); if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); + .attr('class', classChartBar); contextBarEnter = contextBarUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall($$.classChartBar, $$)); + .attr('class', classChartBar); // Bars for each data contextBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)); + .attr("class", classBars); //-- Line --// contextLineUpdate = context.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); + .attr('class', classChartLine); contextLineEnter = contextLineUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall($$.classChartLine, $$)); + .attr('class', classChartLine); // Lines for each data contextLineEnter.append("g") - .attr("class", generateCall($$.classLines, $$)); + .attr("class", classLines); // Area contextLineEnter.append("g") - .attr("class", generateCall($$.classAreas, $$)); + .attr("class", classAreas); } }; c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { var $$ = this, d3 = $$.d3, context = $$.context, config = $$.config, - contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; + contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub, + barData = $$.barData.bind($$), + lineData = $$.lineData.bind($$), + classBar = $$.classBar.bind($$), + classLine = $$.classLine.bind($$), + classArea = $$.classArea.bind($$), + initialOpacity = $$.initialOpacity.bind($$); // subchart if (config[__subchart_show]) { @@ -5001,13 +5028,13 @@ drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars contextBar = context.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); + .data(barData); contextBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) + .attr("class", classBar) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style("opacity", generateCall($$.initialOpacity, $$)) + .style("opacity", initialOpacity) .transition().duration(duration) .attr('d', drawBarOnSub) .style('opacity', 1); @@ -5016,12 +5043,12 @@ .remove(); // lines contextLine = context.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) - .data(generateCall($$.lineData, $$)); + .data(lineData); contextLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) + .attr('class', classLine) .style('stroke', $$.color); contextLine - .style("opacity", generateCall($$.initialOpacity, $$)) + .style("opacity", initialOpacity) .transition().duration(duration) .attr("d", drawLineOnSub) .style('opacity', 1); @@ -5030,9 +5057,9 @@ .remove(); // area contextArea = context.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) - .data(generateCall($$.lineData, $$)); + .data(lineData); contextArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) + .attr("class", classArea) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea @@ -5504,16 +5531,13 @@ items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; - }, - generateCall = c3_chart_internal_fn.generateCall = function (f, context) { - return function (d, i) { return f.call(context, d, i); }; }; c3_chart_fn.focus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function focus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } @@ -5530,8 +5554,8 @@ c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function defocus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } @@ -5547,8 +5571,8 @@ c3_chart_fn.revert = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } diff --git a/c3.min.js b/c3.min.js index 546f720..a0e9877 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&B.select(this).style("display",b%y?"none":"block")})}else z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!C[vb]&&C[Hb]&&z.rotateTickText(z.axes.x,b.axisX,C[Hb]),l=z.generateDrawArea?z.generateDrawArea(D,!1):void 0,m=z.generateDrawBar?z.generateDrawBar(E):void 0,n=z.generateDrawLine?z.generateDrawLine(F,!1):void 0,o=z.generateXYForText(E,!0),p=z.generateXYForText(E,!1),z.subY.domain(z.y.domain()),z.subY2.domain(z.y2.domain()),z.tooltip.style("display","none"),z.updateXgridFocus(),A.select("text."+pe[Nd]+"."+pe[Md]).attr("x",z.width/2).attr("y",z.height/2).text(C[fb]).transition().style("opacity",H.length?0:1),z.redrawGrid(q,c),z.redrawRegion(q),z.redrawBar(r),z.redrawLine(r),z.redrawArea(r),C[mc]&&z.redrawCircle(),z.hasDataLabel()&&z.redrawText(r),z.redrawArc&&z.redrawArc(q,r,h),z.redrawSubchart&&z.redrawSubchart(d,b,q,r,D,E,F),A.selectAll("."+pe[od]).filter(De(z.isBarType,z)).selectAll("circle").remove(),C[s]&&z.redrawEventRect(),B.transition().duration(q).each(function(){var b=[];z.addTransitionForBar(b,m),z.addTransitionForLine(b,n),z.addTransitionForArea(b,l),z.addTransitionForCircle(b,J,K),z.addTransitionForText(b,o,p,a.flow),z.addTransitionForRegion(b),z.addTransitionForGrid(b),a.flow&&(u=z.generateWait(),b.forEach(function(a){u.add(a)}))}).call(u?u:function(){},function(){var b,c,d,e=1,f=a.flow.index,g=a.flow.length,h=z.getValueOnIndex(z.data.targets[0].values,f),i=z.getValueOnIndex(z.data.targets[0].values,f+g),j=z.x.domain(),k=a.flow.duration||q,r=a.flow.done||function(){},s=z.generateWait(),t=z.xgrid||B.selectAll([]),u=z.xgridLines||B.selectAll([]),v=z.mainRegion||B.selectAll([]),w=z.mainText||B.selectAll([]),x=z.mainBar||B.selectAll([]),y=z.mainLine||B.selectAll([]),A=z.mainArea||B.selectAll([]),D=z.mainCircle||B.selectAll([]);z.data.targets.forEach(function(a){a.values.splice(0,g)}),d=z.updateXDomain(H,!0,!0),z.updateXGrid&&z.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||h.x===i.x?z.x(j[0])-z.x(d[0]):z.isTimeSeries()?z.x(j[0])-z.x(d[0]):z.x(h.x)-z.x(i.x):1!==z.data.targets[0].values.length?b=z.x(j[0])-z.x(d[0]):z.isTimeSeries()?(h=z.getValueOnIndex(z.data.targets[0].values,0),i=z.getValueOnIndex(z.data.targets[0].values,z.data.targets[0].values.length-1),b=z.x(h.x)-z.x(i.x)):b=xe(d)/2,e=xe(j)/xe(d),c="translate("+b+",0) scale("+e+",1)",B.transition().ease("linear").duration(k).each(function(){s.add(z.axes.x.transition().call(z.xAxis)),s.add(x.transition().attr("transform",c)),s.add(y.transition().attr("transform",c)),s.add(A.transition().attr("transform",c)),s.add(D.transition().attr("transform",c)),s.add(w.transition().attr("transform",c)),s.add(v.filter(z.isRegionOnX).transition().attr("transform",c)),s.add(t.transition().attr("transform",c)),s.add(u.transition().attr("transform",c))}).call(s,function(){var a,b=[],c=[],d=[];if(g){for(a=0;g>a;a++)b.push("."+pe[Ad]+"-"+(f+a)),c.push("."+pe[Nd]+"-"+(f+a)),d.push("."+pe[pd]+"-"+(f+a));z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),z.svg.selectAll("."+pe[Od]).selectAll(c).remove(),z.svg.selectAll("."+pe[qd]).selectAll(d).remove(),z.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(z.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",C[vb]?0:I).attr("x2",C[vb]?z.width:I),u.select("text").attr("x",C[vb]?z.width:0).attr("y",I),x.attr("transform",null).attr("d",m),y.attr("transform",null).attr("d",n),A.attr("transform",null).attr("d",l),D.attr("transform",null).attr("cx",J).attr("cy",K),w.attr("transform",null).attr("x",o).attr("y",p).style("fill-opacity",De(z.opacityForText,z)),v.attr("transform",null),v.select("rect").filter(z.isRegionOnX).attr("x",De(z.regionX,z)).attr("width",De(z.regionWidth,z)),z.updateEventRect(),r()})}),z.mapToIds(z.data.targets).forEach(function(a){z.withoutFadeIn[a]=!0}),z.updateZoom&&z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",De(a.getXAxisClipX,a)).attr("y",De(a.getXAxisClipY,a)).attr("width",De(a.getXAxisClipWidth,a)).attr("height",De(a.getXAxisClipHeight,a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",De(a.getYAxisClipX,a)).attr("y",De(a.getYAxisClipY,a)).attr("width",De(a.getYAxisClipWidth,a)).attr("height",De(a.getYAxisClipHeight,a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1); -return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",De(b.classEvent,b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this;c.getCircles(a,b).classed(pe[me],!0).attr("r",De(c.pointExpandedR,c))},f.unexpandCircles=function(a){var b=this;b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",De(b.pointR,b))},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=De(f.yv,f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=De(b.xv,b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)});if(c[Rc]&&!b.hasType("scatter")&&!b.hasArcType()){var e=b.main.selectAll("line."+pe[Vd]);e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",De(b.xx,b)).attr(c[vb]?"y2":"x2",De(b.xx,b)),b.smoothLines(e,"grid") -}},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",De(a.textAnchorForXAxisLabel,a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForYAxisLabel,a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",De(a.textAnchorForY2AxisLabel,a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",De(b.xForXAxisLabel,b)).attr("dx",De(b.dxForXAxisLabel,b)).attr("dy",De(b.dyForXAxisLabel,b)).text(De(b.textForXAxisLabel,b)),(a?d.transition():d).attr("x",De(b.xForYAxisLabel,b)).attr("dx",De(b.dxForYAxisLabel,b)).attr("dy",De(b.dyForYAxisLabel,b)).text(De(b.textForYAxisLabel,b)),(a?e.transition():e).attr("x",De(b.xForY2AxisLabel,b)).attr("dx",De(b.dxForY2AxisLabel,b)).attr("dy",De(b.dyForY2AxisLabel,b)).text(De(b.textForY2AxisLabel,b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main;b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",De(d.classChartArc,d)),c=b.enter().append("g").attr("class",De(d.classChartArc,d)),c.append("g").attr("class",De(d.classArcs,d)),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(De(e.arcData,e)),d.enter().append("path").attr("class",De(e.classArc,e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(De(e.textForArcLabel,e)).attr("transform",De(e.transformForArcLabel,e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",De(b.classRegion,b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this;a.push(b.mainRegion.selectAll("rect").transition().attr("x",De(b.regionX,b)).attr("y",De(b.regionY,b)).attr("width",De(b.regionWidth,b)).attr("height",De(b.regionHeight,b)).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=De(e[vb]?d.circleY:d.circleX,d),g=De(e[vb]?d.circleX:d.circleY,d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",De(d.pointSelectR,d))},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config;h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",De(f.classChartBar,f)),d=e.enter().append("g").style("opacity",0).attr("class",De(f.classChartBar,f)),d.append("g").attr("class",De(f.classBars,f)),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",De(f.classChartLine,f)),b=c.enter().append("g").style("opacity",0).attr("class",De(f.classChartLine,f)),b.append("g").attr("class",De(f.classLines,f)),b.append("g").attr("class",De(f.classAreas,f)))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config;q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(De(n.barData,n)),j.enter().append("path").attr("class",De(n.classBar,n)).style("stroke","none").style("fill",n.color),j.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(De(n.lineData,n)),h.enter().append("path").attr("class",De(n.classLine,n)).style("stroke",n.color),h.style("opacity",De(n.initialOpacity,n)).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(De(n.lineData,n)),i.enter().append("path").attr("class",De(n.classArea,n)).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 -}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}},De=f.generateCall=function(a,b){return function(c,d){return a.call(b,c,d)}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(De(c.isNoneArc,c)),f=d.filter(De(c.isArc,c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&B.select(this).style("display",b%y?"none":"block")})}else z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!C[vb]&&C[Hb]&&z.rotateTickText(z.axes.x,b.axisX,C[Hb]),l=z.generateDrawArea?z.generateDrawArea(D,!1):void 0,m=z.generateDrawBar?z.generateDrawBar(E):void 0,n=z.generateDrawLine?z.generateDrawLine(F,!1):void 0,o=z.generateXYForText(E,!0),p=z.generateXYForText(E,!1),z.subY.domain(z.y.domain()),z.subY2.domain(z.y2.domain()),z.tooltip.style("display","none"),z.updateXgridFocus(),A.select("text."+pe[Nd]+"."+pe[Md]).attr("x",z.width/2).attr("y",z.height/2).text(C[fb]).transition().style("opacity",H.length?0:1),z.redrawGrid(q,c),z.redrawRegion(q),z.redrawBar(r),z.redrawLine(r),z.redrawArea(r),C[mc]&&z.redrawCircle(),z.hasDataLabel()&&z.redrawText(r),z.redrawArc&&z.redrawArc(q,r,h),z.redrawSubchart&&z.redrawSubchart(d,b,q,r,D,E,F),A.selectAll("."+pe[od]).filter(z.isBarType.bind(z)).selectAll("circle").remove(),C[s]&&z.redrawEventRect(),B.transition().duration(q).each(function(){var b=[];z.addTransitionForBar(b,m),z.addTransitionForLine(b,n),z.addTransitionForArea(b,l),z.addTransitionForCircle(b,J,K),z.addTransitionForText(b,o,p,a.flow),z.addTransitionForRegion(b),z.addTransitionForGrid(b),a.flow&&(u=z.generateWait(),b.forEach(function(a){u.add(a)}))}).call(u?u:function(){},function(){var b,c,d,e=1,f=a.flow.index,g=a.flow.length,h=z.getValueOnIndex(z.data.targets[0].values,f),i=z.getValueOnIndex(z.data.targets[0].values,f+g),j=z.x.domain(),k=a.flow.duration||q,r=a.flow.done||function(){},s=z.generateWait(),t=z.xgrid||B.selectAll([]),u=z.xgridLines||B.selectAll([]),v=z.mainRegion||B.selectAll([]),w=z.mainText||B.selectAll([]),x=z.mainBar||B.selectAll([]),y=z.mainLine||B.selectAll([]),A=z.mainArea||B.selectAll([]),D=z.mainCircle||B.selectAll([]);z.data.targets.forEach(function(a){a.values.splice(0,g)}),d=z.updateXDomain(H,!0,!0),z.updateXGrid&&z.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||h.x===i.x?z.x(j[0])-z.x(d[0]):z.isTimeSeries()?z.x(j[0])-z.x(d[0]):z.x(h.x)-z.x(i.x):1!==z.data.targets[0].values.length?b=z.x(j[0])-z.x(d[0]):z.isTimeSeries()?(h=z.getValueOnIndex(z.data.targets[0].values,0),i=z.getValueOnIndex(z.data.targets[0].values,z.data.targets[0].values.length-1),b=z.x(h.x)-z.x(i.x)):b=xe(d)/2,e=xe(j)/xe(d),c="translate("+b+",0) scale("+e+",1)",B.transition().ease("linear").duration(k).each(function(){s.add(z.axes.x.transition().call(z.xAxis)),s.add(x.transition().attr("transform",c)),s.add(y.transition().attr("transform",c)),s.add(A.transition().attr("transform",c)),s.add(D.transition().attr("transform",c)),s.add(w.transition().attr("transform",c)),s.add(v.filter(z.isRegionOnX).transition().attr("transform",c)),s.add(t.transition().attr("transform",c)),s.add(u.transition().attr("transform",c))}).call(s,function(){var a,b=[],c=[],d=[];if(g){for(a=0;g>a;a++)b.push("."+pe[Ad]+"-"+(f+a)),c.push("."+pe[Nd]+"-"+(f+a)),d.push("."+pe[pd]+"-"+(f+a));z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),z.svg.selectAll("."+pe[Od]).selectAll(c).remove(),z.svg.selectAll("."+pe[qd]).selectAll(d).remove(),z.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(z.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",C[vb]?0:I).attr("x2",C[vb]?z.width:I),u.select("text").attr("x",C[vb]?z.width:0).attr("y",I),x.attr("transform",null).attr("d",m),y.attr("transform",null).attr("d",n),A.attr("transform",null).attr("d",l),D.attr("transform",null).attr("cx",J).attr("cy",K),w.attr("transform",null).attr("x",o).attr("y",p).style("fill-opacity",z.opacityForText.bind(z)),v.attr("transform",null),v.select("rect").filter(z.isRegionOnX).attr("x",z.regionX.bind(z)).attr("width",z.regionWidth.bind(z)),z.updateEventRect(),r()})}),z.mapToIds(z.data.targets).forEach(function(a){z.withoutFadeIn[a]=!0}),z.updateZoom&&z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1); +return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid"))) +},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",a.textAnchorForXAxisLabel.bind(a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForYAxisLabel.bind(a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForY2AxisLabel.bind(a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",b.xForXAxisLabel.bind(b)).attr("dx",b.dxForXAxisLabel.bind(b)).attr("dy",b.dyForXAxisLabel.bind(b)).text(b.textForXAxisLabel.bind(b)),(a?d.transition():d).attr("x",b.xForYAxisLabel.bind(b)).attr("dx",b.dxForYAxisLabel.bind(b)).attr("dy",b.dyForYAxisLabel.bind(b)).text(b.textForYAxisLabel.bind(b)),(a?e.transition():e).attr("x",b.xForY2AxisLabel.bind(b)).attr("dx",b.dxForY2AxisLabel.bind(b)).attr("dy",b.dyForY2AxisLabel.bind(b)).text(b.textForY2AxisLabel.bind(b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main,f=d.classChartArc.bind(d),g=d.classArcs.bind(d);b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",f),c=b.enter().append("g").attr("class",f),c.append("g").attr("class",g),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(e.arcData.bind(e)),d.enter().append("path").attr("class",e.classArc.bind(e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(e.textForArcLabel.bind(e)).attr("transform",e.transformForArcLabel.bind(e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",b.classRegion.bind(b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this,c=b.regionX.bind(b),d=b.regionY.bind(b),e=b.regionWidth.bind(b),f=b.regionHeight.bind(b);a.push(b.mainRegion.selectAll("rect").transition().attr("x",c).attr("y",d).attr("width",e).attr("height",f).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=(e[vb]?d.circleY:d.circleX).bind(d),g=(e[vb]?d.circleX:d.circleY).bind(d),h=d.pointSelectR.bind(d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",h)},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config,i=f.classChartBar.bind(f),j=f.classBars.bind(f),k=f.classChartLine.bind(f),l=f.classLines.bind(f),m=f.classAreas.bind(f);h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",i),d=e.enter().append("g").style("opacity",0).attr("class",i),d.append("g").attr("class",j),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",k),b=c.enter().append("g").style("opacity",0).attr("class",k),b.append("g").attr("class",l),b.append("g").attr("class",m))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config,r=n.barData.bind(n),s=n.lineData.bind(n),t=n.classBar.bind(n),u=n.classLine.bind(n),v=n.classArea.bind(n),w=n.initialOpacity.bind(n);q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(r),j.enter().append("path").attr("class",t).style("stroke","none").style("fill",n.color),j.style("opacity",w).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(s),h.enter().append("path").attr("class",u).style("stroke",n.color),h.style("opacity",w).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(s),i.enter().append("path").attr("class",v).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 +}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/api.js b/src/api.js index 5d7eaa6..024410a 100644 --- a/src/api.js +++ b/src/api.js @@ -1,8 +1,8 @@ c3_chart_fn.focus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function focus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } @@ -19,8 +19,8 @@ c3_chart_fn.focus = function (targetId) { c3_chart_fn.defocus = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function defocus(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); } @@ -36,8 +36,8 @@ c3_chart_fn.defocus = function (targetId) { c3_chart_fn.revert = function (targetId) { var $$ = this.internal, candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter(generateCall($$.isNoneArc, $$)), - candidatesForArc = candidates.filter(generateCall($$.isArc, $$)); + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); function revert(targets) { $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); } diff --git a/src/arc.js b/src/arc.js index 9ebfa74..e1dd5eb 100644 --- a/src/arc.js +++ b/src/arc.js @@ -193,14 +193,17 @@ c3_chart_internal_fn.descByStartAngle = function (a, b) { }; c3_chart_internal_fn.updateTargetsForArc = function (targets) { - var $$ = this, main = $$.main, mainPieUpdate, mainPieEnter; + var $$ = this, main = $$.main, + mainPieUpdate, mainPieEnter, + classChartArc = $$.classChartArc.bind($$), + classArcs = $$.classArcs.bind($$); mainPieUpdate = main.select('.' + CLASS[_chartArcs]).selectAll('.' + CLASS[_chartArc]) .data($$.pie(targets)) - .attr("class", generateCall($$.classChartArc, $$)); + .attr("class", classChartArc); mainPieEnter = mainPieUpdate.enter().append("g") - .attr("class", generateCall($$.classChartArc, $$)); + .attr("class", classChartArc); mainPieEnter.append('g') - .attr('class', generateCall($$.classArcs, $$)); + .attr('class', classArcs); mainPieEnter.append("text") .attr("dy", $$.hasType('gauge') ? "-0.35em" : ".35em") .style("opacity", 0) @@ -225,9 +228,9 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf var $$ = this, d3 = $$.d3, config = $$.config, main = $$.main, mainArc; mainArc = main.selectAll('.' + CLASS[_arcs]).selectAll('.' + CLASS[_arc]) - .data(generateCall($$.arcData, $$)); + .data($$.arcData.bind($$)); mainArc.enter().append('path') - .attr("class", generateCall($$.classArc, $$)) + .attr("class", $$.classArc.bind($$)) .style("fill", function (d) { return $$.color(d.data); }) .style("cursor", function (d) { return config[__data_selection_isselectable](d) ? "pointer" : null; }) .style("opacity", 0) @@ -314,8 +317,8 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf main.selectAll('.' + CLASS[_chartArc]).select('text') .style("opacity", 0) .attr('class', function (d) { return $$.isGaugeType(d.data) ? CLASS[_gaugeValue] : ''; }) - .text(generateCall($$.textForArcLabel, $$)) - .attr("transform", generateCall($$.transformForArcLabel, $$)) + .text($$.textForArcLabel.bind($$)) + .attr("transform", $$.transformForArcLabel.bind($$)) .transition().duration(duration) .style("opacity", function (d) { return $$.isTargetToShow(d.data.id) && $$.isArcType(d.data) ? 1 : 0; }); main.select('.' + CLASS[_chartArcsTitle]) diff --git a/src/axis.js b/src/axis.js index 075cd36..0de1dc4 100644 --- a/src/axis.js +++ b/src/axis.js @@ -8,7 +8,7 @@ c3_chart_internal_fn.initAxis = function () { $$.axes.x.append("text") .attr("class", CLASS[_axisXLabel]) .attr("transform", config[__axis_rotated] ? "rotate(-90)" : "") - .style("text-anchor", generateCall($$.textAnchorForXAxisLabel, $$)); + .style("text-anchor", $$.textAnchorForXAxisLabel.bind($$)); $$.axes.y = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY]) @@ -18,7 +18,7 @@ c3_chart_internal_fn.initAxis = function () { $$.axes.y.append("text") .attr("class", CLASS[_axisYLabel]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .style("text-anchor", generateCall($$.textAnchorForYAxisLabel, $$)); + .style("text-anchor", $$.textAnchorForYAxisLabel.bind($$)); $$.axes.y2 = main.append("g") .attr("class", CLASS[_axis] + ' ' + CLASS[_axisY2]) @@ -28,7 +28,7 @@ c3_chart_internal_fn.initAxis = function () { $$.axes.y2.append("text") .attr("class", CLASS[_axisY2Label]) .attr("transform", config[__axis_rotated] ? "" : "rotate(-90)") - .style("text-anchor", generateCall($$.textAnchorForY2AxisLabel, $$)); + .style("text-anchor", $$.textAnchorForY2AxisLabel.bind($$)); }; c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues) { var $$ = this, config = $$.config, @@ -265,20 +265,20 @@ c3_chart_internal_fn.updateAxisLabels = function (withTransition) { axisYLabel = $$.main.select('.' + CLASS[_axisY] + ' .' + CLASS[_axisYLabel]), axisY2Label = $$.main.select('.' + CLASS[_axisY2] + ' .' + CLASS[_axisY2Label]); (withTransition ? axisXLabel.transition() : axisXLabel) - .attr("x", generateCall($$.xForXAxisLabel, $$)) - .attr("dx", generateCall($$.dxForXAxisLabel, $$)) - .attr("dy", generateCall($$.dyForXAxisLabel, $$)) - .text(generateCall($$.textForXAxisLabel, $$)); + .attr("x", $$.xForXAxisLabel.bind($$)) + .attr("dx", $$.dxForXAxisLabel.bind($$)) + .attr("dy", $$.dyForXAxisLabel.bind($$)) + .text($$.textForXAxisLabel.bind($$)); (withTransition ? axisYLabel.transition() : axisYLabel) - .attr("x", generateCall($$.xForYAxisLabel, $$)) - .attr("dx", generateCall($$.dxForYAxisLabel, $$)) - .attr("dy", generateCall($$.dyForYAxisLabel, $$)) - .text(generateCall($$.textForYAxisLabel, $$)); + .attr("x", $$.xForYAxisLabel.bind($$)) + .attr("dx", $$.dxForYAxisLabel.bind($$)) + .attr("dy", $$.dyForYAxisLabel.bind($$)) + .text($$.textForYAxisLabel.bind($$)); (withTransition ? axisY2Label.transition() : axisY2Label) - .attr("x", generateCall($$.xForY2AxisLabel, $$)) - .attr("dx", generateCall($$.dxForY2AxisLabel, $$)) - .attr("dy", generateCall($$.dyForY2AxisLabel, $$)) - .text(generateCall($$.textForY2AxisLabel, $$)); + .attr("x", $$.xForY2AxisLabel.bind($$)) + .attr("dx", $$.dxForY2AxisLabel.bind($$)) + .attr("dy", $$.dyForY2AxisLabel.bind($$)) + .text($$.textForY2AxisLabel.bind($$)); }; c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all) { diff --git a/src/core.js b/src/core.js index 9794fb8..fab64c7 100644 --- a/src/core.js +++ b/src/core.js @@ -404,9 +404,9 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var drawArea, drawBar, drawLine, xForText, yForText; var duration, durationForExit, durationForAxis, waitForDraw; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; - var xv = generateCall($$.xv, $$), - cx = generateCall($$.config[__axis_rotated] ? $$.circleY : $$.circleX, $$), - cy = generateCall($$.config[__axis_rotated] ? $$.circleX : $$.circleY, $$); + var xv = $$.xv.bind($$), + cx = ($$.config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), + cy = ($$.config[__axis_rotated] ? $$.circleX : $$.circleY).bind($$); options = options || {}; withY = getOption(options, "withY", true); @@ -536,7 +536,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) { // circles for select main.selectAll('.' + CLASS[_selectedCircles]) - .filter(generateCall($$.isBarType, $$)) + .filter($$.isBarType.bind($$)) .selectAll('circle') .remove(); @@ -676,12 +676,12 @@ c3_chart_internal_fn.redraw = function (options, transitions) { .attr('transform', null) .attr('x', xForText) .attr('y', yForText) - .style('fill-opacity', generateCall($$.opacityForText, $$)); + .style('fill-opacity', $$.opacityForText.bind($$)); mainRegion .attr('transform', null); mainRegion.select('rect').filter($$.isRegionOnX) - .attr("x", generateCall($$.regionX, $$)) - .attr("width", generateCall($$.regionWidth, $$)); + .attr("x", $$.regionX.bind($$)) + .attr("width", $$.regionWidth.bind($$)); $$.updateEventRect(); // callback for end of flow @@ -831,15 +831,15 @@ c3_chart_internal_fn.updateSvgSize = function () { .attr('width', $$.width) .attr('height', $$.height); $$.svg.select('#' + $$.clipIdForXAxis).select('rect') - .attr('x', generateCall($$.getXAxisClipX, $$)) - .attr('y', generateCall($$.getXAxisClipY, $$)) - .attr('width', generateCall($$.getXAxisClipWidth, $$)) - .attr('height', generateCall($$.getXAxisClipHeight, $$)); + .attr('x', $$.getXAxisClipX.bind($$)) + .attr('y', $$.getXAxisClipY.bind($$)) + .attr('width', $$.getXAxisClipWidth.bind($$)) + .attr('height', $$.getXAxisClipHeight.bind($$)); $$.svg.select('#' + $$.clipIdForYAxis).select('rect') - .attr('x', generateCall($$.getYAxisClipX, $$)) - .attr('y', generateCall($$.getYAxisClipY, $$)) - .attr('width', generateCall($$.getYAxisClipWidth, $$)) - .attr('height', generateCall($$.getYAxisClipHeight, $$)); + .attr('x', $$.getYAxisClipX.bind($$)) + .attr('y', $$.getYAxisClipY.bind($$)) + .attr('width', $$.getYAxisClipWidth.bind($$)) + .attr('height', $$.getYAxisClipHeight.bind($$)); $$.svg.select('.' + CLASS[_zoomRect]) .attr('width', $$.width) .attr('height', $$.height); diff --git a/src/grid.js b/src/grid.js index ef5879b..3dbdfa2 100644 --- a/src/grid.js +++ b/src/grid.js @@ -109,7 +109,7 @@ c3_chart_internal_fn.redrawGrid = function (duration, withY) { .attr('dy', -5) .style("opacity", 0); // update - yv = generateCall($$.yv, $$); + yv = $$.yv.bind($$); $$.ygridLines.select('line') .transition().duration(duration) .attr("x1", config[__axis_rotated] ? yv : 0) @@ -130,7 +130,7 @@ c3_chart_internal_fn.redrawGrid = function (duration, withY) { } }; c3_chart_internal_fn.addTransitionForGrid = function (transitions) { - var $$ = this, config = $$.config, xv = generateCall($$.xv, $$); + var $$ = this, config = $$.config, xv = $$.xv.bind($$); transitions.push($$.xgridLines.select('line').transition() .attr("x1", config[__axis_rotated] ? 0 : xv) .attr("x2", config[__axis_rotated] ? $$.width : xv) @@ -145,16 +145,17 @@ c3_chart_internal_fn.addTransitionForGrid = function (transitions) { }; c3_chart_internal_fn.showXGridFocus = function (selectedData) { var $$ = this, config = $$.config, - dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }); + dataToShow = selectedData.filter(function (d) { return d && isValue(d.value); }), + focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]), + xx = $$.xx.bind($$); if (! config[__tooltip_show]) { return; } // Hide when scatter plot exists if ($$.hasType('scatter') || $$.hasArcType()) { return; } - var focusEl = $$.main.selectAll('line.' + CLASS[_xgridFocus]); focusEl .style("visibility", "visible") .data([dataToShow[0]]) - .attr(config[__axis_rotated] ? 'y1' : 'x1', generateCall($$.xx, $$)) - .attr(config[__axis_rotated] ? 'y2' : 'x2', generateCall($$.xx, $$)); + .attr(config[__axis_rotated] ? 'y1' : 'x1', xx) + .attr(config[__axis_rotated] ? 'y2' : 'x2', xx); $$.smoothLines(focusEl, 'grid'); }; c3_chart_internal_fn.hideXGridFocus = function () { diff --git a/src/interaction.js b/src/interaction.js index 720e1b9..6a8e321 100644 --- a/src/interaction.js +++ b/src/interaction.js @@ -90,7 +90,7 @@ c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) { c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) { var $$ = this, d3 = $$.d3, config = $$.config; eventRectEnter.append("rect") - .attr("class", generateCall($$.classEvent, $$)) + .attr("class", $$.classEvent.bind($$)) .style("cursor", config[__data_selection_enabled] && config[__data_selection_grouped] ? "pointer" : null) .on('mouseover', function (d) { var index = d.index, selectedData, newData; diff --git a/src/region.js b/src/region.js index d1ff972..eec384a 100644 --- a/src/region.js +++ b/src/region.js @@ -9,7 +9,7 @@ c3_chart_internal_fn.redrawRegion = function (duration) { $$.mainRegion = $$.main.select('.' + CLASS[_regions]).selectAll('.' + CLASS[_region]) .data(config[__regions]); $$.mainRegion.enter().append('g') - .attr('class', generateCall($$.classRegion, $$)) + .attr('class', $$.classRegion.bind($$)) .append('rect') .style("fill-opacity", 0); $$.mainRegion.exit().transition().duration(duration) @@ -17,12 +17,16 @@ c3_chart_internal_fn.redrawRegion = function (duration) { .remove(); }; c3_chart_internal_fn.addTransitionForRegion = function (transitions) { - var $$ = this; + var $$ = this, + x = $$.regionX.bind($$), + y = $$.regionY.bind($$), + w = $$.regionWidth.bind($$), + h = $$.regionHeight.bind($$); transitions.push($$.mainRegion.selectAll('rect').transition() - .attr("x", generateCall($$.regionX, $$)) - .attr("y", generateCall($$.regionY, $$)) - .attr("width", generateCall($$.regionWidth, $$)) - .attr("height", generateCall($$.regionHeight, $$)) + .attr("x", x) + .attr("y", y) + .attr("width", w) + .attr("height", h) .style("fill-opacity", function (d) { return isValue(d.opacity) ? d.opacity : 0.1; })); }; c3_chart_internal_fn.regionX = function (d) { diff --git a/src/selection.js b/src/selection.js index 67ddcee..8ae1e48 100644 --- a/src/selection.js +++ b/src/selection.js @@ -1,8 +1,8 @@ c3_chart_internal_fn.selectPoint = function (target, d, i) { var $$ = this, config = $$.config, - cx = generateCall(config[__axis_rotated] ? $$.circleY : $$.circleX, $$), - cy = generateCall(config[__axis_rotated] ? $$.circleX : $$.circleY, $$); - + cx = (config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), + cy = (config[__axis_rotated] ? $$.circleX : $$.circleY).bind($$), + r = $$.pointSelectR.bind($$); config[__data_onselected].call($$.api, d, target.node()); // add selected-circle on low layer g $$.main.select('.' + CLASS[_selectedCircles] + $$.getTargetSelectorSuffix(d.id)).selectAll('.' + CLASS[_selectedCircle] + '-' + i) @@ -14,7 +14,7 @@ c3_chart_internal_fn.selectPoint = function (target, d, i) { .attr("stroke", function () { return $$.color(d); }) .attr("r", function (d) { return $$.pointSelectR(d) * 1.4; }) .transition().duration(100) - .attr("r", generateCall($$.pointSelectR, $$)); + .attr("r", r); }; c3_chart_internal_fn.unselectPoint = function (target, d, i) { var $$ = this; diff --git a/src/shape.bar.js b/src/shape.bar.js index 24cd3e6..0c82f38 100644 --- a/src/shape.bar.js +++ b/src/shape.bar.js @@ -22,15 +22,19 @@ c3_chart_internal_fn.updateTargetsForBar = function (targets) { }; c3_chart_internal_fn.redrawBar = function (durationForExit) { - var $$ = this, CLASS = $$.CLASS; + var $$ = this, CLASS = $$.CLASS, + barData = $$.barData.bind($$), + classBar = $$.classBar.bind($$), + initialOpacity = $$.initialOpacity.bind($$), + color = function (d) { return $$.color(d.id); }; $$.mainBar = $$.main.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); + .data(barData); $$.mainBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) - .style("stroke", function (d) { return $$.color(d.id); }) - .style("fill", function (d) { return $$.color(d.id); }); + .attr("class", classBar) + .style("stroke", color) + .style("fill", color); $$.mainBar - .style("opacity", generateCall($$.initialOpacity, $$)); + .style("opacity", initialOpacity); $$.mainBar.exit().transition().duration(durationForExit) .style('opacity', 0) .remove(); diff --git a/src/shape.line.js b/src/shape.line.js index b84129f..e487f20 100644 --- a/src/shape.line.js +++ b/src/shape.line.js @@ -306,17 +306,19 @@ c3_chart_internal_fn.getCircles = function (i, id) { return (id ? $$.main.selectAll('.' + CLASS[_circles] + $$.getTargetSelectorSuffix(id)) : $$.main).selectAll('.' + CLASS[_circle] + (isValue(i) ? '-' + i : '')); }; c3_chart_internal_fn.expandCircles = function (i, id) { - var $$ = this; + var $$ = this, + r = $$.pointExpandedR.bind($$); $$.getCircles(i, id) .classed(CLASS[_EXPANDED], true) - .attr('r', generateCall($$.pointExpandedR, $$)); + .attr('r', r); }; c3_chart_internal_fn.unexpandCircles = function (i) { - var $$ = this; + var $$ = this, + r = $$.pointR.bind($$); $$.getCircles(i) .filter(function () { return $$.d3.select(this).classed(CLASS[_EXPANDED]); }) .classed(CLASS[_EXPANDED], false) - .attr('r', generateCall($$.pointR, $$)); + .attr('r', r); }; c3_chart_internal_fn.pointR = function (d) { var $$ = this, config = $$.config; diff --git a/src/subchart.js b/src/subchart.js index 44aece6..3781136 100644 --- a/src/subchart.js +++ b/src/subchart.js @@ -47,38 +47,48 @@ c3_chart_internal_fn.initSubchart = function () { }; c3_chart_internal_fn.updateTargetsForSubchart = function (targets) { var $$ = this, context = $$.context, config = $$.config, - contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate; + contextLineEnter, contextLineUpdate, contextBarEnter, contextBarUpdate, + classChartBar = $$.classChartBar.bind($$), + classBars = $$.classBars.bind($$), + classChartLine = $$.classChartLine.bind($$), + classLines = $$.classLines.bind($$), + classAreas = $$.classAreas.bind($$); if (config[__subchart_show]) { - contextBarUpdate = context.select('.' + CLASS[_chartBars]).selectAll('.' + CLASS[_chartBar]) .data(targets) - .attr('class', generateCall($$.classChartBar, $$)); + .attr('class', classChartBar); contextBarEnter = contextBarUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall($$.classChartBar, $$)); + .attr('class', classChartBar); // Bars for each data contextBarEnter.append('g') - .attr("class", generateCall($$.classBars, $$)); + .attr("class", classBars); //-- Line --// contextLineUpdate = context.select('.' + CLASS[_chartLines]).selectAll('.' + CLASS[_chartLine]) .data(targets) - .attr('class', generateCall($$.classChartLine, $$)); + .attr('class', classChartLine); contextLineEnter = contextLineUpdate.enter().append('g') .style('opacity', 0) - .attr('class', generateCall($$.classChartLine, $$)); + .attr('class', classChartLine); // Lines for each data contextLineEnter.append("g") - .attr("class", generateCall($$.classLines, $$)); + .attr("class", classLines); // Area contextLineEnter.append("g") - .attr("class", generateCall($$.classAreas, $$)); + .attr("class", classAreas); } }; c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices) { var $$ = this, d3 = $$.d3, context = $$.context, config = $$.config, - contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub; + contextLine, contextArea, contextBar, drawAreaOnSub, drawBarOnSub, drawLineOnSub, + barData = $$.barData.bind($$), + lineData = $$.lineData.bind($$), + classBar = $$.classBar.bind($$), + classLine = $$.classLine.bind($$), + classArea = $$.classArea.bind($$), + initialOpacity = $$.initialOpacity.bind($$); // subchart if (config[__subchart_show]) { @@ -104,13 +114,13 @@ c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, durat drawLineOnSub = $$.generateDrawLine(lineIndices, true); // bars contextBar = context.selectAll('.' + CLASS[_bars]).selectAll('.' + CLASS[_bar]) - .data(generateCall($$.barData, $$)); + .data(barData); contextBar.enter().append('path') - .attr("class", generateCall($$.classBar, $$)) + .attr("class", classBar) .style("stroke", 'none') .style("fill", $$.color); contextBar - .style("opacity", generateCall($$.initialOpacity, $$)) + .style("opacity", initialOpacity) .transition().duration(duration) .attr('d', drawBarOnSub) .style('opacity', 1); @@ -119,12 +129,12 @@ c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, durat .remove(); // lines contextLine = context.selectAll('.' + CLASS[_lines]).selectAll('.' + CLASS[_line]) - .data(generateCall($$.lineData, $$)); + .data(lineData); contextLine.enter().append('path') - .attr('class', generateCall($$.classLine, $$)) + .attr('class', classLine) .style('stroke', $$.color); contextLine - .style("opacity", generateCall($$.initialOpacity, $$)) + .style("opacity", initialOpacity) .transition().duration(duration) .attr("d", drawLineOnSub) .style('opacity', 1); @@ -133,9 +143,9 @@ c3_chart_internal_fn.redrawSubchart = function (withSubchart, transitions, durat .remove(); // area contextArea = context.selectAll('.' + CLASS[_areas]).selectAll('.' + CLASS[_area]) - .data(generateCall($$.lineData, $$)); + .data(lineData); contextArea.enter().append('path') - .attr("class", generateCall($$.classArea, $$)) + .attr("class", classArea) .style("fill", $$.color) .style("opacity", function () { $$.orgAreaOpacity = +d3.select(this).style('opacity'); return 0; }); contextArea diff --git a/src/text.js b/src/text.js index a61fc8d..ad9ccc3 100644 --- a/src/text.js +++ b/src/text.js @@ -19,11 +19,13 @@ c3_chart_internal_fn.updateTargetsForText = function (targets) { .attr('class', classTexts); }; c3_chart_internal_fn.redrawText = function (durationForExit) { - var $$ = this, config = $$.config, CLASS = $$.CLASS; + var $$ = this, config = $$.config, CLASS = $$.CLASS, + barOrLineData = $$.barOrLineData.bind($$), + classText = $$.classText.bind($$); $$.mainText = $$.main.selectAll('.' + CLASS[_texts]).selectAll('.' + CLASS[_text]) - .data(generateCall($$.barOrLineData, $$)); + .data(barOrLineData); $$.mainText.enter().append('text') - .attr("class", generateCall($$.classText, $$)) + .attr("class", classText) .attr('text-anchor', function (d) { return config[__axis_rotated] ? (d.value < 0 ? 'end' : 'start') : 'middle'; }) .style("stroke", 'none') .style("fill", function (d) { return $$.color(d); }) @@ -36,12 +38,13 @@ c3_chart_internal_fn.redrawText = function (durationForExit) { .remove(); }; c3_chart_internal_fn.addTransitionForText = function (transitions, xForText, yForText, forFlow) { - var $$ = this; + var $$ = this, + opacityForText = forFlow ? 0 : $$.opacityForText.bind($$); transitions.push($$.mainText.transition() .attr('x', xForText) .attr('y', yForText) .style("fill", $$.color) - .style("fill-opacity", forFlow ? 0 : generateCall($$.opacityForText, $$))); + .style("fill-opacity", opacityForText)); }; c3_chart_internal_fn.getTextRect = function (text, cls) { var rect; diff --git a/src/util.js b/src/util.js index f94982d..91cb48b 100644 --- a/src/util.js +++ b/src/util.js @@ -43,7 +43,4 @@ var isValue = c3_chart_internal_fn.isValue = function (v) { items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], minX = items[0].x, minY = Math.min(items[0].y, items[1].y); return {x: minX, y: minY, width: box.width, height: box.height}; - }, - generateCall = c3_chart_internal_fn.generateCall = function (f, context) { - return function (d, i) { return f.call(context, d, i); }; }; From adbfd48879f42158337d05454cc4d5f6647b5683 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 17 Aug 2014 20:32:08 +0900 Subject: [PATCH 41/44] Separate api --- Gruntfile.coffee | 18 +- c3.js | 3 +- src/api.axis.js | 43 ++++ src/api.category.js | 15 ++ src/api.chart.js | 19 ++ src/api.color.js | 5 + src/api.data.js | 27 ++ src/api.flow.js | 140 +++++++++++ src/api.focus.js | 50 ++++ src/api.grid.js | 31 +++ src/api.group.js | 7 + src/api.js | 570 ------------------------------------------- src/api.legend.js | 11 + src/api.load.js | 40 +++ src/api.region.js | 40 +++ src/api.selection.js | 52 ++++ src/api.show.js | 40 +++ src/api.transform.js | 5 + src/api.x.js | 16 ++ src/api.zoom.js | 12 + 20 files changed, 571 insertions(+), 573 deletions(-) create mode 100644 src/api.axis.js create mode 100644 src/api.category.js create mode 100644 src/api.chart.js create mode 100644 src/api.color.js create mode 100644 src/api.data.js create mode 100644 src/api.flow.js create mode 100644 src/api.focus.js create mode 100644 src/api.grid.js create mode 100644 src/api.group.js delete mode 100644 src/api.js create mode 100644 src/api.legend.js create mode 100644 src/api.load.js create mode 100644 src/api.region.js create mode 100644 src/api.selection.js create mode 100644 src/api.show.js create mode 100644 src/api.transform.js create mode 100644 src/api.x.js create mode 100644 src/api.zoom.js diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 3118abf..c6562d9 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -50,7 +50,23 @@ module.exports = (grunt) -> 'src/cache.js', 'src/class.js', 'src/util.js', - 'src/api.js', + 'src/api.focus.js', + 'src/api.show.js', + 'src/api.zoom.js', + 'src/api.load.js', + 'src/api.flow.js', + 'src/api.selection.js', + 'src/api.transform.js', + 'src/api.group.js', + 'src/api.grid.js', + 'src/api.region.js', + 'src/api.data.js', + 'src/api.category.js', + 'src/api.color.js', + 'src/api.x.js', + 'src/api.axis.js', + 'src/api.legend.js', + 'src/api.chart.js', 'src/c3.axis.js', 'src/tail.js' ] diff --git a/c3.js b/c3.js index a42348b..9185332 100644 --- a/c3.js +++ b/c3.js @@ -5987,6 +5987,7 @@ $$.redraw({withLegend: true}); return config[__data_colors]; }; + c3_chart_fn.category = function (i, category) { var $$ = this.internal, config = $$.config; if (arguments.length > 1) { @@ -6026,7 +6027,6 @@ return $$.data.xs; }; - c3_chart_fn.axis = function () {}; c3_chart_fn.axis.labels = function (labels) { var $$ = this.internal; @@ -6071,7 +6071,6 @@ } }; - c3_chart_fn.legend = function () {}; c3_chart_fn.legend.show = function (targetIds) { var $$ = this.internal; diff --git a/src/api.axis.js b/src/api.axis.js new file mode 100644 index 0000000..104a69b --- /dev/null +++ b/src/api.axis.js @@ -0,0 +1,43 @@ +c3_chart_fn.axis = function () {}; +c3_chart_fn.axis.labels = function (labels) { + var $$ = this.internal; + if (arguments.length) { + Object.keys(labels).forEach(function (axisId) { + $$.setAxisLabelText(axisId, labels[axisId]); + }); + $$.updateAxisLabels(); + } + // TODO: return some values? +}; +c3_chart_fn.axis.max = function (max) { + var $$ = this.internal, config = $$.config; + if (arguments.length) { + if (typeof max === 'object') { + if (isValue(max.x)) { config[__axis_x_max] = max.x; } + if (isValue(max.y)) { config[__axis_y_max] = max.y; } + if (isValue(max.y2)) { config[__axis_y2_max] = max.y2; } + } else { + config[__axis_y_max] = config[__axis_y2_max] = max; + } + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } +}; +c3_chart_fn.axis.min = function (min) { + var $$ = this.internal, config = $$.config; + if (arguments.length) { + if (typeof min === 'object') { + if (isValue(min.x)) { config[__axis_x_min] = min.x; } + if (isValue(min.y)) { config[__axis_y_min] = min.y; } + if (isValue(min.y2)) { config[__axis_y2_min] = min.y2; } + } else { + config[__axis_y_min] = config[__axis_y2_min] = min; + } + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } +}; +c3_chart_fn.axis.range = function (range) { + if (arguments.length) { + if (isDefined(range.max)) { this.axis.max(range.max); } + if (isDefined(range.min)) { this.axis.min(range.min); } + } +}; diff --git a/src/api.category.js b/src/api.category.js new file mode 100644 index 0000000..8fca10a --- /dev/null +++ b/src/api.category.js @@ -0,0 +1,15 @@ +c3_chart_fn.category = function (i, category) { + var $$ = this.internal, config = $$.config; + if (arguments.length > 1) { + config[__axis_x_categories][i] = category; + $$.redraw(); + } + return config[__axis_x_categories][i]; +}; +c3_chart_fn.categories = function (categories) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__axis_x_categories]; } + config[__axis_x_categories] = categories; + $$.redraw(); + return config[__axis_x_categories]; +}; diff --git a/src/api.chart.js b/src/api.chart.js new file mode 100644 index 0000000..ee15243 --- /dev/null +++ b/src/api.chart.js @@ -0,0 +1,19 @@ +c3_chart_fn.resize = function (size) { + var $$ = this.internal, config = $$.config; + config[__size_width] = size ? size.width : null; + config[__size_height] = size ? size.height : null; + this.flush(); +}; + +c3_chart_fn.flush = function () { + var $$ = this.internal; + $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); +}; + +c3_chart_fn.destroy = function () { + var $$ = this.internal; + $$.data.targets = undefined; + $$.data.xs = {}; + $$.selectChart.classed('c3', false).html(""); + window.onresize = null; +}; diff --git a/src/api.color.js b/src/api.color.js new file mode 100644 index 0000000..15aaa3e --- /dev/null +++ b/src/api.color.js @@ -0,0 +1,5 @@ +// TODO: fix +c3_chart_fn.color = function (id) { + var $$ = this.internal; + return $$.color(id); // more patterns +}; diff --git a/src/api.data.js b/src/api.data.js new file mode 100644 index 0000000..c6f6da3 --- /dev/null +++ b/src/api.data.js @@ -0,0 +1,27 @@ +c3_chart_fn.data = function () {}; +c3_chart_fn.data.get = function (targetId) { + var target = this.data.getAsTarget(targetId); + return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; +}; +c3_chart_fn.data.getAsTarget = function (targetId) { + var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); + return targets.length > 0 ? targets[0] : undefined; +}; +c3_chart_fn.data.names = function (names) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_names]; } + Object.keys(names).forEach(function (id) { + config[__data_names][id] = names[id]; + }); + $$.redraw({withLegend: true}); + return config[__data_names]; +}; +c3_chart_fn.data.colors = function (colors) { + var $$ = this.internal, config = $$.config; + if (!arguments.length) { return config[__data_colors]; } + Object.keys(colors).forEach(function (id) { + config[__data_colors][id] = colors[id]; + }); + $$.redraw({withLegend: true}); + return config[__data_colors]; +}; diff --git a/src/api.flow.js b/src/api.flow.js new file mode 100644 index 0000000..0237ac2 --- /dev/null +++ b/src/api.flow.js @@ -0,0 +1,140 @@ +c3_chart_fn.flow = function (args) { + var $$ = this.internal, + targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), + dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; + + if (args.json) { + data = $$.convertJsonToData(args.json, args.keys); + } + else if (args.rows) { + data = $$.convertRowsToData(args.rows); + } + else if (args.columns) { + data = $$.convertColumnsToData(args.columns); + } + else { + return; + } + targets = $$.convertDataToTargets(data, true); + + // Update/Add data + $$.data.targets.forEach(function (t) { + var found = false, i, j; + for (i = 0; i < targets.length; i++) { + if (t.id === targets[i].id) { + found = true; + + if (t.values[t.values.length - 1]) { + tail = t.values[t.values.length - 1].index + 1; + } + length = targets[i].values.length; + + for (j = 0; j < length; j++) { + targets[i].values[j].index = tail + j; + if (!$$.isTimeSeries()) { + targets[i].values[j].x = tail + j; + } + } + t.values = t.values.concat(targets[i].values); + + targets.splice(i, 1); + break; + } + } + if (!found) { notfoundIds.push(t.id); } + }); + + // Append null for not found targets + $$.data.targets.forEach(function (t) { + var i, j; + for (i = 0; i < notfoundIds.length; i++) { + if (t.id === notfoundIds[i]) { + tail = t.values[t.values.length - 1].index + 1; + for (j = 0; j < length; j++) { + t.values.push({ + id: t.id, + index: tail + j, + x: $$.isTimeSeries() ? $$.getOtherTargetX(tail + j) : tail + j, + value: null + }); + } + } + } + }); + + // Generate null values for new target + if ($$.data.targets.length) { + targets.forEach(function (t) { + var i, missing = []; + for (i = $$.data.targets[0].values[0].index; i < tail; i++) { + missing.push({ + id: t.id, + index: i, + x: $$.isTimeSeries() ? $$.getOtherTargetX(i) : i, + value: null + }); + } + t.values.forEach(function (v) { + v.index += tail; + if (!$$.isTimeSeries()) { + v.x += tail; + } + }); + t.values = missing.concat(t.values); + }); + } + $$.data.targets = $$.data.targets.concat(targets); // add remained + + // check data count because behavior needs to change when it's only one + dataCount = $$.getMaxDataCount(); + baseTarget = $$.data.targets[0]; + baseValue = baseTarget.values[0]; + + // Update length to flow if needed + if (isDefined(args.to)) { + length = 0; + to = $$.isTimeSeries() ? $$.parseDate(args.to) : args.to; + baseTarget.values.forEach(function (v) { + if (v.x < to) { length++; } + }); + } else if (isDefined(args.length)) { + length = args.length; + } + + // If only one data, update the domain to flow from left edge of the chart + if (!orgDataCount) { + if ($$.isTimeSeries()) { + if (baseTarget.values.length > 1) { + diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; + } else { + diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; + } + } else { + diff = 1; + } + domain = [baseValue.x - diff, baseValue.x]; + $$.updateXDomain(null, true, true, domain); + } else if (orgDataCount === 1) { + if ($$.isTimeSeries()) { + diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; + domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; + $$.updateXDomain(null, true, true, domain); + } + } + + // Set targets + $$.updateTargets($$.data.targets); + + // Redraw with new targets + $$.redraw({ + flow: { + index: baseValue.index, + length: length, + duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], + done: args.done, + orgDataCount: orgDataCount, + }, + withLegend: true, + withTransition: orgDataCount > 1, + }); +}; diff --git a/src/api.focus.js b/src/api.focus.js new file mode 100644 index 0000000..4710d77 --- /dev/null +++ b/src/api.focus.js @@ -0,0 +1,50 @@ +c3_chart_fn.focus = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); + function focus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + this.revert(); + this.defocus(); + focus(candidatesForNoneArc.classed(CLASS[_focused], true)); + focus(candidatesForArc); + if ($$.hasArcType()) { + $$.expandArc(targetId, true); + } + $$.toggleFocusLegend(targetId, true); +}; + +c3_chart_fn.defocus = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); + function defocus(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); + } + this.revert(); + defocus(candidatesForNoneArc.classed(CLASS[_focused], false)); + defocus(candidatesForArc); + if ($$.hasArcType()) { + $$.unexpandArc(targetId); + } + $$.toggleFocusLegend(targetId, false); +}; + +c3_chart_fn.revert = function (targetId) { + var $$ = this.internal, + candidates = $$.svg.selectAll($$.selectorTarget(targetId)), + candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), + candidatesForArc = candidates.filter($$.isArc.bind($$)); + function revert(targets) { + $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); + } + revert(candidatesForNoneArc.classed(CLASS[_focused], false)); + revert(candidatesForArc); + if ($$.hasArcType()) { + $$.unexpandArc(targetId); + } + $$.revertLegend(); +}; diff --git a/src/api.grid.js b/src/api.grid.js new file mode 100644 index 0000000..5d38050 --- /dev/null +++ b/src/api.grid.js @@ -0,0 +1,31 @@ +c3_chart_fn.xgrids = function (grids) { + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_x_lines]; } + config[__grid_x_lines] = grids; + $$.redraw(); + return config[__grid_x_lines]; +}; +c3_chart_fn.xgrids.add = function (grids) { + var $$ = this.internal; + return this.xgrids($$.config[__grid_x_lines].concat(grids ? grids : [])); +}; +c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; + $$.removeGridLines(params, true); +}; + +c3_chart_fn.ygrids = function (grids) { + var $$ = this.internal, config = $$.config; + if (! grids) { return config[__grid_y_lines]; } + config[__grid_y_lines] = grids; + $$.redraw(); + return config[__grid_y_lines]; +}; +c3_chart_fn.ygrids.add = function (grids) { + var $$ = this.internal; + return this.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); +}; +c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple + var $$ = this.internal; + $$.removeGridLines(params, false); +}; diff --git a/src/api.group.js b/src/api.group.js new file mode 100644 index 0000000..7c85494 --- /dev/null +++ b/src/api.group.js @@ -0,0 +1,7 @@ +c3_chart_fn.groups = function (groups) { + var $$ = this.internal, config = $$.config; + if (isUndefined(groups)) { return config[__data_groups]; } + config[__data_groups] = groups; + $$.redraw(); + return config[__data_groups]; +}; diff --git a/src/api.js b/src/api.js deleted file mode 100644 index 024410a..0000000 --- a/src/api.js +++ /dev/null @@ -1,570 +0,0 @@ -c3_chart_fn.focus = function (targetId) { - var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), - candidatesForArc = candidates.filter($$.isArc.bind($$)); - function focus(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); - } - this.revert(); - this.defocus(); - focus(candidatesForNoneArc.classed(CLASS[_focused], true)); - focus(candidatesForArc); - if ($$.hasArcType()) { - $$.expandArc(targetId, true); - } - $$.toggleFocusLegend(targetId, true); -}; - -c3_chart_fn.defocus = function (targetId) { - var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), - candidatesForArc = candidates.filter($$.isArc.bind($$)); - function defocus(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 0.3); - } - this.revert(); - defocus(candidatesForNoneArc.classed(CLASS[_focused], false)); - defocus(candidatesForArc); - if ($$.hasArcType()) { - $$.unexpandArc(targetId); - } - $$.toggleFocusLegend(targetId, false); -}; - -c3_chart_fn.revert = function (targetId) { - var $$ = this.internal, - candidates = $$.svg.selectAll($$.selectorTarget(targetId)), - candidatesForNoneArc = candidates.filter($$.isNoneArc.bind($$)), - candidatesForArc = candidates.filter($$.isArc.bind($$)); - function revert(targets) { - $$.filterTargetsToShow(targets).transition().duration(100).style('opacity', 1); - } - revert(candidatesForNoneArc.classed(CLASS[_focused], false)); - revert(candidatesForArc); - if ($$.hasArcType()) { - $$.unexpandArc(targetId); - } - $$.revertLegend(); -}; - -c3_chart_fn.show = function (targetIds, options) { - var $$ = this.internal; - - targetIds = $$.mapToTargetIds(targetIds); - options = options || {}; - - $$.removeHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) - .transition() - .style('opacity', 1); - - if (options.withLegend) { - $$.showLegend(targetIds); - } - - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); -}; - -c3_chart_fn.hide = function (targetIds, options) { - var $$ = this.internal; - - targetIds = $$.mapToTargetIds(targetIds); - options = options || {}; - - $$.addHiddenTargetIds(targetIds); - $$.svg.selectAll($$.selectorTargets(targetIds)) - .transition() - .style('opacity', 0); - - if (options.withLegend) { - $$.hideLegend(targetIds); - } - - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); -}; - -c3_chart_fn.toggle = function (targetId) { - var $$ = this.internal; - $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); -}; - -c3_chart_fn.zoom = function () { -}; -c3_chart_fn.zoom.enable = function (enabled) { - var $$ = this.internal; - $$.config[__zoom_enabled] = enabled; - $$.updateAndRedraw(); -}; -c3_chart_fn.unzoom = function () { - var $$ = this.internal; - $$.brush.clear().update(); - $$.redraw({withUpdateXDomain: true}); -}; - -c3_chart_fn.load = function (args) { - var $$ = this.internal, config = $$.config; - // update xs if specified - if (args.xs) { - $$.addXs(args.xs); - } - // update classes if exists - if ('classes' in args) { - Object.keys(args.classes).forEach(function (id) { - config[__data_classes][id] = args.classes[id]; - }); - } - // update categories if exists - if ('categories' in args && $$.isCategorized()) { - config[__axis_x_categories] = args.categories; - } - // use cache if exists - if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { - $$.load($$.getCaches(args.cacheIds), args.done); - return; - } - // unload if needed - if ('unload' in args) { - // TODO: do not unload if target will load (included in url/rows/columns) - $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { - $$.loadFromArgs(args); - }); - } else { - $$.loadFromArgs(args); - } -}; - -c3_chart_fn.unload = function (args) { - var $$ = this.internal; - args = args || {}; - $$.unload($$.mapToTargetIds(args.ids), function () { - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); - if (args.done) { args.done(); } - }); -}; - -c3_chart_fn.flow = function (args) { - var $$ = this.internal, - targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), - dataCount, domain, baseTarget, baseValue, length = 0, tail = 0, diff, to; - - if (args.json) { - data = $$.convertJsonToData(args.json, args.keys); - } - else if (args.rows) { - data = $$.convertRowsToData(args.rows); - } - else if (args.columns) { - data = $$.convertColumnsToData(args.columns); - } - else { - return; - } - targets = $$.convertDataToTargets(data, true); - - // Update/Add data - $$.data.targets.forEach(function (t) { - var found = false, i, j; - for (i = 0; i < targets.length; i++) { - if (t.id === targets[i].id) { - found = true; - - if (t.values[t.values.length - 1]) { - tail = t.values[t.values.length - 1].index + 1; - } - length = targets[i].values.length; - - for (j = 0; j < length; j++) { - targets[i].values[j].index = tail + j; - if (!$$.isTimeSeries()) { - targets[i].values[j].x = tail + j; - } - } - t.values = t.values.concat(targets[i].values); - - targets.splice(i, 1); - break; - } - } - if (!found) { notfoundIds.push(t.id); } - }); - - // Append null for not found targets - $$.data.targets.forEach(function (t) { - var i, j; - for (i = 0; i < notfoundIds.length; i++) { - if (t.id === notfoundIds[i]) { - tail = t.values[t.values.length - 1].index + 1; - for (j = 0; j < length; j++) { - t.values.push({ - id: t.id, - index: tail + j, - x: $$.isTimeSeries() ? $$.getOtherTargetX(tail + j) : tail + j, - value: null - }); - } - } - } - }); - - // Generate null values for new target - if ($$.data.targets.length) { - targets.forEach(function (t) { - var i, missing = []; - for (i = $$.data.targets[0].values[0].index; i < tail; i++) { - missing.push({ - id: t.id, - index: i, - x: $$.isTimeSeries() ? $$.getOtherTargetX(i) : i, - value: null - }); - } - t.values.forEach(function (v) { - v.index += tail; - if (!$$.isTimeSeries()) { - v.x += tail; - } - }); - t.values = missing.concat(t.values); - }); - } - $$.data.targets = $$.data.targets.concat(targets); // add remained - - // check data count because behavior needs to change when it's only one - dataCount = $$.getMaxDataCount(); - baseTarget = $$.data.targets[0]; - baseValue = baseTarget.values[0]; - - // Update length to flow if needed - if (isDefined(args.to)) { - length = 0; - to = $$.isTimeSeries() ? $$.parseDate(args.to) : args.to; - baseTarget.values.forEach(function (v) { - if (v.x < to) { length++; } - }); - } else if (isDefined(args.length)) { - length = args.length; - } - - // If only one data, update the domain to flow from left edge of the chart - if (!orgDataCount) { - if ($$.isTimeSeries()) { - if (baseTarget.values.length > 1) { - diff = baseTarget.values[baseTarget.values.length - 1].x - baseValue.x; - } else { - diff = baseValue.x - $$.getXDomain($$.data.targets)[0]; - } - } else { - diff = 1; - } - domain = [baseValue.x - diff, baseValue.x]; - $$.updateXDomain(null, true, true, domain); - } else if (orgDataCount === 1) { - if ($$.isTimeSeries()) { - diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2; - domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)]; - $$.updateXDomain(null, true, true, domain); - } - } - - // Set targets - $$.updateTargets($$.data.targets); - - // Redraw with new targets - $$.redraw({ - flow: { - index: baseValue.index, - length: length, - duration: isValue(args.duration) ? args.duration : $$.config[__transition_duration], - done: args.done, - orgDataCount: orgDataCount, - }, - withLegend: true, - withTransition: orgDataCount > 1, - }); -}; - -c3_chart_fn.selected = function (targetId) { - var $$ = this.internal, d3 = $$.d3; - return d3.merge( - $$.main.selectAll('.' + CLASS[_shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[_shape]) - .filter(function () { return d3.select(this).classed(CLASS[_SELECTED]); }) - .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) - ); -}; -c3_chart_fn.select = function (ids, indices, resetOther) { - var $$ = this.internal, d3 = $$.d3, config = $$.config; - if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, - isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[_SELECTED]); - // line/area selection not supported yet - if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { - return; - } - if (isTargetId && isTargetIndex) { - if (config[__data_selection_isselectable](d) && !isSelected) { - toggle(true, shape.classed(CLASS[_SELECTED], true), d, i); - } - } else if (isDefined(resetOther) && resetOther) { - if (isSelected) { - toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); - } - } - }); -}; -c3_chart_fn.unselect = function (ids, indices) { - var $$ = this.internal, d3 = $$.d3, config = $$.config; - if (! config[__data_selection_enabled]) { return; } - $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { - var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), - isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, - isTargetIndex = !indices || indices.indexOf(i) >= 0, - isSelected = shape.classed(CLASS[_SELECTED]); - // line/area selection not supported yet - if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { - return; - } - if (isTargetId && isTargetIndex) { - if (config[__data_selection_isselectable](d)) { - if (isSelected) { - toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); - } - } - } - }); -}; - -c3_chart_fn.transform = function (type, targetIds) { - var $$ = this.internal, - options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; - $$.transformTo(targetIds, type, options); -}; - -c3_chart_fn.groups = function (groups) { - var $$ = this.internal, config = $$.config; - if (isUndefined(groups)) { return config[__data_groups]; } - config[__data_groups] = groups; - $$.redraw(); - return config[__data_groups]; -}; - -c3_chart_fn.xgrids = function (grids) { - var $$ = this.internal, config = $$.config; - if (! grids) { return config[__grid_x_lines]; } - config[__grid_x_lines] = grids; - $$.redraw(); - return config[__grid_x_lines]; -}; -c3_chart_fn.xgrids.add = function (grids) { - var $$ = this.internal; - return this.xgrids($$.config[__grid_x_lines].concat(grids ? grids : [])); -}; -c3_chart_fn.xgrids.remove = function (params) { // TODO: multiple - var $$ = this.internal; - $$.removeGridLines(params, true); -}; - -c3_chart_fn.ygrids = function (grids) { - var $$ = this.internal, config = $$.config; - if (! grids) { return config[__grid_y_lines]; } - config[__grid_y_lines] = grids; - $$.redraw(); - return config[__grid_y_lines]; -}; -c3_chart_fn.ygrids.add = function (grids) { - var $$ = this.internal; - return this.ygrids($$.config[__grid_y_lines].concat(grids ? grids : [])); -}; -c3_chart_fn.ygrids.remove = function (params) { // TODO: multiple - var $$ = this.internal; - $$.removeGridLines(params, false); -}; - -c3_chart_fn.regions = function (regions) { - var $$ = this.internal, config = $$.config; - if (!regions) { return config[__regions]; } - config[__regions] = regions; - $$.redraw(); - return config[__regions]; -}; -c3_chart_fn.regions.add = function (regions) { - var $$ = this.internal, config = $$.config; - if (!regions) { return config[__regions]; } - config[__regions] = config[__regions].concat(regions); - $$.redraw(); - return config[__regions]; -}; -c3_chart_fn.regions.remove = function (options) { - var $$ = this.internal, config = $$.config, - duration, classes, regions; - - options = options || {}; - duration = $$.getOption(options, "duration", config[__transition_duration]); - classes = $$.getOption(options, "classes", [CLASS[_region]]); - - regions = $$.main.select('.' + CLASS[_regions]).selectAll(classes.map(function (c) { return '.' + c; })); - (duration ? regions.transition().duration(duration) : regions) - .style('opacity', 0) - .remove(); - - config[__regions] = config[__regions].filter(function (region) { - var found = false; - if (!region.class) { - return true; - } - region.class.split(' ').forEach(function (c) { - if (classes.indexOf(c) >= 0) { found = true; } - }); - return !found; - }); - - return config[__regions]; -}; - -c3_chart_fn.data = function () {}; -c3_chart_fn.data.get = function (targetId) { - var target = this.data.getAsTarget(targetId); - return isDefined(target) ? target.values.map(function (d) { return d.value; }) : undefined; -}; -c3_chart_fn.data.getAsTarget = function (targetId) { - var targets = this.data.targets.filter(function (t) { return t.id === targetId; }); - return targets.length > 0 ? targets[0] : undefined; -}; -c3_chart_fn.data.names = function (names) { - var $$ = this.internal, config = $$.config; - if (!arguments.length) { return config[__data_names]; } - Object.keys(names).forEach(function (id) { - config[__data_names][id] = names[id]; - }); - $$.redraw({withLegend: true}); - return config[__data_names]; -}; -c3_chart_fn.data.colors = function (colors) { - var $$ = this.internal, config = $$.config; - if (!arguments.length) { return config[__data_colors]; } - Object.keys(colors).forEach(function (id) { - config[__data_colors][id] = colors[id]; - }); - $$.redraw({withLegend: true}); - return config[__data_colors]; -}; -c3_chart_fn.category = function (i, category) { - var $$ = this.internal, config = $$.config; - if (arguments.length > 1) { - config[__axis_x_categories][i] = category; - $$.redraw(); - } - return config[__axis_x_categories][i]; -}; -c3_chart_fn.categories = function (categories) { - var $$ = this.internal, config = $$.config; - if (!arguments.length) { return config[__axis_x_categories]; } - config[__axis_x_categories] = categories; - $$.redraw(); - return config[__axis_x_categories]; -}; - -// TODO: fix -c3_chart_fn.color = function (id) { - var $$ = this.internal; - return $$.color(id); // more patterns -}; - -c3_chart_fn.x = function (x) { - var $$ = this.internal; - if (arguments.length) { - $$.updateTargetX($$.data.targets, x); - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } - return $$.data.xs; -}; -c3_chart_fn.xs = function (xs) { - var $$ = this.internal; - if (arguments.length) { - $$.updateTargetXs($$.data.targets, xs); - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } - return $$.data.xs; -}; - - -c3_chart_fn.axis = function () {}; -c3_chart_fn.axis.labels = function (labels) { - var $$ = this.internal; - if (arguments.length) { - Object.keys(labels).forEach(function (axisId) { - $$.setAxisLabelText(axisId, labels[axisId]); - }); - $$.updateAxisLabels(); - } - // TODO: return some values? -}; -c3_chart_fn.axis.max = function (max) { - var $$ = this.internal, config = $$.config; - if (arguments.length) { - if (typeof max === 'object') { - if (isValue(max.x)) { config[__axis_x_max] = max.x; } - if (isValue(max.y)) { config[__axis_y_max] = max.y; } - if (isValue(max.y2)) { config[__axis_y2_max] = max.y2; } - } else { - config[__axis_y_max] = config[__axis_y2_max] = max; - } - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } -}; -c3_chart_fn.axis.min = function (min) { - var $$ = this.internal, config = $$.config; - if (arguments.length) { - if (typeof min === 'object') { - if (isValue(min.x)) { config[__axis_x_min] = min.x; } - if (isValue(min.y)) { config[__axis_y_min] = min.y; } - if (isValue(min.y2)) { config[__axis_y2_min] = min.y2; } - } else { - config[__axis_y_min] = config[__axis_y2_min] = min; - } - $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); - } -}; -c3_chart_fn.axis.range = function (range) { - if (arguments.length) { - if (isDefined(range.max)) { this.axis.max(range.max); } - if (isDefined(range.min)) { this.axis.min(range.min); } - } -}; - - -c3_chart_fn.legend = function () {}; -c3_chart_fn.legend.show = function (targetIds) { - var $$ = this.internal; - $$.showLegend($$.mapToTargetIds(targetIds)); - $$.updateAndRedraw({withLegend: true}); -}; -c3_chart_fn.legend.hide = function (targetIds) { - var $$ = this.internal; - $$.hideLegend($$.mapToTargetIds(targetIds)); - $$.updateAndRedraw({withLegend: true}); -}; - -c3_chart_fn.resize = function (size) { - var $$ = this.internal, config = $$.config; - config[__size_width] = size ? size.width : null; - config[__size_height] = size ? size.height : null; - this.flush(); -}; - -c3_chart_fn.flush = function () { - var $$ = this.internal; - $$.updateAndRedraw({withLegend: true, withTransition: false, withTransitionForTransform: false}); -}; - -c3_chart_fn.destroy = function () { - var $$ = this.internal; - $$.data.targets = undefined; - $$.data.xs = {}; - $$.selectChart.classed('c3', false).html(""); - window.onresize = null; -}; diff --git a/src/api.legend.js b/src/api.legend.js new file mode 100644 index 0000000..182caa1 --- /dev/null +++ b/src/api.legend.js @@ -0,0 +1,11 @@ +c3_chart_fn.legend = function () {}; +c3_chart_fn.legend.show = function (targetIds) { + var $$ = this.internal; + $$.showLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); +}; +c3_chart_fn.legend.hide = function (targetIds) { + var $$ = this.internal; + $$.hideLegend($$.mapToTargetIds(targetIds)); + $$.updateAndRedraw({withLegend: true}); +}; diff --git a/src/api.load.js b/src/api.load.js new file mode 100644 index 0000000..98d8dad --- /dev/null +++ b/src/api.load.js @@ -0,0 +1,40 @@ +c3_chart_fn.load = function (args) { + var $$ = this.internal, config = $$.config; + // update xs if specified + if (args.xs) { + $$.addXs(args.xs); + } + // update classes if exists + if ('classes' in args) { + Object.keys(args.classes).forEach(function (id) { + config[__data_classes][id] = args.classes[id]; + }); + } + // update categories if exists + if ('categories' in args && $$.isCategorized()) { + config[__axis_x_categories] = args.categories; + } + // use cache if exists + if ('cacheIds' in args && $$.hasCaches(args.cacheIds)) { + $$.load($$.getCaches(args.cacheIds), args.done); + return; + } + // unload if needed + if ('unload' in args) { + // TODO: do not unload if target will load (included in url/rows/columns) + $$.unload($$.mapToTargetIds((typeof args.unload === 'boolean' && args.unload) ? null : args.unload), function () { + $$.loadFromArgs(args); + }); + } else { + $$.loadFromArgs(args); + } +}; + +c3_chart_fn.unload = function (args) { + var $$ = this.internal; + args = args || {}; + $$.unload($$.mapToTargetIds(args.ids), function () { + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); + if (args.done) { args.done(); } + }); +}; diff --git a/src/api.region.js b/src/api.region.js new file mode 100644 index 0000000..39b7219 --- /dev/null +++ b/src/api.region.js @@ -0,0 +1,40 @@ +c3_chart_fn.regions = function (regions) { + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = regions; + $$.redraw(); + return config[__regions]; +}; +c3_chart_fn.regions.add = function (regions) { + var $$ = this.internal, config = $$.config; + if (!regions) { return config[__regions]; } + config[__regions] = config[__regions].concat(regions); + $$.redraw(); + return config[__regions]; +}; +c3_chart_fn.regions.remove = function (options) { + var $$ = this.internal, config = $$.config, + duration, classes, regions; + + options = options || {}; + duration = $$.getOption(options, "duration", config[__transition_duration]); + classes = $$.getOption(options, "classes", [CLASS[_region]]); + + regions = $$.main.select('.' + CLASS[_regions]).selectAll(classes.map(function (c) { return '.' + c; })); + (duration ? regions.transition().duration(duration) : regions) + .style('opacity', 0) + .remove(); + + config[__regions] = config[__regions].filter(function (region) { + var found = false; + if (!region.class) { + return true; + } + region.class.split(' ').forEach(function (c) { + if (classes.indexOf(c) >= 0) { found = true; } + }); + return !found; + }); + + return config[__regions]; +}; diff --git a/src/api.selection.js b/src/api.selection.js new file mode 100644 index 0000000..e647116 --- /dev/null +++ b/src/api.selection.js @@ -0,0 +1,52 @@ +c3_chart_fn.selected = function (targetId) { + var $$ = this.internal, d3 = $$.d3; + return d3.merge( + $$.main.selectAll('.' + CLASS[_shapes] + $$.getTargetSelectorSuffix(targetId)).selectAll('.' + CLASS[_shape]) + .filter(function () { return d3.select(this).classed(CLASS[_SELECTED]); }) + .map(function (d) { return d.map(function (d) { var data = d.__data__; return data.data ? data.data : data; }); }) + ); +}; +c3_chart_fn.select = function (ids, indices, resetOther) { + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS[_SELECTED]); + // line/area selection not supported yet + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { + return; + } + if (isTargetId && isTargetIndex) { + if (config[__data_selection_isselectable](d) && !isSelected) { + toggle(true, shape.classed(CLASS[_SELECTED], true), d, i); + } + } else if (isDefined(resetOther) && resetOther) { + if (isSelected) { + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); + } + } + }); +}; +c3_chart_fn.unselect = function (ids, indices) { + var $$ = this.internal, d3 = $$.d3, config = $$.config; + if (! config[__data_selection_enabled]) { return; } + $$.main.selectAll('.' + CLASS[_shapes]).selectAll('.' + CLASS[_shape]).each(function (d, i) { + var shape = d3.select(this), id = d.data ? d.data.id : d.id, toggle = $$.getToggle(this), + isTargetId = config[__data_selection_grouped] || !ids || ids.indexOf(id) >= 0, + isTargetIndex = !indices || indices.indexOf(i) >= 0, + isSelected = shape.classed(CLASS[_SELECTED]); + // line/area selection not supported yet + if (shape.classed(CLASS[_line]) || shape.classed(CLASS[_area])) { + return; + } + if (isTargetId && isTargetIndex) { + if (config[__data_selection_isselectable](d)) { + if (isSelected) { + toggle(false, shape.classed(CLASS[_SELECTED], false), d, i); + } + } + } + }); +}; diff --git a/src/api.show.js b/src/api.show.js new file mode 100644 index 0000000..5aca923 --- /dev/null +++ b/src/api.show.js @@ -0,0 +1,40 @@ +c3_chart_fn.show = function (targetIds, options) { + var $$ = this.internal; + + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; + + $$.removeHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 1); + + if (options.withLegend) { + $$.showLegend(targetIds); + } + + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); +}; + +c3_chart_fn.hide = function (targetIds, options) { + var $$ = this.internal; + + targetIds = $$.mapToTargetIds(targetIds); + options = options || {}; + + $$.addHiddenTargetIds(targetIds); + $$.svg.selectAll($$.selectorTargets(targetIds)) + .transition() + .style('opacity', 0); + + if (options.withLegend) { + $$.hideLegend(targetIds); + } + + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); +}; + +c3_chart_fn.toggle = function (targetId) { + var $$ = this.internal; + $$.isTargetToShow(targetId) ? this.hide(targetId) : this.show(targetId); +}; diff --git a/src/api.transform.js b/src/api.transform.js new file mode 100644 index 0000000..6442c7c --- /dev/null +++ b/src/api.transform.js @@ -0,0 +1,5 @@ +c3_chart_fn.transform = function (type, targetIds) { + var $$ = this.internal, + options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; + $$.transformTo(targetIds, type, options); +}; diff --git a/src/api.x.js b/src/api.x.js new file mode 100644 index 0000000..93d25d4 --- /dev/null +++ b/src/api.x.js @@ -0,0 +1,16 @@ +c3_chart_fn.x = function (x) { + var $$ = this.internal; + if (arguments.length) { + $$.updateTargetX($$.data.targets, x); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; +}; +c3_chart_fn.xs = function (xs) { + var $$ = this.internal; + if (arguments.length) { + $$.updateTargetXs($$.data.targets, xs); + $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true}); + } + return $$.data.xs; +}; diff --git a/src/api.zoom.js b/src/api.zoom.js new file mode 100644 index 0000000..12e1a5c --- /dev/null +++ b/src/api.zoom.js @@ -0,0 +1,12 @@ +c3_chart_fn.zoom = function () { +}; +c3_chart_fn.zoom.enable = function (enabled) { + var $$ = this.internal; + $$.config[__zoom_enabled] = enabled; + $$.updateAndRedraw(); +}; +c3_chart_fn.unzoom = function () { + var $$ = this.internal; + $$.brush.clear().update(); + $$.redraw({withUpdateXDomain: true}); +}; From a6ab889abf1c85bc5d394dbd4485208e8a36298f Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 17 Aug 2014 21:05:57 +0900 Subject: [PATCH 42/44] Modularize api.flow --- c3.js | 280 +++++++++++++++++++++++++++--------------------- c3.min.js | 8 +- src/api.flow.js | 140 ++++++++++++++++++++++++ src/core.js | 140 +++--------------------- 4 files changed, 316 insertions(+), 252 deletions(-) diff --git a/c3.js b/c3.js index 9185332..2a1ea8f 100644 --- a/c3.js +++ b/c3.js @@ -407,7 +407,8 @@ var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; - var duration, durationForExit, durationForAxis, waitForDraw; + var duration, durationForExit, durationForAxis; + var waitForDraw, flow; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; var xv = $$.xv.bind($$), cx = ($$.config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), @@ -568,131 +569,22 @@ transitions.forEach(function (t) { waitForDraw.add(t); }); + flow = $$.generateFlow({ + targets: targetsToShow, + flow: options.flow, + duration: duration, + drawBar: drawBar, + drawLine: drawLine, + drawArea: drawArea, + cx: cx, + cy: cy, + xv: xv, + xForText: xForText, + yForText: yForText + }); } }) - .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow - var translateX, scaleX = 1, transform, - flowIndex = options.flow.index, - flowLength = options.flow.length, - flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), - orgDomain = $$.x.domain(), domain, - durationForFlow = options.flow.duration || duration, - done = options.flow.done || function () {}, - wait = $$.generateWait(); - - var xgrid = $$.xgrid || d3.selectAll([]), - xgridLines = $$.xgridLines || d3.selectAll([]), - mainRegion = $$.mainRegion || d3.selectAll([]), - mainText = $$.mainText || d3.selectAll([]), - mainBar = $$.mainBar || d3.selectAll([]), - mainLine = $$.mainLine || d3.selectAll([]), - mainArea = $$.mainArea || d3.selectAll([]), - mainCircle = $$.mainCircle || d3.selectAll([]); - - // remove head data after rendered - $$.data.targets.forEach(function (d) { - d.values.splice(0, flowLength); - }); - - // update x domain to generate axis elements for flow - domain = $$.updateXDomain(targetsToShow, true, true); - // update elements related to x scale - if ($$.updateXGrid) { $$.updateXGrid(true); } - - // generate transform to flow - if (!options.flow.orgDataCount) { // if empty - if ($$.data.targets[0].values.length !== 1) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); - } else { - if ($$.isTimeSeries()) { - flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); - translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); - } else { - translateX = diffDomain(domain) / 2; - } - } - } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); - } else { - if ($$.isTimeSeries()) { - translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); - } else { - translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); - } - } - scaleX = (diffDomain(orgDomain) / diffDomain(domain)); - transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; - - d3.transition().ease('linear').duration(durationForFlow).each(function () { - wait.add($$.axes.x.transition().call($$.xAxis)); - wait.add(mainBar.transition().attr('transform', transform)); - wait.add(mainLine.transition().attr('transform', transform)); - wait.add(mainArea.transition().attr('transform', transform)); - wait.add(mainCircle.transition().attr('transform', transform)); - wait.add(mainText.transition().attr('transform', transform)); - wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); - wait.add(xgrid.transition().attr('transform', transform)); - wait.add(xgridLines.transition().attr('transform', transform)); - }) - .call(wait, function () { - var i, shapes = [], texts = [], eventRects = []; - - // remove flowed elements - if (flowLength) { - for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); - texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); - } - $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS[_xgrid]).remove(); - } - - // draw again for removing flowed elements and reverting attr - xgrid - .attr('transform', null) - .attr($$.xgridAttr); - xgridLines - .attr('transform', null); - xgridLines.select('line') - .attr("x1", config[__axis_rotated] ? 0 : xv) - .attr("x2", config[__axis_rotated] ? $$.width : xv); - xgridLines.select('text') - .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv); - mainBar - .attr('transform', null) - .attr("d", drawBar); - mainLine - .attr('transform', null) - .attr("d", drawLine); - mainArea - .attr('transform', null) - .attr("d", drawArea); - mainCircle - .attr('transform', null) - .attr("cx", cx) - .attr("cy", cy); - mainText - .attr('transform', null) - .attr('x', xForText) - .attr('y', yForText) - .style('fill-opacity', $$.opacityForText.bind($$)); - mainRegion - .attr('transform', null); - mainRegion.select('rect').filter($$.isRegionOnX) - .attr("x", $$.regionX.bind($$)) - .attr("width", $$.regionWidth.bind($$)); - $$.updateEventRect(); - - // callback for end of flow - done(); - }); - }); + .call(waitForDraw || function () {}, flow || function () {}); // update fadein condition $$.mapToIds($$.data.targets).forEach(function (id) { @@ -5820,6 +5712,146 @@ }); }; + c3_chart_internal_fn.generateFlow = function (args) { + var $$ = this, config = $$.config, d3 = $$.d3, CLASS = $$.CLASS; + + return function () { + var targets = args.targets, + flow = args.flow, + drawBar = args.drawBar, + drawLine = args.drawLine, + drawArea = args.drawArea, + cx = args.cx, + cy = args.cy, + xv = args.xv, + xForText = args.xForText, + yForText = args.yForText, + duration = args.duration; + + var translateX, scaleX = 1, transform, + flowIndex = flow.index, + flowLength = flow.length, + flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), + orgDomain = $$.x.domain(), domain, + durationForFlow = flow.duration || duration, + done = flow.done || function () {}, + wait = $$.generateWait(); + + var xgrid = $$.xgrid || d3.selectAll([]), + xgridLines = $$.xgridLines || d3.selectAll([]), + mainRegion = $$.mainRegion || d3.selectAll([]), + mainText = $$.mainText || d3.selectAll([]), + mainBar = $$.mainBar || d3.selectAll([]), + mainLine = $$.mainLine || d3.selectAll([]), + mainArea = $$.mainArea || d3.selectAll([]), + mainCircle = $$.mainCircle || d3.selectAll([]); + + // remove head data after rendered + $$.data.targets.forEach(function (d) { + d.values.splice(0, flowLength); + }); + + // update x domain to generate axis elements for flow + domain = $$.updateXDomain(targets, true, true); + // update elements related to x scale + if ($$.updateXGrid) { $$.updateXGrid(true); } + + // generate transform to flow + if (!flow.orgDataCount) { // if empty + if ($$.data.targets[0].values.length !== 1) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); + } else { + translateX = diffDomain(domain) / 2; + } + } + } else if (flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); + } else { + translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); + } + } + scaleX = (diffDomain(orgDomain) / diffDomain(domain)); + transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; + + d3.transition().ease('linear').duration(durationForFlow).each(function () { + wait.add($$.axes.x.transition().call($$.xAxis)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); + }) + .call(wait, function () { + var i, shapes = [], texts = [], eventRects = []; + + // remove flowed elements + if (flowLength) { + for (i = 0; i < flowLength; i++) { + shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); + } + $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[_xgrid]).remove(); + } + + // draw again for removing flowed elements and reverting attr + xgrid + .attr('transform', null) + .attr($$.xgridAttr); + xgridLines + .attr('transform', null); + xgridLines.select('line') + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv); + xgridLines.select('text') + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv); + mainBar + .attr('transform', null) + .attr("d", drawBar); + mainLine + .attr('transform', null) + .attr("d", drawLine); + mainArea + .attr('transform', null) + .attr("d", drawArea); + mainCircle + .attr('transform', null) + .attr("cx", cx) + .attr("cy", cy); + mainText + .attr('transform', null) + .attr('x', xForText) + .attr('y', yForText) + .style('fill-opacity', $$.opacityForText.bind($$)); + mainRegion + .attr('transform', null); + mainRegion.select('rect').filter($$.isRegionOnX) + .attr("x", $$.regionX.bind($$)) + .attr("width", $$.regionWidth.bind($$)); + $$.updateEventRect(); + + // callback for end of flow + done(); + }); + }; + }; + c3_chart_fn.selected = function (targetId) { var $$ = this.internal, d3 = $$.d3; return d3.merge( diff --git a/c3.min.js b/c3.min.js index a0e9877..7d857ac 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&B.select(this).style("display",b%y?"none":"block")})}else z.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!C[vb]&&C[Hb]&&z.rotateTickText(z.axes.x,b.axisX,C[Hb]),l=z.generateDrawArea?z.generateDrawArea(D,!1):void 0,m=z.generateDrawBar?z.generateDrawBar(E):void 0,n=z.generateDrawLine?z.generateDrawLine(F,!1):void 0,o=z.generateXYForText(E,!0),p=z.generateXYForText(E,!1),z.subY.domain(z.y.domain()),z.subY2.domain(z.y2.domain()),z.tooltip.style("display","none"),z.updateXgridFocus(),A.select("text."+pe[Nd]+"."+pe[Md]).attr("x",z.width/2).attr("y",z.height/2).text(C[fb]).transition().style("opacity",H.length?0:1),z.redrawGrid(q,c),z.redrawRegion(q),z.redrawBar(r),z.redrawLine(r),z.redrawArea(r),C[mc]&&z.redrawCircle(),z.hasDataLabel()&&z.redrawText(r),z.redrawArc&&z.redrawArc(q,r,h),z.redrawSubchart&&z.redrawSubchart(d,b,q,r,D,E,F),A.selectAll("."+pe[od]).filter(z.isBarType.bind(z)).selectAll("circle").remove(),C[s]&&z.redrawEventRect(),B.transition().duration(q).each(function(){var b=[];z.addTransitionForBar(b,m),z.addTransitionForLine(b,n),z.addTransitionForArea(b,l),z.addTransitionForCircle(b,J,K),z.addTransitionForText(b,o,p,a.flow),z.addTransitionForRegion(b),z.addTransitionForGrid(b),a.flow&&(u=z.generateWait(),b.forEach(function(a){u.add(a)}))}).call(u?u:function(){},function(){var b,c,d,e=1,f=a.flow.index,g=a.flow.length,h=z.getValueOnIndex(z.data.targets[0].values,f),i=z.getValueOnIndex(z.data.targets[0].values,f+g),j=z.x.domain(),k=a.flow.duration||q,r=a.flow.done||function(){},s=z.generateWait(),t=z.xgrid||B.selectAll([]),u=z.xgridLines||B.selectAll([]),v=z.mainRegion||B.selectAll([]),w=z.mainText||B.selectAll([]),x=z.mainBar||B.selectAll([]),y=z.mainLine||B.selectAll([]),A=z.mainArea||B.selectAll([]),D=z.mainCircle||B.selectAll([]);z.data.targets.forEach(function(a){a.values.splice(0,g)}),d=z.updateXDomain(H,!0,!0),z.updateXGrid&&z.updateXGrid(!0),a.flow.orgDataCount?b=1===a.flow.orgDataCount||h.x===i.x?z.x(j[0])-z.x(d[0]):z.isTimeSeries()?z.x(j[0])-z.x(d[0]):z.x(h.x)-z.x(i.x):1!==z.data.targets[0].values.length?b=z.x(j[0])-z.x(d[0]):z.isTimeSeries()?(h=z.getValueOnIndex(z.data.targets[0].values,0),i=z.getValueOnIndex(z.data.targets[0].values,z.data.targets[0].values.length-1),b=z.x(h.x)-z.x(i.x)):b=xe(d)/2,e=xe(j)/xe(d),c="translate("+b+",0) scale("+e+",1)",B.transition().ease("linear").duration(k).each(function(){s.add(z.axes.x.transition().call(z.xAxis)),s.add(x.transition().attr("transform",c)),s.add(y.transition().attr("transform",c)),s.add(A.transition().attr("transform",c)),s.add(D.transition().attr("transform",c)),s.add(w.transition().attr("transform",c)),s.add(v.filter(z.isRegionOnX).transition().attr("transform",c)),s.add(t.transition().attr("transform",c)),s.add(u.transition().attr("transform",c))}).call(s,function(){var a,b=[],c=[],d=[];if(g){for(a=0;g>a;a++)b.push("."+pe[Ad]+"-"+(f+a)),c.push("."+pe[Nd]+"-"+(f+a)),d.push("."+pe[pd]+"-"+(f+a));z.svg.selectAll("."+pe[Bd]).selectAll(b).remove(),z.svg.selectAll("."+pe[Od]).selectAll(c).remove(),z.svg.selectAll("."+pe[qd]).selectAll(d).remove(),z.svg.select("."+pe[Rd]).remove()}t.attr("transform",null).attr(z.xgridAttr),u.attr("transform",null),u.select("line").attr("x1",C[vb]?0:I).attr("x2",C[vb]?z.width:I),u.select("text").attr("x",C[vb]?z.width:0).attr("y",I),x.attr("transform",null).attr("d",m),y.attr("transform",null).attr("d",n),A.attr("transform",null).attr("d",l),D.attr("transform",null).attr("cx",J).attr("cy",K),w.attr("transform",null).attr("x",o).attr("y",p).style("fill-opacity",z.opacityForText.bind(z)),v.attr("transform",null),v.select("rect").filter(z.isRegionOnX).attr("x",z.regionX.bind(z)).attr("width",z.regionWidth.bind(z)),z.updateEventRect(),r()})}),z.mapToIds(z.data.targets).forEach(function(a){z.withoutFadeIn[a]=!0}),z.updateZoom&&z.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1); -return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid"))) -},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+="");return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",a.textAnchorForXAxisLabel.bind(a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForYAxisLabel.bind(a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForY2AxisLabel.bind(a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",b.xForXAxisLabel.bind(b)).attr("dx",b.dxForXAxisLabel.bind(b)).attr("dy",b.dyForXAxisLabel.bind(b)).text(b.textForXAxisLabel.bind(b)),(a?d.transition():d).attr("x",b.xForYAxisLabel.bind(b)).attr("dx",b.dxForYAxisLabel.bind(b)).attr("dy",b.dyForYAxisLabel.bind(b)).text(b.textForYAxisLabel.bind(b)),(a?e.transition():e).attr("x",b.xForY2AxisLabel.bind(b)).attr("dx",b.dxForY2AxisLabel.bind(b)).attr("dy",b.dyForY2AxisLabel.bind(b)).text(b.textForY2AxisLabel.bind(b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main,f=d.classChartArc.bind(d),g=d.classArcs.bind(d);b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",f),c=b.enter().append("g").attr("class",f),c.append("g").attr("class",g),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(e.arcData.bind(e)),d.enter().append("path").attr("class",e.classArc.bind(e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(e.textForArcLabel.bind(e)).attr("transform",e.transformForArcLabel.bind(e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",b.classRegion.bind(b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this,c=b.regionX.bind(b),d=b.regionY.bind(b),e=b.regionWidth.bind(b),f=b.regionHeight.bind(b);a.push(b.mainRegion.selectAll("rect").transition().attr("x",c).attr("y",d).attr("width",e).attr("height",f).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=(e[vb]?d.circleY:d.circleX).bind(d),g=(e[vb]?d.circleX:d.circleY).bind(d),h=d.pointSelectR.bind(d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",h)},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config,i=f.classChartBar.bind(f),j=f.classBars.bind(f),k=f.classChartLine.bind(f),l=f.classLines.bind(f),m=f.classAreas.bind(f);h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",i),d=e.enter().append("g").style("opacity",0).attr("class",i),d.append("g").attr("class",j),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",k),b=c.enter().append("g").style("opacity",0).attr("class",k),b.append("g").attr("class",l),b.append("g").attr("class",m))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config,r=n.barData.bind(n),s=n.lineData.bind(n),t=n.classBar.bind(n),u=n.classLine.bind(n),v=n.classArea.bind(n),w=n.initialOpacity.bind(n);q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(r),j.enter().append("path").attr("class",t).style("stroke","none").style("fill",n.color),j.style("opacity",w).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(s),h.enter().append("path").attr("class",u).style("stroke",n.color),h.style("opacity",w).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(s),i.enter().append("path").attr("class",v).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0 -}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain())}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&C.select(this).style("display",b%z?"none":"block")})}else A.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!D[vb]&&D[Hb]&&A.rotateTickText(A.axes.x,b.axisX,D[Hb]),l=A.generateDrawArea?A.generateDrawArea(E,!1):void 0,m=A.generateDrawBar?A.generateDrawBar(F):void 0,n=A.generateDrawLine?A.generateDrawLine(G,!1):void 0,o=A.generateXYForText(F,!0),p=A.generateXYForText(F,!1),A.subY.domain(A.y.domain()),A.subY2.domain(A.y2.domain()),A.tooltip.style("display","none"),A.updateXgridFocus(),B.select("text."+pe[Nd]+"."+pe[Md]).attr("x",A.width/2).attr("y",A.height/2).text(D[fb]).transition().style("opacity",I.length?0:1),A.redrawGrid(q,c),A.redrawRegion(q),A.redrawBar(r),A.redrawLine(r),A.redrawArea(r),D[mc]&&A.redrawCircle(),A.hasDataLabel()&&A.redrawText(r),A.redrawArc&&A.redrawArc(q,r,h),A.redrawSubchart&&A.redrawSubchart(d,b,q,r,E,F,G),B.selectAll("."+pe[od]).filter(A.isBarType.bind(A)).selectAll("circle").remove(),D[s]&&A.redrawEventRect(),C.transition().duration(q).each(function(){var b=[];A.addTransitionForBar(b,m),A.addTransitionForLine(b,n),A.addTransitionForArea(b,l),A.addTransitionForCircle(b,K,L),A.addTransitionForText(b,o,p,a.flow),A.addTransitionForRegion(b),A.addTransitionForGrid(b),a.flow&&(u=A.generateWait(),b.forEach(function(a){u.add(a)}),v=A.generateFlow({targets:I,flow:a.flow,duration:q,drawBar:m,drawLine:n,drawArea:l,cx:K,cy:L,xv:J,xForText:o,yForText:p}))}).call(u||function(){},v||function(){}),A.mapToIds(A.data.targets).forEach(function(a){A.withoutFadeIn[a]=!0}),A.updateZoom&&A.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1);return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config; +return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid")))},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+=""); +return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",a.textAnchorForXAxisLabel.bind(a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForYAxisLabel.bind(a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForY2AxisLabel.bind(a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",b.xForXAxisLabel.bind(b)).attr("dx",b.dxForXAxisLabel.bind(b)).attr("dy",b.dyForXAxisLabel.bind(b)).text(b.textForXAxisLabel.bind(b)),(a?d.transition():d).attr("x",b.xForYAxisLabel.bind(b)).attr("dx",b.dxForYAxisLabel.bind(b)).attr("dy",b.dyForYAxisLabel.bind(b)).text(b.textForYAxisLabel.bind(b)),(a?e.transition():e).attr("x",b.xForY2AxisLabel.bind(b)).attr("dx",b.dxForY2AxisLabel.bind(b)).attr("dy",b.dyForY2AxisLabel.bind(b)).text(b.textForY2AxisLabel.bind(b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main,f=d.classChartArc.bind(d),g=d.classArcs.bind(d);b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",f),c=b.enter().append("g").attr("class",f),c.append("g").attr("class",g),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(e.arcData.bind(e)),d.enter().append("path").attr("class",e.classArc.bind(e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(e.textForArcLabel.bind(e)).attr("transform",e.transformForArcLabel.bind(e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",b.classRegion.bind(b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this,c=b.regionX.bind(b),d=b.regionY.bind(b),e=b.regionWidth.bind(b),f=b.regionHeight.bind(b);a.push(b.mainRegion.selectAll("rect").transition().attr("x",c).attr("y",d).attr("width",e).attr("height",f).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=(e[vb]?d.circleY:d.circleX).bind(d),g=(e[vb]?d.circleX:d.circleY).bind(d),h=d.pointSelectR.bind(d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",h)},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config,i=f.classChartBar.bind(f),j=f.classBars.bind(f),k=f.classChartLine.bind(f),l=f.classLines.bind(f),m=f.classAreas.bind(f);h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",i),d=e.enter().append("g").style("opacity",0).attr("class",i),d.append("g").attr("class",j),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",k),b=c.enter().append("g").style("opacity",0).attr("class",k),b.append("g").attr("class",l),b.append("g").attr("class",m))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config,r=n.barData.bind(n),s=n.lineData.bind(n),t=n.classBar.bind(n),u=n.classLine.bind(n),v=n.classArea.bind(n),w=n.initialOpacity.bind(n);q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(r),j.enter().append("path").attr("class",t).style("stroke","none").style("fill",n.color),j.style("opacity",w).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(s),h.enter().append("path").attr("class",u).style("stroke",n.color),h.style("opacity",w).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(s),i.enter().append("path").attr("class",v).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain()) +}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},f.generateFlow=function(a){var b=this,c=b.config,d=b.d3,e=b.CLASS;return function(){var f,g,h,i=a.targets,j=a.flow,k=a.drawBar,l=a.drawLine,m=a.drawArea,n=a.cx,o=a.cy,p=a.xv,q=a.xForText,r=a.yForText,s=a.duration,t=1,u=j.index,v=j.length,w=b.getValueOnIndex(b.data.targets[0].values,u),x=b.getValueOnIndex(b.data.targets[0].values,u+v),y=b.x.domain(),z=j.duration||s,A=j.done||function(){},B=b.generateWait(),C=b.xgrid||d.selectAll([]),D=b.xgridLines||d.selectAll([]),E=b.mainRegion||d.selectAll([]),F=b.mainText||d.selectAll([]),G=b.mainBar||d.selectAll([]),H=b.mainLine||d.selectAll([]),I=b.mainArea||d.selectAll([]),J=b.mainCircle||d.selectAll([]);b.data.targets.forEach(function(a){a.values.splice(0,v)}),h=b.updateXDomain(i,!0,!0),b.updateXGrid&&b.updateXGrid(!0),j.orgDataCount?f=1===j.orgDataCount||w.x===x.x?b.x(y[0])-b.x(h[0]):b.isTimeSeries()?b.x(y[0])-b.x(h[0]):b.x(w.x)-b.x(x.x):1!==b.data.targets[0].values.length?f=b.x(y[0])-b.x(h[0]):b.isTimeSeries()?(w=b.getValueOnIndex(b.data.targets[0].values,0),x=b.getValueOnIndex(b.data.targets[0].values,b.data.targets[0].values.length-1),f=b.x(w.x)-b.x(x.x)):f=xe(h)/2,t=xe(y)/xe(h),g="translate("+f+",0) scale("+t+",1)",d.transition().ease("linear").duration(z).each(function(){B.add(b.axes.x.transition().call(b.xAxis)),B.add(G.transition().attr("transform",g)),B.add(H.transition().attr("transform",g)),B.add(I.transition().attr("transform",g)),B.add(J.transition().attr("transform",g)),B.add(F.transition().attr("transform",g)),B.add(E.filter(b.isRegionOnX).transition().attr("transform",g)),B.add(C.transition().attr("transform",g)),B.add(D.transition().attr("transform",g))}).call(B,function(){var a,d=[],f=[],g=[];if(v){for(a=0;v>a;a++)d.push("."+e[Ad]+"-"+(u+a)),f.push("."+e[Nd]+"-"+(u+a)),g.push("."+e[pd]+"-"+(u+a));b.svg.selectAll("."+e[Bd]).selectAll(d).remove(),b.svg.selectAll("."+e[Od]).selectAll(f).remove(),b.svg.selectAll("."+e[qd]).selectAll(g).remove(),b.svg.select("."+e[Rd]).remove()}C.attr("transform",null).attr(b.xgridAttr),D.attr("transform",null),D.select("line").attr("x1",c[vb]?0:p).attr("x2",c[vb]?b.width:p),D.select("text").attr("x",c[vb]?b.width:0).attr("y",p),G.attr("transform",null).attr("d",k),H.attr("transform",null).attr("d",l),I.attr("transform",null).attr("d",m),J.attr("transform",null).attr("cx",n).attr("cy",o),F.attr("transform",null).attr("x",q).attr("y",r).style("fill-opacity",b.opacityForText.bind(b)),E.attr("transform",null),E.select("rect").filter(b.isRegionOnX).attr("x",b.regionX.bind(b)).attr("width",b.regionWidth.bind(b)),b.updateEventRect(),A()})}},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/api.flow.js b/src/api.flow.js index 0237ac2..3b0e3a2 100644 --- a/src/api.flow.js +++ b/src/api.flow.js @@ -138,3 +138,143 @@ c3_chart_fn.flow = function (args) { withTransition: orgDataCount > 1, }); }; + +c3_chart_internal_fn.generateFlow = function (args) { + var $$ = this, config = $$.config, d3 = $$.d3, CLASS = $$.CLASS; + + return function () { + var targets = args.targets, + flow = args.flow, + drawBar = args.drawBar, + drawLine = args.drawLine, + drawArea = args.drawArea, + cx = args.cx, + cy = args.cy, + xv = args.xv, + xForText = args.xForText, + yForText = args.yForText, + duration = args.duration; + + var translateX, scaleX = 1, transform, + flowIndex = flow.index, + flowLength = flow.length, + flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), + orgDomain = $$.x.domain(), domain, + durationForFlow = flow.duration || duration, + done = flow.done || function () {}, + wait = $$.generateWait(); + + var xgrid = $$.xgrid || d3.selectAll([]), + xgridLines = $$.xgridLines || d3.selectAll([]), + mainRegion = $$.mainRegion || d3.selectAll([]), + mainText = $$.mainText || d3.selectAll([]), + mainBar = $$.mainBar || d3.selectAll([]), + mainLine = $$.mainLine || d3.selectAll([]), + mainArea = $$.mainArea || d3.selectAll([]), + mainCircle = $$.mainCircle || d3.selectAll([]); + + // remove head data after rendered + $$.data.targets.forEach(function (d) { + d.values.splice(0, flowLength); + }); + + // update x domain to generate axis elements for flow + domain = $$.updateXDomain(targets, true, true); + // update elements related to x scale + if ($$.updateXGrid) { $$.updateXGrid(true); } + + // generate transform to flow + if (!flow.orgDataCount) { // if empty + if ($$.data.targets[0].values.length !== 1) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); + flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); + translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); + } else { + translateX = diffDomain(domain) / 2; + } + } + } else if (flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { + translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); + } else { + if ($$.isTimeSeries()) { + translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); + } else { + translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); + } + } + scaleX = (diffDomain(orgDomain) / diffDomain(domain)); + transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; + + d3.transition().ease('linear').duration(durationForFlow).each(function () { + wait.add($$.axes.x.transition().call($$.xAxis)); + wait.add(mainBar.transition().attr('transform', transform)); + wait.add(mainLine.transition().attr('transform', transform)); + wait.add(mainArea.transition().attr('transform', transform)); + wait.add(mainCircle.transition().attr('transform', transform)); + wait.add(mainText.transition().attr('transform', transform)); + wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); + wait.add(xgrid.transition().attr('transform', transform)); + wait.add(xgridLines.transition().attr('transform', transform)); + }) + .call(wait, function () { + var i, shapes = [], texts = [], eventRects = []; + + // remove flowed elements + if (flowLength) { + for (i = 0; i < flowLength; i++) { + shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); + texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); + eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); + } + $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); + $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); + $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); + $$.svg.select('.' + CLASS[_xgrid]).remove(); + } + + // draw again for removing flowed elements and reverting attr + xgrid + .attr('transform', null) + .attr($$.xgridAttr); + xgridLines + .attr('transform', null); + xgridLines.select('line') + .attr("x1", config[__axis_rotated] ? 0 : xv) + .attr("x2", config[__axis_rotated] ? $$.width : xv); + xgridLines.select('text') + .attr("x", config[__axis_rotated] ? $$.width : 0) + .attr("y", xv); + mainBar + .attr('transform', null) + .attr("d", drawBar); + mainLine + .attr('transform', null) + .attr("d", drawLine); + mainArea + .attr('transform', null) + .attr("d", drawArea); + mainCircle + .attr('transform', null) + .attr("cx", cx) + .attr("cy", cy); + mainText + .attr('transform', null) + .attr('x', xForText) + .attr('y', yForText) + .style('fill-opacity', $$.opacityForText.bind($$)); + mainRegion + .attr('transform', null); + mainRegion.select('rect').filter($$.isRegionOnX) + .attr("x", $$.regionX.bind($$)) + .attr("width", $$.regionWidth.bind($$)); + $$.updateEventRect(); + + // callback for end of flow + done(); + }); + }; +}; diff --git a/src/core.js b/src/core.js index fab64c7..9fc1efa 100644 --- a/src/core.js +++ b/src/core.js @@ -402,7 +402,8 @@ c3_chart_internal_fn.redraw = function (options, transitions) { var withY, withSubchart, withTransition, withTransitionForExit, withTransitionForAxis, withTransform, withUpdateXDomain, withUpdateOrgXDomain, withLegend; var hideAxis = $$.hasArcType(); var drawArea, drawBar, drawLine, xForText, yForText; - var duration, durationForExit, durationForAxis, waitForDraw; + var duration, durationForExit, durationForAxis; + var waitForDraw, flow; var targetsToShow = $$.filterTargetsToShow($$.data.targets), tickValues, i, intervalForCulling; var xv = $$.xv.bind($$), cx = ($$.config[__axis_rotated] ? $$.circleY : $$.circleX).bind($$), @@ -563,131 +564,22 @@ c3_chart_internal_fn.redraw = function (options, transitions) { transitions.forEach(function (t) { waitForDraw.add(t); }); + flow = $$.generateFlow({ + targets: targetsToShow, + flow: options.flow, + duration: duration, + drawBar: drawBar, + drawLine: drawLine, + drawArea: drawArea, + cx: cx, + cy: cy, + xv: xv, + xForText: xForText, + yForText: yForText + }); } }) - .call(waitForDraw ? waitForDraw : function () {}, function () { // only for flow - var translateX, scaleX = 1, transform, - flowIndex = options.flow.index, - flowLength = options.flow.length, - flowStart = $$.getValueOnIndex($$.data.targets[0].values, flowIndex), - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, flowIndex + flowLength), - orgDomain = $$.x.domain(), domain, - durationForFlow = options.flow.duration || duration, - done = options.flow.done || function () {}, - wait = $$.generateWait(); - - var xgrid = $$.xgrid || d3.selectAll([]), - xgridLines = $$.xgridLines || d3.selectAll([]), - mainRegion = $$.mainRegion || d3.selectAll([]), - mainText = $$.mainText || d3.selectAll([]), - mainBar = $$.mainBar || d3.selectAll([]), - mainLine = $$.mainLine || d3.selectAll([]), - mainArea = $$.mainArea || d3.selectAll([]), - mainCircle = $$.mainCircle || d3.selectAll([]); - - // remove head data after rendered - $$.data.targets.forEach(function (d) { - d.values.splice(0, flowLength); - }); - - // update x domain to generate axis elements for flow - domain = $$.updateXDomain(targetsToShow, true, true); - // update elements related to x scale - if ($$.updateXGrid) { $$.updateXGrid(true); } - - // generate transform to flow - if (!options.flow.orgDataCount) { // if empty - if ($$.data.targets[0].values.length !== 1) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); - } else { - if ($$.isTimeSeries()) { - flowStart = $$.getValueOnIndex($$.data.targets[0].values, 0); - flowEnd = $$.getValueOnIndex($$.data.targets[0].values, $$.data.targets[0].values.length - 1); - translateX = $$.x(flowStart.x) - $$.x(flowEnd.x); - } else { - translateX = diffDomain(domain) / 2; - } - } - } else if (options.flow.orgDataCount === 1 || flowStart.x === flowEnd.x) { - translateX = $$.x(orgDomain[0]) - $$.x(domain[0]); - } else { - if ($$.isTimeSeries()) { - translateX = ($$.x(orgDomain[0]) - $$.x(domain[0])); - } else { - translateX = ($$.x(flowStart.x) - $$.x(flowEnd.x)); - } - } - scaleX = (diffDomain(orgDomain) / diffDomain(domain)); - transform = 'translate(' + translateX + ',0) scale(' + scaleX + ',1)'; - - d3.transition().ease('linear').duration(durationForFlow).each(function () { - wait.add($$.axes.x.transition().call($$.xAxis)); - wait.add(mainBar.transition().attr('transform', transform)); - wait.add(mainLine.transition().attr('transform', transform)); - wait.add(mainArea.transition().attr('transform', transform)); - wait.add(mainCircle.transition().attr('transform', transform)); - wait.add(mainText.transition().attr('transform', transform)); - wait.add(mainRegion.filter($$.isRegionOnX).transition().attr('transform', transform)); - wait.add(xgrid.transition().attr('transform', transform)); - wait.add(xgridLines.transition().attr('transform', transform)); - }) - .call(wait, function () { - var i, shapes = [], texts = [], eventRects = []; - - // remove flowed elements - if (flowLength) { - for (i = 0; i < flowLength; i++) { - shapes.push('.' + CLASS[_shape] + '-' + (flowIndex + i)); - texts.push('.' + CLASS[_text] + '-' + (flowIndex + i)); - eventRects.push('.' + CLASS[_eventRect] + '-' + (flowIndex + i)); - } - $$.svg.selectAll('.' + CLASS[_shapes]).selectAll(shapes).remove(); - $$.svg.selectAll('.' + CLASS[_texts]).selectAll(texts).remove(); - $$.svg.selectAll('.' + CLASS[_eventRects]).selectAll(eventRects).remove(); - $$.svg.select('.' + CLASS[_xgrid]).remove(); - } - - // draw again for removing flowed elements and reverting attr - xgrid - .attr('transform', null) - .attr($$.xgridAttr); - xgridLines - .attr('transform', null); - xgridLines.select('line') - .attr("x1", config[__axis_rotated] ? 0 : xv) - .attr("x2", config[__axis_rotated] ? $$.width : xv); - xgridLines.select('text') - .attr("x", config[__axis_rotated] ? $$.width : 0) - .attr("y", xv); - mainBar - .attr('transform', null) - .attr("d", drawBar); - mainLine - .attr('transform', null) - .attr("d", drawLine); - mainArea - .attr('transform', null) - .attr("d", drawArea); - mainCircle - .attr('transform', null) - .attr("cx", cx) - .attr("cy", cy); - mainText - .attr('transform', null) - .attr('x', xForText) - .attr('y', yForText) - .style('fill-opacity', $$.opacityForText.bind($$)); - mainRegion - .attr('transform', null); - mainRegion.select('rect').filter($$.isRegionOnX) - .attr("x", $$.regionX.bind($$)) - .attr("width", $$.regionWidth.bind($$)); - $$.updateEventRect(); - - // callback for end of flow - done(); - }); - }); + .call(waitForDraw || function () {}, flow || function () {}); // update fadein condition $$.mapToIds($$.data.targets).forEach(function (id) { From 24e06dd40c7a8ed7132dec0d2aefbd622b6ef778 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Sun, 17 Aug 2014 21:20:25 +0900 Subject: [PATCH 43/44] Move transformTo to api.transform.js --- c3.js | 20 ++++++++++---------- c3.min.js | 6 +++--- src/api.transform.js | 10 ++++++++++ src/core.js | 10 ---------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/c3.js b/c3.js index 2a1ea8f..3ba3b0b 100644 --- a/c3.js +++ b/c3.js @@ -802,16 +802,6 @@ return callResizeFunctions; }; - c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { - var $$ = this, - withTransitionForAxis = !$$.hasArcType(), - options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; - options.withTransitionForTransform = false; - $$.transiting = false; - $$.setTargetType(targetIds, type); - $$.updateAndRedraw(options); - }; - c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition @@ -5911,6 +5901,16 @@ $$.transformTo(targetIds, type, options); }; + c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { + var $$ = this, + withTransitionForAxis = !$$.hasArcType(), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); + }; + c3_chart_fn.groups = function (groups) { var $$ = this.internal, config = $$.config; if (isUndefined(groups)) { return config[__data_groups]; } diff --git a/c3.min.js b/c3.min.js index 7d857ac..9e895d3 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&C.select(this).style("display",b%z?"none":"block")})}else A.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!D[vb]&&D[Hb]&&A.rotateTickText(A.axes.x,b.axisX,D[Hb]),l=A.generateDrawArea?A.generateDrawArea(E,!1):void 0,m=A.generateDrawBar?A.generateDrawBar(F):void 0,n=A.generateDrawLine?A.generateDrawLine(G,!1):void 0,o=A.generateXYForText(F,!0),p=A.generateXYForText(F,!1),A.subY.domain(A.y.domain()),A.subY2.domain(A.y2.domain()),A.tooltip.style("display","none"),A.updateXgridFocus(),B.select("text."+pe[Nd]+"."+pe[Md]).attr("x",A.width/2).attr("y",A.height/2).text(D[fb]).transition().style("opacity",I.length?0:1),A.redrawGrid(q,c),A.redrawRegion(q),A.redrawBar(r),A.redrawLine(r),A.redrawArea(r),D[mc]&&A.redrawCircle(),A.hasDataLabel()&&A.redrawText(r),A.redrawArc&&A.redrawArc(q,r,h),A.redrawSubchart&&A.redrawSubchart(d,b,q,r,E,F,G),B.selectAll("."+pe[od]).filter(A.isBarType.bind(A)).selectAll("circle").remove(),D[s]&&A.redrawEventRect(),C.transition().duration(q).each(function(){var b=[];A.addTransitionForBar(b,m),A.addTransitionForLine(b,n),A.addTransitionForArea(b,l),A.addTransitionForCircle(b,K,L),A.addTransitionForText(b,o,p,a.flow),A.addTransitionForRegion(b),A.addTransitionForGrid(b),a.flow&&(u=A.generateWait(),b.forEach(function(a){u.add(a)}),v=A.generateFlow({targets:I,flow:a.flow,duration:q,drawBar:m,drawLine:n,drawArea:l,cx:K,cy:L,xv:J,xForText:o,yForText:p}))}).call(u||function(){},v||function(){}),A.mapToIds(A.data.targets).forEach(function(a){A.withoutFadeIn[a]=!0}),A.updateZoom&&A.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1);return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config; -return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value)},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid")))},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+=""); +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&C.select(this).style("display",b%z?"none":"block")})}else A.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!D[vb]&&D[Hb]&&A.rotateTickText(A.axes.x,b.axisX,D[Hb]),l=A.generateDrawArea?A.generateDrawArea(E,!1):void 0,m=A.generateDrawBar?A.generateDrawBar(F):void 0,n=A.generateDrawLine?A.generateDrawLine(G,!1):void 0,o=A.generateXYForText(F,!0),p=A.generateXYForText(F,!1),A.subY.domain(A.y.domain()),A.subY2.domain(A.y2.domain()),A.tooltip.style("display","none"),A.updateXgridFocus(),B.select("text."+pe[Nd]+"."+pe[Md]).attr("x",A.width/2).attr("y",A.height/2).text(D[fb]).transition().style("opacity",I.length?0:1),A.redrawGrid(q,c),A.redrawRegion(q),A.redrawBar(r),A.redrawLine(r),A.redrawArea(r),D[mc]&&A.redrawCircle(),A.hasDataLabel()&&A.redrawText(r),A.redrawArc&&A.redrawArc(q,r,h),A.redrawSubchart&&A.redrawSubchart(d,b,q,r,E,F,G),B.selectAll("."+pe[od]).filter(A.isBarType.bind(A)).selectAll("circle").remove(),D[s]&&A.redrawEventRect(),C.transition().duration(q).each(function(){var b=[];A.addTransitionForBar(b,m),A.addTransitionForLine(b,n),A.addTransitionForArea(b,l),A.addTransitionForCircle(b,K,L),A.addTransitionForText(b,o,p,a.flow),A.addTransitionForRegion(b),A.addTransitionForGrid(b),a.flow&&(u=A.generateWait(),b.forEach(function(a){u.add(a)}),v=A.generateFlow({targets:I,flow:a.flow,duration:q,drawBar:m,drawLine:n,drawArea:l,cx:K,cy:L,xv:J,xForText:o,yForText:p}))}).call(u||function(){},v||function(){}),A.mapToIds(A.data.targets).forEach(function(a){A.withoutFadeIn[a]=!0}),A.updateZoom&&A.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1);return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value) +},e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid")))},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+=""); return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",a.textAnchorForXAxisLabel.bind(a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForYAxisLabel.bind(a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForY2AxisLabel.bind(a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",b.xForXAxisLabel.bind(b)).attr("dx",b.dxForXAxisLabel.bind(b)).attr("dy",b.dyForXAxisLabel.bind(b)).text(b.textForXAxisLabel.bind(b)),(a?d.transition():d).attr("x",b.xForYAxisLabel.bind(b)).attr("dx",b.dxForYAxisLabel.bind(b)).attr("dy",b.dyForYAxisLabel.bind(b)).text(b.textForYAxisLabel.bind(b)),(a?e.transition():e).attr("x",b.xForY2AxisLabel.bind(b)).attr("dx",b.dxForY2AxisLabel.bind(b)).attr("dy",b.dyForY2AxisLabel.bind(b)).text(b.textForY2AxisLabel.bind(b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main,f=d.classChartArc.bind(d),g=d.classArcs.bind(d);b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",f),c=b.enter().append("g").attr("class",f),c.append("g").attr("class",g),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(e.arcData.bind(e)),d.enter().append("path").attr("class",e.classArc.bind(e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(e.textForArcLabel.bind(e)).attr("transform",e.transformForArcLabel.bind(e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",b.classRegion.bind(b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this,c=b.regionX.bind(b),d=b.regionY.bind(b),e=b.regionWidth.bind(b),f=b.regionHeight.bind(b);a.push(b.mainRegion.selectAll("rect").transition().attr("x",c).attr("y",d).attr("width",e).attr("height",f).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=(e[vb]?d.circleY:d.circleX).bind(d),g=(e[vb]?d.circleX:d.circleY).bind(d),h=d.pointSelectR.bind(d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",h)},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config,i=f.classChartBar.bind(f),j=f.classBars.bind(f),k=f.classChartLine.bind(f),l=f.classLines.bind(f),m=f.classAreas.bind(f);h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",i),d=e.enter().append("g").style("opacity",0).attr("class",i),d.append("g").attr("class",j),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",k),b=c.enter().append("g").style("opacity",0).attr("class",k),b.append("g").attr("class",l),b.append("g").attr("class",m))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config,r=n.barData.bind(n),s=n.lineData.bind(n),t=n.classBar.bind(n),u=n.classLine.bind(n),v=n.classArea.bind(n),w=n.initialOpacity.bind(n);q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(r),j.enter().append("path").attr("class",t).style("stroke","none").style("fill",n.color),j.style("opacity",w).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(s),h.enter().append("path").attr("class",u).style("stroke",n.color),h.style("opacity",w).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(s),i.enter().append("path").attr("class",v).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain()) -}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},f.generateFlow=function(a){var b=this,c=b.config,d=b.d3,e=b.CLASS;return function(){var f,g,h,i=a.targets,j=a.flow,k=a.drawBar,l=a.drawLine,m=a.drawArea,n=a.cx,o=a.cy,p=a.xv,q=a.xForText,r=a.yForText,s=a.duration,t=1,u=j.index,v=j.length,w=b.getValueOnIndex(b.data.targets[0].values,u),x=b.getValueOnIndex(b.data.targets[0].values,u+v),y=b.x.domain(),z=j.duration||s,A=j.done||function(){},B=b.generateWait(),C=b.xgrid||d.selectAll([]),D=b.xgridLines||d.selectAll([]),E=b.mainRegion||d.selectAll([]),F=b.mainText||d.selectAll([]),G=b.mainBar||d.selectAll([]),H=b.mainLine||d.selectAll([]),I=b.mainArea||d.selectAll([]),J=b.mainCircle||d.selectAll([]);b.data.targets.forEach(function(a){a.values.splice(0,v)}),h=b.updateXDomain(i,!0,!0),b.updateXGrid&&b.updateXGrid(!0),j.orgDataCount?f=1===j.orgDataCount||w.x===x.x?b.x(y[0])-b.x(h[0]):b.isTimeSeries()?b.x(y[0])-b.x(h[0]):b.x(w.x)-b.x(x.x):1!==b.data.targets[0].values.length?f=b.x(y[0])-b.x(h[0]):b.isTimeSeries()?(w=b.getValueOnIndex(b.data.targets[0].values,0),x=b.getValueOnIndex(b.data.targets[0].values,b.data.targets[0].values.length-1),f=b.x(w.x)-b.x(x.x)):f=xe(h)/2,t=xe(y)/xe(h),g="translate("+f+",0) scale("+t+",1)",d.transition().ease("linear").duration(z).each(function(){B.add(b.axes.x.transition().call(b.xAxis)),B.add(G.transition().attr("transform",g)),B.add(H.transition().attr("transform",g)),B.add(I.transition().attr("transform",g)),B.add(J.transition().attr("transform",g)),B.add(F.transition().attr("transform",g)),B.add(E.filter(b.isRegionOnX).transition().attr("transform",g)),B.add(C.transition().attr("transform",g)),B.add(D.transition().attr("transform",g))}).call(B,function(){var a,d=[],f=[],g=[];if(v){for(a=0;v>a;a++)d.push("."+e[Ad]+"-"+(u+a)),f.push("."+e[Nd]+"-"+(u+a)),g.push("."+e[pd]+"-"+(u+a));b.svg.selectAll("."+e[Bd]).selectAll(d).remove(),b.svg.selectAll("."+e[Od]).selectAll(f).remove(),b.svg.selectAll("."+e[qd]).selectAll(g).remove(),b.svg.select("."+e[Rd]).remove()}C.attr("transform",null).attr(b.xgridAttr),D.attr("transform",null),D.select("line").attr("x1",c[vb]?0:p).attr("x2",c[vb]?b.width:p),D.select("text").attr("x",c[vb]?b.width:0).attr("y",p),G.attr("transform",null).attr("d",k),H.attr("transform",null).attr("d",l),I.attr("transform",null).attr("d",m),J.attr("transform",null).attr("cx",n).attr("cy",o),F.attr("transform",null).attr("x",q).attr("y",r).style("fill-opacity",b.opacityForText.bind(b)),E.attr("transform",null),E.select("rect").filter(b.isRegionOnX).attr("x",b.regionX.bind(b)).attr("width",b.regionWidth.bind(b)),b.updateEventRect(),A()})}},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file +}},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},f.generateFlow=function(a){var b=this,c=b.config,d=b.d3,e=b.CLASS;return function(){var f,g,h,i=a.targets,j=a.flow,k=a.drawBar,l=a.drawLine,m=a.drawArea,n=a.cx,o=a.cy,p=a.xv,q=a.xForText,r=a.yForText,s=a.duration,t=1,u=j.index,v=j.length,w=b.getValueOnIndex(b.data.targets[0].values,u),x=b.getValueOnIndex(b.data.targets[0].values,u+v),y=b.x.domain(),z=j.duration||s,A=j.done||function(){},B=b.generateWait(),C=b.xgrid||d.selectAll([]),D=b.xgridLines||d.selectAll([]),E=b.mainRegion||d.selectAll([]),F=b.mainText||d.selectAll([]),G=b.mainBar||d.selectAll([]),H=b.mainLine||d.selectAll([]),I=b.mainArea||d.selectAll([]),J=b.mainCircle||d.selectAll([]);b.data.targets.forEach(function(a){a.values.splice(0,v)}),h=b.updateXDomain(i,!0,!0),b.updateXGrid&&b.updateXGrid(!0),j.orgDataCount?f=1===j.orgDataCount||w.x===x.x?b.x(y[0])-b.x(h[0]):b.isTimeSeries()?b.x(y[0])-b.x(h[0]):b.x(w.x)-b.x(x.x):1!==b.data.targets[0].values.length?f=b.x(y[0])-b.x(h[0]):b.isTimeSeries()?(w=b.getValueOnIndex(b.data.targets[0].values,0),x=b.getValueOnIndex(b.data.targets[0].values,b.data.targets[0].values.length-1),f=b.x(w.x)-b.x(x.x)):f=xe(h)/2,t=xe(y)/xe(h),g="translate("+f+",0) scale("+t+",1)",d.transition().ease("linear").duration(z).each(function(){B.add(b.axes.x.transition().call(b.xAxis)),B.add(G.transition().attr("transform",g)),B.add(H.transition().attr("transform",g)),B.add(I.transition().attr("transform",g)),B.add(J.transition().attr("transform",g)),B.add(F.transition().attr("transform",g)),B.add(E.filter(b.isRegionOnX).transition().attr("transform",g)),B.add(C.transition().attr("transform",g)),B.add(D.transition().attr("transform",g))}).call(B,function(){var a,d=[],f=[],g=[];if(v){for(a=0;v>a;a++)d.push("."+e[Ad]+"-"+(u+a)),f.push("."+e[Nd]+"-"+(u+a)),g.push("."+e[pd]+"-"+(u+a));b.svg.selectAll("."+e[Bd]).selectAll(d).remove(),b.svg.selectAll("."+e[Od]).selectAll(f).remove(),b.svg.selectAll("."+e[qd]).selectAll(g).remove(),b.svg.select("."+e[Rd]).remove()}C.attr("transform",null).attr(b.xgridAttr),D.attr("transform",null),D.select("line").attr("x1",c[vb]?0:p).attr("x2",c[vb]?b.width:p),D.select("text").attr("x",c[vb]?b.width:0).attr("y",p),G.attr("transform",null).attr("d",k),H.attr("transform",null).attr("d",l),I.attr("transform",null).attr("d",m),J.attr("transform",null).attr("cx",n).attr("cy",o),F.attr("transform",null).attr("x",q).attr("y",r).style("fill-opacity",b.opacityForText.bind(b)),E.attr("transform",null),E.select("rect").filter(b.isRegionOnX).attr("x",b.regionX.bind(b)).attr("width",b.regionWidth.bind(b)),b.updateEventRect(),A()})}},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/api.transform.js b/src/api.transform.js index 6442c7c..62cbe80 100644 --- a/src/api.transform.js +++ b/src/api.transform.js @@ -3,3 +3,13 @@ c3_chart_fn.transform = function (type, targetIds) { options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; $$.transformTo(targetIds, type, options); }; + +c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { + var $$ = this, + withTransitionForAxis = !$$.hasArcType(), + options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; + options.withTransitionForTransform = false; + $$.transiting = false; + $$.setTargetType(targetIds, type); + $$.updateAndRedraw(options); +}; diff --git a/src/core.js b/src/core.js index 9fc1efa..ced1725 100644 --- a/src/core.js +++ b/src/core.js @@ -797,16 +797,6 @@ c3_chart_internal_fn.generateResize = function () { return callResizeFunctions; }; -c3_chart_internal_fn.transformTo = function (targetIds, type, optionsForRedraw) { - var $$ = this, - withTransitionForAxis = !$$.hasArcType(), - options = optionsForRedraw || {withTransitionForAxis: withTransitionForAxis}; - options.withTransitionForTransform = false; - $$.transiting = false; - $$.setTargetType(targetIds, type); - $$.updateAndRedraw(options); -}; - c3_chart_internal_fn.endall = function (transition, callback) { var n = 0; transition From ae7bc0c48367b4a5880b0f2fbb7f4563147e94e1 Mon Sep 17 00:00:00 2001 From: Masayuki Tanaka Date: Tue, 19 Aug 2014 16:59:26 +0900 Subject: [PATCH 44/44] Fix updateSize --- c3.js | 59 ++++++++++++++++++++++++++++------------------------- c3.min.js | 2 +- src/core.js | 59 ++++++++++++++++++++++++++++------------------------- 3 files changed, 63 insertions(+), 57 deletions(-) diff --git a/c3.js b/c3.js index 3ba3b0b..7b5a1a3 100644 --- a/c3.js +++ b/c3.js @@ -323,36 +323,39 @@ $$.currentWidth = $$.getCurrentWidth(); $$.currentHeight = $$.getCurrentHeight(); - // for main, context - if (config[__axis_rotated]) { - $$.margin = { - top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) - }; - $$.margin2 = { - top: $$.margin.top, - right: NaN, - bottom: 20 + legendHeightForBottom, - left: $$.rotated_padding_left - }; - } else { - $$.margin = { - top: 4 + $$.getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: hasArc ? 0 : $$.getCurrentPaddingLeft() - }; - $$.margin2 = { - top: $$.currentHeight - subchartHeight - legendHeightForBottom, - right: NaN, - bottom: xAxisHeight + legendHeightForBottom, - left: $$.margin.left - }; - } + // 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; diff --git a/c3.min.js b/c3.min.js index 9e895d3..b9df0ff 100644 --- a/c3.min.js +++ b/c3.min.js @@ -1,4 +1,4 @@ -!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&C.select(this).style("display",b%z?"none":"block")})}else A.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!D[vb]&&D[Hb]&&A.rotateTickText(A.axes.x,b.axisX,D[Hb]),l=A.generateDrawArea?A.generateDrawArea(E,!1):void 0,m=A.generateDrawBar?A.generateDrawBar(F):void 0,n=A.generateDrawLine?A.generateDrawLine(G,!1):void 0,o=A.generateXYForText(F,!0),p=A.generateXYForText(F,!1),A.subY.domain(A.y.domain()),A.subY2.domain(A.y2.domain()),A.tooltip.style("display","none"),A.updateXgridFocus(),B.select("text."+pe[Nd]+"."+pe[Md]).attr("x",A.width/2).attr("y",A.height/2).text(D[fb]).transition().style("opacity",I.length?0:1),A.redrawGrid(q,c),A.redrawRegion(q),A.redrawBar(r),A.redrawLine(r),A.redrawArea(r),D[mc]&&A.redrawCircle(),A.hasDataLabel()&&A.redrawText(r),A.redrawArc&&A.redrawArc(q,r,h),A.redrawSubchart&&A.redrawSubchart(d,b,q,r,E,F,G),B.selectAll("."+pe[od]).filter(A.isBarType.bind(A)).selectAll("circle").remove(),D[s]&&A.redrawEventRect(),C.transition().duration(q).each(function(){var b=[];A.addTransitionForBar(b,m),A.addTransitionForLine(b,n),A.addTransitionForArea(b,l),A.addTransitionForCircle(b,K,L),A.addTransitionForText(b,o,p,a.flow),A.addTransitionForRegion(b),A.addTransitionForGrid(b),a.flow&&(u=A.generateWait(),b.forEach(function(a){u.add(a)}),v=A.generateFlow({targets:I,flow:a.flow,duration:q,drawBar:m,drawLine:n,drawArea:l,cx:K,cy:L,xv:J,xForText:o,yForText:p}))}).call(u||function(){},v||function(){}),A.mapToIds(A.data.targets).forEach(function(a){A.withoutFadeIn[a]=!0}),A.updateZoom&&A.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1);return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value) +!function(a){"use strict";function b(a){var b=this.internal=new c(this);b.loadConfig(a),b.init(),function d(a,b,c){for(var e in a)b[e]=a[e].bind(c),Object.keys(a[e]).length>0&&d(a[e],b[e],c)}(e,this,this)}function c(b){var c=this;c.d3=a.d3?a.d3:"undefined"!=typeof require?require("d3"):void 0,c.api=b,c.config=c.getDefaultConfig(),c.data={},c.cache={},c.axes={}}function d(a,b){function c(a,b){a.attr("transform",function(a){return"translate("+Math.ceil(b(a)+s)+", 0)"})}function d(a,b){a.attr("transform",function(a){return"translate(0,"+Math.ceil(b(a))+")"})}function e(a){var b=a[0],c=a[a.length-1];return c>b?[b,c]:[c,b]}function f(a){var b,c,d=[];if(a.ticks)return a.ticks.apply(a,k);for(c=a.domain(),b=Math.ceil(c[0]);b0&&d[0]>0&&d.unshift(d[0]-(d[1]-d[0])),d}function g(){var a,c=m.copy();return b&&(a=m.domain(),c.domain([a[0],a[1]-1])),c}function h(a){return j?j(a):a}function i(i){i.each(function(){function i(a){var b=m(a)+s;return B[0]=0&&C.select(this).style("display",b%z?"none":"block")})}else A.svg.selectAll("."+pe[_d]+" .tick text").style("display","block");!D[vb]&&D[Hb]&&A.rotateTickText(A.axes.x,b.axisX,D[Hb]),l=A.generateDrawArea?A.generateDrawArea(E,!1):void 0,m=A.generateDrawBar?A.generateDrawBar(F):void 0,n=A.generateDrawLine?A.generateDrawLine(G,!1):void 0,o=A.generateXYForText(F,!0),p=A.generateXYForText(F,!1),A.subY.domain(A.y.domain()),A.subY2.domain(A.y2.domain()),A.tooltip.style("display","none"),A.updateXgridFocus(),B.select("text."+pe[Nd]+"."+pe[Md]).attr("x",A.width/2).attr("y",A.height/2).text(D[fb]).transition().style("opacity",I.length?0:1),A.redrawGrid(q,c),A.redrawRegion(q),A.redrawBar(r),A.redrawLine(r),A.redrawArea(r),D[mc]&&A.redrawCircle(),A.hasDataLabel()&&A.redrawText(r),A.redrawArc&&A.redrawArc(q,r,h),A.redrawSubchart&&A.redrawSubchart(d,b,q,r,E,F,G),B.selectAll("."+pe[od]).filter(A.isBarType.bind(A)).selectAll("circle").remove(),D[s]&&A.redrawEventRect(),C.transition().duration(q).each(function(){var b=[];A.addTransitionForBar(b,m),A.addTransitionForLine(b,n),A.addTransitionForArea(b,l),A.addTransitionForCircle(b,K,L),A.addTransitionForText(b,o,p,a.flow),A.addTransitionForRegion(b),A.addTransitionForGrid(b),a.flow&&(u=A.generateWait(),b.forEach(function(a){u.add(a)}),v=A.generateFlow({targets:I,flow:a.flow,duration:q,drawBar:m,drawLine:n,drawArea:l,cx:K,cy:L,xv:J,xForText:o,yForText:p}))}).call(u||function(){},v||function(){}),A.mapToIds(A.data.targets).forEach(function(a){A.withoutFadeIn[a]=!0}),A.updateZoom&&A.updateZoom()},f.updateAndRedraw=function(a){var b,c=this,d=c.config;a=a||{},a.withTransition=Ae(a,"withTransition",!0),a.withTransform=Ae(a,"withTransform",!1),a.withLegend=Ae(a,"withLegend",!1),a.withUpdateXDomain=!0,a.withUpdateOrgXDomain=!0,a.withTransitionForExit=!1,a.withTransitionForTransform=Ae(a,"withTransitionForTransform",a.withTransition),c.updateSizes(),a.withLegend&&d[lb]||(b=c.generateAxisTransitions(a.withTransitionForAxis?d[x]:0),c.updateScales(),c.updateSvgSize(),c.transformAll(a.withTransitionForTransform,b)),c.redraw(a,b)},f.isTimeSeries=function(){return"timeseries"===this.config[xb]},f.isCategorized=function(){return this.config[xb].indexOf("categor")>=0},f.isCustomX=function(){var a=this,b=a.config;return!a.isTimeSeries()&&(b[y]||ze(b[z]))},f.getTranslate=function(a){var b,c,d=this,e=d.config;return"main"===a?(b=we(d.margin.left),c=we(d.margin.top)):"context"===a?(b=we(d.margin2.left),c=we(d.margin2.top)):"legend"===a?(b=d.margin3.left,c=d.margin3.top):"x"===a?(b=0,c=e[vb]?0:d.height):"y"===a?(b=0,c=e[vb]?d.height:0):"y2"===a?(b=e[vb]?0:d.width,c=e[vb]?1:0):"subx"===a?(b=0,c=e[vb]?0:d.height2):"arc"===a&&(b=d.arcWidth/2,c=d.arcHeight/2),"translate("+b+","+c+")"},f.initialOpacity=function(a){return null!==a.value&&this.withoutFadeIn[a.id]?1:0},f.opacityForCircle=function(a){var b=this;return qe(a.value)?b.isScatterType(a)?.5:1:0},f.opacityForText=function(){return this.hasDataLabel()?1:0},f.xx=function(a){return a?this.x(a.x):null},f.xv=function(a){var b=this;return Math.ceil(b.x(b.isTimeSeries()?b.parseDate(a.value):a.value))},f.yv=function(a){var b=this,c=a.axis&&"y2"===a.axis?b.y2:b.y;return Math.ceil(c(a.value))},f.subxx=function(a){return a?this.subX(a.x):null},f.transformMain=function(a,b){var c,d,e,f=this;b&&b.axisX?c=b.axisX:(c=f.main.select("."+pe[_d]),a&&(c=c.transition())),b&&b.axisY?d=b.axisY:(d=f.main.select("."+pe[be]),a&&(d=d.transition())),b&&b.axisY2?e=b.axisY2:(e=f.main.select("."+pe[de]),a&&(e=e.transition())),(a?f.main.transition():f.main).attr("transform",f.getTranslate("main")),c.attr("transform",f.getTranslate("x")),d.attr("transform",f.getTranslate("y")),e.attr("transform",f.getTranslate("y2")),f.main.select("."+pe[hd]).attr("transform",f.getTranslate("arc"))},f.transformAll=function(a,b){var c=this;c.transformMain(a,b),c.config[gb]&&c.transformContext(a,b),c.legend&&c.transformLegend(a)},f.updateSvgSize=function(){var a=this;a.svg.attr("width",a.currentWidth).attr("height",a.currentHeight),a.svg.select("#"+a.clipId).select("rect").attr("width",a.width).attr("height",a.height),a.svg.select("#"+a.clipIdForXAxis).select("rect").attr("x",a.getXAxisClipX.bind(a)).attr("y",a.getXAxisClipY.bind(a)).attr("width",a.getXAxisClipWidth.bind(a)).attr("height",a.getXAxisClipHeight.bind(a)),a.svg.select("#"+a.clipIdForYAxis).select("rect").attr("x",a.getYAxisClipX.bind(a)).attr("y",a.getYAxisClipY.bind(a)).attr("width",a.getYAxisClipWidth.bind(a)).attr("height",a.getYAxisClipHeight.bind(a)),a.svg.select("."+pe[td]).attr("width",a.width).attr("height",a.height),a.selectChart.style("max-height",a.currentHeight+"px")},f.updateDimension=function(){var a=this;a.config[vb]?(a.axes.x.call(a.xAxis),a.axes.subx.call(a.subXAxis)):(a.axes.y.call(a.yAxis),a.axes.y2.call(a.y2Axis)),a.updateSizes(),a.updateScales(),a.updateSvgSize(),a.transformAll(!1)},f.observeInserted=function(b){var c=this,d=new MutationObserver(function(e){e.forEach(function(e){if("childList"===e.type&&e.previousSibling){d.disconnect();var f=a.setInterval(function(){b.node().parentNode&&(a.clearInterval(f),c.updateDimension(),c.redraw({withTransform:!0,withUpdateXDomain:!0,withUpdateOrgXDomain:!0,withTransition:!1,withTransitionForTransform:!1,withLegend:!0}),b.transition().style("opacity",1))},10)}})});d.observe(b.node(),{attributes:!0,childList:!0,characterData:!0})},f.generateResize=function(){function a(){b.forEach(function(a){a()})}var b=[];return a.add=function(a){b.push(a)},a},f.endall=function(a,b){var c=0;a.each(function(){++c}).each("end",function(){--c||b.apply(this,arguments)})},f.generateWait=function(){var a=[],b=function(b,c){var d=setInterval(function(){var b=0;a.forEach(function(a){if(a.empty())return void(b+=1);try{a.transition()}catch(c){b+=1}}),b===a.length&&(clearInterval(d),c&&c())},10)};return b.add=function(b){a.push(b)},b},f.parseDate=function(b){var c,d=this;return c=b instanceof Date?b:"number"==typeof b?new Date(b):d.dataTimeFormat(d.config[A]).parse(b),(!c||isNaN(+c))&&a.console.error("Failed to parse x '"+b+"' to Date object"),c};var h="bindto",i="size_width",j="size_height",k="padding_left",l="padding_right",m="padding_top",n="padding_bottom",o="zoom_enabled",p="zoom_extent",q="zoom_privileged",r="zoom_onzoom",s="interaction_enabled",t="onmouseover",u="onmouseout",v="onresize",w="onresized",x="transition_duration",y="data_x",z="data_xs",A="data_xFormat",B="data_xLocaltime",C="data_idConverter",D="data_names",E="data_classes",F="data_groups",G="data_axes",H="data_type",I="data_types",J="data_labels",K="data_order",L="data_regions",M="data_color",N="data_colors",O="data_hide",P="data_filter",Q="data_selection_enabled",R="data_selection_grouped",S="data_selection_isselectable",T="data_selection_multiple",U="data_onclick",V="data_onmouseover",W="data_onmouseout",X="data_onselected",Y="data_onunselected",Z="data_ondragstart",$="data_ondragend",_="data_url",ab="data_json",bb="data_rows",cb="data_columns",db="data_mimeType",eb="data_keys",fb="data_empty_label_text",gb="subchart_show",hb="subchart_size_height",ib="subchart_onbrush",jb="color_pattern",kb="color_threshold",lb="legend_show",mb="legend_position",nb="legend_inset_anchor",ob="legend_inset_x",pb="legend_inset_y",qb="legend_inset_step",rb="legend_item_onclick",sb="legend_item_onmouseover",tb="legend_item_onmouseout",ub="legend_equally",vb="axis_rotated",wb="axis_x_show",xb="axis_x_type",yb="axis_x_localtime",zb="axis_x_categories",Ab="axis_x_tick_centered",Bb="axis_x_tick_format",Cb="axis_x_tick_culling",Db="axis_x_tick_culling_max",Eb="axis_x_tick_count",Fb="axis_x_tick_fit",Gb="axis_x_tick_values",Hb="axis_x_tick_rotate",Ib="axis_x_tick_outer",Jb="axis_x_max",Kb="axis_x_min",Lb="axis_x_padding",Mb="axis_x_height",Nb="axis_x_default",Ob="axis_x_label",Pb="axis_y_show",Qb="axis_y_max",Rb="axis_y_min",Sb="axis_y_center",Tb="axis_y_label",Ub="axis_y_tick_format",Vb="axis_y_tick_outer",Wb="axis_y_padding",Xb="axis_y_ticks",Yb="axis_y2_show",Zb="axis_y2_max",$b="axis_y2_min",_b="axis_y2_center",ac="axis_y2_label",bc="axis_y2_tick_format",cc="axis_y2_tick_outer",dc="axis_y2_padding",ec="axis_y2_ticks",fc="grid_x_show",gc="grid_x_type",hc="grid_x_lines",ic="grid_y_show",jc="grid_y_lines",kc="grid_y_ticks",lc="grid_focus_show",mc="point_show",nc="point_r",oc="point_focus_expand_enabled",pc="point_focus_expand_r",qc="point_select_r",rc="line_connect_null",sc="bar_width",tc="bar_width_ratio",uc="bar_width_max",vc="bar_zerobased",wc="area_zerobased",xc="pie_label_show",yc="pie_label_format",zc="pie_label_threshold",Ac="pie_sort",Bc="pie_expand",Cc="gauge_label_show",Dc="gauge_label_format",Ec="gauge_expand",Fc="gauge_min",Gc="gauge_max",Hc="gauge_units",Ic="gauge_width",Jc="donut_label_show",Kc="donut_label_format",Lc="donut_label_threshold",Mc="donut_width",Nc="donut_sort",Oc="donut_expand",Pc="donut_title",Qc="regions",Rc="tooltip_show",Sc="tooltip_grouped",Tc="tooltip_format_title",Uc="tooltip_format_name",Vc="tooltip_format_value",Wc="tooltip_contents",Xc="tooltip_init_show",Yc="tooltip_init_x",Zc="tooltip_init_position";f.getDefaultConfig=function(){var a={};return a[h]="#chart",a[i]=void 0,a[j]=void 0,a[k]=void 0,a[l]=void 0,a[m]=void 0,a[n]=void 0,a[o]=!1,a[p]=void 0,a[q]=!1,a[r]=function(){},a[s]=!0,a[t]=function(){},a[u]=function(){},a[v]=function(){},a[w]=function(){},a[x]=350,a[y]=void 0,a[z]={},a[A]="%Y-%m-%d",a[B]=!0,a[C]=function(a){return a},a[D]={},a[E]={},a[F]=[],a[G]={},a[H]=void 0,a[I]={},a[J]={},a[K]="desc",a[L]={},a[M]=void 0,a[N]={},a[O]=!1,a[P]=void 0,a[Q]=!1,a[R]=!1,a[S]=function(){return!0},a[T]=!0,a[U]=function(){},a[V]=function(){},a[W]=function(){},a[X]=function(){},a[Y]=function(){},a[Z]=function(){},a[$]=function(){},a[_]=void 0,a[ab]=void 0,a[bb]=void 0,a[cb]=void 0,a[db]=void 0,a[eb]=void 0,a[fb]="",a[gb]=!1,a[hb]=60,a[ib]=function(){},a[jb]=[],a[kb]={},a[lb]=!0,a[mb]="bottom",a[nb]="top-left",a[ob]=10,a[pb]=0,a[qb]=void 0,a[rb]=void 0,a[sb]=void 0,a[tb]=void 0,a[ub]=!1,a[vb]=!1,a[wb]=!0,a[xb]="indexed",a[yb]=!0,a[zb]=[],a[Ab]=!1,a[Bb]=void 0,a[Cb]={},a[Db]=10,a[Eb]=void 0,a[Fb]=!0,a[Gb]=null,a[Hb]=void 0,a[Ib]=!0,a[Jb]=null,a[Kb]=null,a[Lb]={},a[Mb]=void 0,a[Nb]=void 0,a[Ob]={},a[Pb]=!0,a[Qb]=void 0,a[Rb]=void 0,a[Sb]=void 0,a[Tb]={},a[Ub]=void 0,a[Vb]=!0,a[Wb]=void 0,a[Xb]=10,a[Yb]=!1,a[Zb]=void 0,a[$b]=void 0,a[_b]=void 0,a[ac]={},a[bc]=void 0,a[cc]=!0,a[dc]=void 0,a[ec]=10,a[fc]=!1,a[gc]="tick",a[hc]=[],a[ic]=!1,a[jc]=[],a[kc]=10,a[lc]=!0,a[mc]=!0,a[nc]=2.5,a[oc]=!0,a[pc]=void 0,a[qc]=void 0,a[rc]=!1,a[sc]=void 0,a[tc]=.6,a[uc]=void 0,a[vc]=!0,a[wc]=!0,a[xc]=!0,a[yc]=void 0,a[zc]=.05,a[Ac]=!0,a[Bc]=!0,a[Cc]=!0,a[Dc]=void 0,a[Ec]=!0,a[Fc]=0,a[Gc]=100,a[Hc]=void 0,a[Ic]=void 0,a[Jc]=!0,a[Kc]=void 0,a[Lc]=.05,a[Mc]=void 0,a[Nc]=!0,a[Oc]=!0,a[Pc]="",a[Qc]=[],a[Rc]=!0,a[Sc]=!0,a[Tc]=void 0,a[Uc]=void 0,a[Vc]=void 0,a[Wc]=function(a,b,c,d){return this.getTooltipContent?this.getTooltipContent(a,b,c,d):""},a[Xc]=!1,a[Yc]=0,a[Zc]={top:"0px",left:"50px"},Object.keys(this.additionalConfig).forEach(function(b){a[b]=this.additionalConfig[b]},this),a},f.additionalConfig={},f.loadConfig=function(a){function b(){var a=d.shift();return a&&c&&"object"==typeof c&&a in c?(c=c[a],b()):a?void 0:c}var c,d,e,f=this.config;Object.keys(f).forEach(function(g){c=a,d=g.split("_"),e=b(),ue(e)&&(f[g]=e)})},f.getScale=function(a,b,c){return(c?this.d3.time.scale():this.d3.scale.linear()).range([a,b])},f.getX=function(a,b,c,d){var e,f=this,g=f.getScale(a,b,f.isTimeSeries()),h=c?g.domain(c):g;f.isCategorized()?(d=d||function(){return 0},g=function(a,b){var c=h(a)+d(a);return b?c:Math.ceil(c)}):g=function(a,b){var c=h(a);return b?c:Math.ceil(c)};for(e in h)g[e]=h[e];return g.orgDomain=function(){return h.domain()},f.isCategorized()&&(g.domain=function(a){return arguments.length?(h.domain(a),g):(a=this.orgDomain(),[a[0],a[1]+1])}),g},f.getY=function(a,b,c){var d=this.getScale(a,b);return c&&d.domain(c),d},f.getYScale=function(a){return"y2"===this.getAxisId(a)?this.y2:this.y},f.getSubYScale=function(a){return"y2"===this.getAxisId(a)?this.subY2:this.subY},f.updateScales=function(){var a=this,b=a.config,c=!a.x;a.xMin=b[vb]?1:0,a.xMax=b[vb]?a.height:a.width,a.yMin=b[vb]?0:a.height,a.yMax=b[vb]?a.width:1,a.subXMin=a.xMin,a.subXMax=a.xMax,a.subYMin=b[vb]?0:a.height2,a.subYMax=b[vb]?a.width2:1,a.x=a.getX(a.xMin,a.xMax,c?void 0:a.x.orgDomain(),function(){return a.xAxis.tickOffset()}),a.y=a.getY(a.yMin,a.yMax,c?void 0:a.y.domain()),a.y2=a.getY(a.yMin,a.yMax,c?void 0:a.y2.domain()),a.subX=a.getX(a.xMin,a.xMax,a.orgXDomain,function(b){return b%1?0:a.subXAxis.tickOffset()}),a.subY=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY.domain()),a.subY2=a.getY(a.subYMin,a.subYMax,c?void 0:a.subY2.domain()),a.xAxisTickFormat=a.getXAxisTickFormat(),a.xAxisTickValues=b[Gb]?b[Gb]:c?void 0:a.xAxis.tickValues(),a.xAxis=a.getXAxis(a.x,a.xOrient,a.xAxisTickFormat,a.xAxisTickValues),a.subXAxis=a.getXAxis(a.subX,a.subXOrient,a.xAxisTickFormat,a.xAxisTickValues),a.yAxis=a.getYAxis(a.y,a.yOrient,b[Ub],b[Xb]),a.y2Axis=a.getYAxis(a.y2,a.y2Orient,b[bc],b[ec]),c||(a.brush&&a.brush.scale(a.subX),b[o]&&a.zoom.scale(a.x)),a.updateArc&&a.updateArc()},f.getYDomainMin=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasNegativeValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=0>a?a:0}),c=1;c0||(k[d][b]+=+a)});return h.d3.min(Object.keys(k).map(function(a){return h.d3.min(k[a])}))},f.getYDomainMax=function(a){var b,c,d,e,f,g,h=this,i=h.config,j=h.mapToIds(a),k=h.getValuesAsIdKeyed(a);if(i[F].length>0)for(g=h.hasPositiveValueInTargets(a),b=0;b=0}),0!==e.length)for(d=e[0],g&&k[d]&&k[d].forEach(function(a,b){k[d][b]=a>0?a:0}),c=1;c+a||(k[d][b]+=+a)});return h.d3.max(Object.keys(k).map(function(a){return h.d3.max(k[a])}))},f.getYDomain=function(a,b){var c,d,e,f,g,h,i,j,k,l,m=this,n=m.config,o=a.filter(function(a){return m.getAxisId(a.id)===b}),p="y2"===b?n[$b]:n[Rb],q="y2"===b?n[Zb]:n[Qb],r=qe(p)?p:m.getYDomainMin(o),s=qe(q)?q:m.getYDomainMax(o),t="y2"===b?n[_b]:n[Sb],u=m.hasType("bar",o)&&n[vc]||m.hasType("area",o)&&n[wc],v=m.hasDataLabel()&&n[vb],w=m.hasDataLabel()&&!n[vb];return 0===o.length?"y2"===b?m.y2.domain():m.y.domain():(r===s&&(0>r?s=0:r=0),k=r>=0&&s>=0,l=0>=r&&0>=s,u&&(k&&(r=0),l&&(s=0)),c=Math.abs(s-r),d=e=f=.1*c,t&&(g=Math.max(Math.abs(r),Math.abs(s)),s=g-t,r=t-g),v?(h=m.getDataLabelLength(r,s,b,"width"),i=xe(m.y.range()),j=[h[0]/i,h[1]/i],e+=c*(j[1]/(1-j[0]-j[1])),f+=c*(j[0]/(1-j[0]-j[1]))):w&&(h=m.getDataLabelLength(r,s,b,"height"),e+=h[1],f+=h[0]),"y"===b&&n[Wb]&&(e=m.getAxisPadding(n[Wb],"top",d,c),f=m.getAxisPadding(n[Wb],"bottom",d,c)),"y2"===b&&n[dc]&&(e=m.getAxisPadding(n[dc],"top",d,c),f=m.getAxisPadding(n[dc],"bottom",d,c)),u&&(k&&(f=r),l&&(e=-s)),[r-f,s+e])},f.getXDomainMin=function(a){var b=this,c=b.config;return c[Kb]?b.isTimeSeries()?this.parseDate(c[Kb]):c[Kb]:b.d3.min(a,function(a){return b.d3.min(a.values,function(a){return a.x})})},f.getXDomainMax=function(a){var b=this,c=b.config;return c[Jb]?b.isTimeSeries()?this.parseDate(c[Jb]):c[Jb]:b.d3.max(a,function(a){return b.d3.max(a.values,function(a){return a.x})})},f.getXDomainPadding=function(a){var b,c,d,e,f=this,g=f.config,h=this.getEdgeX(a),i=h[1]-h[0];return f.isCategorized()?c=0:f.hasType("bar",a)?(b=f.getMaxDataCount(),c=b>1?i/(b-1)/2:.5):c=.01*i,"object"==typeof g[Lb]&&ze(g[Lb])?(d=qe(g[Lb].left)?g[Lb].left:c,e=qe(g[Lb].right)?g[Lb].right:c):d=e="number"==typeof g[Lb]?g[Lb]:c,{left:d,right:e}},f.getXDomain=function(a){var b=this,c=[b.getXDomainMin(a),b.getXDomainMax(a)],d=c[0],e=c[1],f=b.getXDomainPadding(a),g=0,h=0;return d-e!==0||b.isCategorized()||(d=b.isTimeSeries()?new Date(.5*d.getTime()):-.5,e=b.isTimeSeries()?new Date(1.5*e.getTime()):.5),(d||0===d)&&(g=b.isTimeSeries()?new Date(d.getTime()-f.left):d-f.left),(e||0===e)&&(h=b.isTimeSeries()?new Date(e.getTime()+f.right):e+f.right),[g,h]},f.updateXDomain=function(a,b,c,d){var e=this,f=e.config;return c&&(e.x.domain(d?d:e.d3.extent(e.getXDomain(a))),e.orgXDomain=e.x.domain(),f[o]&&e.zoom.scale(e.x).updateScaleExtent(),e.subX.domain(e.x.domain()),e.brush&&e.brush.scale(e.subX)),b&&(e.x.domain(d?d:!e.brush||e.brush.empty()?e.orgXDomain:e.brush.extent()),f[o]&&e.zoom.scale(e.x).updateScaleExtent()),e.x.domain()},f.isX=function(a){var b=this,c=b.config;return c[y]&&a===c[y]||ze(c[z])&&Be(c[z],a)},f.isNotX=function(a){return!this.isX(a)},f.getXKey=function(a){var b=this,c=b.config;return c[y]?c[y]:ze(c[z])?c[z][a]:null},f.getXValuesOfXKey=function(a,b){var c,d=this,e=b&&ze(b)?d.mapToIds(b):[];return e.forEach(function(b){d.getXKey(b)===a&&(c=d.data.xs[b])}),c},f.getXValue=function(a,b){var c=this;return a in c.data.xs&&c.data.xs[a]&&qe(c.data.xs[a][b])?c.data.xs[a][b]:b},f.getOtherTargetXs=function(){var a=this,b=Object.keys(a.data.xs);return b.length?a.data.xs[b[0]]:null},f.getOtherTargetX=function(a){var b=this.getOtherTargetXs();return b&&a1},f.isMultipleX=function(){var a=this,b=a.config;return ze(b[z])&&a.hasMultipleX(b[z])},f.addName=function(a){var b,c=this;return a&&(b=c.config[D][a.id],a.name=b?b:a.id),a},f.getValueOnIndex=function(a,b){var c=a.filter(function(a){return a.index===b});return c.length?c[0]:null},f.updateTargetX=function(a,b){var c=this;a.forEach(function(a){a.values.forEach(function(d,e){d.x=c.generateTargetX(b[e],a.id,e)}),c.data.xs[a.id]=b})},f.updateTargetXs=function(a,b){var c=this;a.forEach(function(a){b[a.id]&&c.updateTargetX([a],b[a.id])})},f.generateTargetX=function(a,b,c){var d,e=this;return d=e.isTimeSeries()?e.parseDate(a?a:e.getXValue(b,c)):e.isCustomX()&&!e.isCategorized()?qe(a)?+a:e.getXValue(b,c):c},f.cloneTarget=function(a){return{id:a.id,id_org:a.id_org,values:a.values.map(function(a){return{x:a.x,value:a.value,id:a.id}})}},f.getPrevX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a-1);return c?c.x:null},f.getNextX=function(a){var b=this,c=b.getValueOnIndex(b.data.targets[0].values,a+1);return c?c.x:null},f.getMaxDataCount=function(){var a=this;return a.d3.max(a.data.targets,function(a){return a.values.length})},f.getMaxDataCountTarget=function(a){var b,c=a.length,d=0;return c>1?a.forEach(function(a){a.values.length>d&&(b=a,d=a.values.length)}):b=c?a[0]:null,b},f.getEdgeX=function(a){var b,c,d=this.getMaxDataCountTarget(a);return d?(b=d.values[0],c=d.values[d.values.length-1],[b.x,c.x]):[0,0]},f.mapToIds=function(a){return a.map(function(a){return a.id})},f.mapToTargetIds=function(a){var b=this;return a?se(a)?[a]:a:b.mapToIds(b.data.targets)},f.hasTarget=function(a,b){var c,d=this.mapToIds(a);for(c=0;ca})},f.hasPositiveValueInTargets=function(a){return this.checkValueInTargets(a,function(a){return a>0})},f.isOrderDesc=function(){var a=this.config;return a[K]&&"desc"===a[K].toLowerCase()},f.isOrderAsc=function(){var a=this.config;return a[K]&&"asc"===a[K].toLowerCase()},f.orderTargets=function(a){var b=this,c=b.config,d=b.isOrderAsc(),e=b.isOrderDesc();return d||e?a.sort(function(a,b){var c=function(a,b){return a+Math.abs(b.value) },e=a.values.reduce(c,0),f=b.values.reduce(c,0);return d?f-e:e-f}):re(c[K])&&a.sort(c[K]),a},f.filterSameX=function(a,b){return this.d3.merge(a.map(function(a){return a.values})).filter(function(a){return a.x-b===0})},f.filterRemoveNull=function(a){return a.filter(function(a){return qe(a.value)})},f.hasDataLabel=function(){var a=this.config;return"boolean"==typeof a[J]&&a[J]?!0:"object"==typeof a[J]&&ze(a[J])?!0:!1},f.getDataLabelLength=function(a,b,c,d){var e=this,f=[0,0],g=1.3;return e.selectChart.select("svg").selectAll(".dummy").data([a,b]).enter().append("text").text(function(a){return e.formatByAxisId(c)(a)}).each(function(a,b){f[b]=this.getBoundingClientRect()[d]*g}).remove(),f},f.isNoneArc=function(a){return this.hasTarget(this.data.targets,a.id)},f.isArc=function(a){return"data"in a&&this.hasTarget(this.data.targets,a.data.id)},f.findSameXOfValues=function(a,b){var c,d=a[b].x,e=[];for(c=b-1;c>=0&&d===a[c].x;c--)e.push(a[c]);for(c=b;c0?h=i:g=i,h-g===1||0===g&&0===h?(e=[],(a[g].x||0===a[g].x)&&(e=e.concat(f.findSameXOfValues(a,g))),(a[h].x||0===a[h].x)&&(e=e.concat(f.findSameXOfValues(a,h))),f.findClosest(e,b)):f.findClosestOfValues(a,b,g,h)},f.findClosestFromTargets=function(a,b){var c,d=this;return c=a.map(function(a){return d.findClosestOfValues(a.values,b)}),d.findClosest(c,b)},f.findClosest=function(a,b){var c,d,e=this;return a.forEach(function(a){var f=e.dist(a,b);(c>f||!c)&&(c=f,d=a)}),d},f.dist=function(a,b){var c=this,d=c.config,e="y"===c.getAxisId(a.id)?c.y:c.y2,f=d[vb]?1:0,g=d[vb]?0:1;return Math.pow(c.x(a.x)-b[f],2)+Math.pow(e(a.value)-b[g],2)},f.convertUrlToData=function(a,b,c,d){var e=this,f=b?b:"csv";e.d3.xhr(a,function(a,b){var g;g="json"===f?e.convertJsonToData(JSON.parse(b.response),c):e.convertCsvToData(b.response),d.call(e,g)})},f.convertCsvToData=function(a){var b,c=this.d3,d=c.csv.parseRows(a);return 1===d.length?(b=[{}],d[0].forEach(function(a){b[0][a]=null})):b=c.csv.parse(a),b},f.convertJsonToData=function(a,b){var c,d,e=this,f=[];return b?(c=b.value,b.x&&(c.push(b.x),e.config[y]=b.x),f.push(c),a.forEach(function(a){var b=[];c.forEach(function(c){var d=te(a[c])?null:a[c];b.push(d)}),f.push(b)}),d=e.convertRowsToData(f)):(Object.keys(a).forEach(function(b){f.push([b].concat(a[b]))}),d=e.convertColumnsToData(f)),d},f.convertRowsToData=function(a){var b,c,d=a[0],e={},f=[];for(b=1;b=0?d.data.xs[c]=(b&&d.data.xs[c]?d.data.xs[c]:[]).concat(a.map(function(a){return a[f]}).filter(qe).map(function(a,b){return d.generateTargetX(a,c,b)})):e[y]?d.data.xs[c]=d.getOtherTargetXs():ze(e[z])&&(d.data.xs[c]=d.getXValuesOfXKey(f,d.data.targets)):d.data.xs[c]=a.map(function(a,b){return b})}),f.forEach(function(a){if(!d.data.xs[a])throw new Error('x is not defined for id = "'+a+'".')}),c=f.map(function(b,c){var f=e[C](b);return{id:f,id_org:b,values:a.map(function(a,g){var h=d.getXKey(b),i=a[h],j=d.generateTargetX(i,b,g);return d.isCustomX()&&d.isCategorized()&&0===c&&i&&(0===g&&(e[zb]=[]),e[zb].push(i)),(te(a[b])||d.data.xs[b].length<=g)&&(j=void 0),{x:j,value:null===a[b]||isNaN(a[b])?null:+a[b],id:f}}).filter(function(a){return ue(a.x)})}}),c.forEach(function(a){var b;a.values=a.values.sort(function(a,b){var c=a.x||0===a.x?a.x:1/0,d=b.x||0===b.x?b.x:1/0;return c-d}),b=0,a.values.forEach(function(a){a.index=b++}),d.data.xs[a.id].sort(function(a,b){return a-b})}),e[H]&&d.setTargetType(d.mapToIds(c).filter(function(a){return!(a in e[I])}),e[H]),c.forEach(function(a){d.addCache(a.id_org,a)}),c},f.load=function(a,b){var c=this;a&&(b.filter&&(a=a.filter(b.filter)),(b.type||b.types)&&a.forEach(function(a){c.setTargetType(a.id,b.types?b.types[a.id]:b.type)}),c.data.targets.forEach(function(b){for(var c=0;ce?0:e},g=function(a){var b=h.getPrevX(a.index),c=h.data.xs[a.id][a.index];return(h.x(c)+h.x(b?b:c))/2}),b=i[vb]?0:g,c=i[vb]?g:0,d=i[vb]?h.width:f,e=i[vb]?f:h.height),a.attr("class",h.classEvent.bind(h)).attr("x",b).attr("y",c).attr("width",d).attr("height",e)},f.generateEventRectsForSingleX=function(a){var b=this,c=b.d3,d=b.config;a.append("rect").attr("class",b.classEvent.bind(b)).style("cursor",d[Q]&&d[R]?"pointer":null).on("mouseover",function(a){var c,e,f=a.index;b.dragging||b.hasArcType()||(c=b.data.targets.map(function(a){return b.addName(b.getValueOnIndex(a.values,f))}),e=[],Object.keys(d[D]).forEach(function(a){for(var b=0;b0?c:320},f.getCurrentPaddingTop=function(){var a=this.config;return qe(a[m])?a[m]:0},f.getCurrentPaddingBottom=function(){var a=this.config;return qe(a[n])?a[n]:0},f.getCurrentPaddingLeft=function(){var a=this,b=a.config;return qe(b[k])?b[k]:b[vb]?b[wb]?Math.max(ve(a.getAxisWidthByAxisId("x")),40):1:b[Pb]?ve(a.getAxisWidthByAxisId("y")):1},f.getCurrentPaddingRight=function(){var a=this,b=a.config,c=10,d=a.isLegendRight?a.getLegendWidth()+20:0;return qe(b[l])?b[l]+1:b[vb]?c+d:(b[Yb]?ve(a.getAxisWidthByAxisId("y2")):c)+d},f.getParentRectValue=function(a){for(var b,c=this.selectChart.node();c&&"BODY"!==c.tagName&&!(b=c.getBoundingClientRect()[a]);)c=c.parentNode;return b},f.getParentWidth=function(){return this.getParentRectValue("width")},f.getParentHeight=function(){var a=this.selectChart.style("height");return a.indexOf("px")>0?+a.replace("px",""):0},f.getSvgLeft=function(){var a=this,b=a.config,c=b[vb]?pe[_d]:pe[be],d=a.main.select("."+c).node(),e=d?d.getBoundingClientRect():{right:0},f=a.selectChart.node().getBoundingClientRect(),g=a.hasArcType(),h=e.right-f.left-(g?0:a.getCurrentPaddingLeft());return h>0?h:0},f.getAxisWidthByAxisId=function(a){var b=this,c=b.getAxisLabelPositionById(a);return c.isInner?20+b.getMaxTickWidth(a):40+b.getMaxTickWidth(a)},f.getHorizontalAxisHeight=function(a){var b=this,c=b.config;return"x"!==a||c[wb]?"x"===a&&c[Mb]?c[Mb]:"y"!==a||c[Pb]?"y2"!==a||c[Yb]?(b.getAxisLabelPositionById(a).isInner?30:40)+("y2"===a?-10:0):b.rotated_padding_top:!c[lb]||b.isLegendRight||b.isLegendInset?1:10:0},f.getEventRectWidth=function(){var a,b,c,d,e,f,g=this,h=g.getMaxDataCountTarget(g.data.targets);return h?(a=h.values[0],b=h.values[h.values.length-1],c=g.x(b.x)-g.x(a.x),0===c?g.config[vb]?g.height:g.width:(d=g.getMaxDataCount(),e=g.hasType("bar")?(d-(g.isCategorized()?.25:1))/d:1,f=d>1?c*e/(d-1):c,1>f?1:f)):0},f.getShapeIndices=function(a){var b,c,d=this,e=d.config,f={},g=0;return d.filterTargetsToShow(d.data.targets.filter(a,d)).forEach(function(a){for(b=0;b=0&&(j+=h(c.values[g].value)-i)}),j}},f.getInterpolate=function(a){var b=this;return b.isSplineType(a)?"cardinal":b.isStepType(a)?"step-after":"linear"},f.initLine=function(){var a=this,b=a.CLASS;a.main.select("."+b[_c]).append("g").attr("class",b[bd])},f.updateTargetsForLine=function(a){var b,c,d=this,e=d.config,f=d.CLASS,g=d.classChartLine.bind(d),h=d.classLines.bind(d),i=d.classAreas.bind(d),j=d.classCircles.bind(d);b=d.main.select("."+f[bd]).selectAll("."+f[ad]).data(a).attr("class",g),c=b.enter().append("g").attr("class",g).style("opacity",0).style("pointer-events","none"),c.append("g").attr("class",h),c.append("g").attr("class",i),c.append("g").attr("class",function(a){return d.generateClass(f[od],a.id)}),c.append("g").attr("class",j).style("cursor",function(a){return e[S](a)?"pointer":null}),a.forEach(function(a){d.main.selectAll("."+f[od]+d.getTargetSelectorSuffix(a.id)).selectAll("."+f[nd]).each(function(b){b.value=a.values[b.index].value})})},f.redrawLine=function(a){var b=this,c=b.CLASS;b.mainLine=b.main.selectAll("."+c[Dd]).selectAll("."+c[Cd]).data(b.lineData.bind(b)),b.mainLine.enter().append("path").attr("class",b.classLine.bind(b)).style("stroke",b.color),b.mainLine.style("opacity",b.initialOpacity.bind(b)).attr("transform",null),b.mainLine.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForLine=function(a,b){var c=this;a.push(c.mainLine.transition().attr("d",b).style("stroke",c.color).style("opacity",1))},f.generateDrawLine=function(a,b){var c=this,d=c.config,e=c.d3.svg.line(),f=c.generateGetLinePoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x(i).y(h):e.x(h).y(i),d[rc]||(e=e.defined(function(a){return null!=a.value})),function(a){var f,h=d[rc]?c.filterRemoveNull(a.values):a.values,i=b?c.x:c.subX,j=g.call(c,a.id),k=0,l=0;return c.isLineType(a)?f=d[L][a.id]?c.lineWithRegions(h,i,j,d[L][a.id]):e.interpolate(c.getInterpolate(a))(h):(h[0]&&(k=i(h[0].x),l=j(h[0].value)),f=d[vb]?"M "+l+" "+k:"M "+k+" "+l),f?f:"M 0 0"}},f.generateGetLinePoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isLineType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,l-(e-j)]]}},f.lineWithRegions=function(a,b,c,d){function e(a,b){var c;for(c=0;c=g;g+=o)u+=h(a[f-1],a[f],g,n);t=a[f].x}return u},f.redrawArea=function(a){var b=this,c=b.CLASS,d=b.d3;b.mainArea=b.main.selectAll("."+c[Ld]).selectAll("."+c[Kd]).data(b.lineData.bind(b)),b.mainArea.enter().append("path").attr("class",b.classArea.bind(b)).style("fill",b.color).style("opacity",function(){return b.orgAreaOpacity=+d.select(this).style("opacity"),0}),b.mainArea.style("opacity",b.orgAreaOpacity),b.mainArea.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForArea=function(a,b){var c=this;a.push(c.mainArea.transition().attr("d",b).style("fill",c.color).style("opacity",c.orgAreaOpacity))},f.generateDrawArea=function(a,b){var c=this,d=c.config,e=c.d3.svg.area(),f=c.generateGetAreaPoint(a,b),g=b?c.getSubYScale:c.getYScale,h=function(a){return(b?c.subxx:c.xx).call(c,a)},i=function(a,b){return d[F].length>0?f(a,b)[0][1]:g.call(c,a.id)(0)},j=function(a,b){return d[F].length>0?f(a,b)[1][1]:g.call(c,a.id)(a.value)};return e=d[vb]?e.x0(i).x1(j).y(h):e.x(h).y0(i).y1(j),d[rc]||(e=e.defined(function(a){return null!==a.value})),function(a){var b,f=d[rc]?c.filterRemoveNull(a.values):a.values,g=0,h=0;return c.isAreaType(a)?b=e.interpolate(c.getInterpolate(a))(f):(f[0]&&(g=c.x(f[0].x),h=c.getYScale(a.id)(f[0].value)),b=d[vb]?"M "+h+" "+g:"M "+g+" "+h),b?b:"M 0 0"}},f.generateGetAreaPoint=function(a,b){var c=this,d=c.config,e=a.__max__+1,f=c.getShapeX(0,e,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isAreaType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var e=i.call(c,a.id)(0),j=h(a,b)||e,k=f(a),l=g(a);return d[vb]&&(0l||a.value<0&&l>e)&&(l=e),[[k,j],[k,l-(e-j)]]}},f.redrawCircle=function(){var a=this,b=a.CLASS;a.mainCircle=a.main.selectAll("."+b[Hd]).selectAll("."+b[Gd]).data(a.lineOrScatterData.bind(a)),a.mainCircle.enter().append("circle").attr("class",a.classCircle.bind(a)).attr("r",a.pointR.bind(a)).style("fill",a.color),a.mainCircle.style("opacity",a.initialOpacity.bind(a)),a.mainCircle.exit().remove()},f.addTransitionForCircle=function(a,b,c){var d=this;a.push(d.mainCircle.transition().style("opacity",d.opacityForCircle.bind(d)).style("fill",d.color).attr("cx",b).attr("cy",c)),a.push(d.main.selectAll("."+pe[nd]).transition().attr("cx",b).attr("cy",c))},f.circleX=function(a){return a.x||0===a.x?this.x(a.x):null},f.circleY=function(a,b){var c=this,d=c.getShapeIndices(c.isLineType),e=c.generateGetLinePoint(d);return c.config[F].length>0?e(a,b)[0][1]:c.getYScale(a.id)(a.value)},f.getCircles=function(a,b){var c=this;return(b?c.main.selectAll("."+pe[Hd]+c.getTargetSelectorSuffix(b)):c.main).selectAll("."+pe[Gd]+(qe(a)?"-"+a:""))},f.expandCircles=function(a,b){var c=this,d=c.pointExpandedR.bind(c);c.getCircles(a,b).classed(pe[me],!0).attr("r",d)},f.unexpandCircles=function(a){var b=this,c=b.pointR.bind(b);b.getCircles(a).filter(function(){return b.d3.select(this).classed(pe[me])}).classed(pe[me],!1).attr("r",c)},f.pointR=function(a){var b=this,c=b.config;return c[mc]&&!b.isStepType(a)?re(c[nc])?c[nc](a):c[nc]:0},f.pointExpandedR=function(a){var b=this,c=b.config;return c[oc]?c[pc]?c[pc]:1.75*b.pointR(a):b.pointR(a)},f.pointSelectR=function(a){var b=this,c=b.config;return c[qc]?c[qc]:4*b.pointR(a)},f.isWithinCircle=function(a,b){var c=this.d3,d=c.mouse(a),e=c.select(a),f=1*e.attr("cx"),g=1*e.attr("cy");return Math.sqrt(Math.pow(f-d[0],2)+Math.pow(g-d[1],2))d[uc]?d[uc]:e},f.getBars=function(a){var b=this;return b.main.selectAll("."+pe[Ed]+(qe(a)?"-"+a:""))},f.expandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!0)},f.unexpandBars=function(a){var b=this;b.getBars(a).classed(pe[me],!1)},f.generateDrawBar=function(a,b){var c=this,d=c.config,e=c.generateGetBarPoints(a,b);return function(a,b){var c=e(a,b),f=d[vb]?1:0,g=d[vb]?0:1,h="M "+c[0][f]+","+c[0][g]+" L"+c[1][f]+","+c[1][g]+" L"+c[2][f]+","+c[2][g]+" L"+c[3][f]+","+c[3][g]+" z";return h}},f.generateGetBarPoints=function(a,b){var c=this,d=a.__max__+1,e=c.getBarW(c.xAxis,d),f=c.getShapeX(e,d,a,!!b),g=c.getShapeY(!!b),h=c.getShapeOffset(c.isBarType,a,!!b),i=b?c.getSubYScale:c.getYScale;return function(a,b){var d=i.call(c,a.id)(0),j=h(a,b)||d,k=f(a),l=g(a);return c.config[vb]&&(0l||a.value<0&&l>d)&&(l=d),[[k,j],[k,l-(d-j)],[k+e,l-(d-j)],[k+e,j]]}},f.isWithinBar=function(a){var b=this.d3,c=b.mouse(a),d=a.getBoundingClientRect(),e=a.pathSegList.getItem(0),f=a.pathSegList.getItem(1),g=e.x,h=Math.min(e.y,f.y),i=d.width,j=d.height,k=2,l=g-k,m=g+i+k,n=h+j+k,o=h-k;return lf.width?f.width-g.width:d},f.getYForText=function(a,b,c){var d,e=this,f=c.getBoundingClientRect();return d=e.config[vb]?(a[0][0]+a[2][0]+.6*f.height)/2:a[2][1]+(b.value<0?f.height:e.isBarType(b)?-3:-6),d=0||!(b.id in d)&&"line"===a)&&(e=!0)}),e},f.hasArcType=function(a){return this.hasType("pie",a)||this.hasType("donut",a)||this.hasType("gauge",a)},f.isLineType=function(a){var b=this.config,c=se(a)?a:a.id;return!b[I][c]||["line","spline","area","area-spline","step","area-step"].indexOf(b[I][c])>=0},f.isStepType=function(a){var b=se(a)?a:a.id;return["step","area-step"].indexOf(this.config[I][b])>=0},f.isSplineType=function(a){var b=se(a)?a:a.id;return["spline","area-spline"].indexOf(this.config[I][b])>=0},f.isAreaType=function(a){var b=se(a)?a:a.id;return["area","area-spline","area-step"].indexOf(this.config[I][b])>=0},f.isBarType=function(a){var b=se(a)?a:a.id;return"bar"===this.config[I][b]},f.isScatterType=function(a){var b=se(a)?a:a.id;return"scatter"===this.config[I][b]},f.isPieType=function(a){var b=se(a)?a:a.id;return"pie"===this.config[I][b]},f.isGaugeType=function(a){var b=se(a)?a:a.id;return"gauge"===this.config[I][b]},f.isDonutType=function(a){var b=se(a)?a:a.id;return"donut"===this.config[I][b]},f.isArcType=function(a){return this.isPieType(a)||this.isDonutType(a)||this.isGaugeType(a)},f.lineData=function(a){return this.isLineType(a)?[a]:[]},f.arcData=function(a){return this.isArcType(a.data)?[a]:[]},f.barData=function(a){return this.isBarType(a)?a.values:[]},f.lineOrScatterData=function(a){return this.isLineType(a)||this.isScatterType(a)?a.values:[]},f.barOrLineData=function(a){return this.isBarType(a)||this.isLineType(a)?a.values:[]},f.initGrid=function(){var a=this,b=a.config,c=a.CLASS,d=a.d3;a.grid=a.main.append("g").attr("clip-path",a.clipPath).attr("class",c[Qd]),b[fc]&&a.grid.append("g").attr("class",c[Sd]),b[ic]&&a.grid.append("g").attr("class",c[Xd]),a.grid.append("g").attr("class",c[Ud]),a.grid.append("g").attr("class",c[Zd]),b[lc]&&a.grid.append("g").attr("class",c[Vd]).append("line").attr("class",c[Vd]),a.xgrid=d.selectAll([]),a.xgridLines=d.selectAll([])},f.updateXGrid=function(a){var b=this,c=b.config,d=b.CLASS,e=b.d3,f=b.generateGridData(c[gc],b.x),g=b.isCategorized()?b.xAxis.tickOffset():0;b.xgridAttr=c[vb]?{x1:0,x2:b.width,y1:function(a){return b.x(a)-g},y2:function(a){return b.x(a)-g}}:{x1:function(a){return b.x(a)+g},x2:function(a){return b.x(a)+g},y1:0,y2:b.height},b.xgrid=b.main.select("."+d[Sd]).selectAll("."+d[Rd]).data(f),b.xgrid.enter().append("line").attr("class",d[Rd]),a||b.xgrid.attr(b.xgridAttr).style("opacity",function(){return+e.select(this).attr(c[vb]?"y1":"x1")===(c[vb]?b.height:0)?0:1}),b.xgrid.exit().remove()},f.updateYGrid=function(){var a=this,b=a.config,c=a.CLASS;a.ygrid=a.main.select("."+c[Xd]).selectAll("."+c[Wd]).data(a.y.ticks(b[kc])),a.ygrid.enter().append("line").attr("class",c[Wd]),a.ygrid.attr("x1",b[vb]?a.y:0).attr("x2",b[vb]?a.y:a.width).attr("y1",b[vb]?0:a.y).attr("y2",b[vb]?a.height:a.y),a.ygrid.exit().remove(),a.smoothLines(a.ygrid,"grid")},f.redrawGrid=function(a,b){var c,d,e,f=this,g=f.main,h=f.config,i=f.CLASS;g.select("line."+i[Vd]).style("visibility","hidden"),h[fc]&&f.updateXGrid(),f.xgridLines=g.select("."+i[Ud]).selectAll("."+i[Td]).data(h[hc]),c=f.xgridLines.enter().append("g").attr("class",function(a){return i[Td]+(a.class?" "+a.class:"")}),c.append("line").style("opacity",0),c.append("text").attr("text-anchor","end").attr("transform",h[vb]?"":"rotate(-90)").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),f.xgridLines.exit().transition().duration(a).style("opacity",0).remove(),b&&h[ic]&&f.updateYGrid(),b&&(f.ygridLines=g.select("."+i[Zd]).selectAll("."+i[Yd]).data(h[jc]),d=f.ygridLines.enter().append("g").attr("class",function(a){return i[Yd]+(a.class?" "+a.class:"")}),d.append("line").style("opacity",0),d.append("text").attr("text-anchor","end").attr("transform",h[vb]?"rotate(-90)":"").attr("dx",h[vb]?0:-f.margin.top).attr("dy",-5).style("opacity",0),e=f.yv.bind(f),f.ygridLines.select("line").transition().duration(a).attr("x1",h[vb]?e:0).attr("x2",h[vb]?e:f.width).attr("y1",h[vb]?0:e).attr("y2",h[vb]?f.height:e).style("opacity",1),f.ygridLines.select("text").transition().duration(a).attr("x",h[vb]?0:f.width).attr("y",e).text(function(a){return a.text}).style("opacity",1),f.ygridLines.exit().transition().duration(a).style("opacity",0).remove())},f.addTransitionForGrid=function(a){var b=this,c=b.config,d=b.xv.bind(b);a.push(b.xgridLines.select("line").transition().attr("x1",c[vb]?0:d).attr("x2",c[vb]?b.width:d).attr("y1",c[vb]?d:b.margin.top).attr("y2",c[vb]?d:b.height).style("opacity",1)),a.push(b.xgridLines.select("text").transition().attr("x",c[vb]?b.width:0).attr("y",d).text(function(a){return a.text}).style("opacity",1))},f.showXGridFocus=function(a){var b=this,c=b.config,d=a.filter(function(a){return a&&qe(a.value)}),e=b.main.selectAll("line."+pe[Vd]),f=b.xx.bind(b);c[Rc]&&(b.hasType("scatter")||b.hasArcType()||(e.style("visibility","visible").data([d[0]]).attr(c[vb]?"y1":"x1",f).attr(c[vb]?"y2":"x2",f),b.smoothLines(e,"grid")))},f.hideXGridFocus=function(){this.main.select("line."+pe[Vd]).style("visibility","hidden")},f.updateXgridFocus=function(){var a=this,b=a.config;a.main.select("line."+pe[Vd]).attr("x1",b[vb]?0:-10).attr("x2",b[vb]?a.width:-10).attr("y1",b[vb]?-10:0).attr("y2",b[vb]?-10:a.height)},f.generateGridData=function(a,b){var c,d,e,f,g=this,h=[],i=g.main.select("."+pe[_d]).selectAll(".tick").size();if("year"===a)for(c=g.getXDomain(),d=c[0].getFullYear(),e=c[1].getFullYear(),f=d;e>=f;f++)h.push(new Date(f+"-01-01 00:00:00"));else h=b.ticks(10),h.length>i&&(h=h.filter(function(a){return(""+a).indexOf(".")<0}));return h},f.getGridFilterToRemove=function(a){return a?function(b){var c=!1;return[].concat(a).forEach(function(d){("value"in d&&b.value===a.value||"class"in d&&b.class===a.class)&&(c=!0)}),c}:function(){return!0}},f.removeGridLines=function(a,b){var c=this,d=c.config,e=c.getGridFilterToRemove(a),f=function(a){return!e(a)},g=b?pe[Ud]:pe[Zd],h=b?pe[Td]:pe.ygridLine;c.main.select("."+g).selectAll("."+h).filter(e).transition().duration(d[x]).style("opacity",0).remove(),b?d[hc]=d[hc].filter(f):d[jc]=d[jc].filter(f)},f.initTooltip=function(){var a,b=this,c=b.config;if(b.tooltip=b.selectChart.style("position","relative").append("div").style("position","absolute").style("pointer-events","none").style("z-index","10").style("display","none"),c[Xc]){if(b.isTimeSeries()&&se(c[Yc])){for(c[Yc]=b.parseDate(c[Yc]),a=0;a"+(g||0===g?""+g+"":"")),i=n(a[f].name),h=o(a[f].value,a[f].ratio,a[f].id,a[f].index),j=k.levelColor?k.levelColor(a[f].value):d(a[f].id),e+="",e+=""+i+"",e+=""+h+"",e+=""); return e+""},f.showTooltip=function(a,b){var c,d,e,f,g,h,i,j=this,k=j.config,l=j.hasArcType(),m=a.filter(function(a){return a&&qe(a.value)});0!==m.length&&k[Rc]&&(j.tooltip.html(k[Wc].call(j,a,j.getXAxisTickFormat(),j.getYFormat(l),j.color)).style("display","block"),c=j.tooltip.property("offsetWidth"),d=j.tooltip.property("offsetHeight"),l?(f=j.width/2+b[0],h=j.height/2+b[1]+20):(k[vb]?(e=j.getSvgLeft(),f=e+b[0]+100,g=f+c,i=j.getCurrentWidth()-j.getCurrentPaddingRight(),h=j.x(m[0].x)+20):(e=j.getSvgLeft(),f=e+j.getCurrentPaddingLeft()+j.x(m[0].x)+20,g=f+c,i=e+j.getCurrentWidth()-j.getCurrentPaddingRight(),h=b[1]+15),g>i&&(f-=g-i),h+d>j.getCurrentHeight()&&h>d+30&&(h-=d+30)),j.tooltip.style("top",h+"px").style("left",f+"px"))},f.hideTooltip=function(){this.tooltip.style("display","none")},f.initLegend=function(){var a=this;a.legend=a.svg.append("g").attr("transform",a.getTranslate("legend")),a.config[lb]||(a.legend.style("visibility","hidden"),a.hiddenLegendIds=a.mapToIds(a.data.targets)),a.updateLegend(a.mapToIds(a.data.targets),{withTransform:!1,withTransitionForTransform:!1,withTransition:!1})},f.updateSizeForLegend=function(a,b){var c=this,d=c.config,e={top:c.isLegendTop?c.getCurrentPaddingTop()+d[pb]+5.5:c.currentHeight-a-c.getCurrentPaddingBottom()-d[pb],left:c.isLegendLeft?c.getCurrentPaddingLeft()+d[ob]+.5:c.currentWidth-b-c.getCurrentPaddingRight()-d[ob]+.5};c.margin3={top:c.isLegendRight?0:c.isLegendInset?e.top:c.currentHeight-a,right:0/0,bottom:0,left:c.isLegendRight?c.currentWidth-b:c.isLegendInset?e.left:0}},f.transformLegend=function(a){var b=this;(a?b.legend.transition():b.legend).attr("transform",b.getTranslate("legend"))},f.updateLegendStep=function(a){this.legendStep=a},f.updateLegendItemWidth=function(a){this.legendItemWidth=a},f.updateLegendItemHeight=function(a){this.legendItemHeight=a},f.getLegendWidth=function(){var a=this;return a.config[lb]?a.isLegendRight||a.isLegendInset?a.legendItemWidth*(a.legendStep+1):a.currentWidth:0},f.getLegendHeight=function(){var a=this,b=a.config,c=0;return b[lb]&&(c=a.isLegendRight?a.currentHeight:a.isLegendInset?b[qb]?Math.max(20,a.legendItemHeight)*(b[qb]+1):a.height:Math.max(20,a.legendItemHeight)*(a.legendStep+1)),c},f.opacityForLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:1},f.opacityForUnfocusedLegend=function(a){var b=this;return a.classed(pe[je])?b.legendOpacityForHidden:.3},f.toggleFocusLegend=function(a,b){var c=this;c.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(d){var e=c.d3.select(this);return a&&d!==a?b?c.opacityForUnfocusedLegend(e):c.opacityForLegend(e):b?c.opacityForLegend(e):c.opacityForUnfocusedLegend(e)})},f.revertLegend=function(){var a=this,b=a.d3;a.legend.selectAll("."+pe[ge]).transition().duration(100).style("opacity",function(){return a.opacityForLegend(b.select(this))})},f.showLegend=function(a){var b=this,c=b.config;c[lb]||(c[lb]=!0,b.legend.style("visibility","visible")),b.removeHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("visibility","visible").transition().style("opacity",function(){return b.opacityForLegend(b.d3.select(this))})},f.hideLegend=function(a){var b=this,c=b.config;c[lb]&&ye(a)&&(c[lb]=!1,b.legend.style("visibility","hidden")),b.addHiddenLegendIds(a),b.legend.selectAll(b.selectorLegends(a)).style("opacity",0).style("visibility","hidden")},f.updateLegend=function(a,b,c){function d(b,c,d){function e(a,b){b||(f=(l-x-k)/2,w>f&&(f=(l-k)/2,x=0,E++)),C[a]=E,B[E]=q.isLegendInset?10:f,y[a]=x,x+=k}var f,g,h=q.getTextRect(b.textContent,pe[ge]),i=10*Math.ceil((h.width+t)/10),j=10*Math.ceil((h.height+s)/10),k=q.isLegendRight||q.isLegendInset?j:i,l=q.isLegendRight||q.isLegendInset?q.getLegendHeight():q.getLegendWidth();return d&&(x=0,E=0,u=0,v=0),r[lb]&&!q.isLegendToShow(c)?void(z[c]=A[c]=C[c]=y[c]=0):(z[c]=i,A[c]=j,(!u||i>=u)&&(u=i),(!v||j>=v)&&(v=j),g=q.isLegendRight||q.isLegendInset?v:u,void(r[ub]?(Object.keys(z).forEach(function(a){z[a]=u}),Object.keys(A).forEach(function(a){A[a]=v}),f=(l-g*a.length)/2,w>f?(x=0,E=0,a.forEach(function(a){e(a)})):e(c,!0)):e(c)))}var e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=4,t=36,u=0,v=0,w=10,x=0,y={},z={},A={},B=[0],C={},E=0,F=q.legend.selectAll("."+pe[ke]).size();b=b||{},l=Ae(b,"withTransition",!0),m=Ae(b,"withTransitionForTransform",!0),q.isLegendRight?(e=function(a){return u*C[a]},h=function(a){return B[C[a]]+y[a]}):q.isLegendInset?(e=function(a){return u*C[a]+10},h=function(a){return B[C[a]]+y[a]}):(e=function(a){return B[C[a]]+y[a]},h=function(a){return v*C[a]}),f=function(a,b){return e(a,b)+14},i=function(a,b){return h(a,b)+9},g=function(a,b){return e(a,b)-4},j=function(a,b){return h(a,b)-7},k=q.legend.selectAll("."+pe[ge]).data(a).enter().append("g").attr("class",function(a){return q.generateClass(pe[ge],a)}).style("visibility",function(a){return q.isLegendToShow(a)?"visible":"hidden"}).style("cursor","pointer").on("click",function(a){r[rb]?r[rb].call(q,a):q.api.toggle(a)}).on("mouseover",function(a){q.d3.select(this).classed(pe[ke],!0),q.transiting||q.api.focus(a),r[sb]&&r[sb].call(q,a)}).on("mouseout",function(a){q.d3.select(this).classed(pe[ke],!1),q.transiting||q.api.revert(),r[tb]&&r[tb].call(q,a)}),k.append("text").text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}).style("pointer-events","none").attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:i),k.append("rect").attr("class",pe[he]).style("fill-opacity",0).attr("x",q.isLegendRight||q.isLegendInset?g:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:j),k.append("rect").attr("class",pe[ie]).style("pointer-events","none").style("fill",q.color).attr("x",q.isLegendRight||q.isLegendInset?f:-200).attr("y",q.isLegendRight||q.isLegendInset?-200:h).attr("width",10).attr("height",10),q.isLegendInset&&0!==u&&q.legend.insert("g","."+pe[ge]).attr("class",pe[fe]).append("rect").attr("height",q.getLegendHeight()-10).attr("width",u*(E+1)+10),n=q.legend.selectAll("text").data(a).text(function(a){return ue(r[D][a])?r[D][a]:a}).each(function(a,b){d(this,a,0===b)}),(l?n.transition():n).attr("x",f).attr("y",i),o=q.legend.selectAll("rect."+pe[he]).data(a),(l?o.transition():o).attr("width",function(a){return z[a]}).attr("height",function(a){return A[a]}).attr("x",g).attr("y",j),p=q.legend.selectAll("rect."+pe[ie]).data(a),(l?p.transition():p).style("fill",q.color).attr("x",e).attr("y",h),q.legend.selectAll("."+pe[ge]).classed(pe[je],function(a){return!q.isTargetToShow(a)}).transition().style("opacity",function(a){var b=q.d3.select(this);return q.isTargetToShow(a)?!F||b.classed(pe[ke])?q.opacityForLegend(b):q.opacityForUnfocusedLegend(b):q.legendOpacityForHidden}),q.updateLegendItemWidth(u),q.updateLegendItemHeight(v),q.updateLegendStep(E),q.updateSizes(),q.updateScales(),q.updateSvgSize(),q.transformAll(m,c)},f.initAxis=function(){var a=this,b=a.config,c=a.main,d=a.CLASS;a.axes.x=c.append("g").attr("class",d[$d]+" "+d[_d]).attr("clip-path",a.clipPathForXAxis).attr("transform",a.getTranslate("x")).style("visibility",b[wb]?"visible":"hidden"),a.axes.x.append("text").attr("class",d[ae]).attr("transform",b[vb]?"rotate(-90)":"").style("text-anchor",a.textAnchorForXAxisLabel.bind(a)),a.axes.y=c.append("g").attr("class",d[$d]+" "+d[be]).attr("clip-path",a.clipPathForYAxis).attr("transform",a.getTranslate("y")).style("visibility",b[Pb]?"visible":"hidden"),a.axes.y.append("text").attr("class",d[ce]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForYAxisLabel.bind(a)),a.axes.y2=c.append("g").attr("class",d[$d]+" "+d[de]).attr("transform",a.getTranslate("y2")).style("visibility",b[Yb]?"visible":"hidden"),a.axes.y2.append("text").attr("class",d[ee]).attr("transform",b[vb]?"":"rotate(-90)").style("text-anchor",a.textAnchorForY2AxisLabel.bind(a))},f.getXAxis=function(a,b,c,e){var f=this,g=f.config,h=d(f.d3,f.isCategorized()).scale(a).orient(b);return h.tickFormat(c).tickValues(e),f.isCategorized()?(h.tickCentered(g[Ab]),ye(g[Cb])&&(g[Cb]=!1)):h.tickOffset=function(){var a=f.getEdgeX(f.data.targets),b=f.x(a[1])-f.x(a[0]),c=b?b:g[vb]?f.height:f.width;return c/f.getMaxDataCount()/2},h},f.getYAxis=function(a,b,c,e){return d(this.d3).scale(a).orient(b).tickFormat(c).ticks(e)},f.getAxisId=function(a){var b=this.config;return a in b[G]?b[G][a]:"y"},f.getXAxisTickFormat=function(){var a=this,b=a.config,c=a.isTimeSeries()?a.defaultAxisTimeFormat:a.isCategorized()?a.categoryName:function(a){return 0>a?a.toFixed(0):a};return b[Bb]&&(re(b[Bb])?c=b[Bb]:a.isTimeSeries()&&(c=function(c){return c?a.axisTimeFormat(b[Bb])(c):""})),re(c)?function(b){return c.call(a,b)}:c},f.getAxisLabelOptionByAxisId=function(a){var b,c=this,d=c.config;return"y"===a?b=d[Tb]:"y2"===a?b=d[ac]:"x"===a&&(b=d[Ob]),b},f.getAxisLabelText=function(a){var b=this.getAxisLabelOptionByAxisId(a);return se(b)?b:b?b.text:null},f.setAxisLabelText=function(a,b){var c=this,d=c.config,e=c.getAxisLabelOptionByAxisId(a);se(e)?"y"===a?d[Tb]=b:"y2"===a?d[ac]=b:"x"===a&&(d[Ob]=b):e&&(e.text=b)},f.getAxisLabelPosition=function(a,b){var c=this.getAxisLabelOptionByAxisId(a),d=c&&"object"==typeof c&&c.position?c.position:b;return{isInner:d.indexOf("inner")>=0,isOuter:d.indexOf("outer")>=0,isLeft:d.indexOf("left")>=0,isCenter:d.indexOf("center")>=0,isRight:d.indexOf("right")>=0,isTop:d.indexOf("top")>=0,isMiddle:d.indexOf("middle")>=0,isBottom:d.indexOf("bottom")>=0}},f.getXAxisLabelPosition=function(){return this.getAxisLabelPosition("x",this.config[vb]?"inner-top":"inner-right")},f.getYAxisLabelPosition=function(){return this.getAxisLabelPosition("y",this.config[vb]?"inner-right":"inner-top")},f.getY2AxisLabelPosition=function(){return this.getAxisLabelPosition("y2",this.config[vb]?"inner-right":"inner-top")},f.getAxisLabelPositionById=function(a){return"y2"===a?this.getY2AxisLabelPosition():"y"===a?this.getYAxisLabelPosition():this.getXAxisLabelPosition()},f.textForXAxisLabel=function(){return this.getAxisLabelText("x")},f.textForYAxisLabel=function(){return this.getAxisLabelText("y")},f.textForY2AxisLabel=function(){return this.getAxisLabelText("y2")},f.xForAxisLabel=function(a,b){var c=this;return a?b.isLeft?0:b.isCenter?c.width/2:c.width:b.isBottom?-c.height:b.isMiddle?-c.height/2:0},f.dxForAxisLabel=function(a,b){return a?b.isLeft?"0.5em":b.isRight?"-0.5em":"0":b.isTop?"-0.5em":b.isBottom?"0.5em":"0"},f.textAnchorForAxisLabel=function(a,b){return a?b.isLeft?"start":b.isCenter?"middle":"end":b.isBottom?"start":b.isMiddle?"middle":"end"},f.xForXAxisLabel=function(){return this.xForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.xForYAxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.xForY2AxisLabel=function(){return this.xForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dxForXAxisLabel=function(){return this.dxForAxisLabel(!this.config[vb],this.getXAxisLabelPosition())},f.dxForYAxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getYAxisLabelPosition())},f.dxForY2AxisLabel=function(){return this.dxForAxisLabel(this.config[vb],this.getY2AxisLabelPosition())},f.dyForXAxisLabel=function(){var a=this,b=a.config,c=a.getXAxisLabelPosition();return b[vb]?c.isInner?"1.2em":-25-a.getMaxTickWidth("x"):c.isInner?"-0.5em":b[Mb]?b[Mb]-10:"3em"},f.dyForYAxisLabel=function(){var a=this,b=a.getYAxisLabelPosition();return a.config[vb]?b.isInner?"-0.5em":"3em":b.isInner?"1.2em":-20-a.getMaxTickWidth("y")},f.dyForY2AxisLabel=function(){var a=this,b=a.getY2AxisLabelPosition();return a.config[vb]?b.isInner?"1.2em":"-2.2em":b.isInner?"-0.5em":30+this.getMaxTickWidth("y2")},f.textAnchorForXAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(!a.config[vb],a.getXAxisLabelPosition())},f.textAnchorForYAxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getYAxisLabelPosition())},f.textAnchorForY2AxisLabel=function(){var a=this;return a.textAnchorForAxisLabel(a.config[vb],a.getY2AxisLabelPosition())},f.xForRotatedTickText=function(a){return 10*Math.sin(Math.PI*(a/180))},f.yForRotatedTickText=function(a){return 11.5-2.5*(a/15)},f.rotateTickText=function(a,b,c){a.selectAll(".tick text").style("text-anchor","start"),b.selectAll(".tick text").attr("y",this.yForRotatedTickText(c)).attr("x",this.xForRotatedTickText(c)).attr("transform","rotate("+c+")")},f.getMaxTickWidth=function(a){var b,c,d,e=this,f=e.config,g=0;return e.svg&&(b=e.filterTargetsToShow(e.data.targets),"y"===a?(c=e.y.copy().domain(e.getYDomain(b,"y")),d=e.getYAxis(c,e.yOrient,f[Ub],f[Xb])):"y2"===a?(c=e.y2.copy().domain(e.getYDomain(b,"y2")),d=e.getYAxis(c,e.y2Orient,f[bc],f[ec])):(c=e.x.copy().domain(e.getXDomain(b)),d=e.getXAxis(c,e.xOrient,e.getXAxisTickFormat(),f[Gb]?f[Gb]:e.xAxis.tickValues())),e.main.append("g").call(d).each(function(){e.d3.select(this).selectAll("text").each(function(){var a=this.getBoundingClientRect();g=g?e.currentMaxTickWidth:g,e.currentMaxTickWidth},f.updateAxisLabels=function(a){var b=this,c=b.main.select("."+pe[_d]+" ."+pe[ae]),d=b.main.select("."+pe[be]+" ."+pe[ce]),e=b.main.select("."+pe[de]+" ."+pe[ee]);(a?c.transition():c).attr("x",b.xForXAxisLabel.bind(b)).attr("dx",b.dxForXAxisLabel.bind(b)).attr("dy",b.dyForXAxisLabel.bind(b)).text(b.textForXAxisLabel.bind(b)),(a?d.transition():d).attr("x",b.xForYAxisLabel.bind(b)).attr("dx",b.dxForYAxisLabel.bind(b)).attr("dy",b.dyForYAxisLabel.bind(b)).text(b.textForYAxisLabel.bind(b)),(a?e.transition():e).attr("x",b.xForY2AxisLabel.bind(b)).attr("dx",b.dxForY2AxisLabel.bind(b)).attr("dy",b.dyForY2AxisLabel.bind(b)).text(b.textForY2AxisLabel.bind(b))},f.getAxisPadding=function(a,b,c,d){var e="ratio"===a.unit?d:1;return qe(a[b])?a[b]*e:c},f.generateTickValues=function(a,b){var c,d,e,f,g,h,i,j=this,k=a;if(b)if(c=re(b)?b():b,1===c)k=[a[0]];else if(2===c)k=[a[0],a[a.length-1]];else if(c>2){for(f=c-2,d=a[0],e=a[a.length-1],g=(e-d)/(f+1),k=[d],h=0;f>h;h++)i=+d+g*(h+1),k.push(j.isTimeSeries()?new Date(i):i);k.push(e)}return j.isTimeSeries()||(k=k.sort(function(a,b){return a-b})),k},f.generateAxisTransitions=function(a){var b=this,c=b.axes;return{axisX:a?c.x.transition().duration(a):c.x,axisY:a?c.y.transition().duration(a):c.y,axisY2:a?c.y2.transition().duration(a):c.y2,axisSubX:a?c.subx.transition().duration(a):c.subx}},f.redrawAxis=function(a,b){var c=this;c.axes.x.style("opacity",b?0:1),c.axes.y.style("opacity",b?0:1),c.axes.y2.style("opacity",b?0:1),c.axes.subx.style("opacity",b?0:1),a.axisX.call(c.xAxis),a.axisY.call(c.yAxis),a.axisY2.call(c.y2Axis),a.axisSubX.call(c.subXAxis)},f.getClipPath=function(b){var c=a.navigator.appVersion.toLowerCase().indexOf("msie 9.")>=0;return"url("+(c?"":document.URL.split("#")[0])+"#"+b+")"},f.getAxisClipX=function(a){return a?-31:-(this.margin.left-1)},f.getAxisClipY=function(a){return a?-20:-4},f.getXAxisClipX=function(){var a=this;return a.getAxisClipX(!a.config[vb])},f.getXAxisClipY=function(){var a=this;return a.getAxisClipY(!a.config[vb])},f.getYAxisClipX=function(){var a=this;return a.getAxisClipX(a.config[vb])},f.getYAxisClipY=function(){var a=this;return a.getAxisClipY(a.config[vb])},f.getAxisClipWidth=function(a){var b=this;return a?b.width+2+30+30:b.margin.left+20},f.getAxisClipHeight=function(a){var b=this,c=b.config;return a?(c[Mb]?c[Mb]:0)+80:b.height+8},f.getXAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(!a.config[vb])},f.getXAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(!a.config[vb])},f.getYAxisClipWidth=function(){var a=this;return a.getAxisClipWidth(a.config[vb])},f.getYAxisClipHeight=function(){var a=this;return a.getAxisClipHeight(a.config[vb])},f.initPie=function(){var a=this,b=a.d3,c=a.config;a.pie=b.layout.pie().value(function(a){return a.values.reduce(function(a,b){return a+b.value},0)}),c[K]&&c[Ac]&&c[Nc]||a.pie.sort(null)},f.updateRadius=function(){var a=this,b=a.config,c=b[Ic]||b[Mc];a.radiusExpanded=Math.min(a.arcWidth,a.arcHeight)/2,a.radius=.95*a.radiusExpanded,a.innerRadiusRatio=c?(a.radius-c)/a.radius:.6,a.innerRadius=a.hasType("donut")||a.hasType("gauge")?a.radius*a.innerRadiusRatio:0},f.updateArc=function(){var a=this;a.svgArc=a.getSvgArc(),a.svgArcExpanded=a.getSvgArcExpanded(),a.svgArcExpandedSub=a.getSvgArcExpanded(.98)},f.updateAngle=function(a){var b=this,c=b.config,d=!1,e=0;if(b.pie(b.filterTargetsToShow(b.data.targets)).sort(b.descByStartAngle).forEach(function(b){d||b.data.id!==a.data.id||(d=!0,a=b,a.index=e),e++}),isNaN(a.endAngle)&&(a.endAngle=a.startAngle),b.isGaugeType(a.data)){var f=c[Fc],g=c[Gc],h=Math.abs(f)+g,i=Math.PI/h;a.startAngle=-1*(Math.PI/2)+i*Math.abs(f),a.endAngle=a.startAngle+i*(a.value>g?g:a.value)}return d?a:null},f.getSvgArc=function(){var a=this,b=a.d3.svg.arc().outerRadius(a.radius).innerRadius(a.innerRadius),c=function(c,d){var e;return d?b(c):(e=a.updateAngle(c),e?b(e):"M 0 0")};return c.centroid=b.centroid,c},f.getSvgArcExpanded=function(a){var b=this,c=b.d3.svg.arc().outerRadius(b.radiusExpanded*(a?a:1)).innerRadius(b.innerRadius);return function(a){var d=b.updateAngle(a);return d?c(d):"M 0 0"}},f.getArc=function(a,b,c){return c||this.isArcType(a.data)?this.svgArc(a,b):"M 0 0"},f.transformForArcLabel=function(a){var b,c,d,e,f,g=this,h=g.updateAngle(a),i="";return h&&!g.hasType("gauge")&&(b=this.svgArc.centroid(h),c=isNaN(b[0])?0:b[0],d=isNaN(b[1])?0:b[1],e=Math.sqrt(c*c+d*d),f=g.radius&&e?(36/g.radius>.375?1.175-36/g.radius:.8)*g.radius/e:0,i="translate("+c*f+","+d*f+")"),i},f.getArcRatio=function(a){var b=this,c=b.hasType("gauge")?Math.PI:2*Math.PI;return a?(a.endAngle-a.startAngle)/c:null},f.convertToArcData=function(a){return this.addName({id:a.data.id,value:a.value,ratio:this.getArcRatio(a),index:a.index})},f.textForArcLabel=function(a){var b,c,d,e,f=this;return f.shouldShowArcLabel()?(b=f.updateAngle(a),c=b?b.value:null,d=f.getArcRatio(b),f.hasType("gauge")||f.meetsArcLabelThreshold(d)?(e=f.getArcLabelFormat(),e?e(c,d):f.defaultArcValueFormat(c,d)):""):""},f.expandArc=function(a,b){var c=this,d=c.svg.selectAll("."+pe[gd]+c.selectorTarget(a)),e=c.svg.selectAll("."+pe[Id]).filter(function(b){return b.data.id!==a});c.shouldExpand(a)&&d.selectAll("path").transition().duration(50).attr("d",c.svgArcExpanded).transition().duration(100).attr("d",c.svgArcExpandedSub).each(function(a){c.isDonutType(a.data)}),b||e.style("opacity",.3)},f.unexpandArc=function(a){var b=this,c=b.svg.selectAll("."+pe[gd]+b.selectorTarget(a));c.selectAll("path."+pe[Id]).transition().duration(50).attr("d",b.svgArc),b.svg.selectAll("."+pe[Id]).style("opacity",1)},f.shouldExpand=function(a){var b=this,c=b.config;return b.isDonutType(a)&&c[Oc]||b.isGaugeType(a)&&c[Ec]||b.isPieType(a)&&c[Bc]},f.shouldShowArcLabel=function(){var a=this,b=a.config,c=!0;return a.hasType("donut")?c=b[Jc]:a.hasType("pie")&&(c=b[xc]),c},f.meetsArcLabelThreshold=function(a){var b=this,c=b.config,d=b.hasType("donut")?c[Lc]:c[zc];return a>=d},f.getArcLabelFormat=function(){var a=this,b=a.config,c=b[yc];return a.hasType("gauge")?c=b[Dc]:a.hasType("donut")&&(c=b[Kc]),c},f.getArcTitle=function(){var a=this;return a.hasType("donut")?a.config[Pc]:""},f.descByStartAngle=function(a,b){return a.startAngle-b.startAngle},f.updateTargetsForArc=function(a){var b,c,d=this,e=d.main,f=d.classChartArc.bind(d),g=d.classArcs.bind(d);b=e.select("."+pe[hd]).selectAll("."+pe[gd]).data(d.pie(a)).attr("class",f),c=b.enter().append("g").attr("class",f),c.append("g").attr("class",g),c.append("text").attr("dy",d.hasType("gauge")?"-0.35em":".35em").style("opacity",0).style("text-anchor","middle").style("pointer-events","none")},f.initArc=function(){var a=this;a.arcs=a.main.select("."+pe[_c]).append("g").attr("class",pe[hd]).attr("transform",a.getTranslate("arc")),a.arcs.append("text").attr("class",pe[id]).style("text-anchor","middle").text(a.getArcTitle())},f.redrawArc=function(a,b,c){var d,e=this,f=e.d3,g=e.config,h=e.main;d=h.selectAll("."+pe[Jd]).selectAll("."+pe[Id]).data(e.arcData.bind(e)),d.enter().append("path").attr("class",e.classArc.bind(e)).style("fill",function(a){return e.color(a.data)}).style("cursor",function(a){return g[S](a)?"pointer":null}).style("opacity",0).each(function(a){e.isGaugeType(a.data)&&(a.startAngle=a.endAngle=-1*(Math.PI/2)),this._current=a}).on("mouseover",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.expandArc(b.data.id),e.toggleFocusLegend(b.data.id,!0),e.config[V](c,this))}).on("mousemove",function(a){var b=e.updateAngle(a),c=e.convertToArcData(b),d=[c];e.showTooltip(d,f.mouse(this))}).on("mouseout",function(a){var b,c;e.transiting||(b=e.updateAngle(a),c=e.convertToArcData(b),e.unexpandArc(b.data.id),e.revertLegend(),e.hideTooltip(),e.config[W](c,this))}).on("click",function(a,b){var c,d;e.toggleShape&&(c=e.updateAngle(a),d=e.convertToArcData(c),e.toggleShape(this,d,b))}),d.attr("transform",function(a){return!e.isGaugeType(a.data)&&c?"scale(0)":""}).style("opacity",function(a){return a===this._current?0:1}).each(function(){e.transiting=!0}).transition().duration(a).attrTween("d",function(a){var b,c=e.updateAngle(a);return c?(isNaN(this._current.endAngle)&&(this._current.endAngle=this._current.startAngle),b=f.interpolate(this._current,c),this._current=b(0),function(a){return e.getArc(b(a),!0)}):function(){return"M 0 0"}}).attr("transform",c?"scale(1)":"").style("fill",function(a){return e.levelColor?e.levelColor(a.data.values[0].value):e.color(a.data.id)}).style("opacity",1).call(e.endall,function(){e.transiting=!1}),d.exit().transition().duration(b).style("opacity",0).remove(),h.selectAll("."+pe[gd]).select("text").style("opacity",0).attr("class",function(a){return e.isGaugeType(a.data)?pe[Pd]:""}).text(e.textForArcLabel.bind(e)).attr("transform",e.transformForArcLabel.bind(e)).transition().duration(a).style("opacity",function(a){return e.isTargetToShow(a.data.id)&&e.isArcType(a.data)?1:0}),h.select("."+pe[id]).style("opacity",e.hasType("donut")||e.hasType("gauge")?1:0)},f.initGauge=function(){var a=this,b=a.config,c=a.arcs;a.hasType("gauge")&&(c.append("path").attr("class",pe[jd]).attr("d",function(){var c={data:[{value:b[Gc]}],startAngle:-1*(Math.PI/2),endAngle:Math.PI/2};return a.getArc(c,!0,!0)}),c.append("text").attr("dy",".75em").attr("class",pe[kd]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Hc]:""),c.append("text").attr("dx",-1*(a.innerRadius+(a.radius-a.innerRadius)/2)+"px").attr("dy","1.2em").attr("class",pe[md]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Fc]:""),c.append("text").attr("dx",a.innerRadius+(a.radius-a.innerRadius)/2+"px").attr("dy","1.2em").attr("class",pe[ld]).style("text-anchor","middle").style("pointer-events","none").text(b[Cc]?b[Gc]:""))},f.initRegion=function(){var a=this,b=a.CLASS;a.main.append("g").attr("clip-path",a.clipPath).attr("class",b[xd])},f.redrawRegion=function(a){var b=this,c=b.config,d=b.CLASS;b.mainRegion=b.main.select("."+d[xd]).selectAll("."+d[wd]).data(c[Qc]),b.mainRegion.enter().append("g").attr("class",b.classRegion.bind(b)).append("rect").style("fill-opacity",0),b.mainRegion.exit().transition().duration(a).style("opacity",0).remove()},f.addTransitionForRegion=function(a){var b=this,c=b.regionX.bind(b),d=b.regionY.bind(b),e=b.regionWidth.bind(b),f=b.regionHeight.bind(b);a.push(b.mainRegion.selectAll("rect").transition().attr("x",c).attr("y",d).attr("width",e).attr("height",f).style("fill-opacity",function(a){return qe(a.opacity)?a.opacity:.1}))},f.regionX=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"start"in a?e(a.start):0:0:d[vb]?0:"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0},f.regionY=function(a){var b,c=this,d=c.config,e="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?0:"end"in a?e(a.end):0:d[vb]?"start"in a?c.x(c.isTimeSeries()?c.parseDate(a.start):a.start):0:0},f.regionWidth=function(a){var b,c=this,d=c.config,e=c.regionX(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?"end"in a?f(a.end):c.width:c.width:d[vb]?c.width:"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.width,e>b?0:b-e},f.regionHeight=function(a){var b,c=this,d=c.config,e=this.regionY(a),f="y"===a.axis?c.y:c.y2;return b="y"===a.axis||"y2"===a.axis?d[vb]?c.height:"start"in a?f(a.start):c.height:d[vb]?"end"in a?c.x(c.isTimeSeries()?c.parseDate(a.end):a.end):c.height:c.height,e>b?0:b-e},f.isRegionOnX=function(a){return!a.axis||"x"===a.axis},f.drag=function(a){var b,c,d,e,f,g,h,i,j=this,k=j.config,l=j.main,m=j.d3;j.hasArcType()||k[Q]&&(!k[o]||j.zoom.altDomain)&&k[T]&&(b=j.dragStart[0],c=j.dragStart[1],d=a[0],e=a[1],f=Math.min(b,d),g=Math.max(b,d),h=k[R]?j.margin.top:Math.min(c,e),i=k[R]?j.height:Math.max(c,e),l.select("."+pe[le]).attr("x",f).attr("y",h).attr("width",g-f).attr("height",i-h),l.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).filter(function(a){return k[S](a)}).each(function(a,b){var c,d,e,k,l,n,o=m.select(this),p=o.classed(pe[ne]),q=o.classed(pe[oe]),r=!1;if(o.classed(pe[Gd]))c=1*o.attr("cx"),d=1*o.attr("cy"),l=j.togglePoint,r=c>f&&g>c&&d>h&&i>d;else{if(!o.classed(pe[Ed]))return;n=Ce(this),c=n.x,d=n.y,e=n.width,k=n.height,l=j.toggleBar,r=!(c>g||f>c+e||d>i||h>d+k)}r^q&&(o.classed(pe[oe],!q),o.classed(pe[ne],!p),l.call(j,!p,o,a,b))}))},f.dragstart=function(a){var b=this,c=b.config;b.hasArcType()||c[Q]&&(b.dragStart=a,b.main.select("."+pe[_c]).append("rect").attr("class",pe[le]).style("opacity",.1),b.dragging=!0,b.config[Z]())},f.dragend=function(){var a=this,b=a.config;a.hasArcType()||b[Q]&&(a.main.select("."+pe[le]).transition().duration(100).style("opacity",0).remove(),a.main.selectAll("."+pe[Ad]).classed(pe[oe],!1),a.dragging=!1,a.config[$]())},f.selectPoint=function(a,b,c){var d=this,e=d.config,f=(e[vb]?d.circleY:d.circleX).bind(d),g=(e[vb]?d.circleX:d.circleY).bind(d),h=d.pointSelectR.bind(d);e[X].call(d.api,b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).data([b]).enter().append("circle").attr("class",function(){return d.generateClass(pe[nd],c)}).attr("cx",f).attr("cy",g).attr("stroke",function(){return d.color(b)}).attr("r",function(a){return 1.4*d.pointSelectR(a)}).transition().duration(100).attr("r",h)},f.unselectPoint=function(a,b,c){var d=this;d.config[Y](b,a.node()),d.main.select("."+pe[od]+d.getTargetSelectorSuffix(b.id)).selectAll("."+pe[nd]+"-"+c).transition().duration(100).attr("r",0).remove()},f.togglePoint=function(a,b,c,d){a?this.selectPoint(b,c,d):this.unselectPoint(b,c,d)},f.selectBar=function(a,b){var c=this;c.config[X].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.d3.rgb(c.color(b)).brighter(.75)})},f.unselectBar=function(a,b){var c=this;c.config[Y].call(c,b,a.node()),a.transition().duration(100).style("fill",function(){return c.color(b)})},f.toggleBar=function(a,b,c,d){a?this.selectBar(b,c,d):this.unselectBar(b,c,d)},f.toggleArc=function(a,b,c,d){this.toggleBar(a,b,c.data,d)},f.getToggle=function(a){var b=this;return"circle"===a.nodeName?b.togglePoint:b.d3.select(a).classed(pe[Ed])?b.toggleBar:b.toggleArc},f.toggleShape=function(a,b,c){var d,e,f=this,g=f.d3,h=f.config,i=g.select(a),j=i.classed(pe[ne]);"circle"===a.nodeName?(d=f.isWithinCircle(a,1.5*f.pointSelectR(b)),e=f.togglePoint):"path"===a.nodeName&&(i.classed(pe[Ed])?(d=f.isWithinBar(a),e=f.toggleBar):(d=!0,e=f.toggleArc)),(h[R]||d)&&(h[Q]&&h[S](b)&&(h[T]||f.main.selectAll("."+pe[Bd]+(h[R]?f.getTargetSelectorSuffix(b.id):"")).selectAll("."+pe[Ad]).each(function(a,b){var c=g.select(this);c.classed(pe[ne])&&e.call(f,!1,c.classed(pe[ne],!1),a,b)}),i.classed(pe[ne],!j),e.call(f,!j,i,b,c)),f.config[U].call(f.api,b,a))},f.initBrush=function(){var a=this,b=a.d3;a.brush=b.svg.brush().on("brush",function(){a.redrawForBrush()}),a.brush.update=function(){return a.context&&a.context.select("."+a.CLASS[ud]).call(this),this},a.brush.scale=function(b){return a.config[vb]?this.y(b):this.x(b)}},f.initSubchart=function(){var a=this,b=a.config,c=a.context=a.svg.append("g").attr("transform",a.getTranslate("context"));b[gb]||c.style("visibility","hidden"),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[_c]),c.select("."+pe[_c]).append("g").attr("class",pe[dd]),c.select("."+pe[_c]).append("g").attr("class",pe[bd]),c.append("g").attr("clip-path",a.clipPath).attr("class",pe[ud]).call(a.brush).selectAll("rect").attr(b[vb]?"width":"height",b[vb]?a.width2:a.height2),a.axes.subx=c.append("g").attr("class",pe[_d]).attr("transform",a.getTranslate("subx")).attr("clip-path",b[vb]?"":a.clipPathForXAxis)},f.updateTargetsForSubchart=function(a){var b,c,d,e,f=this,g=f.context,h=f.config,i=f.classChartBar.bind(f),j=f.classBars.bind(f),k=f.classChartLine.bind(f),l=f.classLines.bind(f),m=f.classAreas.bind(f);h[gb]&&(e=g.select("."+pe[dd]).selectAll("."+pe[cd]).data(a).attr("class",i),d=e.enter().append("g").style("opacity",0).attr("class",i),d.append("g").attr("class",j),c=g.select("."+pe[bd]).selectAll("."+pe[ad]).data(a).attr("class",k),b=c.enter().append("g").style("opacity",0).attr("class",k),b.append("g").attr("class",l),b.append("g").attr("class",m))},f.redrawSubchart=function(a,b,c,d,e,f,g){var h,i,j,k,l,m,n=this,o=n.d3,p=n.context,q=n.config,r=n.barData.bind(n),s=n.lineData.bind(n),t=n.classBar.bind(n),u=n.classLine.bind(n),v=n.classArea.bind(n),w=n.initialOpacity.bind(n);q[gb]&&(o.event&&"zoom"===o.event.type&&n.brush.extent(n.x.orgDomain()).update(),a&&(!q[vb]&&q[Hb]&&n.rotateTickText(n.axes.subx,b.axisSubX,q[Hb]),n.brush.empty()||n.brush.extent(n.x.orgDomain()).update(),k=n.generateDrawArea(e,!0),l=n.generateDrawBar(f,!0),m=n.generateDrawLine(g,!0),j=p.selectAll("."+pe[Fd]).selectAll("."+pe[Ed]).data(r),j.enter().append("path").attr("class",t).style("stroke","none").style("fill",n.color),j.style("opacity",w).transition().duration(c).attr("d",l).style("opacity",1),j.exit().transition().duration(c).style("opacity",0).remove(),h=p.selectAll("."+pe[Dd]).selectAll("."+pe[Cd]).data(s),h.enter().append("path").attr("class",u).style("stroke",n.color),h.style("opacity",w).transition().duration(c).attr("d",m).style("opacity",1),h.exit().transition().duration(c).style("opacity",0).remove(),i=p.selectAll("."+pe[Ld]).selectAll("."+pe[Kd]).data(s),i.enter().append("path").attr("class",v).style("fill",n.color).style("opacity",function(){return n.orgAreaOpacity=+o.select(this).style("opacity"),0}),i.style("opacity",0).transition().duration(c).attr("d",k).style("fill",n.color).style("opacity",n.orgAreaOpacity),i.exit().transition().duration(d).style("opacity",0).remove()))},f.redrawForBrush=function(){var a=this,b=a.x;a.redraw({withTransition:!1,withY:!1,withSubchart:!1,withUpdateXDomain:!0}),a.config[ib].call(a.api,b.orgDomain())},f.transformContext=function(a,b){var c,d=this;b&&b.axisSubX?c=b.axisSubX:(c=d.context.select("."+pe[_d]),a&&(c=c.transition())),d.context.attr("transform",d.getTranslate("context")),c.attr("transform",d.getTranslate("subx"))},f.initZoom=function(){var a=this,b=a.d3,c=a.config;a.zoom=b.behavior.zoom().on("zoomstart",function(){a.zoom.altDomain=b.event.sourceEvent.altKey?a.x.orgDomain():null}).on("zoom",function(){a.redrawForZoom.call(a)}),a.zoom.scale=function(a){return c[vb]?this.y(a):this.x(a)},a.zoom.orgScaleExtent=function(){var b=c[p]?c[p]:[1,10];return[b[0],Math.max(a.getMaxDataCount()/b[1],b[1])]},a.zoom.updateScaleExtent=function(){var b=xe(a.x.orgDomain())/xe(a.orgXDomain),c=this.orgScaleExtent();return this.scaleExtent([c[0]*b,c[1]*b]),this}},f.updateZoom=function(){var a=this,b=a.config[o]?a.zoom:function(){};a.main.select("."+a.CLASS[td]).call(b),a.main.selectAll("."+a.CLASS[pd]).call(b)},f.redrawForZoom=function(){var a=this,b=a.d3,c=a.config,d=a.zoom,e=a.x,f=a.orgXDomain;if(c[o]&&0!==a.filterTargetsToShow(a.data.targets).length){if("mousemove"===b.event.sourceEvent.type&&d.altDomain)return e.domain(d.altDomain),void d.scale(e).updateScaleExtent();a.isCategorized()&&e.orgDomain()[0]===f[0]&&e.domain([f[0]-1e-10,e.orgDomain()[1]]),a.redraw({withTransition:!1,withY:!1,withSubchart:!1}),"mousemove"===b.event.sourceEvent.type&&(a.cancelClick=!0),c[r].call(a.api,e.orgDomain()) }},f.generateColor=function(){var a=this,b=a.config,c=a.d3,d=b[N],e=ze(b[jb])?b[jb]:c.scale.category10().range(),f=b[M],g=[];return function(a){var b,c=a.id||a;return d[c]instanceof Function?b=d[c](a):d[c]?b=d[c]:(g.indexOf(c)<0&&g.push(c),b=e[g.indexOf(c)%e.length],d[c]=b),f instanceof Function?f(b,a):b}},f.generateLevelColor=function(){var a=this,b=a.config,c=b[jb],d=b[kb],e="value"===d.unit,f=d.values&&d.values.length?d.values:[],g=d.max||100;return ze(b[kb])?function(a){var b,d,h=c[c.length-1];for(b=0;b0},Ae=f.getOption=function(a,b,c){return ue(a[b])?a[b]:c},Be=f.hasValue=function(a,b){var c=!1;return Object.keys(a).forEach(function(d){a[d]===b&&(c=!0)}),c},Ce=f.getPathBox=function(a){var b=a.getBoundingClientRect(),c=[a.pathSegList.getItem(0),a.pathSegList.getItem(1)],d=c[0].x,e=Math.min(c[0].y,c[1].y);return{x:d,y:e,width:b.width,height:b.height}};e.focus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),this.defocus(),b(e.classed(pe[vd],!0)),b(f),c.hasArcType()&&c.expandArc(a,!0),c.toggleFocusLegend(a,!0)},e.defocus=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",.3)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));this.revert(),b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.toggleFocusLegend(a,!1)},e.revert=function(a){function b(a){c.filterTargetsToShow(a).transition().duration(100).style("opacity",1)}var c=this.internal,d=c.svg.selectAll(c.selectorTarget(a)),e=d.filter(c.isNoneArc.bind(c)),f=d.filter(c.isArc.bind(c));b(e.classed(pe[vd],!1)),b(f),c.hasArcType()&&c.unexpandArc(a),c.revertLegend()},e.show=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.removeHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",1),b.withLegend&&c.showLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.hide=function(a,b){var c=this.internal;a=c.mapToTargetIds(a),b=b||{},c.addHiddenTargetIds(a),c.svg.selectAll(c.selectorTargets(a)).transition().style("opacity",0),b.withLegend&&c.hideLegend(a),c.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0})},e.toggle=function(a){var b=this.internal;b.isTargetToShow(a)?this.hide(a):this.show(a)},e.zoom=function(){},e.zoom.enable=function(a){var b=this.internal;b.config[o]=a,b.updateAndRedraw()},e.unzoom=function(){var a=this.internal;a.brush.clear().update(),a.redraw({withUpdateXDomain:!0})},e.load=function(a){var b=this.internal,c=b.config;return a.xs&&b.addXs(a.xs),"classes"in a&&Object.keys(a.classes).forEach(function(b){c[E][b]=a.classes[b]}),"categories"in a&&b.isCategorized()&&(c[zb]=a.categories),"cacheIds"in a&&b.hasCaches(a.cacheIds)?void b.load(b.getCaches(a.cacheIds),a.done):void("unload"in a?b.unload(b.mapToTargetIds("boolean"==typeof a.unload&&a.unload?null:a.unload),function(){b.loadFromArgs(a)}):b.loadFromArgs(a))},e.unload=function(a){var b=this.internal;a=a||{},b.unload(b.mapToTargetIds(a.ids),function(){b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0,withLegend:!0}),a.done&&a.done()})},e.flow=function(a){var b,c,d,e,f,g,h,i,j=this.internal,k=[],l=j.getMaxDataCount(),m=0,n=0;if(a.json)c=j.convertJsonToData(a.json,a.keys);else if(a.rows)c=j.convertRowsToData(a.rows);else{if(!a.columns)return;c=j.convertColumnsToData(a.columns)}b=j.convertDataToTargets(c,!0),j.data.targets.forEach(function(a){var c,d,e=!1;for(c=0;cd;d++)b[c].values[d].index=n+d,j.isTimeSeries()||(b[c].values[d].x=n+d);a.values=a.values.concat(b[c].values),b.splice(c,1);break}e||k.push(a.id)}),j.data.targets.forEach(function(a){var b,c;for(b=0;bc;c++)a.values.push({id:a.id,index:n+c,x:j.isTimeSeries()?j.getOtherTargetX(n+c):n+c,value:null})}),j.data.targets.length&&b.forEach(function(a){var b,c=[];for(b=j.data.targets[0].values[0].index;n>b;b++)c.push({id:a.id,index:b,x:j.isTimeSeries()?j.getOtherTargetX(b):b,value:null});a.values.forEach(function(a){a.index+=n,j.isTimeSeries()||(a.x+=n)}),a.values=c.concat(a.values)}),j.data.targets=j.data.targets.concat(b),d=j.getMaxDataCount(),f=j.data.targets[0],g=f.values[0],ue(a.to)?(m=0,i=j.isTimeSeries()?j.parseDate(a.to):a.to,f.values.forEach(function(a){a.x1?f.values[f.values.length-1].x-g.x:g.x-j.getXDomain(j.data.targets)[0]:1,e=[g.x-h,g.x],j.updateXDomain(null,!0,!0,e)),j.updateTargets(j.data.targets),j.redraw({flow:{index:g.index,length:m,duration:qe(a.duration)?a.duration:j.config[x],done:a.done,orgDataCount:l},withLegend:!0,withTransition:l>1})},f.generateFlow=function(a){var b=this,c=b.config,d=b.d3,e=b.CLASS;return function(){var f,g,h,i=a.targets,j=a.flow,k=a.drawBar,l=a.drawLine,m=a.drawArea,n=a.cx,o=a.cy,p=a.xv,q=a.xForText,r=a.yForText,s=a.duration,t=1,u=j.index,v=j.length,w=b.getValueOnIndex(b.data.targets[0].values,u),x=b.getValueOnIndex(b.data.targets[0].values,u+v),y=b.x.domain(),z=j.duration||s,A=j.done||function(){},B=b.generateWait(),C=b.xgrid||d.selectAll([]),D=b.xgridLines||d.selectAll([]),E=b.mainRegion||d.selectAll([]),F=b.mainText||d.selectAll([]),G=b.mainBar||d.selectAll([]),H=b.mainLine||d.selectAll([]),I=b.mainArea||d.selectAll([]),J=b.mainCircle||d.selectAll([]);b.data.targets.forEach(function(a){a.values.splice(0,v)}),h=b.updateXDomain(i,!0,!0),b.updateXGrid&&b.updateXGrid(!0),j.orgDataCount?f=1===j.orgDataCount||w.x===x.x?b.x(y[0])-b.x(h[0]):b.isTimeSeries()?b.x(y[0])-b.x(h[0]):b.x(w.x)-b.x(x.x):1!==b.data.targets[0].values.length?f=b.x(y[0])-b.x(h[0]):b.isTimeSeries()?(w=b.getValueOnIndex(b.data.targets[0].values,0),x=b.getValueOnIndex(b.data.targets[0].values,b.data.targets[0].values.length-1),f=b.x(w.x)-b.x(x.x)):f=xe(h)/2,t=xe(y)/xe(h),g="translate("+f+",0) scale("+t+",1)",d.transition().ease("linear").duration(z).each(function(){B.add(b.axes.x.transition().call(b.xAxis)),B.add(G.transition().attr("transform",g)),B.add(H.transition().attr("transform",g)),B.add(I.transition().attr("transform",g)),B.add(J.transition().attr("transform",g)),B.add(F.transition().attr("transform",g)),B.add(E.filter(b.isRegionOnX).transition().attr("transform",g)),B.add(C.transition().attr("transform",g)),B.add(D.transition().attr("transform",g))}).call(B,function(){var a,d=[],f=[],g=[];if(v){for(a=0;v>a;a++)d.push("."+e[Ad]+"-"+(u+a)),f.push("."+e[Nd]+"-"+(u+a)),g.push("."+e[pd]+"-"+(u+a));b.svg.selectAll("."+e[Bd]).selectAll(d).remove(),b.svg.selectAll("."+e[Od]).selectAll(f).remove(),b.svg.selectAll("."+e[qd]).selectAll(g).remove(),b.svg.select("."+e[Rd]).remove()}C.attr("transform",null).attr(b.xgridAttr),D.attr("transform",null),D.select("line").attr("x1",c[vb]?0:p).attr("x2",c[vb]?b.width:p),D.select("text").attr("x",c[vb]?b.width:0).attr("y",p),G.attr("transform",null).attr("d",k),H.attr("transform",null).attr("d",l),I.attr("transform",null).attr("d",m),J.attr("transform",null).attr("cx",n).attr("cy",o),F.attr("transform",null).attr("x",q).attr("y",r).style("fill-opacity",b.opacityForText.bind(b)),E.attr("transform",null),E.select("rect").filter(b.isRegionOnX).attr("x",b.regionX.bind(b)).attr("width",b.regionWidth.bind(b)),b.updateEventRect(),A()})}},e.selected=function(a){var b=this.internal,c=b.d3;return c.merge(b.main.selectAll("."+pe[Bd]+b.getTargetSelectorSuffix(a)).selectAll("."+pe[Ad]).filter(function(){return c.select(this).classed(pe[ne])}).map(function(a){return a.map(function(a){var b=a.__data__;return b.data?b.data:b})}))},e.select=function(a,b,c){var d=this.internal,e=d.d3,f=d.config;f[Q]&&d.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(g,h){var i=e.select(this),j=g.data?g.data.id:g.id,k=d.getToggle(this),l=f[R]||!a||a.indexOf(j)>=0,m=!b||b.indexOf(h)>=0,n=i.classed(pe[ne]);i.classed(pe[Cd])||i.classed(pe[Kd])||(l&&m?f[S](g)&&!n&&k(!0,i.classed(pe[ne],!0),g,h):ue(c)&&c&&n&&k(!1,i.classed(pe[ne],!1),g,h))})},e.unselect=function(a,b){var c=this.internal,d=c.d3,e=c.config;e[Q]&&c.main.selectAll("."+pe[Bd]).selectAll("."+pe[Ad]).each(function(f,g){var h=d.select(this),i=f.data?f.data.id:f.id,j=c.getToggle(this),k=e[R]||!a||a.indexOf(i)>=0,l=!b||b.indexOf(g)>=0,m=h.classed(pe[ne]);h.classed(pe[Cd])||h.classed(pe[Kd])||k&&l&&e[S](f)&&m&&j(!1,h.classed(pe[ne],!1),f,g)})},e.transform=function(a,b){var c=this.internal,d=["pie","donut"].indexOf(a)>=0?{withTransform:!0}:null;c.transformTo(b,a,d)},f.transformTo=function(a,b,c){var d=this,e=!d.hasArcType(),f=c||{withTransitionForAxis:e};f.withTransitionForTransform=!1,d.transiting=!1,d.setTargetType(a,b),d.updateAndRedraw(f)},e.groups=function(a){var b=this.internal,c=b.config;return te(a)?c[F]:(c[F]=a,b.redraw(),c[F])},e.xgrids=function(a){var b=this.internal,c=b.config;return a?(c[hc]=a,b.redraw(),c[hc]):c[hc]},e.xgrids.add=function(a){var b=this.internal;return this.xgrids(b.config[hc].concat(a?a:[]))},e.xgrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!0)},e.ygrids=function(a){var b=this.internal,c=b.config;return a?(c[jc]=a,b.redraw(),c[jc]):c[jc]},e.ygrids.add=function(a){var b=this.internal;return this.ygrids(b.config[jc].concat(a?a:[]))},e.ygrids.remove=function(a){var b=this.internal;b.removeGridLines(a,!1)},e.regions=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=a,b.redraw(),c[Qc]):c[Qc]},e.regions.add=function(a){var b=this.internal,c=b.config;return a?(c[Qc]=c[Qc].concat(a),b.redraw(),c[Qc]):c[Qc]},e.regions.remove=function(a){var b,c,d,e=this.internal,f=e.config;return a=a||{},b=e.getOption(a,"duration",f[x]),c=e.getOption(a,"classes",[pe[wd]]),d=e.main.select("."+pe[xd]).selectAll(c.map(function(a){return"."+a})),(b?d.transition().duration(b):d).style("opacity",0).remove(),f[Qc]=f[Qc].filter(function(a){var b=!1;return a.class?(a.class.split(" ").forEach(function(a){c.indexOf(a)>=0&&(b=!0)}),!b):!0}),f[Qc]},e.data=function(){},e.data.get=function(a){var b=this.data.getAsTarget(a);return ue(b)?b.values.map(function(a){return a.value}):void 0},e.data.getAsTarget=function(a){var b=this.data.targets.filter(function(b){return b.id===a});return b.length>0?b[0]:void 0},e.data.names=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[D][b]=a[b]}),b.redraw({withLegend:!0}),c[D]):c[D]},e.data.colors=function(a){var b=this.internal,c=b.config;return arguments.length?(Object.keys(a).forEach(function(b){c[N][b]=a[b]}),b.redraw({withLegend:!0}),c[N]):c[N]},e.category=function(a,b){var c=this.internal,d=c.config;return arguments.length>1&&(d[zb][a]=b,c.redraw()),d[zb][a]},e.categories=function(a){var b=this.internal,c=b.config;return arguments.length?(c[zb]=a,b.redraw(),c[zb]):c[zb]},e.color=function(a){var b=this.internal;return b.color(a)},e.x=function(a){var b=this.internal;return arguments.length&&(b.updateTargetX(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.xs=function(a){var b=this.internal;return arguments.length&&(b.updateTargetXs(b.data.targets,a),b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0})),b.data.xs},e.axis=function(){},e.axis.labels=function(a){var b=this.internal;arguments.length&&(Object.keys(a).forEach(function(c){b.setAxisLabelText(c,a[c])}),b.updateAxisLabels())},e.axis.max=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Jb]=a.x),qe(a.y)&&(c[Qb]=a.y),qe(a.y2)&&(c[Zb]=a.y2)):c[Qb]=c[Zb]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.min=function(a){var b=this.internal,c=b.config;arguments.length&&("object"==typeof a?(qe(a.x)&&(c[Kb]=a.x),qe(a.y)&&(c[Rb]=a.y),qe(a.y2)&&(c[$b]=a.y2)):c[Rb]=c[$b]=a,b.redraw({withUpdateOrgXDomain:!0,withUpdateXDomain:!0}))},e.axis.range=function(a){arguments.length&&(ue(a.max)&&this.axis.max(a.max),ue(a.min)&&this.axis.min(a.min))},e.legend=function(){},e.legend.show=function(a){var b=this.internal;b.showLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.legend.hide=function(a){var b=this.internal;b.hideLegend(b.mapToTargetIds(a)),b.updateAndRedraw({withLegend:!0})},e.resize=function(a){var b=this.internal,c=b.config;c[i]=a?a.width:null,c[j]=a?a.height:null,this.flush()},e.flush=function(){var a=this.internal;a.updateAndRedraw({withLegend:!0,withTransition:!1,withTransitionForTransform:!1})},e.destroy=function(){var b=this.internal;b.data.targets=void 0,b.data.xs={},b.selectChart.classed("c3",!1).html(""),a.onresize=null},"function"==typeof define&&define.amd?define("c3",["d3"],g):"undefined"!=typeof exports&&"undefined"!=typeof module?module.exports=g:a.c3=g}(window); \ No newline at end of file diff --git a/src/core.js b/src/core.js index ced1725..21c2b22 100644 --- a/src/core.js +++ b/src/core.js @@ -318,36 +318,39 @@ c3_chart_internal_fn.updateSizes = function () { $$.currentWidth = $$.getCurrentWidth(); $$.currentHeight = $$.getCurrentHeight(); - // for main, context - if (config[__axis_rotated]) { - $$.margin = { - top: $$.getHorizontalAxisHeight('y2') + $$.getCurrentPaddingTop(), - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: $$.getHorizontalAxisHeight('y') + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: subchartHeight + (hasArc ? 0 : $$.getCurrentPaddingLeft()) - }; - $$.margin2 = { - top: $$.margin.top, - right: NaN, - bottom: 20 + legendHeightForBottom, - left: $$.rotated_padding_left - }; - } else { - $$.margin = { - top: 4 + $$.getCurrentPaddingTop(), // for top tick text - right: hasArc ? 0 : $$.getCurrentPaddingRight(), - bottom: xAxisHeight + subchartHeight + legendHeightForBottom + $$.getCurrentPaddingBottom(), - left: hasArc ? 0 : $$.getCurrentPaddingLeft() - }; - $$.margin2 = { - top: $$.currentHeight - subchartHeight - legendHeightForBottom, - right: NaN, - bottom: xAxisHeight + legendHeightForBottom, - left: $$.margin.left - }; - } + // 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;