From b4c81f015d294adc77ada7decbb403788d8c5f4c Mon Sep 17 00:00:00 2001 From: Toshiki Saito Date: Mon, 26 Dec 2016 18:34:01 +0800 Subject: [PATCH 1/3] Fix : Scale 1.Rotation of scale label when scale is right. 2.Scale position at rotation when scale is top. --- src/core/core.scale.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 06047e4e39a..7c2ce5a7090 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -338,8 +338,13 @@ module.exports = function(Chart) { // Ensure that our ticks are always inside the canvas. When rotated, ticks are right aligned which means that the right padding is dominated // by the font height - me.paddingLeft = me.labelRotation !== 0 ? (cosRotation * firstLabelWidth) + 3 : firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges - me.paddingRight = me.labelRotation !== 0 ? (sinRotation * lineSpace) + 3 : lastLabelWidth / 2 + 3; // when rotated + if (me.labelRotation !== 0) { + me.paddingLeft = opts.position === 'bottom'? (cosRotation * firstLabelWidth) + 3: (cosRotation * lineSpace) + 3; // add 3 px to move away from canvas edges + me.paddingRight = opts.position === 'bottom'? (cosRotation * lineSpace) + 3: (cosRotation * lastLabelWidth) + 3; + } else { + me.paddingLeft = firstLabelWidth / 2 + 3; // add 3 px to move away from canvas edges + me.paddingRight = lastLabelWidth / 2 + 3; + } } else { // A vertical axis is more constrained by the width. Labels are the dominant factor here, so get that length first // Account for padding @@ -578,15 +583,21 @@ module.exports = function(Chart) { var textBaseline = 'middle'; if (isHorizontal) { - if (!isRotated) { - textBaseline = options.position === 'top' ? 'bottom' : 'top'; - } - textAlign = isRotated ? 'right' : 'center'; + if (options.position === 'bottom') { + // bottom + textBaseline = !isRotated? 'top':'middle'; + textAlign = !isRotated? 'center': 'right'; + labelY = isRotated? me.top + tl: me.top + tl; + } else { + // top + textBaseline = !isRotated? 'bottom':'middle'; + textAlign = !isRotated? 'center': 'left'; + labelY = isRotated? me.bottom - tl: me.bottom - tl; + } var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines labelX = me.getPixelForTick(index, gridLines.offsetGridLines) + optionTicks.labelOffset; // x values for optionTicks (need to consider offsetLabel option) - labelY = (isRotated) ? me.top + 12 : options.position === 'top' ? me.bottom - tl : me.top + tl; tx1 = tx2 = x1 = x2 = xLineValue; ty1 = yTickStart; @@ -704,7 +715,7 @@ module.exports = function(Chart) { var isLeft = options.position === 'left'; scaleLabelX = isLeft ? me.left + (scaleLabelFont.size / 2) : me.right - (scaleLabelFont.size / 2); scaleLabelY = me.top + ((me.bottom - me.top) / 2); - rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI; + rotation = -0.5 * Math.PI; } context.save(); From cb9fac99fd49c4569ec74e5cd1117d481c21475b Mon Sep 17 00:00:00 2001 From: Toshiki Saito Date: Fri, 30 Dec 2016 04:36:09 +0800 Subject: [PATCH 2/3] Fix useless code --- src/core/core.scale.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 7c2ce5a7090..1ce9cfa28c3 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -588,12 +588,12 @@ module.exports = function(Chart) { // bottom textBaseline = !isRotated? 'top':'middle'; textAlign = !isRotated? 'center': 'right'; - labelY = isRotated? me.top + tl: me.top + tl; + labelY = me.top + tl; } else { // top textBaseline = !isRotated? 'bottom':'middle'; textAlign = !isRotated? 'center': 'left'; - labelY = isRotated? me.bottom - tl: me.bottom - tl; + labelY = me.bottom - tl; } var xLineValue = me.getPixelForTick(index) + helpers.aliasPixel(lineWidth); // xvalues for grid lines From 272bc832ca75fef16f67a0df048542cb06326696 Mon Sep 17 00:00:00 2001 From: "T.Saito" Date: Thu, 5 Jan 2017 14:47:34 +0800 Subject: [PATCH 3/3] Cancel label rotation. --- src/core/core.scale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 1ce9cfa28c3..b7d04354755 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -715,7 +715,7 @@ module.exports = function(Chart) { var isLeft = options.position === 'left'; scaleLabelX = isLeft ? me.left + (scaleLabelFont.size / 2) : me.right - (scaleLabelFont.size / 2); scaleLabelY = me.top + ((me.bottom - me.top) / 2); - rotation = -0.5 * Math.PI; + rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI; } context.save();