Skip to content

Commit

Permalink
Merge pull request #37 from JCCDex/zcZhang_dev
Browse files Browse the repository at this point in the history
Zc zhang dev
  • Loading branch information
zcZhang123 authored Feb 23, 2019
2 parents 82e173c + d58e6bd commit 5feaf73
Show file tree
Hide file tree
Showing 17 changed files with 255 additions and 81 deletions.
6 changes: 6 additions & 0 deletions src/components/fullScreenMobileKline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ export default {
klineDataObj() {
if (this.klineDataObj) {
this.message = getLanguage();
let precision = {
price: this.klineDataObj.pricePrecision,
amount: this.klineDataObj.amountPrecision
}
if (this.klineDataObj.cycle !== "everyhour") {
var mobileKlineData = splitData(this.klineDataObj.klineData, this.platform)
this.klineDataObj.categoryData = mobileKlineData.categoryData
mobileKlineData.precision = precision
}
if (this.klineDataObj.cycle !== this.cycle) {
this.clearChart()
Expand All @@ -98,6 +103,7 @@ export default {
}
if (this.klineDataObj.cycle === "everyhour") {
let timeDivisionData = this.klineDataObj.timeDivisionData
timeDivisionData.precision = precision
let divisionData = handleDivisionData(timeDivisionData)
this.divisionTime = divisionData.divisionTime
if (timeDivisionData !== null && divisionData.times !== null && divisionData.averages !== null && divisionData.prices !== null && divisionData.volumes !== null) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/kline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ export default {
klineDataObj() {
if (this.klineDataObj) {
this.message = getLanguage();
let precision = {
price: this.klineDataObj.pricePrecision,
amount: this.klineDataObj.amountPrecision
}
let klineData = splitData(this.klineDataObj.klineData, this.platform)
let depthData = getDepthData(this.klineDataObj.depthData, this.klineDataObj.coinType);
let depthData = getDepthData(this.klineDataObj.depthData, this.klineDataObj.coinType, precision);
let data = Object.assign({}, klineData, depthData);
data.precision = precision;
this.klineData = data
if (data.values && data.volumes && data.categoryData) {
if(this.cycle !== this.klineDataObj.cycle || JSON.stringify(this.coinType) !== JSON.stringify(this.klineDataObj.coinType)) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/marketDepth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export default {
watch: {
klineDataObj() {
if (this.klineDataObj) {
let depthData = getDepthData(this.klineDataObj.depthData, this.klineDataObj.coinType);
let precision = {
price: this.klineDataObj.pricePrecision,
amount: this.klineDataObj.amountPrecision
}
let depthData = getDepthData(this.klineDataObj.depthData, this.klineDataObj.coinType, precision);
depthData.precision = precision;
if (depthData) {
if(JSON.stringify(this.coinType) !== JSON.stringify(this.klineDataObj.coinType)) {
this.clearChart();
Expand Down
6 changes: 6 additions & 0 deletions src/components/mobileKline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ export default {
klineDataObj() {
if (this.klineDataObj) {
this.message = getLanguage();
let precision = {
price: this.klineDataObj.pricePrecision,
amount: this.klineDataObj.amountPrecision
}
if (this.klineDataObj.cycle !== "everyhour") {
var mobileKlineData = splitData(this.klineDataObj.klineData, this.platform)
this.klineDataObj.categoryData = mobileKlineData.categoryData
mobileKlineData.precision = precision
}
if (this.klineDataObj.cycle !== this.cycle) {
this.clearChart()
Expand All @@ -101,6 +106,7 @@ export default {
}
if (this.klineDataObj.cycle === "everyhour") {
let timeDivisionData = this.klineDataObj.timeDivisionData
timeDivisionData.precision = precision
let divisionData = handleDivisionData(timeDivisionData)
this.divisionTime = divisionData.divisionTime
if (timeDivisionData !== null && divisionData.times !== null && divisionData.averages !== null && divisionData.prices !== null && divisionData.volumes !== null) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/timeSharing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ export default {
watch: {
klineDataObj() {
if (this.klineDataObj.timeDivisionData) {
let precision = {
price: this.klineDataObj.pricePrecision,
amount: this.klineDataObj.amountPrecision
}
let timeDivisionData = this.klineDataObj.timeDivisionData;
let divisionData = handleDivisionData(timeDivisionData)
this.divisionTime = divisionData.divisionTime;
this.message = getLanguage();
timeDivisionData.precision = precision;
if (JSON.stringify(this.coinType) !== JSON.stringify(this.klineDataObj.coinType)) {
this.clearChart()
this.timeSharingTipData = this.timeSharing.setTimeSharingOption(timeDivisionData, divisionData)
Expand Down
58 changes: 32 additions & 26 deletions src/js/KLineMobileSetChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var cycle;
var config;
var timeDivisionconfig;
var toolTipData;
var amountsPrecision = 2;
var pricePrecision = 6;


class KLineMobileSetChartController {
Expand Down Expand Up @@ -108,20 +110,22 @@ class KLineMobileSetChartController {
}

updateOption(data) {
pricePrecision = data.precision.price ? data.precision.price : pricePrecision;
amountsPrecision = data.precision.amount ? data.precision.amount : amountsPrecision;
let length = data.values.length - 1;
if (!toolTipData) {
toolTipData = {
time: data.categoryData[length],
volume: formatDecimal(data.values[length][5], 2, 5),
opening: data.values[length][0].toFixed(6),
closing: data.values[length][1].toFixed(6),
max: data.values[length][3].toFixed(6),
min: data.values[length][2].toFixed(6),
MA5: calculateMA(5, data)[length],
MA10: calculateMA(10, data)[length],
MA20: calculateMA(20, data)[length],
MA30: calculateMA(30, data)[length],
MA60: calculateMA(60, data)[length],
volume: formatDecimal(data.values[length][5], amountsPrecision, true),
opening: formatDecimal(data.values[length][0], pricePrecision, true),
closing: formatDecimal(data.values[length][1], pricePrecision, true),
max: formatDecimal(data.values[length][3], pricePrecision, true),
min: formatDecimal(data.values[length][2], pricePrecision, true),
MA5: formatDecimal(calculateMA(5, data)[length], pricePrecision, true),
MA10: formatDecimal(calculateMA(10, data)[length], pricePrecision, true),
MA20: formatDecimal(calculateMA(20, data)[length], pricePrecision, true),
MA30: formatDecimal(calculateMA(30, data)[length], pricePrecision, true),
MA60: formatDecimal(calculateMA(60, data)[length], pricePrecision, true),
color: data.volumes[length][2],
type: 'normal'
};
Expand All @@ -141,16 +145,16 @@ class KLineMobileSetChartController {
var index = param.data[0];
toolTipData = {
time: param.name,
volume: formatDecimal(data.values[index][5], 2, 5),
opening: data.values[index][0].toFixed(6),
closing: data.values[index][1].toFixed(6),
max: data.values[index][3].toFixed(6),
min: data.values[index][2].toFixed(6),
MA5: calculateMA(5, data)[index],
MA10: calculateMA(10, data)[index],
MA20: calculateMA(20, data)[index],
MA30: calculateMA(30, data)[index],
MA60: calculateMA(60, data)[index],
volume: formatDecimal(data.values[index][5], amountsPrecision, true),
opening: formatDecimal(data.values[index][0], pricePrecision, true),
closing: formatDecimal(data.values[index][1], pricePrecision, true),
max: formatDecimal(data.values[index][3], pricePrecision, true),
min: formatDecimal(data.values[index][2], pricePrecision, true),
MA5: formatDecimal(calculateMA(5, data)[index], pricePrecision, true),
MA10: formatDecimal(calculateMA(10, data)[index], pricePrecision, true),
MA20: formatDecimal(calculateMA(20, data)[index], pricePrecision, true),
MA30: formatDecimal(calculateMA(30, data)[index], pricePrecision, true),
MA60: formatDecimal(calculateMA(60, data)[index], pricePrecision, true),
color: data.volumes[index][2],
type: 'normal'
};
Expand Down Expand Up @@ -205,14 +209,16 @@ class KLineMobileSetChartController {
}

updateTimeDivisionOption(timeDivisionData, data) {
pricePrecision = timeDivisionData.precision.price ? timeDivisionData.precision.price : pricePrecision;
amountsPrecision = timeDivisionData.precision.amount ? timeDivisionData.precision.amount : amountsPrecision;
let { times, averages, prices, volumes } = data;
let length = timeDivisionData.length - 1;
if (!toolTipData) {
toolTipData = {
time: formatTime(timeDivisionData[length][3]),
volume: formatDecimal(timeDivisionData[length][1], 2, 5),
price: timeDivisionData[length][2].toFixed(6),
averagePrice: averages[length].toFixed(6),
volume: formatDecimal(timeDivisionData[length][1], amountsPrecision, true),
price: formatDecimal(timeDivisionData[length][2], pricePrecision, true),
averagePrice: formatDecimal(averages[length], pricePrecision, true),
color: volumes[length][2]
};
}
Expand Down Expand Up @@ -245,9 +251,9 @@ class KLineMobileSetChartController {
let data = timeDivisionData[dataIndex];
toolTipData = {
time: formatTime(data[3]),
volume: formatDecimal(data[1], 2, 5),
price: data[2].toFixed(6),
averagePrice: averages[dataIndex].toFixed(6),
volume: formatDecimal(data[1], amountsPrecision, true),
price: formatDecimal(data[2], pricePrecision, true),
averagePrice: formatDecimal(averages[dataIndex], pricePrecision, true),
color: volumes[dataIndex][2]
};

Expand Down
46 changes: 26 additions & 20 deletions src/js/KLineSetChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var klineSize = {
var config;
var toolTipData;
var oldKlineData;
var amountsPrecision = 2;
var pricePrecision = 6;

class KLineSetChartController {
constructor(configs) {
Expand Down Expand Up @@ -135,19 +137,21 @@ class KLineSetChartController {
};
config = JSON.parse(JSON.stringify(this.klineConfig));
if (data) {
pricePrecision = data.precision.price ? data.precision.price : pricePrecision;
amountsPrecision = data.precision.amount ? data.precision.amount : amountsPrecision;
let length = data.values.length - 1;
toolTipData = {
time: data.categoryData[length],
volume: formatDecimal(data.values[length][5], 2, 5),
opening: data.values[length][0].toFixed(6),
closing: data.values[length][1].toFixed(6),
max: data.values[length][3].toFixed(6),
min: data.values[length][2].toFixed(6),
MA5: calculateMA(5, data)[length],
MA10: calculateMA(10, data)[length],
MA20: calculateMA(20, data)[length],
MA30: calculateMA(30, data)[length],
MA60: calculateMA(60, data)[length],
volume: formatDecimal(data.values[length][5], amountsPrecision, true),
opening: formatDecimal(data.values[length][0], pricePrecision, true),
closing: formatDecimal(data.values[length][1], pricePrecision, true),
max: formatDecimal(data.values[length][3], pricePrecision, true),
min: formatDecimal(data.values[length][2], pricePrecision, true),
MA5: formatDecimal(calculateMA(5, data)[length], pricePrecision, true),
MA10: formatDecimal(calculateMA(10, data)[length], pricePrecision, true),
MA20: formatDecimal(calculateMA(20, data)[length], pricePrecision, true),
MA30: formatDecimal(calculateMA(30, data)[length], pricePrecision, true),
MA60: formatDecimal(calculateMA(60, data)[length], pricePrecision, true),
color: data.volumes[length][2]
};
this.kline.hideLoading();
Expand All @@ -165,6 +169,8 @@ class KLineSetChartController {
}

updateOption(data, cycle) {
pricePrecision = data.precision.price ? data.precision.price : pricePrecision;
amountsPrecision = data.precision.amount ? data.precision.amount : amountsPrecision;
oldKlineData = {
oldData: data,
oldCycle: cycle
Expand Down Expand Up @@ -206,16 +212,16 @@ class KLineSetChartController {
toolTipData = {
seriesName: param.seriesName,
time: param.name,
volume: formatDecimal(data.values[index][5], 2, 5),
opening: data.values[index][0].toFixed(6),
closing: data.values[index][1].toFixed(6),
max: data.values[index][3].toFixed(6),
min: data.values[index][2].toFixed(6),
MA5: calculateMA(5, data)[index],
MA10: calculateMA(10, data)[index],
MA20: calculateMA(20, data)[index],
MA30: calculateMA(30, data)[index],
MA60: calculateMA(60, data)[index],
volume: formatDecimal(data.values[index][5], amountsPrecision, true),
opening: formatDecimal(data.values[index][0], pricePrecision, true),
closing: formatDecimal(data.values[index][1], pricePrecision, true),
max: formatDecimal(data.values[index][3], pricePrecision, true),
min: formatDecimal(data.values[index][2], pricePrecision, true),
MA5: formatDecimal(calculateMA(5, data)[index], pricePrecision, true),
MA10: formatDecimal(calculateMA(10, data)[index], pricePrecision, true),
MA20: formatDecimal(calculateMA(20, data)[index], pricePrecision, true),
MA30: formatDecimal(calculateMA(30, data)[index], pricePrecision, true),
MA60: formatDecimal(calculateMA(60, data)[index], pricePrecision, true),
color: data.volumes[index][2]
};
}
Expand Down
22 changes: 14 additions & 8 deletions src/js/SetDepthChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import 'echarts/lib/chart/line';
import 'echarts/lib/component/dataZoom';
import 'echarts/lib/component/legend';
import merge from 'lodash.merge';
import { getClientWidth, getLanguage, getClientHeight } from './utils';
import { getClientWidth, getLanguage, getClientHeight, formatDecimal } from './utils';

var depthSize = {
width: 0,
height: 0
};
var depthOption;
var oldDepthData;
var amountsPrecision = 2;
var pricePrecision = 6;

class DepthChart {
constructor(configs) {
Expand Down Expand Up @@ -126,6 +128,8 @@ class DepthChart {
setDepthOption(data) {
oldDepthData = data;
if (data) {
pricePrecision = data.precision.price ? data.precision.price : pricePrecision;
amountsPrecision = data.precision.amount ? data.precision.amount : amountsPrecision;
depthOption = JSON.parse(JSON.stringify(this.depthConfig));
let message = getLanguage();
let buy = message.buy;
Expand All @@ -152,6 +156,8 @@ class DepthChart {
}

updateDepthOption(data) {
pricePrecision = data.precision.price ? data.precision.price : pricePrecision;
amountsPrecision = data.precision.amount ? data.precision.amount : amountsPrecision;
let message = getLanguage();
let buy = message.buy;
let sell = message.sell;
Expand Down Expand Up @@ -200,35 +206,35 @@ class DepthChart {
let message = getLanguage();
var fontSize = '';
if (this.depthConfig.platform === 'mobile') {
fontSize = 'font-size:20px'
fontSize = 'font-size:20px';
}
var toolTip = {
formatter: function (param) {
param = param[0];
if (param) {
if (param.seriesName === 'Sell' || param.seriesName === '卖出') {
return [
'<div style="text-align:left; '+fontSize+'">',
'<div style="text-align:left; ' + fontSize + '">',
'<div style="width:10px;height:10px;background:#28b869;border-radius:4px;float:left;margin-top:7px;margin-right:2px;"></div>' +
message.sellPrice +
param.data[0] +
formatDecimal(param.data[0], pricePrecision, true) +
'<br/>',
'<div style="width:10px;height:10px;background:#28b869;border-radius:4px;float:left;margin-top:7px;margin-right:2px;"></div>' +
message.sellTotal +
param.data[1] +
formatDecimal(param.data[1], amountsPrecision, true) +
'<br/>',
'</div>'
].join('');
} else if (param.seriesName === 'Buy' || param.seriesName === '买入') {
return [
'<div style="text-align:left; '+fontSize+'">',
'<div style="text-align:left; ' + fontSize + '">',
'<div style="width:6px;height:6px;background:#ee4b4b;border-radius:4px;float:left;margin-top:7px;margin-right:2px;"></div>' +
message.buyPrice +
param.data[0] +
formatDecimal(param.data[0], pricePrecision, true) +
'<br/>',
'<div style="width:6px;height:6px;background:#ee4b4b;border-radius:4px;float:left;margin-top:7px;margin-right:2px;"></div>' +
message.buyTotal +
param.data[1] +
formatDecimal(param.data[1], amountsPrecision, true) +
'<br/>',
'</div>'
].join('');
Expand Down
Loading

0 comments on commit 5feaf73

Please sign in to comment.