Skip to content

Commit

Permalink
feat: improved
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jan 3, 2020
1 parent 2e45324 commit e260f0a
Show file tree
Hide file tree
Showing 14 changed files with 803 additions and 517 deletions.
100 changes: 50 additions & 50 deletions demo_vue/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ module.exports = env => {
'nativescript-vue': 'nativescript-akylas-vue'
};

// if (hasRootLevelScopedModules) {
// coreModulesPackageName = '@nativescript/core';
// alias['tns-core-modules'] = coreModulesPackageName;
// }
if (hasRootLevelScopedModules) {
coreModulesPackageName = '@nativescript/core';
alias['tns-core-modules'] = coreModulesPackageName;
}

const appResourcesFullPath = resolve(projectRoot, appResourcesPath);

Expand All @@ -95,13 +95,13 @@ module.exports = env => {
mode: mode,
context: appFullPath,
externals,
// watchOptions: {
// ignored: [
// appResourcesFullPath,
// // Don't watch hidden files
// '**/.*'
// ]
// },
watchOptions: {
ignored: [
appResourcesFullPath,
// Don't watch hidden files
'**/.*'
]
},
target: nativescriptTarget,
// target: nativeScriptVueTarget,
entry: entries,
Expand Down Expand Up @@ -134,45 +134,45 @@ module.exports = env => {
fs: 'empty',
__dirname: false
},
// devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
// optimization: {
// runtimeChunk: 'single',
// noEmitOnErrors: true,
// splitChunks: {
// cacheGroups: {
// vendor: {
// name: 'vendor',
// chunks: 'all',
// test: module => {
// const moduleName = module.nameForCondition ? module.nameForCondition() : '';
// return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some(comp => comp === moduleName);
// },
// enforce: true
// }
// }
// },
// minimize: Boolean(production),
// minimizer: [
// new TerserPlugin({
// parallel: true,
// cache: true,
// sourceMap: isAnySourceMapEnabled,
// terserOptions: {
// output: {
// comments: false,
// semicolons: !isAnySourceMapEnabled
// },
// compress: {
// // The Android SBG has problems parsing the output
// // when these options are enabled
// collapse_vars: platform !== 'android',
// sequences: platform !== 'android'
// },
// keep_fnames: true
// }
// })
// ]
// },
devtool: hiddenSourceMap ? 'hidden-source-map' : sourceMap ? 'inline-source-map' : 'none',
optimization: {
runtimeChunk: 'single',
noEmitOnErrors: true,
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
chunks: 'all',
test: module => {
const moduleName = module.nameForCondition ? module.nameForCondition() : '';
return /[\\/]node_modules[\\/]/.test(moduleName) || appComponents.some(comp => comp === moduleName);
},
enforce: true
}
}
},
minimize: Boolean(production),
minimizer: [
new TerserPlugin({
parallel: true,
cache: true,
sourceMap: isAnySourceMapEnabled,
terserOptions: {
output: {
comments: false,
semicolons: !isAnySourceMapEnabled
},
compress: {
// The Android SBG has problems parsing the output
// when these options are enabled
collapse_vars: platform !== 'android',
sequences: platform !== 'android'
},
keep_fnames: true
}
})
]
},
module: {
rules: [
{
Expand Down
5 changes: 3 additions & 2 deletions src/charting/charts/BarLineChartBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
* @return
*/
public getDataSetByTouchPoint(x, y) {
console.log('getDataSetByTouchPoint', x, y);
const h = this.getHighlightByTouchPoint(x, y);
if (h != null) {
return this.mData.getDataSetByIndex(h.dataSetIndex);
Expand Down Expand Up @@ -1479,7 +1480,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte

protected mOnSizeChangedBuffer = Array.create('float', 2);

public onSizeChanged(w: number, h: number) {
public onSizeChanged(w: number, h: number, oldw:number, oldh:number) {
// Saving current position of chart.
this.mOnSizeChangedBuffer[0] = this.mOnSizeChangedBuffer[1] = 0;

Expand All @@ -1490,7 +1491,7 @@ export abstract class BarLineChartBase<U extends Entry, D extends IBarLineScatte
}

//Superclass transforms chart.
super.onSizeChanged(w, h);
super.onSizeChanged(w, h, oldw, oldh);

if (this.mKeepPositionOnRotation) {
//Restoring old position of chart.
Expand Down
53 changes: 29 additions & 24 deletions src/charting/charts/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { ChartTouchListener } from '../listener/ChartTouchListener';

const LOG_TAG = 'MPAndroidChart';

declare module '@nativescript/core/ui/core/view' {
interface View {
_raiseLayoutChangedEvent();
}
}
// declare module '@nativescript/core/ui/core/view' {
// interface View {
// _raiseLayoutChangedEvent();
// }
// }

/**
* Baseclass of all Chart-Views.
Expand Down Expand Up @@ -153,29 +153,33 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
*/
constructor() {
super();
console.log('constructor')
this.init();
}

initNativeView() {
console.log('initNativeView')
super.initNativeView();
this.mChartTouchListener.init();
this.mChartTouchListener && this.mChartTouchListener.init();
}
disposeNativeView() {
console.log('disposeNativeView')
super.disposeNativeView();
this.mChartTouchListener.dispose();
this.mChartTouchListener && this.mChartTouchListener.dispose();
}

/**
* initialize all paints and stuff
*/
@profile
protected init() {
console.log('init')
this.mAnimator = new ChartAnimator(()=>{
this.invalidate();
});

// initialize the utils
Utils.init(this._context);
// Utils.init(this._context);
this.mMaxHighlightDistance = Utils.convertDpToPixel(500);

this.mDescription = new Description();
Expand Down Expand Up @@ -333,10 +337,10 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
this.invalidate();
}

invalidate() {
console.log('invalidate', new Error().stack);
super.invalidate();
}
// invalidate() {
// console.log('invalidate', new Error().stack);
// super.invalidate();
// }

/**
* Returns true if the chart is empty (meaning it's data object is either
Expand Down Expand Up @@ -610,7 +614,7 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch

if (high == null) this.mIndicesToHighlight = null;
else {
if (this.mLogEnabled) console.log(LOG_TAG, 'Highlighted: ' + high.toString());
if (this.mLogEnabled) console.log(LOG_TAG, 'Highlighted', high);

e = this.mData.getEntryForHighlight(high);
if (e == null) {
Expand Down Expand Up @@ -1530,20 +1534,21 @@ export abstract class Chart<U extends Entry, D extends IDataSet<U>, T extends Ch
// resolveSize(size,
// heightMeasureSpec)));
// }
public onLayout(left: number, top: number, right: number, bottom: number) {
super.onLayout(left, top, right, bottom);
}
// public onLayout(left: number, top: number, right: number, bottom: number) {
// super.onLayout(left, top, right, bottom);
// }

public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
// public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
// super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// }

_raiseLayoutChangedEvent() {
super._raiseLayoutChangedEvent();
this.onSizeChanged(this.getMeasuredWidth(), this.getMeasuredHeight());
}
// _raiseLayoutChangedEvent() {
// super._raiseLayoutChangedEvent();
// this.onSizeChanged(this.getMeasuredWidth(), this.getMeasuredHeight());
// }

public onSizeChanged(w: number, h: number): void {
public onSizeChanged(w: number, h: number, oldw:number, oldh:number): void {
super.onSizeChanged(w, h,oldw,oldh);
// super.setMeasuredDimension(measuredWidth, measuredHeight);
const needsDataSetChanged = !this.mViewPortHandler.hasChartDimens();
if (this.mLogEnabled) console.log(LOG_TAG, 'OnSizeChanged', w, h, needsDataSetChanged);
Expand Down
8 changes: 7 additions & 1 deletion src/charting/charts/LineChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Entry } from '../data/Entry';
import { LineDataSet } from '../data/LineDataSet';
import { LineChartRenderer } from '../renderer/LineChartRenderer';

export class LineChart extends BarLineChartBase<Entry, LineDataSet, LineData> implements LineDataProvider {
export default class LineChart extends BarLineChartBase<Entry, LineDataSet, LineData> implements LineDataProvider {
// public LineChart(Context context) {
// super(context);
// }
Expand All @@ -17,8 +17,14 @@ export class LineChart extends BarLineChartBase<Entry, LineDataSet, LineData> im
// public LineChart(Context context, AttributeSet attrs, let defStyle) {
// super(context, attrs, defStyle);
// }
constructor() {
super();
console.log('LineChart','constructor')
this.init();
}

protected init() {
console.log('LineChart', 'init');
super.init();

this.mRenderer = new LineChartRenderer(this, this.mAnimator, this.mViewPortHandler);
Expand Down
10 changes: 7 additions & 3 deletions src/charting/data/ChartData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IDataSet } from '../interfaces/datasets/IDataSet';
import { Entry } from './Entry';
import { AxisDependency } from '../components/YAxis';
import { Highlight } from '../highlight/Highlight';

export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
/**
Expand Down Expand Up @@ -281,10 +282,13 @@ export abstract class ChartData<U extends Entry, T extends IDataSet<U>> {
* @param highlight
* @return the entry that is highlighted
*/
public getEntryForHighlight(highlight) {
if (highlight.getDataSetIndex() >= this.mDataSets.length) return null;
public getEntryForHighlight(highlight: Highlight) {
if (highlight.entry) {
return highlight.entry;
}
if (highlight.dataSetIndex >= this.mDataSets.length) return null;
else {
return this.mDataSets[highlight.getDataSetIndex()].getEntryForXValue(highlight.getX(), highlight.getY());
return this.mDataSets[highlight.dataSetIndex].getEntryForXValue(highlight.x, highlight.y);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/charting/data/DataSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,18 @@ export abstract class DataSet<T extends Entry> extends BaseDataSet<T> {
let high = this.mValues.length - 1;

while (low <= high) {
let m = (high + low) / 2;
let m = Math.floor((high + low) / 2);
let entry = this.mValues[m];

// if we have a match
if (xValue == entry[this.xProperty]) {
while (m > 0 && this.mValues[m - 1][this.xProperty] == xValue) m--;
if (xValue === entry[this.xProperty]) {
while (m > 0 && this.mValues[m - 1][this.xProperty] === xValue) m--;

high = this.mValues.length;

// loop over all "equal" entries
for (; m < high; m++) {
entry = this.mValues[m];
if (entry[this.xProperty] == xValue) {
if (entry[this.xProperty] === xValue) {
entries.push(entry);
} else {
break;
Expand Down
12 changes: 6 additions & 6 deletions src/charting/highlight/ChartHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
*/
protected getHighlightForX(xVal, x, y) {
const closestValues = this.getHighlightsAtXValue(xVal, x, y);

if (closestValues.length === 0) {
return null;
}
Expand All @@ -78,13 +77,13 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
* @param axis
* @return
*/
protected getMinimumDistance(closestValues, pos, axis) {
protected getMinimumDistance(closestValues: Highlight[], pos, axis) {
let distance = Number.MAX_VALUE;

for (let i = 0; i < closestValues.length; i++) {
const high = closestValues.get(i);
const high = closestValues[i];

if (high.getAxis() == axis) {
if (high.axis == axis) {
let tempDistance = Math.abs(this.getHighlightPos(high) - pos);
if (tempDistance < distance) {
distance = tempDistance;
Expand Down Expand Up @@ -138,14 +137,14 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
protected buildHighlights(set: IDataSet<Entry>, dataSetIndex, xVal, rounding) {
const xProperty = set.xProperty;
const yProperty = set.yProperty;
const highlights = [];
const highlights: Highlight[] = [];

//noinspection unchecked
let entries = set.getEntriesForXValue(xVal);
if (entries.length == 0) {
// Try to find closest x-value and take all entries for that x-value
const closest = set.getEntryForXValue(xVal, NaN, rounding);
if (closest != null) {
if (closest !== null) {
//noinspection unchecked
entries = set.getEntriesForXValue(closest[xProperty]);
}
Expand All @@ -157,6 +156,7 @@ export class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
const pixels = this.mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e[xProperty], e[yProperty]);

highlights.push({
entry:e,
x: e[xProperty],
y: e[yProperty],
xPx: pixels.x,
Expand Down
5 changes: 5 additions & 0 deletions src/charting/highlight/Highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ export interface Highlight {
* the y-position (pixels) on which this highlight object was last drawn
*/
drawY?;

/**
* the associated entry
*/
entry?;
}
1 change: 0 additions & 1 deletion src/charting/jobs/AnimatedViewPortJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export abstract class AnimatedViewPortJob extends ViewPortJob implements Animato
this.phase = obj.value;
()=>this.onAnimationUpdate(this.animator)
})
.start();
}


Expand Down
Loading

0 comments on commit e260f0a

Please sign in to comment.