Skip to content

Commit 241ec78

Browse files
committed
fix: almost everything is working!
1 parent 1fd33c1 commit 241ec78

24 files changed

+415
-433
lines changed

src/charting/charts/BarLineChartBase.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
13511351
this.getTransformer(AxisDependency.LEFT).getValuesByTouchPoint(this.mViewPortHandler.contentRight(), this.mViewPortHandler.contentBottom(), this.posForGetHighestVisibleX);
13521352
// console.log('getHighestVisibleX', this.mViewPortHandler.contentRight(), this.mViewPortHandler.contentBottom(), this.posForGetHighestVisibleX, this.mXAxis.mAxisMaximum);
13531353
const result = Math.min(this.mXAxis.mAxisMaximum, this.posForGetHighestVisibleX.x);
1354+
13541355
return result;
13551356
}
13561357

src/charting/charts/CombinedChart.ts

+66-97
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,72 @@
1+
import { Canvas } from '@nativescript-community/ui-canvas';
2+
import { BarLineScatterCandleBubbleDataSet } from '../data/BarLineScatterCandleBubbleDataSet';
3+
import { CombinedData } from '../data/CombinedData';
4+
import { Entry } from '../data/Entry';
5+
import { CombinedHighlighter } from '../highlight/CombinedHighlighter';
6+
import { CombinedDataProvider } from '../interfaces/dataprovider/CombinedDataProvider';
7+
import { IDataSet } from '../interfaces/datasets/IDataSet';
8+
import { BarLineChartBase } from './BarLineChartBase';
9+
import { CombinedChartRenderer } from '../renderer/CombinedChartRenderer';
110

11+
/**
12+
* enum that allows to specify the order in which the different data objects
13+
* for the combined-chart are drawn
14+
*/
15+
export enum DrawOrder {
16+
BAR,
17+
BUBBLE,
18+
LINE,
19+
CANDLE,
20+
SCATTER,
21+
}
222
/**
323
* This chart class allows the combination of lines, bars, scatter and candle
424
* data all displayed in one chart area.
525
*
626
* @author Philipp Jahoda
727
*/
8-
export class CombinedChart extends BarLineChartBase<CombinedData> implements CombinedDataProvider {
9-
28+
export class CombinedChart extends BarLineChartBase<Entry, BarLineScatterCandleBubbleDataSet<Entry>, CombinedData> implements CombinedDataProvider {
1029
/**
1130
* if set to true, all values are drawn above their bars, instead of below
1231
* their top
1332
*/
14-
private boolean this.mDrawValueAboveBar = true;
15-
33+
mDrawValueAboveBar = true;
1634

1735
/**
1836
* flag that indicates whether the highlight should be full-bar oriented, or single-value?
1937
*/
20-
protected boolean this.mHighlightFullBarEnabled = false;
38+
mHighlightFullBarEnabled = false;
2139

2240
/**
2341
* if set to true, a grey area is drawn behind each bar that indicates the
2442
* maximum value
2543
*/
26-
private boolean this.mDrawBarShadow = false;
27-
28-
protected DrawOrder[] this.mDrawOrder;
44+
mDrawBarShadow = false;
2945

30-
/**
31-
* enum that allows to specify the order in which the different data objects
32-
* for the combined-chart are drawn
33-
*/
34-
public enum DrawOrder {
35-
BAR, BUBBLE, LINE, CANDLE, SCATTER
36-
}
37-
38-
public CombinedChart(Context context) {
39-
super(context);
40-
}
41-
42-
public CombinedChart(Context context, AttributeSet attrs) {
43-
super(context, attrs);
44-
}
46+
mDrawOrder: DrawOrder[];
4547

46-
public CombinedChart(Context context, AttributeSet attrs, let defStyle) {
47-
super(context, attrs, defStyle);
48-
}
49-
50-
5148
protected init() {
5249
super.init();
5350

5451
// Default values are not ready here yet
55-
this.mDrawOrder = new DrawOrder[]{
56-
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER
57-
};
52+
this.mDrawOrder = [DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER];
5853

59-
setHighlighter(new CombinedHighlighter(this, this));
54+
this.setHighlighter(new CombinedHighlighter(this, this));
6055

6156
// Old default behaviour
62-
setHighlightFullBarEnabled(true);
57+
this.setHighlightFullBarEnabled(true);
6358

6459
this.mRenderer = new CombinedChartRenderer(this, this.mAnimator, this.mViewPortHandler);
6560
}
6661

67-
68-
public CombinedData getCombinedData() {
62+
public getCombinedData() {
6963
return this.mData;
7064
}
7165

72-
73-
public setData(CombinedData data) {
66+
public setData(data: CombinedData) {
7467
super.setData(data);
75-
setHighlighter(new CombinedHighlighter(this, this));
76-
((CombinedChartRenderer)mRenderer).createRenderers();
68+
this.setHighlighter(new CombinedHighlighter(this, this));
69+
(this.mRenderer as CombinedChartRenderer).createRenderers();
7770
this.mRenderer.initBuffers();
7871
}
7972

@@ -86,64 +79,49 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
8679
* @param y
8780
* @return
8881
*/
89-
90-
public Highlight getHighlightByTouchPoint(let x, let y) {
9182

92-
if (mData == null) {
93-
console.error(LOG_TAG, "Can't select by touch. No data set.");
83+
public getHighlightByTouchPoint(x, y) {
84+
if (this.mData == null) {
85+
console.error("Can't select by touch. No data set.");
9486
return null;
9587
} else {
96-
Highlight h = getHighlighter().getHighlight(x, y);
97-
if (h == null || !isHighlightFullBarEnabled()) return h;
88+
const h = this.getHighlighter().getHighlight(x, y);
89+
if (h == null || !this.isHighlightFullBarEnabled()) return h;
9890

9991
// For isHighlightFullBarEnabled, remove stackIndex
100-
return new Highlight(h.getX(), h.getY(),
101-
h.getXPx(), h.getYPx(),
102-
h.getDataSetIndex(), -1, h.getAxis());
92+
return Object.assign({}, h, {});
10393
}
10494
}
10595

106-
107-
public LineData getLineData() {
108-
if (mData == null)
109-
return null;
96+
public getLineData() {
97+
if (this.mData == null) return null;
11098
return this.mData.getLineData();
11199
}
112100

113-
114-
public BarData getBarData() {
115-
if (mData == null)
116-
return null;
101+
public getBarData() {
102+
if (this.mData == null) return null;
117103
return this.mData.getBarData();
118104
}
119105

120-
121-
public ScatterData getScatterData() {
122-
if (mData == null)
123-
return null;
106+
public getScatterData() {
107+
if (this.mData == null) return null;
124108
return this.mData.getScatterData();
125109
}
126110

127-
128-
public CandleData getCandleData() {
129-
if (mData == null)
130-
return null;
111+
public getCandleData() {
112+
if (this.mData == null) return null;
131113
return this.mData.getCandleData();
132114
}
133115

134-
135-
public BubbleData getBubbleData() {
136-
if (mData == null)
137-
return null;
116+
public getBubbleData() {
117+
if (this.mData == null) return null;
138118
return this.mData.getBubbleData();
139119
}
140120

141-
142121
public isDrawBarShadowEnabled() {
143122
return this.mDrawBarShadow;
144123
}
145124

146-
147125
public isDrawValueAboveBarEnabled() {
148126
return this.mDrawValueAboveBar;
149127
}
@@ -154,18 +132,17 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
154132
*
155133
* @param enabled
156134
*/
157-
public setDrawValueAboveBar( enabled) {
135+
public setDrawValueAboveBar(enabled) {
158136
this.mDrawValueAboveBar = enabled;
159137
}
160138

161-
162139
/**
163140
* If set to true, a grey area is drawn behind each bar that indicates the
164141
* maximum value. Enabling his will reduce performance by about 50%.
165142
*
166143
* @param enabled
167144
*/
168-
public setDrawBarShadow( enabled) {
145+
public setDrawBarShadow(enabled) {
169146
this.mDrawBarShadow = enabled;
170147
}
171148

@@ -175,14 +152,14 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
175152
*
176153
* @param enabled
177154
*/
178-
public setHighlightFullBarEnabled( enabled) {
155+
public setHighlightFullBarEnabled(enabled) {
179156
this.mHighlightFullBarEnabled = enabled;
180157
}
181158

182159
/**
183160
* @return true the highlight operation is be full-bar oriented, false if single-value
184161
*/
185-
162+
186163
public isHighlightFullBarEnabled() {
187164
return this.mHighlightFullBarEnabled;
188165
}
@@ -192,7 +169,7 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
192169
*
193170
* @return
194171
*/
195-
public DrawOrder[] getDrawOrder() {
172+
public getDrawOrder() {
196173
return this.mDrawOrder;
197174
}
198175

@@ -204,49 +181,41 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
204181
*
205182
* @param order
206183
*/
207-
public setDrawOrder(DrawOrder[] order) {
208-
if (order == null || order.length <= 0)
209-
return;
184+
public setDrawOrder(order: DrawOrder[]) {
185+
if (order == null || order.length <= 0) return;
210186
this.mDrawOrder = order;
211187
}
212188

213189
/**
214190
* draws all MarkerViews on the highlighted positions
215191
*/
216-
protected drawMarkers(c: Canvasanvas) {
217-
192+
protected drawMarkers(c: Canvas) {
218193
// if there is no marker view or drawing marker is disabled
219-
if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
220-
return;
194+
if (this.mMarker == null || !this.isDrawMarkersEnabled() || !this.valuesToHighlight()) return;
221195

222196
for (let i = 0; i < this.mIndicesToHighlight.length; i++) {
197+
const highlight = this.mIndicesToHighlight[i];
223198

224-
Highlight highlight = this.mIndicesToHighlight[i];
225-
226-
set:IDataSet = this.mData.getDataSetByHighlight(highlight);
199+
const set: IDataSet<Entry> = this.mData.getDataSetByHighlight(highlight);
227200

228-
Entry e = this.mData.getEntryForHighlight(highlight);
229-
if (e == null)
230-
continue;
201+
const e = this.mData.getEntryForHighlight(highlight);
202+
if (e == null) continue;
231203

232-
let entryIndex = set.getEntryIndex(e);
204+
const entryIndex = set.getEntryIndex(e);
233205

234206
// make sure entry not null
235-
if (entryIndex > set.getEntryCount() * this.mAnimator.getPhaseX())
236-
continue;
207+
if (entryIndex > set.getEntryCount() * this.mAnimator.getPhaseX()) continue;
237208

238-
float[] pos = getMarkerPosition(highlight);
209+
const pos = this.getMarkerPosition(highlight);
239210

240211
// check bounds
241-
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
242-
continue;
212+
if (!this.mViewPortHandler.isInBounds(pos[0], pos[1])) continue;
243213

244214
// callbacks to update the content
245215
this.mMarker.refreshContent(e, highlight);
246216

247217
// draw the marker
248-
this.mMarker.draw(canvas, pos[0], pos[1]);
218+
this.mMarker.draw(c, pos[0], pos[1]);
249219
}
250220
}
251-
252221
}

src/charting/data/BarDataSet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> impl
3737

3838
constructor(values, label, xProperty?, yProperty?) {
3939
super(values, label, xProperty, yProperty);
40-
4140
this.mHighLightColor = 'black';
41+
this.init();
4242
}
4343

4444
private calcEntryRanges(e: BarEntry) {

src/charting/data/BaseDataSet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
307307
}
308308

309309
public getValueTextColor(index = 0) {
310-
return this.mValueColors[index % this.mValueColors.length];
310+
return this.mValueColors[Math.floor(index) % this.mValueColors.length];
311311
}
312312

313313
public getValueTypeface() {

src/charting/data/BubbleDataSet.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,44 @@ import { BubbleEntry } from './BubbleEntry';
44

55
export class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry> implements IBubbleDataSet {
66
mMaxSize: number;
7-
mNormalizeSize = true;
7+
mNormalizeSize: boolean;
88

99
mHighlightCircleWidth = 2.5;
1010

11+
/**
12+
* property to access the "high" value of an entry for this set
13+
*
14+
*/
15+
sizeProperty: string = 'size';
16+
17+
constructor(yVals, label, xProperty?, yProperty?, sizeProperty?) {
18+
super(yVals, label, xProperty, yProperty);
19+
if (sizeProperty) {
20+
this.sizeProperty = sizeProperty;
21+
}
22+
this.init();
23+
}
24+
1125
public setHighlightCircleWidth(width: number) {
1226
this.mHighlightCircleWidth = width;
1327
}
1428

1529
public getHighlightCircleWidth() {
1630
return this.mHighlightCircleWidth;
1731
}
18-
32+
init() {
33+
// ! init is called before init of class vars
34+
this.mMaxSize = -Infinity;
35+
this.mNormalizeSize = true;
36+
super.init();
37+
}
38+
calcMinMax() {
39+
super.calcMinMax();
40+
}
1941
calcMinMaxForEntry(e: BubbleEntry, index?: number) {
2042
super.calcMinMaxForEntry(e, index);
2143

2244
const size = e.size;
23-
2445
if (size > this.mMaxSize) {
2546
this.mMaxSize = size;
2647
}

0 commit comments

Comments
 (0)