Skip to content

Commit

Permalink
fix: almost everything is working!
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Sep 29, 2020
1 parent 1fd33c1 commit 241ec78
Show file tree
Hide file tree
Showing 24 changed files with 415 additions and 433 deletions.
1 change: 1 addition & 0 deletions src/charting/charts/BarLineChartBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
this.getTransformer(AxisDependency.LEFT).getValuesByTouchPoint(this.mViewPortHandler.contentRight(), this.mViewPortHandler.contentBottom(), this.posForGetHighestVisibleX);
// console.log('getHighestVisibleX', this.mViewPortHandler.contentRight(), this.mViewPortHandler.contentBottom(), this.posForGetHighestVisibleX, this.mXAxis.mAxisMaximum);
const result = Math.min(this.mXAxis.mAxisMaximum, this.posForGetHighestVisibleX.x);

return result;
}

Expand Down
163 changes: 66 additions & 97 deletions src/charting/charts/CombinedChart.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,72 @@
import { Canvas } from '@nativescript-community/ui-canvas';
import { BarLineScatterCandleBubbleDataSet } from '../data/BarLineScatterCandleBubbleDataSet';
import { CombinedData } from '../data/CombinedData';
import { Entry } from '../data/Entry';
import { CombinedHighlighter } from '../highlight/CombinedHighlighter';
import { CombinedDataProvider } from '../interfaces/dataprovider/CombinedDataProvider';
import { IDataSet } from '../interfaces/datasets/IDataSet';
import { BarLineChartBase } from './BarLineChartBase';
import { CombinedChartRenderer } from '../renderer/CombinedChartRenderer';

/**
* enum that allows to specify the order in which the different data objects
* for the combined-chart are drawn
*/
export enum DrawOrder {
BAR,
BUBBLE,
LINE,
CANDLE,
SCATTER,
}
/**
* This chart class allows the combination of lines, bars, scatter and candle
* data all displayed in one chart area.
*
* @author Philipp Jahoda
*/
export class CombinedChart extends BarLineChartBase<CombinedData> implements CombinedDataProvider {

export class CombinedChart extends BarLineChartBase<Entry, BarLineScatterCandleBubbleDataSet<Entry>, CombinedData> implements CombinedDataProvider {
/**
* if set to true, all values are drawn above their bars, instead of below
* their top
*/
private boolean this.mDrawValueAboveBar = true;

mDrawValueAboveBar = true;

/**
* flag that indicates whether the highlight should be full-bar oriented, or single-value?
*/
protected boolean this.mHighlightFullBarEnabled = false;
mHighlightFullBarEnabled = false;

/**
* if set to true, a grey area is drawn behind each bar that indicates the
* maximum value
*/
private boolean this.mDrawBarShadow = false;

protected DrawOrder[] this.mDrawOrder;
mDrawBarShadow = false;

/**
* enum that allows to specify the order in which the different data objects
* for the combined-chart are drawn
*/
public enum DrawOrder {
BAR, BUBBLE, LINE, CANDLE, SCATTER
}

public CombinedChart(Context context) {
super(context);
}

public CombinedChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
mDrawOrder: DrawOrder[];

public CombinedChart(Context context, AttributeSet attrs, let defStyle) {
super(context, attrs, defStyle);
}


protected init() {
super.init();

// Default values are not ready here yet
this.mDrawOrder = new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER
};
this.mDrawOrder = [DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.LINE, DrawOrder.CANDLE, DrawOrder.SCATTER];

setHighlighter(new CombinedHighlighter(this, this));
this.setHighlighter(new CombinedHighlighter(this, this));

// Old default behaviour
setHighlightFullBarEnabled(true);
this.setHighlightFullBarEnabled(true);

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


public CombinedData getCombinedData() {
public getCombinedData() {
return this.mData;
}


public setData(CombinedData data) {
public setData(data: CombinedData) {
super.setData(data);
setHighlighter(new CombinedHighlighter(this, this));
((CombinedChartRenderer)mRenderer).createRenderers();
this.setHighlighter(new CombinedHighlighter(this, this));
(this.mRenderer as CombinedChartRenderer).createRenderers();
this.mRenderer.initBuffers();
}

Expand All @@ -86,64 +79,49 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
* @param y
* @return
*/

public Highlight getHighlightByTouchPoint(let x, let y) {

if (mData == null) {
console.error(LOG_TAG, "Can't select by touch. No data set.");
public getHighlightByTouchPoint(x, y) {
if (this.mData == null) {
console.error("Can't select by touch. No data set.");
return null;
} else {
Highlight h = getHighlighter().getHighlight(x, y);
if (h == null || !isHighlightFullBarEnabled()) return h;
const h = this.getHighlighter().getHighlight(x, y);
if (h == null || !this.isHighlightFullBarEnabled()) return h;

// For isHighlightFullBarEnabled, remove stackIndex
return new Highlight(h.getX(), h.getY(),
h.getXPx(), h.getYPx(),
h.getDataSetIndex(), -1, h.getAxis());
return Object.assign({}, h, {});
}
}


public LineData getLineData() {
if (mData == null)
return null;
public getLineData() {
if (this.mData == null) return null;
return this.mData.getLineData();
}


public BarData getBarData() {
if (mData == null)
return null;
public getBarData() {
if (this.mData == null) return null;
return this.mData.getBarData();
}


public ScatterData getScatterData() {
if (mData == null)
return null;
public getScatterData() {
if (this.mData == null) return null;
return this.mData.getScatterData();
}


public CandleData getCandleData() {
if (mData == null)
return null;
public getCandleData() {
if (this.mData == null) return null;
return this.mData.getCandleData();
}


public BubbleData getBubbleData() {
if (mData == null)
return null;
public getBubbleData() {
if (this.mData == null) return null;
return this.mData.getBubbleData();
}


public isDrawBarShadowEnabled() {
return this.mDrawBarShadow;
}


public isDrawValueAboveBarEnabled() {
return this.mDrawValueAboveBar;
}
Expand All @@ -154,18 +132,17 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
*
* @param enabled
*/
public setDrawValueAboveBar( enabled) {
public setDrawValueAboveBar(enabled) {
this.mDrawValueAboveBar = enabled;
}


/**
* If set to true, a grey area is drawn behind each bar that indicates the
* maximum value. Enabling his will reduce performance by about 50%.
*
* @param enabled
*/
public setDrawBarShadow( enabled) {
public setDrawBarShadow(enabled) {
this.mDrawBarShadow = enabled;
}

Expand All @@ -175,14 +152,14 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
*
* @param enabled
*/
public setHighlightFullBarEnabled( enabled) {
public setHighlightFullBarEnabled(enabled) {
this.mHighlightFullBarEnabled = enabled;
}

/**
* @return true the highlight operation is be full-bar oriented, false if single-value
*/

public isHighlightFullBarEnabled() {
return this.mHighlightFullBarEnabled;
}
Expand All @@ -192,7 +169,7 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
*
* @return
*/
public DrawOrder[] getDrawOrder() {
public getDrawOrder() {
return this.mDrawOrder;
}

Expand All @@ -204,49 +181,41 @@ export class CombinedChart extends BarLineChartBase<CombinedData> implements Com
*
* @param order
*/
public setDrawOrder(DrawOrder[] order) {
if (order == null || order.length <= 0)
return;
public setDrawOrder(order: DrawOrder[]) {
if (order == null || order.length <= 0) return;
this.mDrawOrder = order;
}

/**
* draws all MarkerViews on the highlighted positions
*/
protected drawMarkers(c: Canvasanvas) {

protected drawMarkers(c: Canvas) {
// if there is no marker view or drawing marker is disabled
if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight())
return;
if (this.mMarker == null || !this.isDrawMarkersEnabled() || !this.valuesToHighlight()) return;

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

Highlight highlight = this.mIndicesToHighlight[i];

set:IDataSet = this.mData.getDataSetByHighlight(highlight);
const set: IDataSet<Entry> = this.mData.getDataSetByHighlight(highlight);

Entry e = this.mData.getEntryForHighlight(highlight);
if (e == null)
continue;
const e = this.mData.getEntryForHighlight(highlight);
if (e == null) continue;

let entryIndex = set.getEntryIndex(e);
const entryIndex = set.getEntryIndex(e);

// make sure entry not null
if (entryIndex > set.getEntryCount() * this.mAnimator.getPhaseX())
continue;
if (entryIndex > set.getEntryCount() * this.mAnimator.getPhaseX()) continue;

float[] pos = getMarkerPosition(highlight);
const pos = this.getMarkerPosition(highlight);

// check bounds
if (!mViewPortHandler.isInBounds(pos[0], pos[1]))
continue;
if (!this.mViewPortHandler.isInBounds(pos[0], pos[1])) continue;

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

// draw the marker
this.mMarker.draw(canvas, pos[0], pos[1]);
this.mMarker.draw(c, pos[0], pos[1]);
}
}

}
2 changes: 1 addition & 1 deletion src/charting/data/BarDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class BarDataSet extends BarLineScatterCandleBubbleDataSet<BarEntry> impl

constructor(values, label, xProperty?, yProperty?) {
super(values, label, xProperty, yProperty);

this.mHighLightColor = 'black';
this.init();
}

private calcEntryRanges(e: BarEntry) {
Expand Down
2 changes: 1 addition & 1 deletion src/charting/data/BaseDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
}

public getValueTextColor(index = 0) {
return this.mValueColors[index % this.mValueColors.length];
return this.mValueColors[Math.floor(index) % this.mValueColors.length];
}

public getValueTypeface() {
Expand Down
27 changes: 24 additions & 3 deletions src/charting/data/BubbleDataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@ import { BubbleEntry } from './BubbleEntry';

export class BubbleDataSet extends BarLineScatterCandleBubbleDataSet<BubbleEntry> implements IBubbleDataSet {
mMaxSize: number;
mNormalizeSize = true;
mNormalizeSize: boolean;

mHighlightCircleWidth = 2.5;

/**
* property to access the "high" value of an entry for this set
*
*/
sizeProperty: string = 'size';

constructor(yVals, label, xProperty?, yProperty?, sizeProperty?) {
super(yVals, label, xProperty, yProperty);
if (sizeProperty) {
this.sizeProperty = sizeProperty;
}
this.init();
}

public setHighlightCircleWidth(width: number) {
this.mHighlightCircleWidth = width;
}

public getHighlightCircleWidth() {
return this.mHighlightCircleWidth;
}

init() {
// ! init is called before init of class vars
this.mMaxSize = -Infinity;
this.mNormalizeSize = true;
super.init();
}
calcMinMax() {
super.calcMinMax();
}
calcMinMaxForEntry(e: BubbleEntry, index?: number) {
super.calcMinMaxForEntry(e, index);

const size = e.size;

if (size > this.mMaxSize) {
this.mMaxSize = size;
}
Expand Down
Loading

0 comments on commit 241ec78

Please sign in to comment.