Skip to content

Commit 663ea99

Browse files
committed
fix: a few fixes
1 parent d982eab commit 663ea99

File tree

8 files changed

+64
-44
lines changed

8 files changed

+64
-44
lines changed

src/charting/charts/Chart.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { profile } from '@nativescript/core/profiling/profiling';
1919
import { ChartAnimator } from '../animation/ChartAnimator';
2020
import { ViewPortJob } from '../jobs/ViewPortJob';
2121
import { ChartTouchListener } from '../listener/ChartTouchListener';
22-
import { isIOS } from '@nativescript/core/platform';
22+
import { isAndroid, isIOS } from '@nativescript/core/platform';
23+
import { layout } from '@nativescript/core/utils/utils';
2324

2425
const LOG_TAG = 'NSChart';
2526

@@ -110,7 +111,7 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
110111
/**
111112
* text that is displayed when the chart is empty
112113
*/
113-
private mNoDataText = 'No chart data available.';
114+
private mNoDataText = null;
114115

115116
/**
116117
* Gesture listener for custom callbacks when making gestures on the chart.
@@ -1544,17 +1545,15 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
15441545
// this.onSizeChanged(this.getMeasuredWidth(), this.getMeasuredHeight());
15451546
// }
15461547

1547-
public onSizeChanged(w: number, h: number, oldw: number, oldh: number): void {
1548-
super.onSizeChanged(w, h, oldw, oldh);
1549-
// super.setMeasuredDimension(measuredWidth, measuredHeight);
1548+
onSetWidthHeight(w: number, h: number) {
15501549
const needsDataSetChanged = !this.mViewPortHandler.hasChartDimens();
1551-
if (this.mLogEnabled) console.log(LOG_TAG, 'OnSizeChanged', w, h, needsDataSetChanged);
1550+
if (this.mLogEnabled) console.log(LOG_TAG, 'OnSizeChanged', w, h, needsDataSetChanged, new Error().stack);
15521551

15531552
if (w > 0 && h > 0 && h < 10000 && h < 10000) {
15541553
if (this.mLogEnabled) console.log(LOG_TAG, 'Setting chart dimens, width: ' + w + ', height: ' + h);
15551554
this.mViewPortHandler.setChartDimens(w, h);
15561555
} else {
1557-
if (this.mLogEnabled) console.warn(LOG_TAG, '*Avoiding* setting chart dimens! width: ' + w + ', height: ' + h);
1556+
console.warn(LOG_TAG, '*Avoiding* setting chart dimens! width: ' + w + ', height: ' + h);
15581557
}
15591558

15601559
// This may cause the chart view to mutate properties affecting the view port --
@@ -1574,7 +1573,20 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
15741573

15751574
this.mJobs = [];
15761575

1577-
// super.onSizeChanged(w, h);
1576+
}
1577+
public onLayout(left: number, top: number, right: number, bottom: number) {
1578+
super.onLayout(left, top, right, bottom);
1579+
1580+
if (isIOS) {
1581+
this.onSetWidthHeight(layout.toDeviceIndependentPixels(right - left), layout.toDeviceIndependentPixels(bottom - top));
1582+
}
1583+
1584+
}
1585+
public onSizeChanged(w: number, h: number, oldw: number, oldh: number): void {
1586+
super.onSizeChanged(w, h, oldw, oldh);
1587+
if (isAndroid) {
1588+
this.onSetWidthHeight(w, h);
1589+
}
15781590
}
15791591

15801592
/**

src/charting/components/AxisBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export abstract class AxisBase extends ComponentBase {
475475
*
476476
* @param f
477477
*/
478-
public setValueFormatter(f) {
478+
public setValueFormatter(f: ValueFormatter) {
479479
if (f == null) this.mAxisValueFormatter = new DefaultAxisValueFormatter(this.mDecimals);
480480
else this.mAxisValueFormatter = f;
481481
}

src/charting/components/LimitLine.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export class LimitLine extends ComponentBase {
6767
* @param width
6868
*/
6969
public setLineWidth(width) {
70-
if (width < 0.2) width = 0.2;
71-
if (width > 12.0) width = 12.0;
72-
this.mLineWidth = Utils.convertDpToPixel(width);
70+
// if (width < 0.2) width = 0.2;
71+
// if (width > 12.0) width = 12.0;
72+
this.mLineWidth = (width);
7373
}
7474

7575
/**

src/charting/components/XAxis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class XAxis extends AxisBase {
7878
*
7979
* @param pos
8080
*/
81-
public setPosition(pos) {
81+
public setPosition(pos:XAxisPosition) {
8282
this.mPosition = pos;
8383
}
8484

src/charting/components/YAxis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class YAxis extends AxisBase {
162162
*
163163
* @param pos
164164
*/
165-
public setPosition( pos) {
165+
public setPosition( pos: YAxisLabelPosition) {
166166
this.mPosition = pos;
167167
}
168168

src/charting/renderer/LineChartRenderer.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class LineChartRenderer extends LineRadarRenderer {
160160
const lineData = this.mChart.getLineData();
161161
let needsBitmapDrawing = false;
162162
for (let set of lineData.getVisibleDataSets()) {
163-
needsBitmapDrawing = this.drawDataSet(c, set) || needsBitmapDrawing;
163+
needsBitmapDrawing = this.drawDataSet(c, set) || needsBitmapDrawing;
164164
}
165165
if (needsBitmapDrawing) {
166166
c.drawBitmap(drawBitmap, 0, 0, this.mRenderPaint);
@@ -226,7 +226,6 @@ export class LineChartRenderer extends LineRadarRenderer {
226226
}
227227
prev = cur;
228228
cur = dataSet.getEntryForIndex(j);
229-
230229

231230
let cpx = prev[xKey] + (cur[xKey] - prev[xKey]) / 2.0;
232231

@@ -294,7 +293,6 @@ export class LineChartRenderer extends LineRadarRenderer {
294293
prevPrev = prev;
295294
prev = cur;
296295
cur = nextIndex == j ? next : newEntry;
297-
298296

299297
nextIndex = j + 1 < dataSet.getEntryCount() ? j + 1 : j;
300298
next = dataSet.getEntryForIndex(nextIndex);
@@ -399,9 +397,10 @@ export class LineChartRenderer extends LineRadarRenderer {
399397
// result = true;
400398
}
401399

402-
trans.pathValueToPixel(this.linePath);
403-
404-
this.drawPath(c, this.linePath, this.mRenderPaint);
400+
if (dataSet.getLineWidth() > 0) {
401+
trans.pathValueToPixel(this.linePath);
402+
this.drawPath(c, this.linePath, this.mRenderPaint);
403+
}
405404

406405
return result;
407406
}
@@ -424,9 +423,10 @@ export class LineChartRenderer extends LineRadarRenderer {
424423
// result = true;
425424
}
426425

427-
trans.pathValueToPixel(this.linePath);
428-
429-
this.drawPath(c, this.linePath, this.mRenderPaint);
426+
if (dataSet.getLineWidth() > 0) {
427+
trans.pathValueToPixel(this.linePath);
428+
this.drawPath(c, this.linePath, this.mRenderPaint);
429+
}
430430

431431
return result;
432432
}
@@ -449,8 +449,10 @@ export class LineChartRenderer extends LineRadarRenderer {
449449
}
450450

451451
// if (isAndroid || dataSet.isDashedLineEnabled()) {
452-
trans.pathValueToPixel(this.linePath);
453-
this.drawPath(c, this.linePath, this.mRenderPaint);
452+
if (dataSet.getLineWidth() > 0) {
453+
trans.pathValueToPixel(this.linePath);
454+
this.drawPath(c, this.linePath, this.mRenderPaint);
455+
}
454456
// } else {
455457
// const points = res[0];
456458
// const length = res[1];
@@ -621,7 +623,6 @@ export class LineChartRenderer extends LineRadarRenderer {
621623
protected drawCircles(c: Canvas) {
622624
this.mRenderPaint.setStyle(Style.FILL);
623625

624-
625626
this.mCirclesBuffer[0] = 0;
626627
this.mCirclesBuffer[1] = 0;
627628

src/charting/renderer/XAxisRenderer.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class XAxisRenderer extends AxisRenderer {
126126
}
127127

128128
public renderAxisLine(c: Canvas) {
129-
if (!this.mXAxis.isDrawAxisLineEnabled() || !this.mXAxis.isEnabled()) return;
129+
if (!this.mXAxis.isDrawAxisLineEnabled() || !this.mXAxis.isEnabled() || this.mXAxis.getAxisLineWidth() === 0) return;
130130

131131
this.mAxisLinePaint.setColor(this.mXAxis.getAxisLineColor());
132132
this.mAxisLinePaint.setStrokeWidth(this.mXAxis.getAxisLineWidth());
@@ -164,7 +164,9 @@ export class XAxisRenderer extends AxisRenderer {
164164
} else {
165165
positions[i] = mXAxis.mEntries[i / 2];
166166
}
167-
positions[i + 1] = 0;
167+
if (i + 1 < length) {
168+
positions[i + 1] = 0;
169+
}
168170
}
169171
this.mTrans.pointValuesToPixel(positions);
170172
const chartWidth = mViewPortHandler.getChartWidth();
@@ -217,7 +219,9 @@ export class XAxisRenderer extends AxisRenderer {
217219
const positions = this.mRenderGridLinesBuffer;
218220
for (let i = 0; i < length; i += 2) {
219221
positions[i] = this.mXAxis.mEntries[i / 2];
220-
positions[i+1] = 0;
222+
if (i+1 < length) {
223+
positions[i+1] = 0;
224+
}
221225
}
222226
this.mTrans.pointValuesToPixel(positions);
223227

@@ -287,7 +291,7 @@ export class XAxisRenderer extends AxisRenderer {
287291
gridLinePath.reset();
288292
}
289293

290-
protected mRenderLimitLinesBuffer = [];
294+
protected mRenderLimitLinesBuffer = Utils.createNativeArray(2);
291295
protected mLimitLineClippingRect = new RectF(0, 0, 0, 0);
292296

293297
/**
@@ -309,18 +313,21 @@ export class XAxisRenderer extends AxisRenderer {
309313
const l = limitLines[i];
310314

311315
if (!l.isEnabled()) continue;
316+
const lineWidth = l.getLineWidth();
312317

313318
let clipRestoreCount = c.save();
314319
this.mLimitLineClippingRect.set(this.mViewPortHandler.getContentRect());
315-
this.mLimitLineClippingRect.inset(-l.getLineWidth(), 0);
320+
this.mLimitLineClippingRect.inset(-lineWidth, 0);
316321
c.clipRect(this.mLimitLineClippingRect);
317322

318323
position[0] = l.getLimit();
319324
position[1] = 0;
320325

321326
this.mTrans.pointValuesToPixel(position);
322327

323-
this.renderLimitLineLine(c, l, position);
328+
if (lineWidth > 0) {
329+
this.renderLimitLineLine(c, l, position);
330+
}
324331
this.renderLimitLineLabel(c, l, position, 2 + l.getYOffset());
325332

326333
c.restoreToCount(clipRestoreCount);

src/charting/renderer/YAxisRenderer.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class YAxisRenderer extends AxisRenderer {
7777
}
7878

7979
public renderAxisLine(c: Canvas) {
80-
if (!this.mYAxis.isEnabled() || !this.mYAxis.isDrawAxisLineEnabled()) return;
80+
if (!this.mYAxis.isEnabled() || !this.mYAxis.isDrawAxisLineEnabled() || this.mYAxis.getAxisLineWidth() === 0) return;
8181

8282
this.mAxisLinePaint.setColor(this.mYAxis.getAxisLineColor());
8383
this.mAxisLinePaint.setStrokeWidth(this.mYAxis.getAxisLineWidth());
@@ -244,7 +244,7 @@ export class YAxisRenderer extends AxisRenderer {
244244
}
245245

246246
protected mRenderLimitLines = new Path();
247-
protected mRenderLimitLinesBuffer = [];
247+
protected mRenderLimitLinesBuffer = Utils.createNativeArray(2);
248248
protected mLimitLineClippingRect = new RectF(0, 0, 0, 0);
249249
/**
250250
* Draws the LimitLines associated with this axis to the screen.
@@ -266,26 +266,26 @@ export class YAxisRenderer extends AxisRenderer {
266266
const l = limitLines[i];
267267

268268
if (!l.isEnabled()) continue;
269-
269+
const lineWidth = l.getLineWidth();
270270
let clipRestoreCount = c.save();
271271
this.mLimitLineClippingRect.set(this.mViewPortHandler.getContentRect());
272-
this.mLimitLineClippingRect.inset(0, -l.getLineWidth());
272+
this.mLimitLineClippingRect.inset(0, -lineWidth);
273273
c.clipRect(this.mLimitLineClippingRect);
274274

275275
this.mLimitLinePaint.setStyle(Style.STROKE);
276276
this.mLimitLinePaint.setColor(l.getLineColor());
277-
this.mLimitLinePaint.setStrokeWidth(l.getLineWidth());
277+
this.mLimitLinePaint.setStrokeWidth(lineWidth);
278278
this.mLimitLinePaint.setPathEffect(l.getDashPathEffect());
279279

280280
pts[1] = l.getLimit();
281-
282281
this.mTrans.pointValuesToPixel(pts);
283-
284-
limitLinePath.moveTo(this.mViewPortHandler.contentLeft(), pts[1]);
285-
limitLinePath.lineTo(this.mViewPortHandler.contentRight(), pts[1]);
286-
287-
c.drawPath(limitLinePath, this.mLimitLinePaint);
288-
limitLinePath.reset();
282+
283+
if (lineWidth > 0) {
284+
limitLinePath.moveTo(this.mViewPortHandler.contentLeft(), pts[1]);
285+
limitLinePath.lineTo(this.mViewPortHandler.contentRight(), pts[1]);
286+
c.drawPath(limitLinePath, this.mLimitLinePaint);
287+
limitLinePath.reset();
288+
}
289289
// c.drawLines(pts, this.mLimitLinePaint);
290290

291291
let label = l.getLabel();

0 commit comments

Comments
 (0)