Browse Source

Fix load API to accept unload without input - #342

pull/373/merge
Masayuki Tanaka 11 years ago
parent
commit
cc0e2babdd
  1. 15
      c3.js
  2. 4
      c3.min.js
  3. 104
      htdocs/samples/data_load.html

15
c3.js

@ -4476,24 +4476,23 @@
}
}
function loadFromArgs(args) {
// load data
if ('data' in args) {
if (args.data) {
load(convertDataToTargets(args.data), args);
}
else if ('url' in args) {
else if (args.url) {
d3.csv(args.url, function (error, data) {
load(convertDataToTargets(data), args);
});
}
else if ('rows' in 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 ('columns' in args) {
else if (args.columns) {
load(convertDataToTargets(convertColumnsToData(args.columns)), args);
}
else {
throw Error('url or rows or columns is required.');
}
}
function unload(targetIds, done) {

4
c3.min.js vendored

File diff suppressed because one or more lines are too long

104
htdocs/samples/data_load.html

@ -8,6 +8,7 @@
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
var chart = c3.generate({
data: {
url: '/data/c3_test.csv',
@ -27,36 +28,19 @@
}
});
setTimeout(function () {
var queue = [
function () {
chart.load({
url: '/data/c3_test2.csv',
filter: function (t) {
return t.id !== 'data1';
}
});
}, 1000);
setTimeout(function () {
// chart.unload(['data1', 'data2']);
// chart.unload('data1');
chart.unload('data2');
}, 2000);
setTimeout(function () {
chart.load({
columns: [
['data1@test', 30, 20, 50, 40, 60, 50],
],
unload: true,
// unload: ['data2', 'data3'],
// unload: ['data2']
});
}, 3000);
setTimeout(function () {
},
function () {
chart.load({
rows: [
['data1@test', 'data2', 'data3'],
['data4', 'data5', 'data6'],
[90, 120, 300],
[40, 160, 240],
[50, 200, 290],
@ -65,36 +49,57 @@
[90, 220, 320],
]
});
}, 4000);
setTimeout(function () {
},
function () {
chart.unload(['data4', 'data5']);
},
function () {
chart.unload('data6');
},
function () {
chart.load({
columns:[
['data1', 30, 20, 50, 40, 60, 50,100,200]
['data1', 30, 20, 50, 40, 60, 50, 100, 200],
['data7', 230, 220, 250, 240, 260, 250, 300, 400]
]
});
}, 5000);
setTimeout(function () {
chart.unload('data1@test');
}, 6000);
setTimeout(function () {
},
function () {
chart.load({
columns:[
['data2', null, 30, 20, 50, 40, 60, 50]
]
json: {
data1: [1030, 1020, 1050, 1040, 1060, 1050, 1100, 1200],
data7: [430, 420, 450, 440, 460, 550, 400, 200]
}
});
}, 7000);
setTimeout(function () {
},
function () {
chart.load({
columns: [
['data8', 30, 20, 50, 40, 60, 50],
],
unload: true,
});
},
function () {
chart.load({
columns: [
['data9', 130, 120, 150, 140, 160, 150],
],
unload: ['data7', 'data8'],
});
},
function () {
chart.load({
unload: ['data1', 'data2'],
});
},
function () {
chart.unload();
}, 8000);
setTimeout(function () {
},
function () {
chart.load({
rows: [
['data1@test', 'data2', 'data3'],
['data1', 'data2', 'data3'],
[90, 120, 300],
[40, 160, 240],
[50, 200, 290],
@ -103,11 +108,16 @@
[90, 220, 320],
]
});
}, 9000);
setTimeout(function () {
},
function () {
chart.unload(['data2', 'data3']);
}, 10000);
},
];
var i = 0;
queue.forEach(function (f) {
setTimeout(f, 1500 * i++);
});
</script>
</body>

Loading…
Cancel
Save