Browse Source

Merge branch 'master' of https://github.com/masayuki0812/c3 into domain

Conflicts:
	c3.min.js
pull/603/head
michalkop93 10 years ago
parent
commit
9eb8420547
  1. 79
      c3.js
  2. 8
      c3.min.js
  3. 2
      package.json
  4. 90
      spec/axis-spec.js
  5. 12
      spec/c3-helper.js
  6. 100
      spec/shape.bar-spec.js
  7. 43
      src/axis.js
  8. 6
      src/config.js
  9. 11
      src/core.js
  10. 10
      src/scale.js
  11. 9
      src/shape.bar.js

79
c3.js

@ -460,7 +460,7 @@
$$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain); $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain);
// update axis tick values according to options // update axis tick values according to options
if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) { if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) {
tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count); tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries());
$$.xAxis.tickValues(tickValues); $$.xAxis.tickValues(tickValues);
$$.subXAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues);
} }
@ -472,6 +472,15 @@
$$.y.domain($$.getYDomain(targetsToShow, 'y')); $$.y.domain($$.getYDomain(targetsToShow, 'y'));
$$.y2.domain($$.getYDomain(targetsToShow, 'y2')); $$.y2.domain($$.getYDomain(targetsToShow, 'y2'));
if (!config.axis_y_tick_values && config.axis_y_tick_count) {
tickValues = $$.generateTickValues($$.y.domain(), config.axis_y_tick_count);
$$.yAxis.tickValues(tickValues);
}
if (!config.axis_y2_tick_values && config.axis_y2_tick_count) {
tickValues = $$.generateTickValues($$.y2.domain(), config.axis_y2_tick_count);
$$.y2Axis.tickValues(tickValues);
}
// axes // axes
$$.redrawAxis(transitions, hideAxis); $$.redrawAxis(transitions, hideAxis);
@ -974,8 +983,9 @@
axis_y_label: {}, axis_y_label: {},
axis_y_tick_format: undefined, axis_y_tick_format: undefined,
axis_y_tick_outer: true, axis_y_tick_outer: true,
axis_y_tick_values: null,
axis_y_tick_count: undefined,
axis_y_padding: {}, axis_y_padding: {},
axis_y_ticks: 10,
axis_y_default: undefined, axis_y_default: undefined,
axis_y2_show: false, axis_y2_show: false,
axis_y2_max: undefined, axis_y2_max: undefined,
@ -984,8 +994,9 @@
axis_y2_label: {}, axis_y2_label: {},
axis_y2_tick_format: undefined, axis_y2_tick_format: undefined,
axis_y2_tick_outer: true, axis_y2_tick_outer: true,
axis_y2_tick_values: null,
axis_y2_tick_count: undefined,
axis_y2_padding: {}, axis_y2_padding: {},
axis_y2_ticks: 10,
axis_y2_default: undefined, axis_y2_default: undefined,
// grid // grid
grid_x_show: false, grid_x_show: false,
@ -1155,11 +1166,15 @@
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain()); $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain());
// update axes // update axes
$$.xAxisTickFormat = $$.getXAxisTickFormat(); $$.xAxisTickFormat = $$.getXAxisTickFormat();
$$.xAxisTickValues = config.axis_x_tick_values ? config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxisTickValues = $$.getXAxisTickValues();
$$.yAxisTickValues = $$.getYAxisTickValues();
$$.y2AxisTickValues = $$.getY2AxisTickValues();
$$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.yAxis = $$.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, config.axis_y_ticks, config.axis_y_tick_outer); $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, config.axis_y_tick_outer);
$$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, config.axis_y2_ticks, config.axis_y2_tick_outer); $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, config.axis_y2_tick_outer);
// Set initialized scales to brush and zoom // Set initialized scales to brush and zoom
if (!forInit) { if (!forInit) {
if ($$.brush) { $$.brush.scale($$.subX); } if ($$.brush) { $$.brush.scale($$.subX); }
@ -2955,11 +2970,12 @@
]; ];
}; };
}; };
c3_chart_internal_fn.isWithinBar = function (_this) { c3_chart_internal_fn.isWithinBar = function (that) {
var d3 = this.d3, var d3 = this.d3,
mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), mouse = d3.mouse(that), box = that.getBoundingClientRect(),
seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), seg0 = that.pathSegList.getItem(0), seg1 = that.pathSegList.getItem(1),
x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, x = Math.min(seg0.x, seg1.x), y = Math.min(seg0.y, seg1.y),
w = box.width, h = box.height, offset = 2,
sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset;
return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy;
}; };
@ -3832,9 +3848,9 @@
return axis; return axis;
}; };
c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks, 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).ticks(ticks); 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;
@ -3854,6 +3870,18 @@
} }
return isFunction(format) ? function (v) { return format.call($$, v); } : format; return isFunction(format) ? function (v) { return format.call($$, v); } : format;
}; };
c3_chart_internal_fn.getAxisTickValues = function (tickValues, axis) {
return tickValues ? tickValues : axis ? axis.tickValues() : undefined;
};
c3_chart_internal_fn.getXAxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_x_tick_values, this.xAxis);
};
c3_chart_internal_fn.getYAxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_y_tick_values, this.yAxis);
};
c3_chart_internal_fn.getY2AxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_y2_tick_values, this.y2Axis);
};
c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) {
var $$ = this, config = $$.config, option; var $$ = this, config = $$.config, option;
if (axisId === 'y') { if (axisId === 'y') {
@ -4021,13 +4049,13 @@
targetsToShow = $$.filterTargetsToShow($$.data.targets); targetsToShow = $$.filterTargetsToShow($$.data.targets);
if (id === 'y') { if (id === 'y') {
scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y'));
axis = $$.getYAxis(scale, $$.yOrient, config.axis_y_tick_format, config.axis_y_ticks); axis = $$.getYAxis(scale, $$.yOrient, config.axis_y_tick_format, $$.getYAxisTickValues());
} else if (id === 'y2') { } else if (id === 'y2') {
scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2'));
axis = $$.getYAxis(scale, $$.y2Orient, config.axis_y2_tick_format, config.axis_y2_ticks); axis = $$.getYAxis(scale, $$.y2Orient, config.axis_y2_tick_format, $$.getY2AxisTickValues());
} else { } else {
scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); scale = $$.x.copy().domain($$.getXDomain(targetsToShow));
axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config.axis_x_tick_values ? config.axis_x_tick_values : $$.xAxis.tickValues()); axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), $$.getXAxisTickValues());
} }
$$.d3.select('body').append("g").style('visibility', 'hidden').call(axis).each(function () { $$.d3.select('body').append("g").style('visibility', 'hidden').call(axis).each(function () {
$$.d3.select(this).selectAll('text').each(function () { $$.d3.select(this).selectAll('text').each(function () {
@ -4067,31 +4095,30 @@
return isValue(padding[key]) ? padding[key] * ratio : defaultValue; return isValue(padding[key]) ? padding[key] * ratio : defaultValue;
}; };
c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { c3_chart_internal_fn.generateTickValues = function (values, tickCount, forTimeSeries) {
var $$ = this; var tickValues = values, targetCount, start, end, count, interval, i, tickValue;
var tickValues = xs, targetCount, start, end, count, interval, i, tickValue;
if (tickCount) { if (tickCount) {
targetCount = isFunction(tickCount) ? tickCount() : tickCount; targetCount = isFunction(tickCount) ? tickCount() : tickCount;
// compute ticks according to $$.config.axis_x_tick_count // compute ticks according to tickCount
if (targetCount === 1) { if (targetCount === 1) {
tickValues = [xs[0]]; tickValues = [values[0]];
} else if (targetCount === 2) { } else if (targetCount === 2) {
tickValues = [xs[0], xs[xs.length - 1]]; tickValues = [values[0], values[values.length - 1]];
} else if (targetCount > 2) { } else if (targetCount > 2) {
count = targetCount - 2; count = targetCount - 2;
start = xs[0]; start = values[0];
end = xs[xs.length - 1]; end = values[values.length - 1];
interval = (end - start) / (count + 1); interval = (end - start) / (count + 1);
// re-construct uniqueXs // re-construct unique values
tickValues = [start]; tickValues = [start];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
tickValue = +start + interval * (i + 1); tickValue = +start + interval * (i + 1);
tickValues.push($$.isTimeSeries() ? new Date(tickValue) : tickValue); tickValues.push(forTimeSeries ? new Date(tickValue) : tickValue);
} }
tickValues.push(end); tickValues.push(end);
} }
} }
if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } if (!forTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); }
return tickValues; return tickValues;
}; };
c3_chart_internal_fn.generateAxisTransitions = function (duration) { c3_chart_internal_fn.generateAxisTransitions = function (duration) {

8
c3.min.js vendored

File diff suppressed because one or more lines are too long

2
package.json

@ -23,7 +23,7 @@
"grunt": "~0.4.1", "grunt": "~0.4.1",
"grunt-contrib-concat": "~0.5.0", "grunt-contrib-concat": "~0.5.0",
"grunt-contrib-cssmin": "^0.10.0", "grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-jasmine": "~0.5.2", "grunt-contrib-jasmine": "~0.8.0",
"grunt-contrib-jshint": "~0.7.1", "grunt-contrib-jshint": "~0.7.1",
"grunt-contrib-uglify": "~0.4.0", "grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "^0.6.1", "grunt-contrib-watch": "^0.6.1",

90
spec/axis-spec.js

@ -0,0 +1,90 @@
var describe = window.describe,
expect = window.expect,
it = window.it,
beforeEach = window.beforeEach;
describe('c3 chart axis', function () {
'use strict';
var chart, d3;
var args = {
data: {
columns: [
['data1', 30, 200, 100, 400, 150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', 150, 120, 110, 140, 115, 125]
]
},
axis: {
y: {
tick: {
values: null,
count: undefined
}
},
y2: {
tick: {
values: null,
count: undefined
}
}
}
};
beforeEach(function () {
window.initDom();
chart = window.c3.generate(args);
d3 = chart.internal.d3;
});
describe('axis.y.tick.count', function () {
var i = 1;
beforeEach(function () {
args.axis.y.tick.count = i++;
chart = window.c3.generate(args);
});
it('should have only 1 tick on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(1);
});
it('should have 2 ticks on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(2);
});
it('should have 3 ticks on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(3);
});
});
describe('axis.y.tick.values', function () {
var values = [100, 500];
beforeEach(function () {
args.axis.y.tick.values = values;
chart = window.c3.generate(args);
});
it('should have only 2 tick on y axis', function () {
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size();
expect(ticksSize).toBe(2);
});
it('should have specified tick texts', function () {
d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) {
var text = d3.select(this).select('text').text();
expect(+text).toBe(values[i]);
});
});
});
});

12
spec/c3-helper.js

@ -9,3 +9,15 @@ function initDom() {
document.body.style.margin = '0px'; document.body.style.margin = '0px';
} }
typeof initDom !== 'undefined'; typeof initDom !== 'undefined';
function setEvent(chart, x, y) {
'use strict';
var paddingLeft = chart.internal.main.node().transform.baseVal.getItem(0).matrix.e,
evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, x + paddingLeft, y + 5,
false, false, false, false, 0, null);
chart.internal.d3.event = evt;
}
typeof setEvent !== 'undefined';

100
spec/shape.bar-spec.js

@ -0,0 +1,100 @@
var describe = window.describe,
expect = window.expect,
it = window.it,
beforeEach = window.beforeEach;
var initDom = window.initDom,
setEvent = window.setEvent;
describe('c3 chart shape bar', function () {
'use strict';
var chart, d3;
var args = {
data: {
columns: [
['data1', 30, 200, 100, 400, -150, 250],
['data2', 50, 20, 10, 40, 15, 25],
['data3', -150, 120, 110, 140, 115, 125]
],
type: 'bar'
},
axis: {
rotated: false
}
};
beforeEach(function (done) {
if (typeof chart === 'undefined') {
initDom();
}
chart = window.c3.generate(args);
d3 = chart.internal.d3;
chart.internal.d3.select('.jasmine_html-reporter').style('display', 'none');
window.setTimeout(function () {
done();
}, 10);
});
describe('internal.isWithinBar', function () {
describe('with normal axis', function () {
it('should not be within bar', function () {
var bar = d3.select('.c3-target-data1 .c3-bar-0').node();
setEvent(chart, 0, 0);
expect(chart.internal.isWithinBar(bar)).toBeFalsy();
});
it('should be within bar', function () {
var bar = d3.select('.c3-target-data1 .c3-bar-0').node();
setEvent(chart, 31, 280);
expect(chart.internal.isWithinBar(bar)).toBeTruthy();
});
it('should not be within bar of negative value', function () {
var bar = d3.select('.c3-target-data3 .c3-bar-0').node();
setEvent(chart, 68, 280);
expect(chart.internal.isWithinBar(bar)).toBeFalsy();
});
it('should be within bar of negative value', function () {
var bar = d3.select('.c3-target-data3 .c3-bar-0').node();
setEvent(chart, 68, 350);
expect(chart.internal.isWithinBar(bar)).toBeTruthy();
});
});
describe('with rotated axis', function () {
it('should change the chart as axis rotated', function () {
args.axis.rotated = true;
expect(true).toBeTruthy();
});
it('should not be within bar', function () {
var bar = d3.select('.c3-target-data1 .c3-bar-0').node();
setEvent(chart, 0, 0);
expect(chart.internal.isWithinBar(bar)).toBeFalsy();
});
it('should be within bar', function () {
var bar = d3.select('.c3-target-data1 .c3-bar-0').node();
setEvent(chart, 190, 20);
expect(chart.internal.isWithinBar(bar)).toBeTruthy();
});
it('should be within bar of negative value', function () {
var bar = d3.select('.c3-target-data3 .c3-bar-0').node();
setEvent(chart, 68, 50);
expect(chart.internal.isWithinBar(bar)).toBeTruthy();
});
});
});
});

43
src/axis.js

@ -58,9 +58,9 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
return axis; return axis;
}; };
c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, ticks, 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).ticks(ticks); 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;
@ -80,6 +80,18 @@ c3_chart_internal_fn.getXAxisTickFormat = function () {
} }
return isFunction(format) ? function (v) { return format.call($$, v); } : format; return isFunction(format) ? function (v) { return format.call($$, v); } : format;
}; };
c3_chart_internal_fn.getAxisTickValues = function (tickValues, axis) {
return tickValues ? tickValues : axis ? axis.tickValues() : undefined;
};
c3_chart_internal_fn.getXAxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_x_tick_values, this.xAxis);
};
c3_chart_internal_fn.getYAxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_y_tick_values, this.yAxis);
};
c3_chart_internal_fn.getY2AxisTickValues = function () {
return this.getAxisTickValues(this.config.axis_y2_tick_values, this.y2Axis);
};
c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) { c3_chart_internal_fn.getAxisLabelOptionByAxisId = function (axisId) {
var $$ = this, config = $$.config, option; var $$ = this, config = $$.config, option;
if (axisId === 'y') { if (axisId === 'y') {
@ -247,13 +259,13 @@ c3_chart_internal_fn.getMaxTickWidth = function (id) {
targetsToShow = $$.filterTargetsToShow($$.data.targets); targetsToShow = $$.filterTargetsToShow($$.data.targets);
if (id === 'y') { if (id === 'y') {
scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y')); scale = $$.y.copy().domain($$.getYDomain(targetsToShow, 'y'));
axis = $$.getYAxis(scale, $$.yOrient, config.axis_y_tick_format, config.axis_y_ticks); axis = $$.getYAxis(scale, $$.yOrient, config.axis_y_tick_format, $$.getYAxisTickValues());
} else if (id === 'y2') { } else if (id === 'y2') {
scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2')); scale = $$.y2.copy().domain($$.getYDomain(targetsToShow, 'y2'));
axis = $$.getYAxis(scale, $$.y2Orient, config.axis_y2_tick_format, config.axis_y2_ticks); axis = $$.getYAxis(scale, $$.y2Orient, config.axis_y2_tick_format, $$.getY2AxisTickValues());
} else { } else {
scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); scale = $$.x.copy().domain($$.getXDomain(targetsToShow));
axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), config.axis_x_tick_values ? config.axis_x_tick_values : $$.xAxis.tickValues()); axis = $$.getXAxis(scale, $$.xOrient, $$.getXAxisTickFormat(), $$.getXAxisTickValues());
} }
$$.d3.select('body').append("g").style('visibility', 'hidden').call(axis).each(function () { $$.d3.select('body').append("g").style('visibility', 'hidden').call(axis).each(function () {
$$.d3.select(this).selectAll('text').each(function () { $$.d3.select(this).selectAll('text').each(function () {
@ -293,31 +305,30 @@ c3_chart_internal_fn.getAxisPadding = function (padding, key, defaultValue, all)
return isValue(padding[key]) ? padding[key] * ratio : defaultValue; return isValue(padding[key]) ? padding[key] * ratio : defaultValue;
}; };
c3_chart_internal_fn.generateTickValues = function (xs, tickCount) { c3_chart_internal_fn.generateTickValues = function (values, tickCount, forTimeSeries) {
var $$ = this; var tickValues = values, targetCount, start, end, count, interval, i, tickValue;
var tickValues = xs, targetCount, start, end, count, interval, i, tickValue;
if (tickCount) { if (tickCount) {
targetCount = isFunction(tickCount) ? tickCount() : tickCount; targetCount = isFunction(tickCount) ? tickCount() : tickCount;
// compute ticks according to $$.config.axis_x_tick_count // compute ticks according to tickCount
if (targetCount === 1) { if (targetCount === 1) {
tickValues = [xs[0]]; tickValues = [values[0]];
} else if (targetCount === 2) { } else if (targetCount === 2) {
tickValues = [xs[0], xs[xs.length - 1]]; tickValues = [values[0], values[values.length - 1]];
} else if (targetCount > 2) { } else if (targetCount > 2) {
count = targetCount - 2; count = targetCount - 2;
start = xs[0]; start = values[0];
end = xs[xs.length - 1]; end = values[values.length - 1];
interval = (end - start) / (count + 1); interval = (end - start) / (count + 1);
// re-construct uniqueXs // re-construct unique values
tickValues = [start]; tickValues = [start];
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
tickValue = +start + interval * (i + 1); tickValue = +start + interval * (i + 1);
tickValues.push($$.isTimeSeries() ? new Date(tickValue) : tickValue); tickValues.push(forTimeSeries ? new Date(tickValue) : tickValue);
} }
tickValues.push(end); tickValues.push(end);
} }
} }
if (!$$.isTimeSeries()) { tickValues = tickValues.sort(function (a, b) { return a - b; }); } if (!forTimeSeries) { tickValues = tickValues.sort(function (a, b) { return a - b; }); }
return tickValues; return tickValues;
}; };
c3_chart_internal_fn.generateAxisTransitions = function (duration) { c3_chart_internal_fn.generateAxisTransitions = function (duration) {

6
src/config.js

@ -104,8 +104,9 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_y_label: {}, axis_y_label: {},
axis_y_tick_format: undefined, axis_y_tick_format: undefined,
axis_y_tick_outer: true, axis_y_tick_outer: true,
axis_y_tick_values: null,
axis_y_tick_count: undefined,
axis_y_padding: {}, axis_y_padding: {},
axis_y_ticks: 10,
axis_y_default: undefined, axis_y_default: undefined,
axis_y2_show: false, axis_y2_show: false,
axis_y2_max: undefined, axis_y2_max: undefined,
@ -114,8 +115,9 @@ c3_chart_internal_fn.getDefaultConfig = function () {
axis_y2_label: {}, axis_y2_label: {},
axis_y2_tick_format: undefined, axis_y2_tick_format: undefined,
axis_y2_tick_outer: true, axis_y2_tick_outer: true,
axis_y2_tick_values: null,
axis_y2_tick_count: undefined,
axis_y2_padding: {}, axis_y2_padding: {},
axis_y2_ticks: 10,
axis_y2_default: undefined, axis_y2_default: undefined,
// grid // grid
grid_x_show: false, grid_x_show: false,

11
src/core.js

@ -455,7 +455,7 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain); $$.updateXDomain(targetsToShow, withUpdateXDomain, withUpdateOrgXDomain, withTrimXDomain);
// update axis tick values according to options // update axis tick values according to options
if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) { if (!config.axis_x_tick_values && (config.axis_x_tick_fit || config.axis_x_tick_count)) {
tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count); tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targetsToShow), config.axis_x_tick_count, $$.isTimeSeries());
$$.xAxis.tickValues(tickValues); $$.xAxis.tickValues(tickValues);
$$.subXAxis.tickValues(tickValues); $$.subXAxis.tickValues(tickValues);
} }
@ -467,6 +467,15 @@ c3_chart_internal_fn.redraw = function (options, transitions) {
$$.y.domain($$.getYDomain(targetsToShow, 'y')); $$.y.domain($$.getYDomain(targetsToShow, 'y'));
$$.y2.domain($$.getYDomain(targetsToShow, 'y2')); $$.y2.domain($$.getYDomain(targetsToShow, 'y2'));
if (!config.axis_y_tick_values && config.axis_y_tick_count) {
tickValues = $$.generateTickValues($$.y.domain(), config.axis_y_tick_count);
$$.yAxis.tickValues(tickValues);
}
if (!config.axis_y2_tick_values && config.axis_y2_tick_count) {
tickValues = $$.generateTickValues($$.y2.domain(), config.axis_y2_tick_count);
$$.y2Axis.tickValues(tickValues);
}
// axes // axes
$$.redrawAxis(transitions, hideAxis); $$.redrawAxis(transitions, hideAxis);

10
src/scale.js

@ -70,11 +70,15 @@ c3_chart_internal_fn.updateScales = function () {
$$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain()); $$.subY2 = $$.getY($$.subYMin, $$.subYMax, forInit ? config.axis_y2_default : $$.subY2.domain());
// update axes // update axes
$$.xAxisTickFormat = $$.getXAxisTickFormat(); $$.xAxisTickFormat = $$.getXAxisTickFormat();
$$.xAxisTickValues = config.axis_x_tick_values ? config.axis_x_tick_values : (forInit ? undefined : $$.xAxis.tickValues()); $$.xAxisTickValues = $$.getXAxisTickValues();
$$.yAxisTickValues = $$.getYAxisTickValues();
$$.y2AxisTickValues = $$.getY2AxisTickValues();
$$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.xAxis = $$.getXAxis($$.x, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer); $$.subXAxis = $$.getXAxis($$.subX, $$.subXOrient, $$.xAxisTickFormat, $$.xAxisTickValues, config.axis_x_tick_outer);
$$.yAxis = $$.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, config.axis_y_ticks, config.axis_y_tick_outer); $$.yAxis = $$.getYAxis($$.y, $$.yOrient, config.axis_y_tick_format, $$.yAxisTickValues, config.axis_y_tick_outer);
$$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, config.axis_y2_ticks, config.axis_y2_tick_outer); $$.y2Axis = $$.getYAxis($$.y2, $$.y2Orient, config.axis_y2_tick_format, $$.y2AxisTickValues, config.axis_y2_tick_outer);
// Set initialized scales to brush and zoom // Set initialized scales to brush and zoom
if (!forInit) { if (!forInit) {
if ($$.brush) { $$.brush.scale($$.subX); } if ($$.brush) { $$.brush.scale($$.subX); }

9
src/shape.bar.js

@ -111,11 +111,12 @@ c3_chart_internal_fn.generateGetBarPoints = function (barIndices, isSub) {
]; ];
}; };
}; };
c3_chart_internal_fn.isWithinBar = function (_this) { c3_chart_internal_fn.isWithinBar = function (that) {
var d3 = this.d3, var d3 = this.d3,
mouse = d3.mouse(_this), box = _this.getBoundingClientRect(), mouse = d3.mouse(that), box = that.getBoundingClientRect(),
seg0 = _this.pathSegList.getItem(0), seg1 = _this.pathSegList.getItem(1), seg0 = that.pathSegList.getItem(0), seg1 = that.pathSegList.getItem(1),
x = seg0.x, y = Math.min(seg0.y, seg1.y), w = box.width, h = box.height, offset = 2, x = Math.min(seg0.x, seg1.x), y = Math.min(seg0.y, seg1.y),
w = box.width, h = box.height, offset = 2,
sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset; sx = x - offset, ex = x + w + offset, sy = y + h + offset, ey = y - offset;
return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy; return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy;
}; };

Loading…
Cancel
Save