Skip to content

Commit

Permalink
1. 修复切换时间K线不重绘BUG
Browse files Browse the repository at this point in the history
2. 修复bids为0报错
  • Loading branch information
chxj1992 committed Jan 10, 2018
1 parent 442f632 commit ed19a98
Show file tree
Hide file tree
Showing 18 changed files with 42,428 additions and 184 deletions.
42,243 changes: 42,242 additions & 1 deletion dist/kline.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/kline.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/stomp.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ <h1>K线图</h1>
symbol: "BTC",
symbolName: "BTC/USD",
type: "stomp", // poll/stomp
url: 'http://127.0.0.1:35003/v1/socket',
url: 'https://47.92.51.163:50001/v1/socket',
limit: 1000,
intervalTime: 5000,
subscribePath: "/trade/kline",
Expand Down
16 changes: 8 additions & 8 deletions src/js/areas.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class MainArea extends ChartArea {
}

onMouseMove(x, y) {
let mgr = new ChartManager();
let mgr = ChartManager.instance;
if (mgr._capturingMouseArea === this)
if (this._dragStarted === false)
if (Math.abs(this._oldX - x) > 1 || Math.abs(this._oldY - y) > 1)
Expand Down Expand Up @@ -257,7 +257,7 @@ export class MainArea extends ChartArea {
}

onMouseDown(x, y) {
let mgr = new ChartManager();
let mgr = ChartManager.instance;
mgr.getTimeline(this.getDataSourceName()).startMove();
this._oldX = x;
this._oldY = y;
Expand All @@ -268,7 +268,7 @@ export class MainArea extends ChartArea {
}

onMouseUp(x, y) {
let mgr = new ChartManager();
let mgr = ChartManager.instance;
let ret = null;
if (this._dragStarted) {
this._dragStarted = false;
Expand All @@ -292,7 +292,7 @@ export class IndicatorArea extends ChartArea {
}

onMouseMove(x, y) {
let mgr = new ChartManager();
let mgr = ChartManager.instance;
if (mgr._capturingMouseArea === this) {
if (this._dragStarted === false) {
if (this._oldX !== x || this._oldY !== y) {
Expand Down Expand Up @@ -325,7 +325,7 @@ export class IndicatorArea extends ChartArea {


onMouseDown(x, y) {
let mgr = new ChartManager();
let mgr = ChartManager.instance;
mgr.getTimeline(this.getDataSourceName()).startMove();
this._oldX = x;
this._oldY = y;
Expand All @@ -351,7 +351,7 @@ export class MainRangeArea extends ChartArea {
}

onMouseMove(x, y) {
new ChartManager().showCursor();
ChartManager.instance.showCursor();
return this;
}

Expand All @@ -365,7 +365,7 @@ export class IndicatorRangeArea extends ChartArea {
}

onMouseMove(x, y) {
new ChartManager().showCursor();
ChartManager.instance.showCursor();
return this;
}

Expand All @@ -379,7 +379,7 @@ export class TimelineArea extends ChartArea {
}

onMouseMove(x, y) {
new ChartManager().showCursor();
ChartManager.instance.showCursor();
return this;
}

Expand Down
46 changes: 23 additions & 23 deletions src/js/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export class Chart {
}

setTitle() {
let lang = new ChartManager().getLanguage();
let lang = ChartManager.instance.getLanguage();
let title = Kline.instance.symbolName;
title += ' ';
title += this.strIsLine ? Chart.strPeriod[lang]['line'] : Chart.strPeriod[lang][this._range];
title += (this._contract_unit + '/' + this._money_type).toUpperCase();
new ChartManager().setTitle('frame0.k0', title);
ChartManager.instance.setTitle('frame0.k0', title);
}


Expand All @@ -91,8 +91,8 @@ export class Chart {
updateDataAndDisplay() {
Kline.instance.symbol = this._symbol;
Kline.instance.range = this._range;
new ChartManager().setCurrentDataSource('frame0.k0', this._symbol + '.' + this._range);
new ChartManager().setNormalMode();
ChartManager.instance.setCurrentDataSource('frame0.k0', this._symbol + '.' + this._range);
ChartManager.instance.setNormalMode();
let f = Kline.instance.chartMgr.getDataSource("frame0.k0").getLastDate();

$('.symbol-title>a').text(Kline.instance.symbolName);
Expand All @@ -104,7 +104,7 @@ export class Chart {
Kline.instance.requestParam = Control.setHttpRequestParam(Kline.instance.symbol, Kline.instance.range, null, f.toString());
Control.requestData();
}
new ChartManager().redraw('All', false);
ChartManager.instance.redraw('All', false);
}


Expand All @@ -130,13 +130,13 @@ export class Chart {

updateDataSource(data) {
this._data = data;
new ChartManager().updateData("frame0.k0", this._data);
ChartManager.instance.updateData("frame0.k0", this._data);
}

updateDepth(array) {
if (array === null) {
this._depthData.array = [];
new ChartManager().redraw('All', false);
ChartManager.instance.redraw('All', false);
return;
}
if (!array.asks || !array.bids || array.asks === '' || array.bids === '')
Expand All @@ -159,8 +159,8 @@ export class Chart {
_data.bids_count = array.bids.length;
_data.asks_si = _data.asks_count - 1;
_data.asks_ei = 0;
_data.bids_si = _data.asks_count;
_data.bids_ei = _data.asks_count + _data.bids_count - 1;
_data.bids_si = _data.asks_count - 1;
_data.bids_ei = _data.asks_count + _data.bids_count - 2;
for (let i = _data.asks_si; i >= _data.asks_ei; i--) {
if (i === _data.asks_si) {
_data.array[i].amounts = _data.array[i].amount;
Expand All @@ -175,50 +175,50 @@ export class Chart {
_data.array[i].amounts = _data.array[i - 1].amounts + _data.array[i].amount;
}
}
new ChartManager().redraw('All', false);
ChartManager.instance.redraw('All', false);
}

setMainIndicator(indicName) {
this._mainIndicator = indicName;
if (indicName === 'NONE') {
new ChartManager().removeMainIndicator('frame0.k0');
ChartManager.instance.removeMainIndicator('frame0.k0');
} else {
new ChartManager().setMainIndicator('frame0.k0', indicName);
ChartManager.instance.setMainIndicator('frame0.k0', indicName);
}
new ChartManager().redraw('All', true);
ChartManager.instance.redraw('All', true);
}

setIndicator(index, indicName) {
if (indicName === 'NONE') {
let index = 2;
if (Template.displayVolume === false)
index = 1;
let areaName = new ChartManager().getIndicatorAreaName('frame0.k0', index);
let areaName = ChartManager.instance.getIndicatorAreaName('frame0.k0', index);
if (areaName !== '')
new ChartManager().removeIndicator(areaName);
ChartManager.instance.removeIndicator(areaName);
} else {
let index = 2;
if (Template.displayVolume === false)
index = 1;
let areaName = new ChartManager().getIndicatorAreaName('frame0.k0', index);
let areaName = ChartManager.instance.getIndicatorAreaName('frame0.k0', index);
if (areaName === '') {
Template.createIndicatorChartComps('frame0.k0', indicName);
} else {
new ChartManager().setIndicator(areaName, indicName);
ChartManager.instance.setIndicator(areaName, indicName);
}
}
new ChartManager().redraw('All', true);
ChartManager.instance.redraw('All', true);
}

addIndicator(indicName) {
new ChartManager().addIndicator(indicName);
new ChartManager().redraw('All', true);
ChartManager.instance.addIndicator(indicName);
ChartManager.instance.redraw('All', true);
}

removeIndicator(indicName) {
let areaName = new ChartManager().getIndicatorAreaName(2);
new ChartManager().removeIndicator(areaName);
new ChartManager().redraw('All', true);
let areaName = ChartManager.instance.getIndicatorAreaName(2);
ChartManager.instance.removeIndicator(areaName);
ChartManager.instance.redraw('All', true);
};

}
54 changes: 29 additions & 25 deletions src/js/chart_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ export class ChartManager {
}

redraw(layer, refresh) {
if (layer === undefined || refresh)
if (layer === undefined || refresh) {
layer = "All";
}
if (layer === "All" || layer === "MainCanvas") {
if (refresh)
if (refresh) {
this.getFrame("frame0").setChanged(true);
this.layout(this._mainContext, "frame0",
0, 0, this._mainCanvas.width, this._mainCanvas.height);
}
this.layout(this._mainContext, "frame0", 0, 0, this._mainCanvas.width, this._mainCanvas.height);
this.drawMain("frame0", this._mainContext);
}
if (layer === "All" || layer === "OverlayCanvas") {
this._overlayContext.clearRect(
0, 0, this._overlayCanvas.width, this._overlayCanvas.height);
this._overlayContext.clearRect(0, 0, this._overlayCanvas.width, this._overlayCanvas.height);
this.drawOverlay("frame0", this._overlayContext);
}
}
Expand All @@ -98,8 +98,9 @@ export class ChartManager {
} else if (layer === "overlay") {
this._overlayCanvas = canvas;
this._overlayContext = canvas.getContext("2d");
if (this._captureMouseWheelDirectly)
if (this._captureMouseWheelDirectly) {
$(this._overlayCanvas).bind('mousewheel', Control.mouseWheel);
}
}
}

Expand All @@ -124,7 +125,7 @@ export class ChartManager {
delete this._ranges['frame0.k0.indic1Range'];
delete this._areas['frame0.k0.indic1'];
delete this._areas['frame0.k0.indic1Range'];
new templates.DefaultTemplate().loadTemplate("frame0.k0", "");
templates.DefaultTemplate.loadTemplate("frame0.k0", "");
this.redraw('All', true);
}

Expand Down Expand Up @@ -332,14 +333,9 @@ export class ChartManager {
if (cached !== undefined && cached !== null) {
this.setDataSource(dsName, cached, true);
} else {
let ds = this.getDataSource(dsName);
if (ds !== undefined && ds !== null) {
this.setCachedDataSource(dsAlias, cached);
} else {
cached = new data_sources.MainDataSource(dsAlias);
this.setDataSource(dsName, cached, true);
this.setCachedDataSource(dsAlias, cached);
}
cached = new data_sources.MainDataSource(dsAlias);
this.setDataSource(dsName, cached, true);
this.setCachedDataSource(dsAlias, cached);
}
}

Expand Down Expand Up @@ -544,43 +540,51 @@ export class ChartManager {

updateData(dsName, data) {
let ds = this.getDataSource(dsName);
if (ds === undefined)
if (ds === undefined || ds === null) {
return;
if (data !== null) {
if (!ds.update(data))
}
if (data !== undefined && data !== null) {
if (!ds.update(data)) {
return false;
}
if (ds.getUpdateMode() === data_sources.DataSource.UpdateMode.DoNothing)
return true;
} else {
ds.setUpdateMode(data_sources.DataSource.UpdateMode.Refresh);
}
let timeline = this.getTimeline(dsName);
if (timeline !== undefined)
if (timeline !== undefined && timeline !== null) {
timeline.update();
if (ds.getDataCount() < 1)
}
if (ds.getDataCount() < 1) {
return true;
}
let dpNames = [".main", ".secondary"];
let area, areaName;
for (let n in this._areas) {
area = this._areas[n];
if (Util.isInstance(area, areas.ChartAreaGroup))
if (Util.isInstance(area, areas.ChartAreaGroup)) {
continue;
if (area.getDataSourceName() !== dsName)
}
if (area.getDataSourceName() !== dsName) {
continue;
}
areaName = area.getName();
for (let i = 0; i < dpNames.length; i++) {
let dp = this.getDataProvider(areaName + dpNames[i]);
if (dp !== undefined)
if (dp !== undefined && dp !== null) {
dp.updateData();
}
}
}
return true;
}

updateRange(dsName) {
let ds = this.getDataSource(dsName);
if (ds.getDataCount() < 1)
if (ds.getDataCount() < 1) {
return;
}
let dpNames = [".main", ".secondary"];
let area, areaName;
for (let n in this._areas) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/chart_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ChartSettings {
let _indic_param = {};
let _name = ['MA', 'EMA', 'VOLUME', 'MACD', 'KDJ', 'StochRSI', 'RSI', 'DMI', 'OBV', 'BOLL', 'DMA', 'TRIX', 'BRAR', 'VR', 'EMV', 'WR', 'ROC', 'MTM', 'PSY'];
for (let i = 0; i < _name.length; i++) {
let _value = new ChartManager().createIndicatorAndRange('', _name[i], true);
let _value = ChartManager.instance.createIndicatorAndRange('', _name[i], true);
if (_value === null) continue;
_indic_param[_name[i]] = [];
let param = _value.indic.getParameters();
Expand Down
Loading

0 comments on commit ed19a98

Please sign in to comment.