Skip to content

Commit 32ff06f

Browse files
committed
fix: custom shader support for LineDataSet
1 parent 8275177 commit 32ff06f

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/ui-chart/data/ChartData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
269269
* @param ignorecase if true, the search is not case-sensitive
270270
* @return
271271
*/
272-
protected getDataSetIndexByLabel(dataSets: T[], label: string, ignorecase) {
272+
protected getDataSetIndexByLabel(dataSets: T[], label: string, ignorecase: boolean = false) {
273273
if (ignorecase) {
274274
const toTest = label.toLowerCase();
275275
for (let i = 0; i < dataSets.length; i++) if (toTest === dataSets[i].label?.toLowerCase()) return i;
@@ -334,7 +334,7 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
334334
* @param ignorecase
335335
* @return
336336
*/
337-
public getDataSetByLabel(label, ignorecase) {
337+
public getDataSetByLabel(label: string, ignorecase: boolean = false) {
338338
const index = this.getDataSetIndexByLabel(this.mDataSets, label, ignorecase);
339339

340340
if (index < 0 || index >= this.mDataSets.length) return null;

src/ui-chart/data/LineDataSet.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DashPathEffect } from '@nativescript-community/ui-canvas';
1+
import { DashPathEffect, Shader } from '@nativescript-community/ui-canvas';
22
import { ObservableArray, profile } from '@nativescript/core';
33
import { Color } from '@nativescript/core/color';
44
import { createLTTB } from 'downsample/methods/LTTB';
@@ -53,6 +53,11 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
5353
*/
5454
dashPathEffect: DashPathEffect = null;
5555

56+
/**
57+
* the path effect of this DataSet that makes dashed lines possible
58+
*/
59+
shader: Shader = null;
60+
5661
/**
5762
* formatter for customizing the position of the fill-line
5863
*/
@@ -83,7 +88,6 @@ export class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet
8388
return this.circleColors[Math.floor(index)] || this.getColor();
8489
}
8590

86-
8791
/**
8892
* Sets the colors that should be used for the circles of this DataSet.
8993
* Colors are reused as soon as the number of Entries the DataSet represents

src/ui-chart/highlight/ChartHighlighter.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,8 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
141141
protected buildHighlights(set: IDataSet<Entry>, dataSetIndex, touchX, touchY, xVal, rounding) {
142142
const yKey = set.yProperty;
143143
const highlights: Highlight[] = [];
144-
145-
if (set['setIgnoreFiltered']) {
146-
(set as LineDataSet).ignoreFiltered = true;
144+
if (set instanceof LineDataSet) {
145+
set.ignoreFiltered = true;
147146
}
148147
//noinspection unchecked
149148
let entries = set.getEntriesAndIndexesForXValue(xVal);
@@ -176,8 +175,8 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
176175
axis: set.axisDependency
177176
});
178177
}
179-
if (set['setIgnoreFiltered']) {
180-
(set as LineDataSet).ignoreFiltered = false;
178+
if (set instanceof LineDataSet) {
179+
set.ignoreFiltered = false;
181180
}
182181

183182
return highlights;

src/ui-chart/renderer/LineChartRenderer.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ export class LineChartRenderer extends LineRadarRenderer {
234234
if (dataSet.entryCount < 1) return false;
235235
const renderPaint = this.renderPaint;
236236
renderPaint.setStrokeWidth(dataSet.lineWidth);
237-
renderPaint.setPathEffect(dataSet.dashPathEffect);
237+
if (dataSet.dashPathEffect) {
238+
renderPaint.setPathEffect(dataSet.dashPathEffect);
239+
}
240+
if (dataSet.shader) {
241+
renderPaint.setShader(dataSet.shader);
242+
}
238243
renderPaint.setColor(dataSet.getColor());
239244
renderPaint.setStyle(Style.STROKE);
240245

@@ -482,9 +487,9 @@ export class LineChartRenderer extends LineRadarRenderer {
482487
let colorIndex = color[xKey || 'index'] as number;
483488
// if filtered we need to get the real index
484489
if ((dataSet as any).isFiltered()) {
485-
(dataSet as any).setIgnoreFiltered(true);
490+
dataSet.ignoreFiltered = true;
486491
const entry = dataSet.getEntryForIndex(colorIndex);
487-
(dataSet as any).setIgnoreFiltered(false);
492+
dataSet.ignoreFiltered = false;
488493
if (entry) {
489494
colorIndex = dataSet.getEntryIndexForXValue(dataSet.getEntryXValue(entry, colorIndex), NaN, Rounding.CLOSEST);
490495
}

0 commit comments

Comments
 (0)