Browse Source

Refactor tick char size calculation - #730

pull/742/head
Masayuki Tanaka 10 years ago
parent
commit
9038715730
  1. 4
      c3.js
  2. 2
      c3.min.js
  3. 12
      spec/axis-spec.js
  4. 4
      src/c3.axis.js

4
c3.js

@ -6525,7 +6525,7 @@
tickOffset = tickX = 0; tickOffset = tickX = 0;
} }
var text, tspan, sizeFor1Char = getSizeFor1Char(tick), counts = []; var text, tspan, sizeFor1Char = getSizeFor1Char(g.select('.tick')), counts = [];
var tickLength = Math.max(innerTickSize, 0) + tickPadding, var tickLength = Math.max(innerTickSize, 0) + tickPadding,
isVertical = orient === 'left' || orient === 'right'; isVertical = orient === 'left' || orient === 'right';
@ -6539,7 +6539,7 @@
} }
if (!maxWidth || maxWidth <= 0) { if (!maxWidth || maxWidth <= 0) {
maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 10) : 110; maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 12) : 110;
} }
function split(splitted, text) { function split(splitted, text) {

2
c3.min.js vendored

File diff suppressed because one or more lines are too long

12
spec/axis-spec.js

@ -378,8 +378,8 @@ describe('c3 chart axis', function () {
var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'), var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
tspans = tick.selectAll('tspan'), tspans = tick.selectAll('tspan'),
expectedTickTexts = [ expectedTickTexts = [
'this is a very', 'this is a very long',
'long tick text on', 'tick text on',
'category axis' 'category axis'
], ],
expectedX = '0'; expectedX = '0';
@ -427,8 +427,8 @@ describe('c3 chart axis', function () {
tspans = tick.selectAll('tspan'), tspans = tick.selectAll('tspan'),
expectedTickTexts = [ expectedTickTexts = [
'this is a very long', 'this is a very long',
'tick text on', 'tick text on category',
'category axis' 'axis'
], ],
expectedX = '-9'; expectedX = '-9';
expect(tspans.size()).toBe(3); expect(tspans.size()).toBe(3);
@ -479,8 +479,8 @@ describe('c3 chart axis', function () {
var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'), var tick = chart.internal.main.select('.c3-axis-x').select('g.tick'),
tspans = tick.selectAll('tspan'), tspans = tick.selectAll('tspan'),
expectedTickTexts = [ expectedTickTexts = [
'this is a very long tick text', 'this is a very long tick text on',
'on category axis' 'category axis'
], ],
expectedX = '-9'; expectedX = '-9';
expect(tspans.size()).toBe(2); expect(tspans.size()).toBe(2);

4
src/c3.axis.js

@ -97,7 +97,7 @@ function c3_axis(d3, params) {
tickOffset = tickX = 0; tickOffset = tickX = 0;
} }
var text, tspan, sizeFor1Char = getSizeFor1Char(tick), counts = []; var text, tspan, sizeFor1Char = getSizeFor1Char(g.select('.tick')), counts = [];
var tickLength = Math.max(innerTickSize, 0) + tickPadding, var tickLength = Math.max(innerTickSize, 0) + tickPadding,
isVertical = orient === 'left' || orient === 'right'; isVertical = orient === 'left' || orient === 'right';
@ -111,7 +111,7 @@ function c3_axis(d3, params) {
} }
if (!maxWidth || maxWidth <= 0) { if (!maxWidth || maxWidth <= 0) {
maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 10) : 110; maxWidth = isVertical ? 95 : params.isCategory ? (Math.ceil(scale1(ticks[1]) - scale1(ticks[0])) - 12) : 110;
} }
function split(splitted, text) { function split(splitted, text) {

Loading…
Cancel
Save