Browse Source

Switch to rollup (#2037)

* chore: define run scripts, reduce grunt usage

* refactor(rollup): switch to rollup

* chore: fix node.js version on ci env
pull/1595/merge
Yoshiya Hinosawa 8 years ago committed by Ændrew Rininsland
parent
commit
c17ec0ab23
  1. 7
      .jshintrc
  2. 5
      .travis.yml
  3. 80
      Gruntfile.coffee
  4. 8
      package.json
  5. 3
      src/api.axis.js
  6. 2
      src/api.category.js
  7. 2
      src/api.chart.js
  8. 2
      src/api.color.js
  9. 2
      src/api.data.js
  10. 4
      src/api.flow.js
  11. 3
      src/api.focus.js
  12. 2
      src/api.grid.js
  13. 3
      src/api.group.js
  14. 2
      src/api.legend.js
  15. 2
      src/api.load.js
  16. 4
      src/api.region.js
  17. 4
      src/api.selection.js
  18. 2
      src/api.show.js
  19. 3
      src/api.tooltip.js
  20. 2
      src/api.transform.js
  21. 2
      src/api.x.js
  22. 3
      src/api.zoom.js
  23. 4
      src/arc.js
  24. 7
      src/axis.js
  25. 2
      src/c3.axis.js
  26. 2
      src/cache.js
  27. 2
      src/category.js
  28. 101
      src/class-utils.js
  29. 100
      src/class.js
  30. 2
      src/clip.js
  31. 3
      src/color.js
  32. 3
      src/config.js
  33. 38
      src/core.js
  34. 3
      src/data.convert.js
  35. 4
      src/data.js
  36. 3
      src/data.load.js
  37. 3
      src/domain.js
  38. 4
      src/drag.js
  39. 3
      src/format.js
  40. 4
      src/grid.js
  41. 4
      src/head.js
  42. 58
      src/index.js
  43. 3
      src/interaction.js
  44. 4
      src/legend.js
  45. 4
      src/region.js
  46. 2
      src/scale.js
  47. 3
      src/selection.js
  48. 4
      src/shape.bar.js
  49. 4
      src/shape.js
  50. 4
      src/shape.line.js
  51. 4
      src/size.js
  52. 4
      src/subchart.js
  53. 9
      src/tail.js
  54. 3
      src/text.js
  55. 3
      src/title.js
  56. 4
      src/tooltip.js
  57. 3
      src/type.js
  58. 2
      src/ua.js
  59. 56
      src/util.js
  60. 4
      src/zoom.js

7
.jshintrc

@ -1,7 +1,7 @@
{ {
"eqeqeq": true, "eqeqeq": true,
"curly": true, "curly": true,
"strict": true, "strict": false,
"trailing": true, "trailing": true,
"white": true, "white": true,
"maxlen": 210, "maxlen": 210,
@ -24,7 +24,10 @@
"beforeAll": false, "beforeAll": false,
"it": false, "it": false,
"expect": false, "expect": false,
"d3": false "d3": false,
"module": false,
"require": false,
"define": false
} }
} }

5
.travis.yml

@ -1,12 +1,11 @@
language: node_js language: node_js
node_js:
- 6
before_install: before_install:
- npm install -g grunt-cli - npm install -g grunt-cli
- gem install sass - gem install sass
script:
- grunt
after_success: after_success:
- npm run codecov - npm run codecov

80
Gruntfile.coffee

@ -1,84 +1,12 @@
module.exports = (grunt) -> module.exports = (grunt) ->
require('load-grunt-tasks') grunt, pattern: ['grunt-contrib-*', 'grunt-sass', 'grunt-karma'] require('load-grunt-tasks') grunt, pattern: ['grunt-contrib-*', 'grunt-sass']
grunt.initConfig grunt.initConfig
watch: watch:
concat:
tasks: 'concat'
files: ['src/*.js']
sass: sass:
tasks: 'sass' tasks: 'sass'
files: ['src/scss/*.scss'] files: ['src/scss/*.scss']
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/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/interaction.js',
'src/size.js',
'src/shape.js',
'src/shape.line.js',
'src/shape.bar.js',
'src/text.js',
'src/type.js',
'src/grid.js',
'src/tooltip.js',
'src/legend.js',
'src/title.js',
'src/axis.js',
'src/clip.js',
'src/arc.js',
'src/region.js',
'src/drag.js',
'src/selection.js',
'src/subchart.js',
'src/zoom.js',
'src/color.js',
'src/format.js',
'src/cache.js',
'src/class.js',
'src/util.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/api.tooltip.js',
'src/c3.axis.js',
'src/ua.js',
'src/polyfill.js',
'src/tail.js'
]
dest: 'c3.js'
jshint: jshint:
c3: 'c3.js' c3: 'c3.js'
spec: 'spec/*.js' spec: 'spec/*.js'
@ -86,10 +14,6 @@ module.exports = (grunt) ->
reporter: require('jshint-stylish') reporter: require('jshint-stylish')
jshintrc: '.jshintrc' jshintrc: '.jshintrc'
karma:
unit:
configFile: 'karma.conf.js'
uglify: uglify:
c3: c3:
files: files:
@ -108,7 +32,5 @@ module.exports = (grunt) ->
'c3.css': 'src/scss/main.scss' 'c3.css': 'src/scss/main.scss'
grunt.registerTask 'lint', ['jshint'] grunt.registerTask 'lint', ['jshint']
grunt.registerTask 'test', ['karma']
grunt.registerTask 'build', ['concat', 'sass'] grunt.registerTask 'build', ['concat', 'sass']
grunt.registerTask 'minify', ['cssmin', 'uglify'] grunt.registerTask 'minify', ['cssmin', 'uglify']
grunt.registerTask 'default', ['lint', 'build', 'test', 'minify']

8
package.json

@ -6,7 +6,10 @@
"scripts": { "scripts": {
"prepublish": "grunt", "prepublish": "grunt",
"lint": "grunt lint", "lint": "grunt lint",
"test": "karma start karma.conf.js", "build": "rollup -f umd --name c3 src/index.js > c3.js",
"minify": "grunt minify",
"test": "npm run build && npm run lint && karma start karma.conf.js",
"dist": "npm run build && npm run minify",
"codecov": "cat coverage/*/lcov.info | codecov" "codecov": "cat coverage/*/lcov.info | codecov"
}, },
"repository": { "repository": {
@ -43,6 +46,7 @@
"karma-phantomjs-launcher": "^0.2.1", "karma-phantomjs-launcher": "^0.2.1",
"karma-spec-reporter": "0.0.20", "karma-spec-reporter": "0.0.20",
"load-grunt-tasks": "~0.2.0", "load-grunt-tasks": "~0.2.0",
"phantomjs": "^1.9.18" "phantomjs": "^1.9.18",
"rollup": "^0.41.6"
} }
} }

3
src/api.axis.js

@ -1,3 +1,6 @@
import { c3_chart_fn } from './core';
import { isValue, isDefined } from './util';
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; var $$ = this.internal;

2
src/api.category.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.category = function (i, category) { c3_chart_fn.category = function (i, category) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
if (arguments.length > 1) { if (arguments.length > 1) {

2
src/api.chart.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.resize = function (size) { c3_chart_fn.resize = function (size) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
config.size_width = size ? size.width : null; config.size_width = size ? size.width : null;

2
src/api.color.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
// TODO: fix // TODO: fix
c3_chart_fn.color = function (id) { c3_chart_fn.color = function (id) {
var $$ = this.internal; var $$ = this.internal;

2
src/api.data.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.data = function (targetIds) { c3_chart_fn.data = function (targetIds) {
var targets = this.internal.data.targets; var targets = this.internal.data.targets;
return typeof targetIds === 'undefined' ? targets : targets.filter(function (t) { return typeof targetIds === 'undefined' ? targets : targets.filter(function (t) {

4
src/api.flow.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_fn, c3_chart_internal_fn } from './core';
import { isValue, isDefined, diffDomain } from './util';
c3_chart_fn.flow = function (args) { c3_chart_fn.flow = function (args) {
var $$ = this.internal, var $$ = this.internal,
targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(), targets, data, notfoundIds = [], orgDataCount = $$.getMaxDataCount(),

3
src/api.focus.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_fn } from './core';
c3_chart_fn.focus = function (targetIds) { c3_chart_fn.focus = function (targetIds) {
var $$ = this.internal, candidates; var $$ = this.internal, candidates;

2
src/api.grid.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.xgrids = function (grids) { c3_chart_fn.xgrids = function (grids) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
if (! grids) { return config.grid_x_lines; } if (! grids) { return config.grid_x_lines; }

3
src/api.group.js

@ -1,3 +1,6 @@
import { c3_chart_fn } from './core';
import { isUndefined } from './util';
c3_chart_fn.groups = function (groups) { c3_chart_fn.groups = function (groups) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
if (isUndefined(groups)) { return config.data_groups; } if (isUndefined(groups)) { return config.data_groups; }

2
src/api.legend.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
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; var $$ = this.internal;

2
src/api.load.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.load = function (args) { c3_chart_fn.load = function (args) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
// update xs if specified // update xs if specified

4
src/api.region.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_fn } from './core';
import { getOption } from './util';
c3_chart_fn.regions = function (regions) { c3_chart_fn.regions = function (regions) {
var $$ = this.internal, config = $$.config; var $$ = this.internal, config = $$.config;
if (!regions) { return config.regions; } if (!regions) { return config.regions; }

4
src/api.selection.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_fn } from './core';
import { isDefined } from './util';
c3_chart_fn.selected = function (targetId) { c3_chart_fn.selected = function (targetId) {
var $$ = this.internal, d3 = $$.d3; var $$ = this.internal, d3 = $$.d3;
return d3.merge( return d3.merge(

2
src/api.show.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.show = function (targetIds, options) { c3_chart_fn.show = function (targetIds, options) {
var $$ = this.internal, targets; var $$ = this.internal, targets;

3
src/api.tooltip.js

@ -1,3 +1,6 @@
import { c3_chart_fn } from './core';
import { isValue } from './util';
c3_chart_fn.tooltip = function () {}; c3_chart_fn.tooltip = function () {};
c3_chart_fn.tooltip.show = function (args) { c3_chart_fn.tooltip.show = function (args) {
var $$ = this.internal, index, mouse; var $$ = this.internal, index, mouse;

2
src/api.transform.js

@ -1,3 +1,5 @@
import { c3_chart_fn, c3_chart_internal_fn } from './core';
c3_chart_fn.transform = function (type, targetIds) { c3_chart_fn.transform = function (type, targetIds) {
var $$ = this.internal, var $$ = this.internal,
options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null; options = ['pie', 'donut'].indexOf(type) >= 0 ? {withTransform: true} : null;

2
src/api.x.js

@ -1,3 +1,5 @@
import { c3_chart_fn } from './core';
c3_chart_fn.x = function (x) { c3_chart_fn.x = function (x) {
var $$ = this.internal; var $$ = this.internal;
if (arguments.length) { if (arguments.length) {

3
src/api.zoom.js

@ -1,3 +1,6 @@
import { c3_chart_fn } from './core';
import { isDefined } from './util';
c3_chart_fn.zoom = function (domain) { c3_chart_fn.zoom = function (domain) {
var $$ = this.internal; var $$ = this.internal;
if (domain) { if (domain) {

4
src/arc.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isFunction } from './util';
c3_chart_internal_fn.initPie = function () { c3_chart_internal_fn.initPie = function () {
var $$ = this, d3 = $$.d3, config = $$.config; var $$ = this, d3 = $$.d3, config = $$.config;
$$.pie = d3.layout.pie().value(function (d) { $$.pie = d3.layout.pie().value(function (d) {

7
src/axis.js

@ -1,4 +1,9 @@
function Axis(owner) { import CLASS from './class';
import { inherit, API } from './core'
import { isValue, isFunction, isString, isEmpty } from './util';
import c3_axis from './c3.axis'
export default function Axis(owner) {
API.call(this, owner); API.call(this, owner);
} }

2
src/c3.axis.js

@ -3,7 +3,7 @@
// 2. ceil values of translate/x/y to int for half pixel antialiasing // 2. ceil values of translate/x/y to int for half pixel antialiasing
// 3. multiline tick text // 3. multiline tick text
var tickTextCharSize; var tickTextCharSize;
function c3_axis(d3, params) { export default function c3_axis(d3, params) {
var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize, tickPadding = 3, tickValues = null, tickFormat, tickArguments; var scale = d3.scale.linear(), orient = "bottom", innerTickSize = 6, outerTickSize, tickPadding = 3, tickValues = null, tickFormat, tickArguments;
var tickOffset = 0, tickCulling = true, tickCentered; var tickOffset = 0, tickCulling = true, tickCentered;

2
src/cache.js

@ -1,3 +1,5 @@
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.hasCaches = function (ids) { c3_chart_internal_fn.hasCaches = function (ids) {
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
if (! (ids[i] in this.cache)) { return false; } if (! (ids[i] in this.cache)) { return false; }

2
src/category.js

@ -1,3 +1,5 @@
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.categoryName = function (i) { c3_chart_internal_fn.categoryName = function (i) {
var config = this.config; var config = this.config;
return i < config.axis_x_categories.length ? config.axis_x_categories[i] : i; return i < config.axis_x_categories.length ? config.axis_x_categories[i] : i;

101
src/class-utils.js

@ -0,0 +1,101 @@
import CLASS from './class'
import { c3_chart_internal_fn } from './core';
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.classFocus = function (d) {
return this.classFocused(d) + this.classDefocused(d);
};
c3_chart_internal_fn.classFocused = function (d) {
return ' ' + (this.focusedTargetIds.indexOf(d.id) >= 0 ? CLASS.focused : '');
};
c3_chart_internal_fn.classDefocused = function (d) {
return ' ' + (this.defocusedTargetIds.indexOf(d.id) >= 0 ? CLASS.defocused : '');
};
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(/[\s?!@#$%^&*()_=+,.<>'":;\[\]\/|~`{}\\]/g, '-') : '';
};
c3_chart_internal_fn.selectorTarget = function (id, prefix) {
return (prefix || '') + '.' + CLASS.target + this.getTargetSelectorSuffix(id);
};
c3_chart_internal_fn.selectorTargets = function (ids, prefix) {
var $$ = this;
ids = ids || [];
return ids.length ? ids.map(function (id) { return $$.selectorTarget(id, prefix); }) : 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 && ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null;
};

100
src/class.js

@ -1,4 +1,4 @@
var CLASS = c3_chart_internal_fn.CLASS = { export default {
target: 'c3-target', target: 'c3-target',
chart: 'c3-chart', chart: 'c3-chart',
chartLine: 'c3-chart-line', chartLine: 'c3-chart-line',
@ -75,101 +75,3 @@ var CLASS = c3_chart_internal_fn.CLASS = {
SELECTED: '_selected_', SELECTED: '_selected_',
INCLUDED: '_included_' 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.classFocus = function (d) {
return this.classFocused(d) + this.classDefocused(d);
};
c3_chart_internal_fn.classFocused = function (d) {
return ' ' + (this.focusedTargetIds.indexOf(d.id) >= 0 ? CLASS.focused : '');
};
c3_chart_internal_fn.classDefocused = function (d) {
return ' ' + (this.defocusedTargetIds.indexOf(d.id) >= 0 ? CLASS.defocused : '');
};
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(/[\s?!@#$%^&*()_=+,.<>'":;\[\]\/|~`{}\\]/g, '-') : '';
};
c3_chart_internal_fn.selectorTarget = function (id, prefix) {
return (prefix || '') + '.' + CLASS.target + this.getTargetSelectorSuffix(id);
};
c3_chart_internal_fn.selectorTargets = function (ids, prefix) {
var $$ = this;
ids = ids || [];
return ids.length ? ids.map(function (id) { return $$.selectorTarget(id, prefix); }) : 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 && ids.length ? ids.map(function (id) { return $$.selectorLegend(id); }) : null;
};

2
src/clip.js

@ -1,3 +1,5 @@
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.getClipPath = function (id) { c3_chart_internal_fn.getClipPath = function (id) {
var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0; var isIE9 = window.navigator.appVersion.toLowerCase().indexOf("msie 9.") >= 0;
return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")"; return "url(" + (isIE9 ? "" : document.URL.split('#')[0]) + "#" + id + ")";

3
src/color.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { notEmpty } from './util';
c3_chart_internal_fn.generateColor = function () { c3_chart_internal_fn.generateColor = function () {
var $$ = this, config = $$.config, d3 = $$.d3, var $$ = this, config = $$.config, d3 = $$.d3,
colors = config.data_colors, colors = config.data_colors,

3
src/config.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { isDefined } from './util';
c3_chart_internal_fn.getDefaultConfig = function () { c3_chart_internal_fn.getDefaultConfig = function () {
var config = { var config = {
bindto: '#chart', bindto: '#chart',

38
src/core.js

@ -1,14 +1,20 @@
var c3 = { version: "0.4.11" }; import Axis from './axis';
import CLASS from './class';
import { isValue, isFunction, isString, isUndefined, isDefined, ceil10, asHalfPixel, diffDomain, isEmpty, notEmpty, getOption, hasValue, sanitise, getPathBox } from './util';
var c3_chart_fn, export var c3 = { version: "0.4.11" };
c3_chart_internal_fn,
c3_chart_internal_axis_fn;
function API(owner) { export var c3_chart_fn;
export var c3_chart_internal_fn;
export var c3_chart_internal_axis_fn;
var d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined;
export function API(owner) {
this.owner = owner; this.owner = owner;
} }
function inherit(base, derived) { export function inherit(base, derived) {
if (Object.create) { if (Object.create) {
derived.prototype = Object.create(base.prototype); derived.prototype = Object.create(base.prototype);
@ -44,7 +50,7 @@ function Chart(config) {
function ChartInternal(api) { function ChartInternal(api) {
var $$ = this; var $$ = this;
$$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined; $$.d3 = d3
$$.api = api; $$.api = api;
$$.config = $$.getDefaultConfig(); $$.config = $$.getDefaultConfig();
$$.data = {}; $$.data = {};
@ -1059,3 +1065,21 @@ c3_chart_internal_fn.isTabVisible = function () {
return document[hidden] ? false : true; return document[hidden] ? false : true;
}; };
c3_chart_internal_fn.isValue = isValue;
c3_chart_internal_fn.isFunction = isFunction;
c3_chart_internal_fn.isString = isString;
c3_chart_internal_fn.isUndefined = isUndefined;
c3_chart_internal_fn.isDefined = isDefined;
c3_chart_internal_fn.ceil10 = ceil10;
c3_chart_internal_fn.asHalfPixel = asHalfPixel;
c3_chart_internal_fn.diffDomain = diffDomain;
c3_chart_internal_fn.isEmpty = isEmpty;
c3_chart_internal_fn.notEmpty = notEmpty;
c3_chart_internal_fn.notEmpty = notEmpty;
c3_chart_internal_fn.getOption = getOption;
c3_chart_internal_fn.hasValue = hasValue;
c3_chart_internal_fn.sanitise = sanitise;
c3_chart_internal_fn.getPathBox = getPathBox;
c3_chart_internal_fn.CLASS = CLASS;

3
src/data.convert.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { isValue, isUndefined, isDefined, notEmpty } from './util';
c3_chart_internal_fn.convertUrlToData = function (url, mimeType, headers, keys, done) { c3_chart_internal_fn.convertUrlToData = function (url, mimeType, headers, keys, done) {
var $$ = this, type = mimeType ? mimeType : 'csv'; var $$ = this, type = mimeType ? mimeType : 'csv';
var req = $$.d3.xhr(url); var req = $$.d3.xhr(url);

4
src/data.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue, isFunction, notEmpty, hasValue } from './util';
c3_chart_internal_fn.isX = function (key) { c3_chart_internal_fn.isX = function (key) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return (config.data_x && key === config.data_x) || (notEmpty(config.data_xs) && hasValue(config.data_xs, key)); return (config.data_x && key === config.data_x) || (notEmpty(config.data_xs) && hasValue(config.data_xs, key));

3
src/data.load.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.load = function (targets, args) { c3_chart_internal_fn.load = function (targets, args) {
var $$ = this; var $$ = this;
if (targets) { if (targets) {

3
src/domain.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { isValue, isDefined, diffDomain, notEmpty } from './util';
c3_chart_internal_fn.getYDomainMin = function (targets) { c3_chart_internal_fn.getYDomainMin = function (targets) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets), ids = $$.mapToIds(targets), ys = $$.getValuesAsIdKeyed(targets),

4
src/drag.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { getPathBox } from './util';
c3_chart_internal_fn.drag = function (mouse) { c3_chart_internal_fn.drag = function (mouse) {
var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3; var $$ = this, config = $$.config, main = $$.main, d3 = $$.d3;
var sx, sy, mx, my, minX, maxX, minY, maxY; var sx, sy, mx, my, minX, maxX, minY, maxY;

3
src/format.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { isValue } from './util';
c3_chart_internal_fn.getYFormat = function (forArc) { c3_chart_internal_fn.getYFormat = function (forArc) {
var $$ = this, var $$ = this,
formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat, formatForY = forArc && !$$.hasType('gauge') ? $$.defaultArcValueFormat : $$.yFormat,

4
src/grid.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue } from './util';
c3_chart_internal_fn.initGrid = function () { c3_chart_internal_fn.initGrid = function () {
var $$ = this, config = $$.config, d3 = $$.d3; var $$ = this, config = $$.config, d3 = $$.d3;
$$.grid = $$.main.append('g') $$.grid = $$.main.append('g')

4
src/head.js

@ -1,4 +0,0 @@
(function (window) {
'use strict';
/*global define, module, exports, require */

58
src/index.js

@ -0,0 +1,58 @@
import { c3 } from './core'
import './polyfill';
import './api.axis';
import './api.category';
import './api.chart';
import './api.color';
import './api.data';
import './api.flow';
import './api.focus';
import './api.grid';
import './api.group';
import './api.legend';
import './api.load';
import './api.region';
import './api.selection';
import './api.show';
import './api.tooltip';
import './api.transform';
import './api.x';
import './api.zoom';
import './arc';
import './axis';
import './c3.axis';
import './cache';
import './category';
import './class';
import './class-utils';
import './clip';
import './color';
import './config';
import './data.convert';
import './data';
import './data.load';
import './domain';
import './drag';
import './format';
import './grid';
import './interaction';
import './legend';
import './region';
import './scale';
import './selection';
import './shape.bar';
import './shape';
import './shape.line';
import './size';
import './subchart';
import './text';
import './title';
import './tooltip';
import './type';
import './ua';
import './util';
import './zoom';
export default c3

3
src/interaction.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.initEventRect = function () { c3_chart_internal_fn.initEventRect = function () {
var $$ = this; var $$ = this;
$$.main.select('.' + CLASS.chart).append("g") $$.main.select('.' + CLASS.chart).append("g")

4
src/legend.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isDefined, isEmpty, getOption } from './util';
c3_chart_internal_fn.initLegend = function () { c3_chart_internal_fn.initLegend = function () {
var $$ = this; var $$ = this;
$$.legendItemTextBox = {}; $$.legendItemTextBox = {};

4
src/region.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue } from './util';
c3_chart_internal_fn.initRegion = function () { c3_chart_internal_fn.initRegion = function () {
var $$ = this; var $$ = this;
$$.region = $$.main.append('g') $$.region = $$.main.append('g')

2
src/scale.js

@ -1,3 +1,5 @@
import { c3_chart_internal_fn } from './core';
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]); return (forTimeseries ? this.d3.time.scale() : this.d3.scale.linear()).range([min, max]);
}; };

3
src/selection.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.selectPoint = function (target, d, i) { c3_chart_internal_fn.selectPoint = function (target, d, i) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
cx = (config.axis_rotated ? $$.circleY : $$.circleX).bind($$), cx = (config.axis_rotated ? $$.circleY : $$.circleX).bind($$),

4
src/shape.bar.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue } from './util';
c3_chart_internal_fn.initBar = function () { c3_chart_internal_fn.initBar = function () {
var $$ = this; var $$ = this;
$$.main.select('.' + CLASS.chart).append("g") $$.main.select('.' + CLASS.chart).append("g")

4
src/shape.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isUndefined } from './util';
c3_chart_internal_fn.getShapeIndices = function (typeFilter) { c3_chart_internal_fn.getShapeIndices = function (typeFilter) {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
indices = {}, i = 0, j, k; indices = {}, i = 0, j, k;

4
src/shape.line.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue, isFunction, isUndefined, isDefined } from './util';
c3_chart_internal_fn.initLine = function () { c3_chart_internal_fn.initLine = function () {
var $$ = this; var $$ = this;
$$.main.select('.' + CLASS.chart).append("g") $$.main.select('.' + CLASS.chart).append("g")

4
src/size.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue, ceil10 } from './util';
c3_chart_internal_fn.getCurrentWidth = function () { c3_chart_internal_fn.getCurrentWidth = function () {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
return config.size_width ? config.size_width : $$.getParentWidth(); return config.size_width ? config.size_width : $$.getParentWidth();

4
src/subchart.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isFunction } from './util';
c3_chart_internal_fn.initBrush = function () { c3_chart_internal_fn.initBrush = function () {
var $$ = this, d3 = $$.d3; var $$ = this, d3 = $$.d3;
$$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); }); $$.brush = d3.svg.brush().on("brush", function () { $$.redrawForBrush(); });

9
src/tail.js

@ -1,9 +0,0 @@
if (typeof define === 'function' && define.amd) {
define("c3", ["d3"], function () { return c3; });
} else if ('undefined' !== typeof exports && 'undefined' !== typeof module) {
module.exports = c3;
} else {
window.c3 = c3;
}
})(window);

3
src/text.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.initText = function () { c3_chart_internal_fn.initText = function () {
var $$ = this; var $$ = this;
$$.main.select('.' + CLASS.chart).append("g") $$.main.select('.' + CLASS.chart).append("g")

3
src/title.js

@ -1,3 +1,6 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.initTitle = function () { c3_chart_internal_fn.initTitle = function () {
var $$ = this; var $$ = this;
$$.title = $$.svg.append("text") $$.title = $$.svg.append("text")

4
src/tooltip.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { isValue, isString, sanitise } from './util';
c3_chart_internal_fn.initTooltip = function () { c3_chart_internal_fn.initTooltip = function () {
var $$ = this, config = $$.config, i; var $$ = this, config = $$.config, i;
$$.tooltip = $$.selectChart $$.tooltip = $$.selectChart

3
src/type.js

@ -1,3 +1,6 @@
import { c3_chart_internal_fn } from './core';
import { isString } from './util';
c3_chart_internal_fn.setTargetType = function (targetIds, type) { c3_chart_internal_fn.setTargetType = function (targetIds, type) {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
$$.mapToTargetIds(targetIds).forEach(function (id) { $$.mapToTargetIds(targetIds).forEach(function (id) {

2
src/ua.js

@ -1,3 +1,5 @@
import { c3_chart_internal_fn } from './core';
c3_chart_internal_fn.isSafari = function () { c3_chart_internal_fn.isSafari = function () {
var ua = window.navigator.userAgent; var ua = window.navigator.userAgent;
return ua.indexOf('Safari') >= 0 && ua.indexOf('Chrome') < 0; return ua.indexOf('Safari') >= 0 && ua.indexOf('Chrome') < 0;

56
src/util.js

@ -1,47 +1,49 @@
var isValue = c3_chart_internal_fn.isValue = function (v) { import { c3_chart_internal_fn } from './core';
export var isValue = function (v) {
return v || v === 0; return v || v === 0;
}, };
isFunction = c3_chart_internal_fn.isFunction = function (o) { export var isFunction = function (o) {
return typeof o === 'function'; return typeof o === 'function';
}, };
isString = c3_chart_internal_fn.isString = function (o) { export var isString = function (o) {
return typeof o === 'string'; return typeof o === 'string';
}, };
isUndefined = c3_chart_internal_fn.isUndefined = function (v) { export var isUndefined = function (v) {
return typeof v === 'undefined'; return typeof v === 'undefined';
}, };
isDefined = c3_chart_internal_fn.isDefined = function (v) { export var isDefined = function (v) {
return typeof v !== 'undefined'; return typeof v !== 'undefined';
}, };
ceil10 = c3_chart_internal_fn.ceil10 = function (v) { export var ceil10 = function (v) {
return Math.ceil(v / 10) * 10; return Math.ceil(v / 10) * 10;
}, };
asHalfPixel = c3_chart_internal_fn.asHalfPixel = function (n) { export var asHalfPixel = function (n) {
return Math.ceil(n) + 0.5; return Math.ceil(n) + 0.5;
}, };
diffDomain = c3_chart_internal_fn.diffDomain = function (d) { export var diffDomain = function (d) {
return d[1] - d[0]; return d[1] - d[0];
}, };
isEmpty = c3_chart_internal_fn.isEmpty = function (o) { export var isEmpty = function (o) {
return typeof o === 'undefined' || o === null || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); return typeof o === 'undefined' || o === null || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0);
}, };
notEmpty = c3_chart_internal_fn.notEmpty = function (o) { export var notEmpty = function (o) {
return !c3_chart_internal_fn.isEmpty(o); return !c3_chart_internal_fn.isEmpty(o);
}, };
getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { export var getOption = function (options, key, defaultValue) {
return isDefined(options[key]) ? options[key] : defaultValue; return isDefined(options[key]) ? options[key] : defaultValue;
}, };
hasValue = c3_chart_internal_fn.hasValue = function (dict, value) { export var hasValue = function (dict, value) {
var found = false; var found = false;
Object.keys(dict).forEach(function (key) { Object.keys(dict).forEach(function (key) {
if (dict[key] === value) { found = true; } if (dict[key] === value) { found = true; }
}); });
return found; return found;
}, };
sanitise = c3_chart_internal_fn.sanitise = function (str) { export var sanitise = function (str) {
return typeof str === 'string' ? str.replace(/</g, '&lt;').replace(/>/g, '&gt;') : str; return typeof str === 'string' ? str.replace(/</g, '&lt;').replace(/>/g, '&gt;') : str;
}, };
getPathBox = c3_chart_internal_fn.getPathBox = function (path) { export var getPathBox = function (path) {
var box = path.getBoundingClientRect(), var box = path.getBoundingClientRect(),
items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)], items = [path.pathSegList.getItem(0), path.pathSegList.getItem(1)],
minX = items[0].x, minY = Math.min(items[0].y, items[1].y); minX = items[0].x, minY = Math.min(items[0].y, items[1].y);

4
src/zoom.js

@ -1,3 +1,7 @@
import CLASS from './class';
import { c3_chart_internal_fn } from './core';
import { diffDomain } from './util';
c3_chart_internal_fn.initZoom = function () { c3_chart_internal_fn.initZoom = function () {
var $$ = this, d3 = $$.d3, config = $$.config, startEvent; var $$ = this, d3 = $$.d3, config = $$.config, startEvent;

Loading…
Cancel
Save