Skip to content

Commit

Permalink
#23: Added axis-x-type to bit-c3 to config chart with axis; c3-data-c…
Browse files Browse the repository at this point in the history
…olumn can accept axis-x for axis data
  • Loading branch information
ilyavf committed May 10, 2017
1 parent 425d8e4 commit 59d4458
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import ChartVM from './viewmodel';
*
* ```html
* <bit-c3></bit-c3>
*
* <bit-c3 axis-x-type="category"></bit-c3>
* ```
*/
Component.extend({
Expand All @@ -31,14 +33,25 @@ Component.extend({
events: {
inserted: function(viewModel, ev) {
var rootElement = ev.target,
graphBaseElement = d3.select(rootElement.getElementsByClassName('chart-container')[0]),
chart = c3.generate({
bindto: graphBaseElement,
data: {
columns: []
graphBaseElement = d3.select(rootElement.getElementsByClassName('chart-container')[0]),
axisXType = this.viewModel.attr('axisXType'),
config = {
bindto: graphBaseElement,
data: {
columns: []
}
};

if (axisXType){
config.data.x = 'x';
config.axis = {
x: {
type: axisXType
}
});
this.viewModel.chart = chart;
}
}

this.viewModel.chart = c3.generate(config);
},
removed: function() {
if (this.viewModel.chart){
Expand Down
9 changes: 9 additions & 0 deletions src/data/column/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ import canViewModel from 'can-view-model';
* </bit-c3-data>
* </bit-c3>
* ```
*
* With axis-x (`axis-x-type` must be defined fir `bit-c3`):
* ```html
* <bit-c3>
* <bit-c3-data>
* <bit-c3-data-column key="dataSet1" value="[1, 2, 3]" axis-x="['x','cat 1','cat 2','cat 3']" />
* </bit-c3-data>
* </bit-c3>
* ```
*/
Component.extend({
tag: "bit-c3-data-column",
Expand Down
9 changes: 7 additions & 2 deletions src/data/column/viewmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ export default DefineMap.extend({seal: false}, {
var value = this.dequeueKey(this.value),
key = this.key,
chart = this.chart,
pushing = [key].concat(value);
pushing = [key].concat(value),
columns = [pushing];

if (this.attr('axisX')){
columns.unshift(this.attr('axisX').attr());
}
if(value && value.length) {
chart.load({
columns: [pushing]
columns: columns
});
} else {
this.unloadColumn();
Expand Down

0 comments on commit 59d4458

Please sign in to comment.