From 9f732a1b1aaeea81bed6adaae6365dbfca08da50 Mon Sep 17 00:00:00 2001 From: Evan Grantham-Brown Date: Fri, 16 Jan 2015 17:05:31 -0500 Subject: [PATCH] Update c3.axis.js On axis labels, allow lines to break on hyphens and slashes as well as spaces. --- src/c3.axis.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/c3.axis.js b/src/c3.axis.js index 5c7601c..6a21aa6 100644 --- a/src/c3.axis.js +++ b/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) ); }