Skip to content

Commit 439ffa6

Browse files
committed
fix: legendrender fix
1 parent d901d74 commit 439ffa6

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/charting/renderer/LegendRenderer.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class LegendRenderer extends Renderer {
2828
*/
2929
protected mLegend: Legend;
3030

31+
protected legendFontMetrics = new FontMetrics();
32+
33+
protected computedEntries: LegendEntry[] = [];
34+
3135
constructor(viewPortHandler: ViewPortHandler, legend: Legend) {
3236
super(viewPortHandler);
3337

@@ -61,8 +65,6 @@ export class LegendRenderer extends Renderer {
6165
return this.mLegendFormPaint;
6266
}
6367

64-
protected computedEntries: LegendEntry[] = [];
65-
6668
/**
6769
* Prepares the legend and calculates all needed forms, labels and colors.
6870
*
@@ -94,8 +96,8 @@ export class LegendRenderer extends Renderer {
9496
// add the legend description label
9597
this.computedEntries.push(new LegendEntry(dataSet.getLabel(), LegendForm.NONE, NaN, NaN, null, ColorTemplate.COLOR_NONE));
9698
}
97-
} else if (dataSet instanceof PieDataSet) {
98-
const pds = dataSet;
99+
} else if (dataSet.constructor.name === 'PieDataSet') {
100+
const pds = dataSet as PieDataSet;
99101

100102
for (let j = 0; j < clrs.length && j < entryCount; j++) {
101103
const label = pds.getEntryForIndex(j).label;
@@ -110,15 +112,16 @@ export class LegendRenderer extends Renderer {
110112
// add the legend description label
111113
this.computedEntries.push(new LegendEntry(dataSet.getLabel(), LegendForm.NONE, NaN, NaN, null, ColorTemplate.COLOR_NONE));
112114
}
113-
} else if (dataSet instanceof CandleDataSet && dataSet.getDecreasingColor() !== ColorTemplate.COLOR_NONE) {
114-
const decreasingColor = dataSet.getDecreasingColor();
115-
const increasingColor = dataSet.getIncreasingColor();
115+
} else if (dataSet.constructor.name === 'CandleDataSet') {
116+
const dSet = dataSet as CandleDataSet;
117+
if (dSet.getDecreasingColor() !== ColorTemplate.COLOR_NONE) {
118+
const decreasingColor = dSet.getDecreasingColor();
119+
const increasingColor = dSet.getIncreasingColor();
116120

117-
this.computedEntries.push(new LegendEntry(null, dataSet.getForm(), dataSet.getFormSize(), dataSet.getFormLineWidth(), dataSet.getFormLineDashEffect(), decreasingColor));
121+
this.computedEntries.push(new LegendEntry(null, dSet.getForm(), dSet.getFormSize(), dSet.getFormLineWidth(), dSet.getFormLineDashEffect(), decreasingColor));
118122

119-
this.computedEntries.push(
120-
new LegendEntry(dataSet.getLabel(), dataSet.getForm(), dataSet.getFormSize(), dataSet.getFormLineWidth(), dataSet.getFormLineDashEffect(), increasingColor)
121-
);
123+
this.computedEntries.push(new LegendEntry(dSet.getLabel(), dSet.getForm(), dSet.getFormSize(), dSet.getFormLineWidth(), dSet.getFormLineDashEffect(), increasingColor));
124+
}
122125
} else {
123126
// all others
124127

@@ -147,14 +150,11 @@ export class LegendRenderer extends Renderer {
147150
}
148151

149152
this.mLegendLabelPaint.setTypeface(this.mLegend.getTypeface());
150-
this.mLegendLabelPaint.setColor(this.mLegend.getTextColor());
151153

152154
// calculate all dimensions of the this.mLegend
153155
this.mLegend.calculateDimensions(this.mLegendLabelPaint, this.mViewPortHandler);
154156
}
155157

156-
protected legendFontMetrics = new FontMetrics();
157-
158158
@profile
159159
public renderLegend(c: Canvas) {
160160
if (!this.mLegend.isEnabled()) return;

0 commit comments

Comments
 (0)