未验证 提交 0541f793 编写于 作者: A abigale Li 提交者: GitHub

modify overlay and offset chart view interplay problem (#118)

上级 6292c438
...@@ -24,9 +24,7 @@ import {format, precisionRound} from 'd3-format'; ...@@ -24,9 +24,7 @@ import {format, precisionRound} from 'd3-format';
// service // service
import {getPluginHistogramsHistograms} from '../../service'; import {getPluginHistogramsHistograms} from '../../service';
const highlightLineColor = '#2f4554'; let zrDrawElement = {};
const defaultLineColor = '#d14a61';
const lineWidth = 1;
// the time to refresh chart data // the time to refresh chart data
const intervalTime = 15; const intervalTime = 15;
...@@ -63,7 +61,7 @@ export default { ...@@ -63,7 +61,7 @@ export default {
let tagInfo = this.data.get('tagInfo'); let tagInfo = this.data.get('tagInfo');
this.initChart(tagInfo); this.initChart(tagInfo);
this.initChartEvent(); // this.initChartEvent();
if (this.data.get('running')) { if (this.data.get('running')) {
this.startInterval(); this.startInterval();
} }
...@@ -88,14 +86,11 @@ export default { ...@@ -88,14 +86,11 @@ export default {
initChartOption() { initChartOption() {
this.myChart.clear(); this.myChart.clear();
let chartType = this.data.get('chartType');
// var ob = this.myChart.getOption();
let data = this.data.get('originData'); let data = this.data.get('originData');
let visData = originDataToChartData(data); let visData = originDataToChartData(data);
let tagInfo = this.data.get('tagInfo'); let tagInfo = this.data.get('tagInfo');
let title = tagInfo.tag.displayName + '(' + tagInfo.run + ')'; let title = tagInfo.tag.displayName + '(' + tagInfo.run + ')';
let chartType = this.data.get('chartType');
this.setChartOptions(visData, title, chartType); this.setChartOptions(visData, title, chartType);
}, },
...@@ -106,7 +101,6 @@ export default { ...@@ -106,7 +101,6 @@ export default {
right: '10%', right: '10%',
bottom: '8%' bottom: '8%'
}; };
let title = { let title = {
text: tag, text: tag,
textStyle: { textStyle: {
...@@ -133,8 +127,8 @@ export default { ...@@ -133,8 +127,8 @@ export default {
lineStyle: { lineStyle: {
normal: { normal: {
// opacity: originLinesOpacity, // opacity: originLinesOpacity,
width: lineWidth, width: 1,
color: defaultLineColor color: '#008c99'
} }
}, },
encode: { encode: {
...@@ -172,7 +166,19 @@ export default { ...@@ -172,7 +166,19 @@ export default {
}, },
series: seriesOption series: seriesOption
}; };
this.myChart.setOption(option);
var zr1 = this.myChart.getZr();
zr1.on('mousemove', function (e) {
zr1.remove(zrDrawElement.hoverLine);
zr1.remove(zrDrawElement.tooltip);
zr1.remove(zrDrawElement.tooltipX);
zr1.remove(zrDrawElement.tooltipY);
zrDrawElement.hoverDots.forEach(dot => zr1.remove(dot));
zrDrawElement.hoverDots.length = 0;
});
this.myChart.setOption(option, {notMerge: true});
}, },
setOffsetChartOption({chartData, min, max}, title, grid) { setOffsetChartOption({chartData, min, max}, title, grid) {
...@@ -243,7 +249,7 @@ export default { ...@@ -243,7 +249,7 @@ export default {
params.dataIndex, params.dataIndex,
api.value, api.value,
api.coord, api.coord,
params.coordSys.y - 5 params.coordSys.y - 10
); );
return { return {
type: 'polygon', type: 'polygon',
...@@ -289,23 +295,18 @@ export default { ...@@ -289,23 +295,18 @@ export default {
return pt; return pt;
} }
let hoverLine; zrDrawElement.hoverDots = [];
let maxLine;
let hoverDots = [];
let tooltip;
let tooltipX;
let tooltipY;
let zr = ecChart.getZr(); let zr = ecChart.getZr();
function removeTooltip(){ function removeTooltip(){
if (hoverLine) { if (zrDrawElement.hoverLine) {
zr.remove(hoverLine); zr.remove(zrDrawElement.hoverLine);
zr.remove(tooltip); zr.remove(zrDrawElement.tooltip);
hoverDots.forEach(dot => zr.remove(dot)); zrDrawElement.hoverDots.forEach(dot => zr.remove(dot));
hoverDots.length = 0; zrDrawElement.hoverDots.length = 0;
zr.remove(tooltipX); zr.remove(zrDrawElement.tooltipX);
zr.remove(tooltipY); zr.remove(zrDrawElement.tooltipY);
} }
} }
...@@ -320,15 +321,18 @@ export default { ...@@ -320,15 +321,18 @@ export default {
let getCoord = function(pt) { let getCoord = function(pt) {
return ecChart.convertToPixel('grid', pt); return ecChart.convertToPixel('grid', pt);
}; };
let gridRect = ecChart.getModel().getComponent('grid', 0).coordinateSystem.getRect();
let linePoints = makePolyPoints( let linePoints = makePolyPoints(
nearestIndex.itemIndex, nearestIndex.itemIndex,
function (i) { function (i) {
return rawData[nearestIndex.itemIndex][i]; return rawData[nearestIndex.itemIndex][i];
}, },
getCoord getCoord,
gridRect.y - 10
); );
zr.add(hoverLine = new echarts.graphic.Polyline({ zr.add(zrDrawElement.hoverLine = new echarts.graphic.Polyline({
silent: true, silent: true,
shape: { shape: {
points: linePoints points: linePoints
...@@ -362,11 +366,11 @@ export default { ...@@ -362,11 +366,11 @@ export default {
z: 1000 z: 1000
}); });
zr.add(dot); zr.add(dot);
hoverDots.push(dot); zrDrawElement.hoverDots.push(dot);
}); });
let hoveredItem = chartData[nearestIndex.itemIndex]; let hoveredItem = chartData[nearestIndex.itemIndex];
tooltip = new echarts.graphic.Text({ zrDrawElement.tooltip = new echarts.graphic.Text({
position: [e.offsetX + 30, e.offsetY - 50], position: [e.offsetX + 30, e.offsetY - 50],
style: { style: {
text: hoveredItem.items[nearestIndex.binIndex][3], text: hoveredItem.items[nearestIndex.binIndex][3],
...@@ -381,11 +385,9 @@ export default { ...@@ -381,11 +385,9 @@ export default {
}, },
z: 2000 z: 2000
}); });
zr.add(tooltip); zr.add(zrDrawElement.tooltip);
let gridRect = ecChart.getModel().getComponent('grid', 0).coordinateSystem.getRect(); zrDrawElement.tooltipX = new echarts.graphic.Text({
tooltipX = new echarts.graphic.Text({
position: [ position: [
itemX, itemX,
gridRect.y + gridRect.height gridRect.y + gridRect.height
...@@ -402,9 +404,9 @@ export default { ...@@ -402,9 +404,9 @@ export default {
}, },
z: 2000 z: 2000
}); });
zr.add(tooltipX); zr.add(zrDrawElement.tooltipX);
tooltipY = new echarts.graphic.Text({ zrDrawElement.tooltipY = new echarts.graphic.Text({
position: [ position: [
gridRect.x + gridRect.width, gridRect.x + gridRect.width,
linePoints[linePoints.length - 1][1] linePoints[linePoints.length - 1][1]
...@@ -421,7 +423,7 @@ export default { ...@@ -421,7 +423,7 @@ export default {
}, },
z: 2000 z: 2000
}); });
zr.add(tooltipY); zr.add(zrDrawElement.tooltipY);
} }
}); });
...@@ -456,7 +458,7 @@ export default { ...@@ -456,7 +458,7 @@ export default {
} }
} }
ecChart.setOption(option); ecChart.setOption(option, {notMerge: true});
}, },
...@@ -484,32 +486,32 @@ export default { ...@@ -484,32 +486,32 @@ export default {
}); });
}, },
lightHoveredLine({seriesIndex}) { // lightHoveredLine({seriesIndex}) {
let series = this.myChart.getOption().series; // let series = this.myChart.getOption().series;
let newSeries = series.map((item, index) => { // let newSeries = series.map((item, index) => {
if (seriesIndex === index) { // if (seriesIndex === index) {
item.lineStyle.normal.color = highlightLineColor; // item.lineStyle.normal.color = highlightLineColor;
item.zlevel = 1; // item.zlevel = 1;
} // }
else { // else {
item.lineStyle.normal.color = defaultLineColor; // item.lineStyle.normal.color = defaultLineColor;
item.zlevel = 0; // item.zlevel = 0;
} // }
return item; // return item;
}); // });
this.myChart.setOption({ // this.myChart.setOption({
series: newSeries // series: newSeries
}); // });
}, // },
initChartEvent() { // initChartEvent() {
this.myChart.on('mousemove', params => { // this.myChart.on('mousemove', params => {
let chartType = this.data.get('chartType'); // let chartType = this.data.get('chartType');
if (chartType === 'overlay') { // if (chartType === 'overlay') {
this.lightHoveredLine(params); // this.lightHoveredLine(params);
} // }
}); // });
}, // },
expandArea() { expandArea() {
let isExpand = this.data.get('isExpand'); let isExpand = this.data.get('isExpand');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册