Browse Source

Merge branch 'master' of https://github.com/w-green/c3 into w-green-master

pull/713/merge
Masayuki Tanaka 10 years ago
parent
commit
0b6b69f11d
  1. 18
      c3.js
  2. 46
      spec/axis-spec.js
  3. 8
      src/axis.js
  4. 5
      src/config.js
  5. 3
      src/core.js
  6. 2
      src/scale.js

18
c3.js

@ -657,6 +657,9 @@
c3_chart_internal_fn.isTimeSeries = function () { c3_chart_internal_fn.isTimeSeries = function () {
return this.config.axis_x_type === 'timeseries'; return this.config.axis_x_type === 'timeseries';
}; };
c3_chart_internal_fn.isYaxisTimeSeries = function () {
return this.config.axis_y_type === 'timeseries';
};
c3_chart_internal_fn.isCategorized = function () { c3_chart_internal_fn.isCategorized = function () {
return this.config.axis_x_type.indexOf('categor') >= 0; return this.config.axis_x_type.indexOf('categor') >= 0;
}; };
@ -996,6 +999,7 @@
axis_x_extent: undefined, axis_x_extent: undefined,
axis_x_label: {}, axis_x_label: {},
axis_y_show: true, axis_y_show: true,
axis_y_type: undefined,
axis_y_max: undefined, axis_y_max: undefined,
axis_y_min: undefined, axis_y_min: undefined,
axis_y_center: undefined, axis_y_center: undefined,
@ -1004,6 +1008,10 @@
axis_y_tick_outer: true, axis_y_tick_outer: true,
axis_y_tick_values: null, axis_y_tick_values: null,
axis_y_tick_count: undefined, axis_y_tick_count: undefined,
axis_y_ticks: {},
axis_y_ticks_time: {},
axis_y_ticks_time_value: undefined,
axis_y_ticks_time_interval: undefined,
axis_y_padding: {}, axis_y_padding: {},
axis_y_default: undefined, axis_y_default: undefined,
axis_y2_show: false, axis_y2_show: false,
@ -1156,7 +1164,7 @@
return scale; return scale;
}; };
c3_chart_internal_fn.getY = function (min, max, domain) { c3_chart_internal_fn.getY = function (min, max, domain) {
var scale = this.getScale(min, max); var scale = this.getScale(min, max, this.isYaxisTimeSeries());
if (domain) { scale.domain(domain); } if (domain) { scale.domain(domain); }
return scale; return scale;
}; };
@ -3982,7 +3990,13 @@
}; };
c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) { c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) {
var axisParams = {withOuterTick: withOuterTick}; var axisParams = {withOuterTick: withOuterTick};
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues); if (this.isYaxisTimeSeries()) {
var timeValue = this.config.axis_y_ticks_time_value;
var timeInterval = this.config.axis_y_ticks_time_interval;
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).ticks(this.d3.time[timeValue], timeInterval);
} else {
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues);
}
}; };
c3_chart_internal_fn.getAxisId = function (id) { c3_chart_internal_fn.getAxisId = function (id) {
var config = this.config; var config = this.config;

46
spec/axis-spec.js

@ -86,6 +86,52 @@ describe('c3 chart axis', function () {
}); });
describe('axis y timeseries', function () {
var args = {
data: {
columns: [
["times", 60000, 120000, 180000, 240000]
]
},
axis: {
y: {
type : 'timeseries',
tick: {
values: null,
count: undefined,
},
ticks : {
time : {
value : 'seconds',
interval : 30
}
},
},
}
};
beforeEach(function () {
chart = window.c3.generate(args);
});
it('should have 7 ticks on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(7); // the count starts at initial value and increments by the set interval
});
it('should have specified 30 second intervals', function () {
var prevValue;
d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) {
if (i !== 0) {
var result = d - prevValue;
expect(result).toEqual(30000); // expressed in milliseconds
}
prevValue = d;
});
});
});
describe('axis.x.tick.width', function () { describe('axis.x.tick.width', function () {
describe('indexed x axis and y/y2 axis', function () { describe('indexed x axis and y/y2 axis', function () {

8
src/axis.js

@ -65,7 +65,13 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
}; };
c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) { c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) {
var axisParams = {withOuterTick: withOuterTick}; var axisParams = {withOuterTick: withOuterTick};
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues); if (this.isYaxisTimeSeries()) {
var timeValue = this.config.axis_y_ticks_time_value;
var timeInterval = this.config.axis_y_ticks_time_interval;
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).ticks(this.d3.time[timeValue], timeInterval);
} else {
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues);
}
}; };
c3_chart_internal_fn.getAxisId = function (id) { c3_chart_internal_fn.getAxisId = function (id) {
var config = this.config; var config = this.config;

5
src/config.js

@ -101,6 +101,7 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_x_extent: undefined, axis_x_extent: undefined,
axis_x_label: {}, axis_x_label: {},
axis_y_show: true, axis_y_show: true,
axis_y_type: undefined,
axis_y_max: undefined, axis_y_max: undefined,
axis_y_min: undefined, axis_y_min: undefined,
axis_y_center: undefined, axis_y_center: undefined,
@ -109,6 +110,10 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_y_tick_outer: true, axis_y_tick_outer: true,
axis_y_tick_values: null, axis_y_tick_values: null,
axis_y_tick_count: undefined, axis_y_tick_count: undefined,
axis_y_ticks: {},
axis_y_ticks_time: {},
axis_y_ticks_time_value: undefined,
axis_y_ticks_time_interval: undefined,
axis_y_padding: {}, axis_y_padding: {},
axis_y_default: undefined, axis_y_default: undefined,
axis_y2_show: false, axis_y2_show: false,

3
src/core.js

@ -652,6 +652,9 @@ c3_chart_internal_fn.updateAndRedraw = function (options) {
c3_chart_internal_fn.isTimeSeries = function () { c3_chart_internal_fn.isTimeSeries = function () {
return this.config.axis_x_type === 'timeseries'; return this.config.axis_x_type === 'timeseries';
}; };
c3_chart_internal_fn.isYaxisTimeSeries = function () {
return this.config.axis_y_type === 'timeseries';
};
c3_chart_internal_fn.isCategorized = function () { c3_chart_internal_fn.isCategorized = function () {
return this.config.axis_x_type.indexOf('categor') >= 0; return this.config.axis_x_type.indexOf('categor') >= 0;
}; };

2
src/scale.js

@ -39,7 +39,7 @@ c3_chart_internal_fn.getX = function (min, max, domain, offset) {
return scale; return scale;
}; };
c3_chart_internal_fn.getY = function (min, max, domain) { c3_chart_internal_fn.getY = function (min, max, domain) {
var scale = this.getScale(min, max); var scale = this.getScale(min, max, this.isYaxisTimeSeries());
if (domain) { scale.domain(domain); } if (domain) { scale.domain(domain); }
return scale; return scale;
}; };

Loading…
Cancel
Save