Commit c42899d0 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix y axis timeseries - #703

parent 0e37a5b2
...@@ -657,9 +657,6 @@ ...@@ -657,9 +657,6 @@
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;
}; };
...@@ -668,6 +665,10 @@ ...@@ -668,6 +665,10 @@
return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs)); return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
}; };
c3_chart_internal_fn.isTimeSeriesY = function () {
return this.config.axis_y_type === 'timeseries';
};
c3_chart_internal_fn.getTranslate = function (target) { c3_chart_internal_fn.getTranslate = function (target) {
var $$ = this, config = $$.config, x, y; var $$ = this, config = $$.config, x, y;
if (target === 'main') { if (target === 'main') {
...@@ -1008,10 +1009,8 @@ ...@@ -1008,10 +1009,8 @@
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_tick_time_value: undefined,
axis_y_ticks_time: {}, axis_y_tick_time_interval: undefined,
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,
...@@ -1164,7 +1163,7 @@ ...@@ -1164,7 +1163,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, this.isYaxisTimeSeries()); var scale = this.getScale(min, max, this.isTimeSeriesY());
if (domain) { scale.domain(domain); } if (domain) { scale.domain(domain); }
return scale; return scale;
}; };
...@@ -3989,14 +3988,14 @@ ...@@ -3989,14 +3988,14 @@
return axis; return axis;
}; };
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},
if (this.isYaxisTimeSeries()) { axis = c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat);
var timeValue = this.config.axis_y_ticks_time_value; if (this.isTimeSeriesY()) {
var timeInterval = this.config.axis_y_ticks_time_interval; axis.ticks(this.d3.time[this.config.axis_y_tick_time_value], this.config.axis_y_tick_time_interval);
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).ticks(this.d3.time[timeValue], timeInterval);
} else { } else {
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues); axis.tickValues(tickValues);
} }
return axis;
}; };
c3_chart_internal_fn.getAxisId = function (id) { c3_chart_internal_fn.getAxisId = function (id) {
var config = this.config; var config = this.config;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -98,16 +98,10 @@ describe('c3 chart axis', function () { ...@@ -98,16 +98,10 @@ describe('c3 chart axis', function () {
y: { y: {
type : 'timeseries', type : 'timeseries',
tick: { tick: {
values: null, time: {
count: undefined,
},
ticks : {
time : {
value : 'seconds',
interval : 30
} }
}, }
}, }
} }
}; };
...@@ -130,6 +124,30 @@ describe('c3 chart axis', function () { ...@@ -130,6 +124,30 @@ describe('c3 chart axis', function () {
prevValue = d; prevValue = d;
}); });
}); });
it('should update args to set axis.y.time', function () {
args.axis.y.tick.time = {
value : 'seconds',
interval : 60
};
expect(true).toBeTruthy();
});
it('should have 4 ticks on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(4); // the count starts at initial value and increments by the set interval
});
it('should have specified 60 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(60000); // expressed in milliseconds
}
prevValue = d;
});
});
}); });
describe('axis.x.tick.width', function () { describe('axis.x.tick.width', function () {
......
...@@ -64,14 +64,14 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues, ...@@ -64,14 +64,14 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
return axis; return axis;
}; };
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},
if (this.isYaxisTimeSeries()) { axis = c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat);
var timeValue = this.config.axis_y_ticks_time_value; if (this.isTimeSeriesY()) {
var timeInterval = this.config.axis_y_ticks_time_interval; axis.ticks(this.d3.time[this.config.axis_y_tick_time_value], this.config.axis_y_tick_time_interval);
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).ticks(this.d3.time[timeValue], timeInterval);
} else { } else {
return c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat).tickValues(tickValues); axis.tickValues(tickValues);
} }
return axis;
}; };
c3_chart_internal_fn.getAxisId = function (id) { c3_chart_internal_fn.getAxisId = function (id) {
var config = this.config; var config = this.config;
......
...@@ -110,10 +110,8 @@ c3_chart_internal_fn.getDefaultConfig = function () { ...@@ -110,10 +110,8 @@ 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_tick_time_value: undefined,
axis_y_ticks_time: {}, axis_y_tick_time_interval: undefined,
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,
......
...@@ -652,9 +652,6 @@ c3_chart_internal_fn.updateAndRedraw = function (options) { ...@@ -652,9 +652,6 @@ 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;
}; };
...@@ -663,6 +660,10 @@ c3_chart_internal_fn.isCustomX = function () { ...@@ -663,6 +660,10 @@ c3_chart_internal_fn.isCustomX = function () {
return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs)); return !$$.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
}; };
c3_chart_internal_fn.isTimeSeriesY = function () {
return this.config.axis_y_type === 'timeseries';
};
c3_chart_internal_fn.getTranslate = function (target) { c3_chart_internal_fn.getTranslate = function (target) {
var $$ = this, config = $$.config, x, y; var $$ = this, config = $$.config, x, y;
if (target === 'main') { if (target === 'main') {
......
...@@ -39,7 +39,7 @@ c3_chart_internal_fn.getX = function (min, max, domain, offset) { ...@@ -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, this.isYaxisTimeSeries()); var scale = this.getScale(min, max, this.isTimeSeriesY());
if (domain) { scale.domain(domain); } if (domain) { scale.domain(domain); }
return scale; return scale;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment