|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* @license C3.js v0.4.20 | (c) C3 Team and other contributors | http://c3js.org/ */ |
|
|
|
|
/* @license C3.js v0.4.21 | (c) C3 Team and other contributors | http://c3js.org/ */ |
|
|
|
|
(function (global, factory) { |
|
|
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|
|
|
|
typeof define === 'function' && define.amd ? define(factory) : |
|
|
|
@ -46,6 +46,7 @@ var CLASS = {
|
|
|
|
|
circle: 'c3-circle', |
|
|
|
|
circles: 'c3-circles', |
|
|
|
|
arc: 'c3-arc', |
|
|
|
|
arcLabelLine: 'c3-arc-label-line', |
|
|
|
|
arcs: 'c3-arcs', |
|
|
|
|
area: 'c3-area', |
|
|
|
|
areas: 'c3-areas', |
|
|
|
@ -1002,7 +1003,7 @@ c3_axis_fn.redraw = function redraw(transitions, isHidden) {
|
|
|
|
|
transitions.axisSubX.call($$.subXAxis); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var c3 = { version: "0.4.20" }; |
|
|
|
|
var c3 = { version: "0.4.21" }; |
|
|
|
|
|
|
|
|
|
var c3_chart_fn; |
|
|
|
|
var c3_chart_internal_fn; |
|
|
|
@ -1219,11 +1220,6 @@ c3_chart_internal_fn.initWithData = function (data) {
|
|
|
|
|
$$.addHiddenLegendIds(config.legend_hide === true ? $$.mapToIds($$.data.targets) : config.legend_hide); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// when gauge, hide legend // TODO: fix
|
|
|
|
|
if ($$.hasType('gauge')) { |
|
|
|
|
config.legend_show = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Init sizes and scales
|
|
|
|
|
$$.updateSizes(); |
|
|
|
|
$$.updateScales(); |
|
|
|
@ -1803,7 +1799,7 @@ c3_chart_internal_fn.getTranslate = function (target) {
|
|
|
|
|
y = config.axis_rotated ? 0 : $$.height2; |
|
|
|
|
} else if (target === 'arc') { |
|
|
|
|
x = $$.arcWidth / 2; |
|
|
|
|
y = $$.arcHeight / 2; |
|
|
|
|
y = $$.arcHeight / 2 - ($$.hasType('gauge') ? 6 : 0); // to prevent wrong display of min and max label
|
|
|
|
|
} |
|
|
|
|
return "translate(" + x + "," + y + ")"; |
|
|
|
|
}; |
|
|
|
@ -4349,11 +4345,13 @@ c3_chart_internal_fn.initPie = function () {
|
|
|
|
|
c3_chart_internal_fn.updateRadius = function () { |
|
|
|
|
var $$ = this, |
|
|
|
|
config = $$.config, |
|
|
|
|
w = config.gauge_width || config.donut_width; |
|
|
|
|
$$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2; |
|
|
|
|
w = config.gauge_width || config.donut_width, |
|
|
|
|
gaugeArcWidth = $$.filterTargetsToShow($$.data.targets).length * $$.config.gauge_arcs_minWidth; |
|
|
|
|
$$.radiusExpanded = Math.min($$.arcWidth, $$.arcHeight) / 2 * ($$.hasType('gauge') ? 0.85 : 1); |
|
|
|
|
$$.radius = $$.radiusExpanded * 0.95; |
|
|
|
|
$$.innerRadiusRatio = w ? ($$.radius - w) / $$.radius : 0.6; |
|
|
|
|
$$.innerRadius = $$.hasType('donut') || $$.hasType('gauge') ? $$.radius * $$.innerRadiusRatio : 0; |
|
|
|
|
$$.gaugeArcWidth = w ? w : gaugeArcWidth <= $$.radius - $$.innerRadius ? $$.radius - $$.innerRadius : gaugeArcWidth <= $$.radius ? gaugeArcWidth : $$.radius; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.updateArc = function () { |
|
|
|
@ -4404,7 +4402,13 @@ c3_chart_internal_fn.updateAngle = function (d) {
|
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.getSvgArc = function () { |
|
|
|
|
var $$ = this, |
|
|
|
|
arc = $$.d3.svg.arc().outerRadius($$.radius).innerRadius($$.innerRadius), |
|
|
|
|
hasGaugeType = $$.hasType('gauge'), |
|
|
|
|
singleArcWidth = $$.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length, |
|
|
|
|
arc = $$.d3.svg.arc().outerRadius(function (d) { |
|
|
|
|
return hasGaugeType ? $$.radius - singleArcWidth * d.index : $$.radius; |
|
|
|
|
}).innerRadius(function (d) { |
|
|
|
|
return hasGaugeType ? $$.radius - singleArcWidth * (d.index + 1) : $$.innerRadius; |
|
|
|
|
}), |
|
|
|
|
newArc = function newArc(d, withoutUpdate) { |
|
|
|
|
var updated; |
|
|
|
|
if (withoutUpdate) { |
|
|
|
@ -4419,8 +4423,16 @@ c3_chart_internal_fn.getSvgArc = function () {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.getSvgArcExpanded = function (rate) { |
|
|
|
|
var $$ = this, |
|
|
|
|
arc = $$.d3.svg.arc().outerRadius($$.radiusExpanded * (rate ? rate : 1)).innerRadius($$.innerRadius); |
|
|
|
|
rate = rate || 1; |
|
|
|
|
var $$ = this, |
|
|
|
|
hasGaugeType = $$.hasType('gauge'), |
|
|
|
|
singleArcWidth = $$.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length, |
|
|
|
|
expandWidth = Math.min($$.radiusExpanded * rate - $$.radius, singleArcWidth * 0.8 - (1 - rate) * 100), |
|
|
|
|
arc = $$.d3.svg.arc().outerRadius(function (d) { |
|
|
|
|
return hasGaugeType ? $$.radius - singleArcWidth * d.index + expandWidth : $$.radiusExpanded * rate; |
|
|
|
|
}).innerRadius(function (d) { |
|
|
|
|
return hasGaugeType ? $$.radius - singleArcWidth * (d.index + 1) : $$.innerRadius; |
|
|
|
|
}); |
|
|
|
|
return function (d) { |
|
|
|
|
var updated = $$.updateAngle(d); |
|
|
|
|
return updated ? arc(updated) : "M 0 0"; |
|
|
|
@ -4440,8 +4452,9 @@ c3_chart_internal_fn.transformForArcLabel = function (d) {
|
|
|
|
|
y, |
|
|
|
|
h, |
|
|
|
|
ratio, |
|
|
|
|
translate = ""; |
|
|
|
|
if (updated && !$$.hasType('gauge')) { |
|
|
|
|
translate = "", |
|
|
|
|
hasGauge = $$.hasType('gauge'); |
|
|
|
|
if (updated && !hasGauge) { |
|
|
|
|
c = this.svgArc.centroid(updated); |
|
|
|
|
x = isNaN(c[0]) ? 0 : c[0]; |
|
|
|
|
y = isNaN(c[1]) ? 0 : c[1]; |
|
|
|
@ -4454,6 +4467,11 @@ c3_chart_internal_fn.transformForArcLabel = function (d) {
|
|
|
|
|
ratio = $$.radius && h ? (36 / $$.radius > 0.375 ? 1.175 - 36 / $$.radius : 0.8) * $$.radius / h : 0; |
|
|
|
|
} |
|
|
|
|
translate = "translate(" + x * ratio + ',' + y * ratio + ")"; |
|
|
|
|
} else if (updated && hasGauge && $$.filterTargetsToShow($$.data.targets).length > 1) { |
|
|
|
|
var y1 = Math.sin(updated.endAngle - Math.PI / 2); |
|
|
|
|
x = Math.cos(updated.endAngle - Math.PI / 2) * ($$.radiusExpanded + 25); |
|
|
|
|
y = y1 * ($$.radiusExpanded + 15 - Math.abs(y1 * 10)) + 3; |
|
|
|
|
translate = "translate(" + x + ',' + y + ")"; |
|
|
|
|
} |
|
|
|
|
return translate; |
|
|
|
|
}; |
|
|
|
@ -4641,7 +4659,10 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
|
|
|
|
|
d3 = $$.d3, |
|
|
|
|
config = $$.config, |
|
|
|
|
main = $$.main, |
|
|
|
|
mainArc; |
|
|
|
|
mainArc, |
|
|
|
|
backgroundArc, |
|
|
|
|
mainArcLabelLine, |
|
|
|
|
hasGaugeType = $$.hasType('gauge'); |
|
|
|
|
mainArc = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arc).data($$.arcData.bind($$)); |
|
|
|
|
mainArc.enter().append('path').attr("class", $$.classArc.bind($$)).style("fill", function (d) { |
|
|
|
|
return $$.color(d.data); |
|
|
|
@ -4653,6 +4674,37 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
|
|
|
|
|
} |
|
|
|
|
this._current = d; |
|
|
|
|
}); |
|
|
|
|
if (hasGaugeType) { |
|
|
|
|
mainArcLabelLine = main.selectAll('.' + CLASS.arcs).selectAll('.' + CLASS.arcLabelLine).data($$.arcData.bind($$)); |
|
|
|
|
mainArcLabelLine.enter().append('rect').attr("class", function (d) { |
|
|
|
|
return CLASS.arcLabelLine + ' ' + CLASS.target + ' ' + CLASS.target + '-' + d.data.id; |
|
|
|
|
}); |
|
|
|
|
if ($$.filterTargetsToShow($$.data.targets).length === 1) { |
|
|
|
|
mainArcLabelLine.style("display", "none"); |
|
|
|
|
} else { |
|
|
|
|
mainArcLabelLine.style("fill", function (d) { |
|
|
|
|
return config.color_pattern.length > 0 ? $$.levelColor(d.data.values[0].value) : $$.color(d.data); |
|
|
|
|
}).style("display", config.gauge_labelLine_show ? "" : "none").each(function (d) { |
|
|
|
|
var lineLength = 0, |
|
|
|
|
lineThickness = 2, |
|
|
|
|
x = 0, |
|
|
|
|
y = 0, |
|
|
|
|
transform = ""; |
|
|
|
|
if ($$.hiddenTargetIds.indexOf(d.data.id) < 0) { |
|
|
|
|
var updated = $$.updateAngle(d), |
|
|
|
|
innerLineLength = $$.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length * (updated.index + 1), |
|
|
|
|
lineAngle = updated.endAngle - Math.PI / 2, |
|
|
|
|
arcInnerRadius = $$.radius - innerLineLength, |
|
|
|
|
linePositioningAngle = lineAngle - (arcInnerRadius === 0 ? 0 : 1 / arcInnerRadius); |
|
|
|
|
lineLength = $$.radiusExpanded - $$.radius + innerLineLength; |
|
|
|
|
x = Math.cos(linePositioningAngle) * arcInnerRadius; |
|
|
|
|
y = Math.sin(linePositioningAngle) * arcInnerRadius; |
|
|
|
|
transform = "rotate(" + lineAngle * 180 / Math.PI + ", " + x + ", " + y + ")"; |
|
|
|
|
} |
|
|
|
|
d3.select(this).attr({ x: x, y: y, width: lineLength, height: lineThickness, transform: transform }).style("stroke-dasharray", "0, " + (lineLength + lineThickness) + ", 0"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
mainArc.attr("transform", function (d) { |
|
|
|
|
return !$$.isGaugeType(d.data) && withTransform ? "scale(0)" : ""; |
|
|
|
|
}).on('mouseover', config.interaction_enabled ? function (d) { |
|
|
|
@ -4743,21 +4795,33 @@ 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($$.textForArcLabel.bind($$)).attr("transform", $$.transformForArcLabel.bind($$)).style('font-size', function (d) { |
|
|
|
|
return $$.isGaugeType(d.data) ? Math.round($$.radius / 5) + 'px' : ''; |
|
|
|
|
return $$.isGaugeType(d.data) && $$.filterTargetsToShow($$.data.targets).length === 1 ? Math.round($$.radius / 5) + 'px' : ''; |
|
|
|
|
}).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); |
|
|
|
|
main.select('.' + CLASS.chartArcsTitle).style("opacity", $$.hasType('donut') || hasGaugeType ? 1 : 0); |
|
|
|
|
|
|
|
|
|
if (hasGaugeType) { |
|
|
|
|
var index = 0; |
|
|
|
|
backgroundArc = $$.arcs.select('g.' + CLASS.chartArcsBackground).selectAll('path.' + CLASS.chartArcsBackground).data($$.data.targets); |
|
|
|
|
backgroundArc.enter().append("path"); |
|
|
|
|
backgroundArc.attr("class", function (d, i) { |
|
|
|
|
return CLASS.chartArcsBackground + ' ' + CLASS.chartArcsBackground + '-' + i; |
|
|
|
|
}).attr("d", function (d1) { |
|
|
|
|
if ($$.hiddenTargetIds.indexOf(d1.id) >= 0) { |
|
|
|
|
return "M 0 0"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($$.hasType('gauge')) { |
|
|
|
|
$$.arcs.select('.' + CLASS.chartArcsBackground).attr("d", function () { |
|
|
|
|
var d = { |
|
|
|
|
data: [{ value: config.gauge_max }], |
|
|
|
|
startAngle: config.gauge_startingAngle, |
|
|
|
|
endAngle: -1 * config.gauge_startingAngle * (config.gauge_fullCircle ? Math.PI : 1) |
|
|
|
|
endAngle: -1 * config.gauge_startingAngle * (config.gauge_fullCircle ? Math.PI : 1), |
|
|
|
|
index: index++ |
|
|
|
|
}; |
|
|
|
|
return $$.getArc(d, true, true); |
|
|
|
|
}); |
|
|
|
|
backgroundArc.exit().remove(); |
|
|
|
|
|
|
|
|
|
$$.arcs.select('.' + CLASS.chartArcsGaugeUnit).attr("dy", ".75em").text(config.gauge_label_show ? config.gauge_units : ''); |
|
|
|
|
$$.arcs.select('.' + CLASS.chartArcsGaugeMin).attr("dx", -1 * ($$.innerRadius + ($$.radius - $$.innerRadius) / (config.gauge_fullCircle ? 1 : 2)) + "px").attr("dy", "1.2em").text(config.gauge_label_show ? $$.textForGaugeMinMax(config.gauge_min, false) : ''); |
|
|
|
|
$$.arcs.select('.' + CLASS.chartArcsGaugeMax).attr("dx", $$.innerRadius + ($$.radius - $$.innerRadius) / (config.gauge_fullCircle ? 1 : 2) + "px").attr("dy", "1.2em").text(config.gauge_label_show ? $$.textForGaugeMinMax(config.gauge_max, true) : ''); |
|
|
|
@ -4766,7 +4830,7 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
|
|
|
|
|
c3_chart_internal_fn.initGauge = function () { |
|
|
|
|
var arcs = this.arcs; |
|
|
|
|
if (this.hasType('gauge')) { |
|
|
|
|
arcs.append('path').attr("class", CLASS.chartArcsBackground); |
|
|
|
|
arcs.append('g').attr("class", CLASS.chartArcsBackground); |
|
|
|
|
arcs.append("text").attr("class", CLASS.chartArcsGaugeUnit).style("text-anchor", "middle").style("pointer-events", "none"); |
|
|
|
|
arcs.append("text").attr("class", CLASS.chartArcsGaugeMin).style("text-anchor", "middle").style("pointer-events", "none"); |
|
|
|
|
arcs.append("text").attr("class", CLASS.chartArcsGaugeMax).style("text-anchor", "middle").style("pointer-events", "none"); |
|
|
|
@ -5208,6 +5272,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
|
|
|
|
|
// gauge
|
|
|
|
|
gauge_fullCircle: false, |
|
|
|
|
gauge_label_show: true, |
|
|
|
|
gauge_labelLine_show: true, |
|
|
|
|
gauge_label_format: undefined, |
|
|
|
|
gauge_min: 0, |
|
|
|
|
gauge_max: 100, |
|
|
|
@ -5215,6 +5280,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
|
|
|
|
|
gauge_label_extents: undefined, |
|
|
|
|
gauge_units: undefined, |
|
|
|
|
gauge_width: undefined, |
|
|
|
|
gauge_arcs_minWidth: 5, |
|
|
|
|
gauge_expand: {}, |
|
|
|
|
gauge_expand_duration: 50, |
|
|
|
|
// donut
|
|
|
|
@ -7479,7 +7545,9 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
|
|
|
|
|
}).attr('x', xForLegendRect).attr('y', yForLegendRect); |
|
|
|
|
|
|
|
|
|
tiles = $$.legend.selectAll('line.' + CLASS.legendItemTile).data(targetIds); |
|
|
|
|
(withTransition ? tiles.transition() : tiles).style('stroke', $$.color).attr('x1', x1ForLegendTile).attr('y1', yForLegendTile).attr('x2', x2ForLegendTile).attr('y2', yForLegendTile); |
|
|
|
|
(withTransition ? tiles.transition() : tiles).style('stroke', $$.levelColor ? function (id) { |
|
|
|
|
return $$.levelColor($$.cache[id].values[0].value); |
|
|
|
|
} : $$.color).attr('x1', x1ForLegendTile).attr('y1', yForLegendTile).attr('x2', x2ForLegendTile).attr('y2', yForLegendTile); |
|
|
|
|
|
|
|
|
|
if (background) { |
|
|
|
|
(withTransition ? background.transition() : background).attr('height', $$.getLegendHeight() - 12).attr('width', maxWidth * (step + 1) + 10); |
|
|
|
@ -9002,7 +9070,7 @@ c3_chart_internal_fn.tooltipPosition = function (dataToShow, tWidth, tHeight, el
|
|
|
|
|
// Determin tooltip position
|
|
|
|
|
if (forArc) { |
|
|
|
|
tooltipLeft = ($$.width - ($$.isLegendRight ? $$.getLegendWidth() : 0)) / 2 + mouse[0]; |
|
|
|
|
tooltipTop = $$.height / 2 + mouse[1] + 20; |
|
|
|
|
tooltipTop = ($$.hasType('gauge') ? $$.height : $$.height / 2) + mouse[1] + 20; |
|
|
|
|
} else { |
|
|
|
|
svgLeft = $$.getSvgLeft(true); |
|
|
|
|
if (config.axis_rotated) { |
|
|
|
|