Skip to content

Commit 713abda

Browse files
committed
fix: new log system using Trace so that it can removed in production
1 parent 20e2322 commit 713abda

9 files changed

+105
-52
lines changed

src/charting/charts/BarLineChartBase.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Canvas, Matrix, Paint, RectF, Style } from '@nativescript-community/ui-canvas';
2-
import { EventData, Observable, profile } from '@nativescript/core';
2+
import { EventData, Observable, Trace, profile } from '@nativescript/core';
33
import { getEventOrGestureName } from '@nativescript/core/ui/core/bindable';
44
import { GestureTypes } from '@nativescript/core/ui/gestures';
55
import { LegendHorizontalAlignment, LegendOrientation, LegendVerticalAlignment } from '../components/Legend';
@@ -18,7 +18,7 @@ import { BarLineChartTouchListener } from '../listener/BarLineChartTouchListener
1818
import { XAxisRenderer } from '../renderer/XAxisRenderer';
1919
import { YAxisRenderer } from '../renderer/YAxisRenderer';
2020
import { Transformer } from '../utils/Transformer';
21-
import { Utils } from '../utils/Utils';
21+
import { CLog, CLogTypes, Utils } from '../utils/Utils';
2222
import { Chart } from './Chart';
2323

2424
const LOG_TAG = 'BarLineChartBase';
@@ -263,12 +263,12 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
263263
this.drawMarkers(canvas);
264264

265265
this.notify({ eventName: 'drawn', object: this });
266-
if (this.mLogEnabled) {
266+
if (Trace.isEnabled()) {
267267
const drawtime = Date.now() - startTime;
268268
this.totalTime += drawtime;
269269
this.drawCycles += 1;
270270
const average = this.totalTime / this.drawCycles;
271-
console.log(this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
271+
CLog(CLogTypes.log, this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
272272
}
273273
}
274274

@@ -281,8 +281,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
281281
}
282282

283283
protected prepareValuePxMatrix() {
284-
if (this.mLogEnabled) {
285-
console.log(LOG_TAG, 'Preparing Value-Px Matrix, xmin: ' + this.mXAxis.mAxisMinimum + ', xmax: ' + this.mXAxis.mAxisMaximum + ', xdelta: ' + this.mXAxis.mAxisRange);
284+
if (Trace.isEnabled()) {
285+
CLog(CLogTypes.info, LOG_TAG, 'Preparing Value-Px Matrix, xmin: ' + this.mXAxis.mAxisMinimum + ', xmax: ' + this.mXAxis.mAxisMaximum + ', xdelta: ' + this.mXAxis.mAxisRange);
286286
}
287287
if (this.mAxisRight.isEnabled()) {
288288
this.mRightAxisTransformer.prepareMatrixValuePx(this.mXAxis.mAxisMinimum, this.mXAxis.mAxisRange, this.mAxisRight.mAxisRange, this.mAxisRight.mAxisMinimum);
@@ -303,18 +303,18 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
303303

304304
public notifyDataSetChanged() {
305305
if (this.mData == null) {
306-
if (this.mLogEnabled) {
307-
console.log(LOG_TAG, 'Preparing... DATA NOT SET.');
306+
if (Trace.isEnabled()) {
307+
CLog(CLogTypes.info, LOG_TAG, 'Preparing... DATA NOT SET.');
308308
}
309309
return;
310310
} else if (!this.mViewPortHandler.hasChartDimens()) {
311-
if (this.mLogEnabled) {
312-
console.log(LOG_TAG, 'Preparing... NOT SIZED YET.');
311+
if (Trace.isEnabled()) {
312+
CLog(CLogTypes.info, LOG_TAG, 'Preparing... NOT SIZED YET.');
313313
}
314314
return;
315315
} else {
316-
if (this.mLogEnabled) {
317-
console.log(LOG_TAG, 'Preparing...');
316+
if (Trace.isEnabled()) {
317+
CLog(CLogTypes.info, LOG_TAG, 'Preparing...');
318318
}
319319
}
320320

@@ -480,8 +480,8 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
480480

481481
this.mViewPortHandler.restrainViewPort(Math.max(minOffset, offsetLeft), Math.max(minOffset, offsetTop), Math.max(minOffset, offsetRight), Math.max(minOffset, offsetBottom));
482482

483-
if (this.mLogEnabled) {
484-
console.log(LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
483+
if (Trace.isEnabled()) {
484+
CLog(CLogTypes.info, LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
485485
console.log(LOG_TAG, 'Content: ' + this.mViewPortHandler.getContentRect().toString());
486486
}
487487
}

src/charting/charts/Chart.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ChartData } from '../data/ChartData';
55
import { ChartInterface } from '../interfaces/dataprovider/ChartInterface';
66
import { Align, Canvas, CanvasView, Paint } from '@nativescript-community/ui-canvas';
77
import { DefaultValueFormatter } from '../formatter/DefaultValueFormatter';
8-
import { Utils } from '../utils/Utils';
8+
import { CLog, CLogTypes, Utils } from '../utils/Utils';
99
import { Color } from '@nativescript/core/color';
1010
import { Highlight } from '../highlight/Highlight';
1111
import { Legend } from '../components/Legend';
@@ -21,7 +21,7 @@ import { ChartAnimator, EasingFunction } from '../animation/ChartAnimator';
2121
import { ViewPortJob } from '../jobs/ViewPortJob';
2222
import { ChartTouchListener } from '../listener/ChartTouchListener';
2323
import { layout } from '@nativescript/core/utils/utils';
24-
import { EventData } from '@nativescript/core';
24+
import { EventData, Trace } from '@nativescript/core';
2525
import { addWeakEventListener, removeWeakEventListener } from '@nativescript/core/ui/core/weak-event-listener';
2626

2727
const LOG_TAG = 'NSChart';
@@ -217,7 +217,9 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
217217
this.mInfoPaint.setTextAlign(Align.CENTER);
218218
this.mInfoPaint.setTextSize(12);
219219

220-
if (this.mLogEnabled) console.log('', 'Chart.init()');
220+
if (Trace.isEnabled()) {
221+
CLog(CLogTypes.log, this.constructor.name, 'init()');
222+
}
221223
}
222224

223225
/**
@@ -528,8 +530,6 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
528530
if (high == null) {
529531
this.mIndicesToHighlight = null;
530532
} else {
531-
// if (this.mLogEnabled) console.log(LOG_TAG, 'Highlighted', high);
532-
533533
e = this.mData.getEntryForHighlight(high);
534534
if (e == null) {
535535
this.mIndicesToHighlight = null;
@@ -901,6 +901,7 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
901901
* Set this to true to enable logcat outputs for the chart. Beware that
902902
* logcat output decreases rendering performance. Default: disabled.
903903
*
904+
* @deprecated use Nativescript Trace with ChartTraceCategory
904905
* @param enabled
905906
*/
906907
public setLogEnabled(enabled) {
@@ -910,6 +911,7 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
910911
/**
911912
* Returns true if log-output is enabled for the chart, fals if not.
912913
*
914+
* @deprecated use Nativescript Trace with ChartTraceCategory
913915
* @return
914916
*/
915917
public isLogEnabled() {
@@ -1403,13 +1405,19 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
14031405

14041406
onSetWidthHeight(w: number, h: number) {
14051407
const needsDataSetChanged = !this.mViewPortHandler.hasChartDimens();
1406-
if (this.mLogEnabled) console.log(LOG_TAG, 'OnSizeChanged', w, h, needsDataSetChanged);
1408+
if (Trace.isEnabled()) {
1409+
CLog(CLogTypes.info, LOG_TAG, 'OnSizeChanged', w, h, needsDataSetChanged);
1410+
}
14071411

14081412
if (w > 0 && h > 0 && h < 10000 && h < 10000) {
1409-
if (this.mLogEnabled) console.log(LOG_TAG, 'Setting chart dimens, width: ' + w + ', height: ' + h);
1413+
if (Trace.isEnabled()) {
1414+
CLog(CLogTypes.info, LOG_TAG, 'Setting chart dimens, width: ' + w + ', height: ' + h);
1415+
}
14101416
this.mViewPortHandler.setChartDimens(w, h);
14111417
} else {
1412-
console.warn(LOG_TAG, '*Avoiding* setting chart dimens! width: ' + w + ', height: ' + h);
1418+
if (Trace.isEnabled()) {
1419+
CLog(CLogTypes.warning, LOG_TAG, '*Avoiding* setting chart dimens! width: ' + w + ', height: ' + h);
1420+
}
14131421
}
14141422

14151423
// This may cause the chart view to mutate properties affecting the view port --

src/charting/charts/HorizontalBarChart.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import { YAxisRendererHorizontalBarChart } from '../renderer/YAxisRendererHorizo
1313
import { XAxisRendererHorizontalBarChart } from '../renderer/XAxisRendererHorizontalBarChart';
1414
import { HorizontalViewPortHandler } from '../utils/HorizontalViewPortHandler';
1515
import { TransformerHorizontalBarChart } from '../utils/TransformerHorizontalBarChart';
16-
import { Utils } from '../utils/Utils';
16+
import { CLog, CLogTypes, Utils } from '../utils/Utils';
1717
import { RectF } from '@nativescript-community/ui-canvas';
1818
import { getEntryXValue } from '../data/BaseEntry';
19+
import { Trace } from '@nativescript/core';
1920

2021
const LOG_TAG = 'HorizontalBarChart';
2122

@@ -84,8 +85,8 @@ export class HorizontalBarChart extends BarChart {
8485

8586
this.mViewPortHandler.restrainViewPort(Math.max(minOffset, offsetLeft), Math.max(minOffset, offsetTop), Math.max(minOffset, offsetRight), Math.max(minOffset, offsetBottom));
8687

87-
if (this.mLogEnabled) {
88-
console.log(LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
88+
if (Trace.isEnabled()) {
89+
CLog(CLogTypes.info, LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
8990
console.log(LOG_TAG, 'Content: ' + this.mViewPortHandler.getContentRect().toString());
9091
}
9192

@@ -179,8 +180,8 @@ export class HorizontalBarChart extends BarChart {
179180

180181
public getHighlightByTouchPoint(x, y): Highlight {
181182
if (this.mData == null) {
182-
if (this.mLogEnabled) {
183-
console.error(LOG_TAG, "Can't select by touch. No data set.");
183+
if (Trace.isEnabled()) {
184+
CLog(CLogTypes.error, LOG_TAG, "Can't select by touch. No data set.");
184185
}
185186
return null;
186187
}

src/charting/charts/PieChart.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { PieHighlighter } from '../highlight/PieHighlighter';
77
import { Highlight } from '../highlight/Highlight';
88
import { PieChartRenderer } from '../renderer/PieChartRenderer';
99
import { MPPointF } from '../utils/MPPointF';
10-
import { Utils } from '../utils/Utils';
10+
import { CLog, CLogTypes, Utils } from '../utils/Utils';
1111
import { Font } from '@nativescript/core/ui/styling/font';
1212
import { Canvas, Paint, Path, RectF } from '@nativescript-community/ui-canvas';
13+
import { Trace } from '@nativescript/core';
1314

1415
const LOG_TAG = 'PieChart';
1516

@@ -132,12 +133,12 @@ export class PieChart extends PieRadarChartBase<Entry, PieDataSet, PieData> {
132133
this.drawDescription(canvas);
133134
this.drawMarkers(canvas);
134135
this.notify({ eventName: 'drawn', object: this });
135-
if (this.mLogEnabled) {
136+
if (Trace.isEnabled()) {
136137
const drawtime = Date.now() - startTime;
137138
this.totalTime += drawtime;
138139
this.drawCycles += 1;
139140
const average = this.totalTime / this.drawCycles;
140-
console.log(this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
141+
CLog(CLogTypes.log, this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
141142
}
142143
}
143144

src/charting/charts/PieRadarChartBase.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ export abstract class PieRadarChartBase<U extends Entry, D extends IDataSet<U>,
198198

199199
this.mViewPortHandler.restrainViewPort(offsetLeft, offsetTop, offsetRight, offsetBottom);
200200

201-
if (this.mLogEnabled) console.log(LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
201+
if (Trace.isEnabled()) {
202+
CLog(CLogTypes.info, LOG_TAG, 'offsetLeft: ' + offsetLeft + ', offsetTop: ' + offsetTop + ', offsetRight: ' + offsetRight + ', offsetBottom: ' + offsetBottom);
203+
}
202204
}
203205

204206
/**

src/charting/charts/RadarChart.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Canvas, Paint } from '@nativescript-community/ui-canvas';
2-
import { Color } from '@nativescript/core';
2+
import { Color, Trace } from '@nativescript/core';
33
import { PieRadarChartBase } from './PieRadarChartBase';
44
import { AxisDependency, YAxis } from '../components/YAxis';
55
import { RadarData } from '../data/RadarData';
@@ -9,7 +9,7 @@ import { RadarHighlighter } from '../highlight/RadarHighlighter';
99
import { RadarChartRenderer } from '../renderer/RadarChartRenderer';
1010
import { XAxisRendererRadarChart } from '../renderer/XAxisRendererRadarChart';
1111
import { YAxisRendererRadarChart } from '../renderer/YAxisRendererRadarChart';
12-
import { Utils } from '../utils/Utils';
12+
import { CLog, CLogTypes, Utils } from '../utils/Utils';
1313
import { Highlight } from '../highlight/Highlight';
1414

1515
const LOG_TAG = 'RadarChart';
@@ -113,7 +113,7 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
113113
if (this.mXAxis.isEnabled()) {
114114
this.mXAxisRenderer.computeAxis(this.mXAxis.mAxisMinimum, this.mXAxis.mAxisMaximum, false);
115115
this.mXAxisRenderer.renderAxisLabels(c);
116-
};
116+
}
117117

118118
if (this.mDrawWeb) this.mRenderer.drawExtras(c);
119119

@@ -123,7 +123,7 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
123123

124124
if (this.valuesToHighlight()) this.mRenderer.drawHighlighted(c, this.mIndicesToHighlight);
125125

126-
if (this.mYAxis.isEnabled() && !this.mYAxis.isDrawLimitLinesBehindDataEnabled()){
126+
if (this.mYAxis.isEnabled() && !this.mYAxis.isDrawLimitLinesBehindDataEnabled()) {
127127
this.mYAxisRenderer.renderLimitLines(c);
128128
this.mYAxisRenderer.renderAxisLabels(c);
129129
}
@@ -137,12 +137,12 @@ export class RadarChart extends PieRadarChartBase<Entry, RadarDataSet, RadarData
137137
this.drawMarkers(c);
138138

139139
this.notify({ eventName: 'drawn', object: this });
140-
if (this.mLogEnabled) {
140+
if (Trace.isEnabled()) {
141141
const drawtime = Date.now() - startTime;
142142
this.totalTime += drawtime;
143143
this.drawCycles += 1;
144144
const average = this.totalTime / this.drawCycles;
145-
console.log(this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
145+
CLog(CLogTypes.log, this.constructor.name, 'Drawtime: ' + drawtime + ' ms, average: ' + average + ' ms, cycles: ' + this.drawCycles);
146146
}
147147
}
148148

src/charting/charts/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export { CandleStickChart } from './CandleStickChart';
99
export { CombinedChart } from './CombinedChart';
1010
import { install as installGestures } from '@nativescript-community/gesturehandler';
1111

12+
export { ChartTraceCategory } from '../utils/utils';
1213
export function install() {
1314
installGestures();
1415
}

0 commit comments

Comments
 (0)