Browse Source

Add type and types param to load API

pull/155/head
Masayuki Tanaka 11 years ago
parent
commit
a4805bcb51
  1. 22
      c3.js
  2. 4
      c3.min.js

22
c3.js

@ -3537,7 +3537,13 @@
.style("opacity", 1); .style("opacity", 1);
} }
function load(targets, done) { function load(targets, args) {
// 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 // Update/Add data
c3.data.targets.forEach(function (d) { c3.data.targets.forEach(function (d) {
for (var i = 0; i < targets.length; i++) { for (var i = 0; i < targets.length; i++) {
@ -3556,23 +3562,25 @@
// Redraw with new targets // Redraw with new targets
redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true}); redraw({withUpdateOrgXDomain: true, withUpdateXDomain: true, withLegend: true});
if (typeof done === 'function') { done(); } if (typeof args.done === 'function') {
args.done();
}
} }
function loadFromArgs(args) { function loadFromArgs(args) {
// load data // load data
if ('data' in args) { if ('data' in args) {
load(convertDataToTargets(args.data), args.done); load(convertDataToTargets(args.data), args);
} }
else if ('url' in args) { else if ('url' in args) {
d3.csv(args.url, function (error, data) { d3.csv(args.url, function (error, data) {
load(convertDataToTargets(data), args.done); load(convertDataToTargets(data), args);
}); });
} }
else if ('rows' in args) { else if ('rows' in args) {
load(convertDataToTargets(convertRowsToData(args.rows)), args.done); load(convertDataToTargets(convertRowsToData(args.rows)), args);
} }
else if ('columns' in args) { else if ('columns' in args) {
load(convertDataToTargets(convertColumnsToData(args.columns)), args.done); load(convertDataToTargets(convertColumnsToData(args.columns)), args);
} }
else { else {
throw Error('url or rows or columns is required.'); throw Error('url or rows or columns is required.');
@ -3907,7 +3915,7 @@
}; };
c3.load = function (args) { c3.load = function (args) {
// update xs if exists // update xs if specified
if (args.xs) { if (args.xs) {
addXs(args.xs); addXs(args.xs);
} }

4
c3.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save