Browse Source

Fix y axis timeseries - #703

pull/713/merge
Masayuki Tanaka 10 years ago
parent
commit
c42899d0dc
  1. 27
      c3.js
  2. 10
      c3.min.js
  3. 36
      spec/axis-spec.js
  4. 12
      src/axis.js
  5. 6
      src/config.js
  6. 7
      src/core.js
  7. 2
      src/scale.js

27
c3.js

@ -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 @@
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 @@
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 @@
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 @@
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;

10
c3.min.js vendored

File diff suppressed because one or more lines are too long

36
spec/axis-spec.js

@ -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 () {
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 () {

12
src/axis.js

@ -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;

6
src/config.js

@ -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,

7
src/core.js

@ -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 () {
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') {

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, this.isYaxisTimeSeries()); var scale = this.getScale(min, max, this.isTimeSeriesY());
if (domain) { scale.domain(domain); } if (domain) { scale.domain(domain); }
return scale; return scale;
}; };

Loading…
Cancel
Save