diff --git a/js/Axis.js b/js/Axis.js index 7ce6a3ed..627983aa 100644 --- a/js/Axis.js +++ b/js/Axis.js @@ -174,7 +174,7 @@ Axis.prototype = { this.maxLabel = T.dimensions( maxLabel, {size:options.fontSize, angle: Flotr.toRad(this.options.labelsAngle)}, - 'font-size:smaller;', + 'font-size:' + this.options.fontSize + ';', 'flotr-grid-label' ); diff --git a/js/DefaultOptions.js b/js/DefaultOptions.js index 1a1681da..9a45b428 100644 --- a/js/DefaultOptions.js +++ b/js/DefaultOptions.js @@ -20,6 +20,7 @@ Flotr.defaultOptions = { showLabels: true, // => setting to true will show the axis ticks labels, hide otherwise showMinorLabels: false,// => true to show the axis minor ticks labels, false to hide labelsAngle: 0, // => labels' angle, in degrees + fontSize: 'smaller', // => font size of the xaxis labels title: null, // => axis title titleAngle: 0, // => axis title's angle, in degrees noTicks: 5, // => number of ticks for automagically generated ticks @@ -47,6 +48,7 @@ Flotr.defaultOptions = { showLabels: true, // => setting to true will show the axis ticks labels, hide otherwise showMinorLabels: false,// => true to show the axis minor ticks labels, false to hide labelsAngle: 0, // => labels' angle, in degrees + fontSize: 'smaller', // => font size of the xaxis labels - should be a string title: null, // => axis title titleAngle: 90, // => axis title's angle, in degrees noTicks: 5, // => number of ticks for automagically generated ticks diff --git a/js/plugins/labels.js b/js/plugins/labels.js index 8e016c8f..278b3771 100644 --- a/js/plugins/labels.js +++ b/js/plugins/labels.js @@ -13,20 +13,14 @@ Flotr.addPlugin('labels', { draw: function(){ // Construct fixed width label boxes, which can be styled easily. var - axis, tick, left, top, xBoxWidth, + axis, tick, left, top, radius, sides, coeff, angle, div, i, html = '', - noLabels = 0, options = this.options, ctx = this.ctx, a = this.axes, style = { size: options.fontSize }; - for (i = 0; i < a.x.ticks.length; ++i){ - if (a.x.ticks[i].label) { ++noLabels; } - } - xBoxWidth = this.plotWidth / noLabels; - if (options.grid.circular) { ctx.save(); ctx.translate(this.plotOffset.left + this.plotWidth / 2, @@ -67,14 +61,6 @@ Flotr.addPlugin('labels', { ctx.stroke(); ctx.restore(); - div = D.create('div'); - D.setStyles(div, { - fontSize: 'smaller', - color: options.grid.color - }); - div.className = 'flotr-labels'; - D.insert(this.el, div); - D.insert(div, html); } function drawLabelCircular (graph, axis, minorTicks) { @@ -175,7 +161,8 @@ Flotr.addPlugin('labels', { isFirst = axis.n === 1, name = '', left, style, top, - offset = graph.plotOffset; + offset = graph.plotOffset, + i, xBoxWidth, noLabels = 0; if (!isX && !isFirst) { ctx.save(); @@ -184,16 +171,21 @@ Flotr.addPlugin('labels', { } if (axis.options.showLabels && (isFirst ? true : axis.used)) { + for (i = 0; i < axis.ticks.length; ++i){ + if (axis.ticks[i].label) { ++noLabels; } + } + xBoxWidth = graph.plotWidth / noLabels; + for (i = 0; i < axis.ticks.length; ++i) { tick = axis.ticks[i]; if (!tick.label || !tick.label.length || - ((isX ? offset.left : offset.top) + axis.d2p(tick.v) < 0) || - ((isX ? offset.left : offset.top) + axis.d2p(tick.v) > (isX ? graph.canvasWidth : graph.canvasHeight))) { + ((isX ? offset.left : offset.top) + axis.d2p(tick.v) < (isX ? (offset.left + options.grid.labelMargin) : 0)) || + ((isX ? offset.left : offset.top) + axis.d2p(tick.v) > (isX ? graph.canvasWidth - offset.right - ctx.measureText(tick.label).width : graph.canvasHeight))) { continue; } top = offset.top + (isX ? - ((isFirst ? 1 : -1 ) * (graph.plotHeight + options.grid.labelMargin)) : + (options.grid.labelMargin + (isFirst ? graph.plotHeight : 0)) : axis.d2p(tick.v) - axis.maxLabel.height / 2); left = isX ? (offset.left + axis.d2p(tick.v) - xBoxWidth / 2) : 0; @@ -219,6 +211,15 @@ Flotr.addPlugin('labels', { ctx.lineTo(offset.left + graph.plotWidth, offset.top + axis.d2p(tick.v)); } } + var div = D.create('div'); + D.setStyles(div, { + fontSize: axis.options.fontSize, + color: options.grid.color + }); + div.className = 'flotr-labels'; + D.insert(graph.el, div); + D.insert(div, html); + html = ''; } } }