Browse Source

Support TSV - #532

pull/590/head
Masayuki Tanaka 10 years ago
parent
commit
0bf66eef2b
  1. 14
      c3.js
  2. 2
      c3.min.js
  3. 6
      htdocs/data/c3_test.tsv
  4. 13
      htdocs/samples/data_url.html
  5. 14
      src/data.convert.js

14
c3.js

@ -1699,24 +1699,32 @@
var d;
if (type === 'json') {
d = $$.convertJsonToData(JSON.parse(data.response), keys);
} else if (type === 'tsv') {
d = $$.convertTsvToData(data.response);
} else {
d = $$.convertCsvToData(data.response);
}
done.call($$, d);
});
};
c3_chart_internal_fn.convertCsvToData = function (csv) {
var d3 = this.d3, rows = d3.csv.parseRows(csv), d;
c3_chart_internal_fn.convertXsvToData = function (xsv, parser) {
var rows = parser.parseRows(xsv), d;
if (rows.length === 1) {
d = [{}];
rows[0].forEach(function (id) {
d[0][id] = null;
});
} else {
d = d3.csv.parse(csv);
d = parser.parse(xsv);
}
return d;
};
c3_chart_internal_fn.convertCsvToData = function (csv) {
return this.convertXsvToData(csv, this.d3.csv);
};
c3_chart_internal_fn.convertTsvToData = function (tsv) {
return this.convertXsvToData(tsv, this.d3.tsv);
};
c3_chart_internal_fn.convertJsonToData = function (json, keys) {
var $$ = this,
new_rows = [], targetKeys, data;

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

6
htdocs/data/c3_test.tsv

@ -0,0 +1,6 @@
data1 data2 data3
520 380 100
540 350 110
570 400 150
550 370 200
580 420 180
1 data1 data2 data3
2 520 380 100
3 540 350 110
4 570 400 150
5 550 370 200
6 580 420 180

13
htdocs/samples/data_url.html

@ -21,6 +21,13 @@
});
}, 1000);
setTimeout(function () {
chart.load({
url: '/data/c3_test.tsv',
mimeType: 'tsv'
});
}, 2000);
setTimeout(function () {
chart = c3.generate({
data: {
@ -28,14 +35,14 @@
mimeType: 'json'
}
});
}, 2000);
}, 3000);
setTimeout(function () {
chart.load({
url: '/data/c3_test_2.json',
mimeType: 'json'
});
}, 3000);
}, 4000);
setTimeout(function () {
chart.load({
@ -45,7 +52,7 @@
value: ['data1', 'data2']
}
});
}, 4000);
}, 5000);
</script>
</body>

14
src/data.convert.js

@ -4,24 +4,32 @@ c3_chart_internal_fn.convertUrlToData = function (url, mimeType, keys, done) {
var d;
if (type === 'json') {
d = $$.convertJsonToData(JSON.parse(data.response), keys);
} else if (type === 'tsv') {
d = $$.convertTsvToData(data.response);
} else {
d = $$.convertCsvToData(data.response);
}
done.call($$, d);
});
};
c3_chart_internal_fn.convertCsvToData = function (csv) {
var d3 = this.d3, rows = d3.csv.parseRows(csv), d;
c3_chart_internal_fn.convertXsvToData = function (xsv, parser) {
var rows = parser.parseRows(xsv), d;
if (rows.length === 1) {
d = [{}];
rows[0].forEach(function (id) {
d[0][id] = null;
});
} else {
d = d3.csv.parse(csv);
d = parser.parse(xsv);
}
return d;
};
c3_chart_internal_fn.convertCsvToData = function (csv) {
return this.convertXsvToData(csv, this.d3.csv);
};
c3_chart_internal_fn.convertTsvToData = function (tsv) {
return this.convertXsvToData(tsv, this.d3.tsv);
};
c3_chart_internal_fn.convertJsonToData = function (json, keys) {
var $$ = this,
new_rows = [], targetKeys, data;

Loading…
Cancel
Save