Browse Source

Update c3.axis.js

On axis labels, allow lines to break on hyphens and slashes as well as spaces.
pull/904/head
Evan Grantham-Brown 10 years ago
parent
commit
9f732a1b1a
  1. 8
      src/c3.axis.js

8
src/c3.axis.js

@ -110,7 +110,7 @@ function c3_axis(d3, params) {
// this should be called only when category axis
function splitTickText(d, maxWidth) {
var tickText = textFormatted(d),
subtext, spaceIndex, textWidth, splitted = [];
subtext, spaceIndex, preserveSpace, textWidth, splitted = [];
if (Object.prototype.toString.call(tickText) === "[object Array]") {
return tickText;
@ -125,13 +125,17 @@ function c3_axis(d3, params) {
for (var i = 1; i < text.length; i++) {
if (text.charAt(i) === ' ') {
spaceIndex = i;
preserveSpace = 0;
} else if (text.charAt(i) === '/' || text.charAt(i) === '-') {
spaceIndex = i;
preserveSpace = 1;
}
subtext = text.substr(0, i + 1);
textWidth = sizeFor1Char.w * subtext.length;
// if text width gets over tick width, split by space index or crrent index
if (maxWidth < textWidth) {
return split(
splitted.concat(text.substr(0, spaceIndex ? spaceIndex : i)),
splitted.concat(text.substr(0, spaceIndex ? spaceIndex + preserveSpace : i)),
text.slice(spaceIndex ? spaceIndex + 1 : i)
);
}

Loading…
Cancel
Save