Browse Source

Remove isFunction

pull/486/head
Masayuki Tanaka 10 years ago
parent
commit
2fa6a3b53f
  1. 68
      c3.js
  2. 8
      c3.min.js
  3. 2
      src/api.js
  4. 2
      src/axis.js
  5. 44
      src/core.js
  6. 6
      src/data.load.js
  7. 4
      src/format.js
  8. 6
      src/legend.js
  9. 4
      src/scale.js

68
c3.js

@ -134,9 +134,9 @@
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
var main, eventRect, binding = true; var main, eventRect, binding = true;
if (isFunction($$.initPie)) { $$.initPie(); } if ($$.initPie) { $$.initPie(); }
if (isFunction($$.initBrush)) { $$.initBrush(); } if ($$.initBrush) { $$.initBrush(); }
if (isFunction($$.initZoom)) { $$.initZoom(); } if ($$.initZoom) { $$.initZoom(); }
$$.selectChart = d3.select(config[__bindto]); $$.selectChart = d3.select(config[__bindto]);
if ($$.selectChart.empty()) { if ($$.selectChart.empty()) {
@ -201,9 +201,9 @@
// Define regions // Define regions
main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main'));
if (isFunction($$.initSubchart)) { $$.initSubchart(); } if ($$.initSubchart) { $$.initSubchart(); }
if (isFunction($$.initTooltip)) { $$.initTooltip(); } if ($$.initTooltip) { $$.initTooltip(); }
if (isFunction($$.initLegend)) { $$.initLegend(); } if ($$.initLegend) { $$.initLegend(); }
/*-- Main Region --*/ /*-- Main Region --*/
@ -240,12 +240,8 @@
.attr("class", CLASS[_chartLines]); .attr("class", CLASS[_chartLines]);
// Define g for arc chart area // Define g for arc chart area
if (isFunction($$.initArc)) { if ($$.initArc) { $$.initArc(); }
$$.initArc(); if ($$.initGauge) { $$.initGauge(); }
}
if (isFunction($$.initGauge)) {
$$.initGauge();
}
main.select('.' + CLASS[_chart]).append("g") main.select('.' + CLASS[_chart]).append("g")
.attr("class", CLASS[_chartTexts]); .attr("class", CLASS[_chartTexts]);
@ -261,7 +257,7 @@
// Set default extent if defined // Set default extent if defined
if (config[__axis_x_default]) { 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 // Add Axis
@ -363,7 +359,7 @@
} }
// for legend // for legend
if (isFunction($$.updateSizeForLegend)) { $$.updateSizeForLegend(legendHeight, legendWidth); } if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); }
$$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.width = $$.currentWidth - $$.margin.left - $$.margin.right;
$$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom;
@ -378,9 +374,7 @@
// for arc // for arc
$$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0);
$$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10);
if (isFunction($$.updateRadius)) { if ($$.updateRadius) { $$.updateRadius(); }
$$.updateRadius();
}
if ($$.isLegendRight && hasArc) { if ($$.isLegendRight && hasArc) {
$$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1;
@ -446,12 +440,8 @@
// MEMO: can not keep same color... // MEMO: can not keep same color...
//mainLineUpdate.exit().remove(); //mainLineUpdate.exit().remove();
if (isFunction($$.updateTargetsForArc)) { if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); }
$$.updateTargetsForArc(targets); if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); }
}
if (isFunction($$.updateTargetsForSubchart)) {
$$.updateTargetsForSubchart(targets);
}
/*-- Show --*/ /*-- Show --*/
@ -658,12 +648,10 @@
} }
// arc // arc
if (isFunction($$.redrawArc)) { if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); }
$$.redrawArc(duration, durationForExit, withTransform);
}
// subchart // subchart
if (isFunction($$.redrawSubchart)) { if ($$.redrawSubchart) {
$$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices);
} }
@ -911,7 +899,7 @@
$$.withoutFadeIn[id] = true; $$.withoutFadeIn[id] = true;
}); });
if (isFunction($$.updateZoom)) { $$.updateZoom(); } if ($$.updateZoom) { $$.updateZoom(); }
}; };
c3_chart_internal_fn.updateAndRedraw = function (options) { c3_chart_internal_fn.updateAndRedraw = function (options) {
@ -1842,9 +1830,7 @@
if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } if (config[__zoom_enabled]) { $$.zoom.scale($$.x); }
} }
// update for arc // update for arc
if (isFunction($$.updateArc)) { if ($$.updateArc) { $$.updateArc(); }
$$.updateArc();
}
}; };
c3_chart_internal_fn.getYDomainMin = function (targets) { c3_chart_internal_fn.getYDomainMin = function (targets) {
@ -2579,9 +2565,7 @@
// Redraw with new targets // Redraw with new targets
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (isFunction(args.done)) { if (args.done) { args.done(); }
args.done();
}
}; };
c3_chart_internal_fn.loadFromArgs = function (args) { c3_chart_internal_fn.loadFromArgs = function (args) {
var $$ = this; var $$ = this;
@ -2608,7 +2592,7 @@
}; };
c3_chart_internal_fn.unload = function (targetIds, done) { c3_chart_internal_fn.unload = function (targetIds, done) {
var $$ = this; var $$ = this;
if (!isFunction(done)) { if (!done) {
done = function () {}; done = function () {};
} }
// filter existing target // filter existing target
@ -3742,14 +3726,14 @@
.style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; }) .style('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; })
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('click', function (id) { .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) { .on('mouseover', function (id) {
$$.d3.select(this).classed(CLASS[_legendItemFocused], true); $$.d3.select(this).classed(CLASS[_legendItemFocused], true);
if (!$$.transiting) { if (!$$.transiting) {
$$.api.focus(id); $$.api.focus(id);
} }
if (isFunction(config[__legend_item_onmouseover])) { if (config[__legend_item_onmouseover]) {
config[__legend_item_onmouseover].call($$, id); config[__legend_item_onmouseover].call($$, id);
} }
}) })
@ -3758,7 +3742,7 @@
if (!$$.transiting) { if (!$$.transiting) {
$$.api.revert(); $$.api.revert();
} }
if (isFunction(config[__legend_item_onmouseout])) { if (config[__legend_item_onmouseout]) {
config[__legend_item_onmouseout].call($$, id); config[__legend_item_onmouseout].call($$, id);
} }
}); });
@ -3903,7 +3887,7 @@
var $$ = this, config = $$.config, 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 (config[__axis_x_tick_format]) {
if (isFunction(config[__axis_x_tick_format])) { if (config[__axis_x_tick_format]) {
format = config[__axis_x_tick_format]; format = config[__axis_x_tick_format];
} else if ($$.isTimeSeries()) { } else if ($$.isTimeSeries()) {
format = function (date) { format = function (date) {
@ -5102,10 +5086,10 @@
var $$ = this, data_labels = $$.config[__data_labels], var $$ = this, data_labels = $$.config[__data_labels],
format = function (v) { return isValue(v) ? +v : ""; }; format = function (v) { return isValue(v) ? +v : ""; };
// find format according to axis id // find format according to axis id
if (isFunction(data_labels.format)) { if (data_labels.format) {
format = data_labels.format; format = data_labels.format;
} else if (typeof data_labels.format === 'object') { } else if (typeof data_labels.format === 'object') {
if (isFunction(data_labels.format[axisId])) { if (data_labels.format[axisId]) {
format = data_labels.format[axisId]; format = data_labels.format[axisId];
} }
} }
@ -5555,7 +5539,7 @@
args = args || {}; args = args || {};
$$.unload($$.mapToTargetIds(args.ids), function () { $$.unload($$.mapToTargetIds(args.ids), function () {
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (isFunction(args.done)) { args.done(); } if (args.done) { args.done(); }
}); });
}; };

8
c3.min.js vendored

File diff suppressed because one or more lines are too long

2
src/api.js

@ -140,7 +140,7 @@ c3_chart_fn.unload = function (args) {
args = args || {}; args = args || {};
$$.unload($$.mapToTargetIds(args.ids), function () { $$.unload($$.mapToTargetIds(args.ids), function () {
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (isFunction(args.done)) { args.done(); } if (args.done) { args.done(); }
}); });
}; };

2
src/axis.js

@ -63,7 +63,7 @@ c3_chart_internal_fn.getXAxisTickFormat = function () {
var $$ = this, config = $$.config, 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 (config[__axis_x_tick_format]) {
if (isFunction(config[__axis_x_tick_format])) { if (config[__axis_x_tick_format]) {
format = config[__axis_x_tick_format]; format = config[__axis_x_tick_format];
} else if ($$.isTimeSeries()) { } else if ($$.isTimeSeries()) {
format = function (date) { format = function (date) {

44
src/core.js

@ -129,9 +129,9 @@ c3_chart_internal_fn.initWithData = function (data) {
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
var main, eventRect, binding = true; var main, eventRect, binding = true;
if (isFunction($$.initPie)) { $$.initPie(); } if ($$.initPie) { $$.initPie(); }
if (isFunction($$.initBrush)) { $$.initBrush(); } if ($$.initBrush) { $$.initBrush(); }
if (isFunction($$.initZoom)) { $$.initZoom(); } if ($$.initZoom) { $$.initZoom(); }
$$.selectChart = d3.select(config[__bindto]); $$.selectChart = d3.select(config[__bindto]);
if ($$.selectChart.empty()) { if ($$.selectChart.empty()) {
@ -196,9 +196,9 @@ c3_chart_internal_fn.initWithData = function (data) {
// Define regions // Define regions
main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main')); main = $$.main = $$.svg.append("g").attr("transform", $$.getTranslate('main'));
if (isFunction($$.initSubchart)) { $$.initSubchart(); } if ($$.initSubchart) { $$.initSubchart(); }
if (isFunction($$.initTooltip)) { $$.initTooltip(); } if ($$.initTooltip) { $$.initTooltip(); }
if (isFunction($$.initLegend)) { $$.initLegend(); } if ($$.initLegend) { $$.initLegend(); }
/*-- Main Region --*/ /*-- Main Region --*/
@ -235,12 +235,8 @@ c3_chart_internal_fn.initWithData = function (data) {
.attr("class", CLASS[_chartLines]); .attr("class", CLASS[_chartLines]);
// Define g for arc chart area // Define g for arc chart area
if (isFunction($$.initArc)) { if ($$.initArc) { $$.initArc(); }
$$.initArc(); if ($$.initGauge) { $$.initGauge(); }
}
if (isFunction($$.initGauge)) {
$$.initGauge();
}
main.select('.' + CLASS[_chart]).append("g") main.select('.' + CLASS[_chart]).append("g")
.attr("class", CLASS[_chartTexts]); .attr("class", CLASS[_chartTexts]);
@ -256,7 +252,7 @@ c3_chart_internal_fn.initWithData = function (data) {
// Set default extent if defined // Set default extent if defined
if (config[__axis_x_default]) { 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 // Add Axis
@ -358,7 +354,7 @@ c3_chart_internal_fn.updateSizes = function () {
} }
// for legend // for legend
if (isFunction($$.updateSizeForLegend)) { $$.updateSizeForLegend(legendHeight, legendWidth); } if ($$.updateSizeForLegend) { $$.updateSizeForLegend(legendHeight, legendWidth); }
$$.width = $$.currentWidth - $$.margin.left - $$.margin.right; $$.width = $$.currentWidth - $$.margin.left - $$.margin.right;
$$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom; $$.height = $$.currentHeight - $$.margin.top - $$.margin.bottom;
@ -373,9 +369,7 @@ c3_chart_internal_fn.updateSizes = function () {
// for arc // for arc
$$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0); $$.arcWidth = $$.width - ($$.isLegendRight ? legendWidth + 10 : 0);
$$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10); $$.arcHeight = $$.height - ($$.isLegendRight ? 0 : 10);
if (isFunction($$.updateRadius)) { if ($$.updateRadius) { $$.updateRadius(); }
$$.updateRadius();
}
if ($$.isLegendRight && hasArc) { if ($$.isLegendRight && hasArc) {
$$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1; $$.margin3.left = $$.arcWidth / 2 + $$.radiusExpanded * 1.1;
@ -441,12 +435,8 @@ c3_chart_internal_fn.updateTargets = function (targets) {
// MEMO: can not keep same color... // MEMO: can not keep same color...
//mainLineUpdate.exit().remove(); //mainLineUpdate.exit().remove();
if (isFunction($$.updateTargetsForArc)) { if ($$.updateTargetsForArc) { $$.updateTargetsForArc(targets); }
$$.updateTargetsForArc(targets); if ($$.updateTargetsForSubchart) { $$.updateTargetsForSubchart(targets); }
}
if (isFunction($$.updateTargetsForSubchart)) {
$$.updateTargetsForSubchart(targets);
}
/*-- Show --*/ /*-- Show --*/
@ -653,12 +643,10 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
} }
// arc // arc
if (isFunction($$.redrawArc)) { if ($$.redrawArc) { $$.redrawArc(duration, durationForExit, withTransform); }
$$.redrawArc(duration, durationForExit, withTransform);
}
// subchart // subchart
if (isFunction($$.redrawSubchart)) { if ($$.redrawSubchart) {
$$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices); $$.redrawSubchart(withSubchart, transitions, duration, durationForExit, areaIndices, barIndices, lineIndices);
} }
@ -906,7 +894,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.withoutFadeIn[id] = true; $$.withoutFadeIn[id] = true;
}); });
if (isFunction($$.updateZoom)) { $$.updateZoom(); } if ($$.updateZoom) { $$.updateZoom(); }
}; };
c3_chart_internal_fn.updateAndRedraw = function (options) { c3_chart_internal_fn.updateAndRedraw = function (options) {

6
src/data.load.js

@ -30,9 +30,7 @@ c3_chart_internal_fn.load = function (targets, args) {
// Redraw with new targets // Redraw with new targets
$$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); $$.redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (isFunction(args.done)) { if (args.done) { args.done(); }
args.done();
}
}; };
c3_chart_internal_fn.loadFromArgs = function (args) { c3_chart_internal_fn.loadFromArgs = function (args) {
var $$ = this; var $$ = this;
@ -59,7 +57,7 @@ c3_chart_internal_fn.loadFromArgs = function (args) {
}; };
c3_chart_internal_fn.unload = function (targetIds, done) { c3_chart_internal_fn.unload = function (targetIds, done) {
var $$ = this; var $$ = this;
if (!isFunction(done)) { if (!done) {
done = function () {}; done = function () {};
} }
// filter existing target // filter existing target

4
src/format.js

@ -27,10 +27,10 @@ c3_chart_internal_fn.formatByAxisId = function (axisId) {
var $$ = this, data_labels = $$.config[__data_labels], var $$ = this, data_labels = $$.config[__data_labels],
format = function (v) { return isValue(v) ? +v : ""; }; format = function (v) { return isValue(v) ? +v : ""; };
// find format according to axis id // find format according to axis id
if (isFunction(data_labels.format)) { if (data_labels.format) {
format = data_labels.format; format = data_labels.format;
} else if (typeof data_labels.format === 'object') { } else if (typeof data_labels.format === 'object') {
if (isFunction(data_labels.format[axisId])) { if (data_labels.format[axisId]) {
format = data_labels.format[axisId]; format = data_labels.format[axisId];
} }
} }

6
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('visibility', function (id) { return $$.isLegendToShow(id) ? 'visible' : 'hidden'; })
.style('cursor', 'pointer') .style('cursor', 'pointer')
.on('click', function (id) { .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) { .on('mouseover', function (id) {
$$.d3.select(this).classed(CLASS[_legendItemFocused], true); $$.d3.select(this).classed(CLASS[_legendItemFocused], true);
if (!$$.transiting) { if (!$$.transiting) {
$$.api.focus(id); $$.api.focus(id);
} }
if (isFunction(config[__legend_item_onmouseover])) { if (config[__legend_item_onmouseover]) {
config[__legend_item_onmouseover].call($$, id); config[__legend_item_onmouseover].call($$, id);
} }
}) })
@ -213,7 +213,7 @@ c3_chart_internal_fn.updateLegend = function (targetIds, options, transitions) {
if (!$$.transiting) { if (!$$.transiting) {
$$.api.revert(); $$.api.revert();
} }
if (isFunction(config[__legend_item_onmouseout])) { if (config[__legend_item_onmouseout]) {
config[__legend_item_onmouseout].call($$, id); config[__legend_item_onmouseout].call($$, id);
} }
}); });

4
src/scale.js

@ -81,7 +81,5 @@ c3_chart_internal_fn.updateScales = function () {
if (config[__zoom_enabled]) { $$.zoom.scale($$.x); } if (config[__zoom_enabled]) { $$.zoom.scale($$.x); }
} }
// update for arc // update for arc
if (isFunction($$.updateArc)) { if ($$.updateArc) { $$.updateArc(); }
$$.updateArc();
}
}; };

Loading…
Cancel
Save