Commit 735d5b10 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix tick width for non-fit category axis - #726

parent 5533e803
...@@ -6539,7 +6539,7 @@ ...@@ -6539,7 +6539,7 @@
} }
if (!maxWidth || maxWidth <= 0) { if (!maxWidth || maxWidth <= 0) {
maxWidth = isVertical ? 95 : params.isCategory ? (tickOffset * 2 - 10) : 110; maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 10) : 110;
} }
function split(splitted, text) { function split(splitted, text) {
...@@ -6570,7 +6570,7 @@ ...@@ -6570,7 +6570,7 @@
if (orient === 'left' || orient === 'right') { if (orient === 'left' || orient === 'right') {
dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - (params.isCategory ? 2 : 3)); dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - (params.isCategory ? 2 : 3));
} else { } else {
dy = params.isCategory ? ".40em" : ".71em"; dy = ".71em";
} }
} }
return dy; return dy;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -362,7 +362,7 @@ describe('c3 chart axis', function () { ...@@ -362,7 +362,7 @@ describe('c3 chart axis', function () {
ticks.each(function (d, i) { ticks.each(function (d, i) {
var tspans = d3.select(this).selectAll('tspan'), var tspans = d3.select(this).selectAll('tspan'),
expectedX = '0', expectedX = '0',
expectedDy = '.40em'; expectedDy = '.71em';
if (i > 0) { // i === 0 should be checked in next test if (i > 0) { // i === 0 should be checked in next test
expect(tspans.size()).toBe(1); expect(tspans.size()).toBe(1);
tspans.each(function () { tspans.each(function () {
...@@ -390,7 +390,7 @@ describe('c3 chart axis', function () { ...@@ -390,7 +390,7 @@ describe('c3 chart axis', function () {
expect(tspan.attr('x')).toBe(expectedX); expect(tspan.attr('x')).toBe(expectedX);
// unable to define pricise number because it differs depends on environment.. // unable to define pricise number because it differs depends on environment..
if (i === 0) { if (i === 0) {
expect(tspan.attr('dy')).toBe('.40em'); expect(tspan.attr('dy')).toBe('.71em');
} else { } else {
expect(tspan.attr('dy')).toBeGreaterThan(8); expect(tspan.attr('dy')).toBeGreaterThan(8);
} }
......
...@@ -111,7 +111,7 @@ function c3_axis(d3, params) { ...@@ -111,7 +111,7 @@ function c3_axis(d3, params) {
} }
if (!maxWidth || maxWidth <= 0) { if (!maxWidth || maxWidth <= 0) {
maxWidth = isVertical ? 95 : params.isCategory ? (tickOffset * 2 - 10) : 110; maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 10) : 110;
} }
function split(splitted, text) { function split(splitted, text) {
...@@ -142,7 +142,7 @@ function c3_axis(d3, params) { ...@@ -142,7 +142,7 @@ function c3_axis(d3, params) {
if (orient === 'left' || orient === 'right') { if (orient === 'left' || orient === 'right') {
dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - (params.isCategory ? 2 : 3)); dy = -((counts[d.index] - 1) * (sizeFor1Char.h / 2) - (params.isCategory ? 2 : 3));
} else { } else {
dy = params.isCategory ? ".40em" : ".71em"; dy = ".71em";
} }
} }
return dy; return dy;
......
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