From eb8f08be3759947b3767d017c42778e8f885b5ff Mon Sep 17 00:00:00 2001 From: Yeray Alonso Date: Tue, 2 Oct 2018 16:10:06 +0200 Subject: [PATCH 1/2] Closes #2103: Improve axis labels formatting --- src/teechart.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/teechart.js b/src/teechart.js index 060e60d..cefe639 100644 --- a/src/teechart.js +++ b/src/teechart.js @@ -2526,6 +2526,23 @@ function Axis(chart,horizontal,otherSide) { this.maxLabelDepth = 0; + function NumberFormatOptions() { + this.localeMatcher; + this.style; + this.currency; + this.currencyDisplay; + this.useGrouping; + this.minimumIntegerDigits; + this.minimumFractionDigits; + this.maximumFractionDigits; + this.minimumSignificantDigits; + this.maximumSignificantDigits; + } + + function FormatValueOptions() { + this.locales; + this.options = new NumberFormatOptions(); + }; /** * @constructor * @public @@ -2593,10 +2610,14 @@ function Axis(chart,horizontal,otherSide) { this._text=s; } - - this.formatValueString=function(value) - { - if (this.valueFormat){ + this.valueFormat = new FormatValueOptions(); + + this.formatValueString=function(value) { + if (this.valueFormat) { + if ((this.valueFormat.locales) || (this.valueFormat.options)) { + return value.toLocaleString(this.valueFormat.locales, this.valueFormat.options); + } + var DecimalSeparator = Number("1.2").toLocaleString().substr(1,1); var AmountWithCommas = (value * 1).toLocaleString(); @@ -2616,7 +2637,7 @@ function Axis(chart,horizontal,otherSide) { return intPart + DecimalSeparator + decPart; else return intPart; - } + } else return value.toFixed(this.decimals); } From 517cd3745f7463a6baab2caf19245f775675cc68 Mon Sep 17 00:00:00 2001 From: Yeray Alonso Date: Mon, 19 Nov 2018 15:09:27 +0100 Subject: [PATCH 2/2] Just some indentation to better understand what's happening --- src/teechart.js | 120 +++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 63 deletions(-) diff --git a/src/teechart.js b/src/teechart.js index cefe639..1e3e49e 100644 --- a/src/teechart.js +++ b/src/teechart.js @@ -1898,59 +1898,57 @@ Tee.ToolTip=function(chart) { var redraw=function(args) { if (args) args[0].hide(); } - this.mousemove=function(p) { - var li=this.chart.series, len=li.count(), ser=null, index=-1; + this.mousemove=function(p) { + var li=this.chart.series, len=li.count(), ser=null, index=-1; if (this.chart.chartRect.contains(p)) - for (var t=len-1; t>=0; t--) { - var s=li.items[t]; + for (var t=len-1; t>=0; t--) { + var s=li.items[t]; - if (s.visible) { - index=s.clicked(p); + if (s.visible) { + index=s.clicked(p); if ((index == -1) && (s.continuous)) { - index = Math.round(this.chart.axes.bottom.fromSizeCalcIndex(p.x-this.chart.axes.bottom.startPos)); - var distance, oldDistance; - for (var n = 0; n < len; n++) { - distance = Math.abs(li.items[n].data.values[index] - this.chart.axes.left.fromPos(p.y)); - if (n == 0) { - oldDistance = distance; - s = li.items[n]; - } - else if(distance 0)) { - clearTimeout(this.timID); - this.timID=window.setTimeout(redraw, this.delay, [this]); + if (this.autoHide && (this.delay > 0)) { + clearTimeout(this.timID); + this.timID=window.setTimeout(redraw, this.delay, [this]); + } } } - } } var o=null; @@ -2649,36 +2647,33 @@ function Axis(chart,horizontal,otherSide) { var v=trunc(value), s, data; if (this._text && (v==value)) { - data=this._text.data; if (data.x) v=data.x.indexOf(v); - - var li=chart.series.items, t, ser; + var li=chart.series.items, t, ser; - //specific case: check for non-std sideAll labelling - if ((li.length > 0) && (li[0] instanceof Tee.Bar) + //specific case: check for non-std sideAll labelling + if ((li.length > 0) && (li[0] instanceof Tee.Bar) && (li[0].stacked == "sideAll")) { - s= data.labels[value]; - } - else { - s= data.labels[v]; - } - - // Last resort, try to find labels from any series in axis: + s= data.labels[value]; + } + else { + s= data.labels[v]; + } - if (!s) { - for(t=0; ser=li[t++];) - if (ser!=this._text) { - if (ser.visible && ser.associatedToAxis(axis)) { - s=ser.data.labels[v]; - if (s) break; - } - } + // Last resort, try to find labels from any series in axis: + if (!s) { + for(t=0; ser=li[t++];) + if (ser!=this._text) { + if (ser.visible && ser.associatedToAxis(axis)) { + s=ser.data.labels[v]; + if (s) break; + } + } - if (s === undefined) + if (s === undefined) s=""; - } + } } else if (axis.dateTime) { @@ -3384,7 +3379,7 @@ function Axis(chart,horizontal,otherSide) { } this.drawLabels=function() { - var v=this.roundMin(), r=new Rectangle(), c=this.axisPos, l=this.labels; + var v=this.roundMin(), r=new Rectangle(), c=this.axisPos, l=this.labels; //var v=(this.minimum