Skip to content

Commit 354bf64

Browse files
committed
feat: values label offset
1 parent 9767ebf commit 354bf64

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/charting/data/BaseDataSet.ts

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
9191
*/
9292
protected mDrawValues = false;
9393

94+
/**
95+
* the offset for drawing values (in dp)
96+
*/
97+
protected mValuesOffset = { x: 0, y: 0 };
98+
9499
/**
95100
* if true, y-icons are drawn on the chart
96101
*/
@@ -349,6 +354,14 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
349354
return this.mDrawValues;
350355
}
351356

357+
public getValuesOffset() {
358+
return this.mValuesOffset;
359+
}
360+
public setValuesOffset(offsetDp) {
361+
this.mValuesOffset.x = offsetDp.x;
362+
this.mValuesOffset.y = offsetDp.y;
363+
}
364+
352365
public setDrawIcons(enabled) {
353366
this.mDrawIcons = enabled;
354367
}

src/charting/renderer/LineChartRenderer.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ export class LineChartRenderer extends LineRadarRenderer {
462462

463463
@profile
464464
drawLines(canvas: Canvas, points: number[], offest, length, paint: Paint, matrix: Matrix) {
465-
console.log('drawLines', points.length, length, typeof points, Array.isArray(points));
466465
canvas.drawLines(points, offest, length, paint, matrix);
467466
}
468467

@@ -504,8 +503,10 @@ export class LineChartRenderer extends LineRadarRenderer {
504503
const positions = trans.generateTransformedValues(dataSet, this.mAnimator.getPhaseX(), this.mAnimator.getPhaseY(), this.mXBounds.min, this.mXBounds.max);
505504
const formatter = dataSet.getValueFormatter();
506505

507-
const iconsOffset = Object.assign({}, dataSet.getIconsOffset());
508-
506+
const iconsOffset = dataSet.getIconsOffset();
507+
const valuesOffset = dataSet.getValuesOffset();
508+
const drawIcons = dataSet.isDrawIconsEnabled();
509+
const drawValues = dataSet.isDrawValuesEnabled();
509510
for (let j = 0; j < positions.length; j += 2) {
510511
let x = positions[j];
511512
let y = positions[j + 1];
@@ -517,11 +518,11 @@ export class LineChartRenderer extends LineRadarRenderer {
517518
let entry = dataSet.getEntryForIndex(j / 2 + this.mXBounds.min);
518519
if (!entry) continue;
519520

520-
if (dataSet.isDrawValuesEnabled()) {
521-
this.drawValue(c, formatter.getFormattedValue(entry[yKey]), x, y - valOffset, dataSet.getValueTextColor(j / 2));
521+
if (drawValues) {
522+
this.drawValue(c, formatter.getFormattedValue(entry[yKey]), valuesOffset.x + x, valuesOffset.y + y - valOffset, dataSet.getValueTextColor(j / 2));
522523
}
523524

524-
if (entry.icon != null && dataSet.isDrawIconsEnabled()) {
525+
if (drawIcons && entry.icon != null) {
525526
let icon = entry.icon;
526527

527528
Utils.drawImage(c, icon, x + iconsOffset.x, y + iconsOffset.y, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());

0 commit comments

Comments
 (0)