未验证 提交 8758370d 编写于 作者: D daminglu 提交者: GitHub

Removed Fit-to-Screen and Slider as we do not need them anymore (#370)

上级 0be5b06c
...@@ -2,20 +2,18 @@ ...@@ -2,20 +2,18 @@
<div class="visual-dl-page-container"> <div class="visual-dl-page-container">
<div class="visual-dl-page-left"> <div class="visual-dl-page-left">
<ui-chart <ui-chart
:fit-screen="fitScreen" :do-download="doDownload"
:download="download"
:scale="config.scale"
:cur-node="curNode" :cur-node="curNode"
@curNodeUpdated="curNode = $event" @curNodeUpdated="curNode = $event"
@triggerDownload="doDownload = $event"
/> />
</div> </div>
<div class="visual-dl-page-right"> <div class="visual-dl-page-right">
<div class="visual-dl-page-config-container"> <div class="visual-dl-page-config-container">
<ui-config <ui-config
:config="config"
:cur-node="curNode" :cur-node="curNode"
@fitScreen="handleFitScreen" :do-download="doDownload"
@download="handleDownload" @triggerDownload="doDownload = $event"
/> />
</div> </div>
</div> </div>
...@@ -36,26 +34,14 @@ export default { ...@@ -36,26 +34,14 @@ export default {
name: 'Graph', name: 'Graph',
data() { data() {
return { return {
config: { doDownload: false,
scale: 0.5,
},
fitScreen: {fitScreen: false},
download: {download: false},
curNode: {}, curNode: {},
}; };
}, },
mounted() { mounted() {
autoAdjustHeight(); autoAdjustHeight();
}, },
methods: { methods: {},
handleFitScreen() {
this.fitScreen = {fitScreen: true};
this.config.scale = 0.5;
},
handleDownload() {
this.download = {fitScreen: true};
},
},
}; };
</script> </script>
......
<template> <template>
<div class="visual-dl-graph-charts"> <div class="visual-dl-graph-charts">
<svg class="visual-dl-page-left"> <svg
class="visual-dl-page-left"
ref="graphSvg">
<g/> <g/>
</svg> </svg>
</div> </div>
</template> </template>
<script> <script>
// libs
import echarts from 'echarts';
import {
dragMovelHandler,
tansformElement,
relativeMove,
} from './dragHelper';
// service // service
import {getPluginGraphsGraph} from '../../service'; import {getPluginGraphsGraph} from '../../service';
// https://github.com/taye/interact.js
import interact from 'interactjs';
// for d3 drawing // for d3 drawing
import * as d3 from 'd3'; import * as d3 from 'd3';
export default { export default {
props: { props: {
'fitScreen': { 'doDownload': {
type: Function, type: Boolean,
required: true,
},
'download': {
type: Function,
required: true, required: true,
}, },
'scale': {
type: Number,
default: 1,
},
'curNode': { 'curNode': {
type: Object, type: Object,
default: {}, default: {},
}}, }},
computed: { computed: {},
computedWidth() {
let scale = this.scale;
return Math.floor(scale * 2 * 700);
},
},
data() { data() {
return { return {
myCY: null,
graphUrl: '',
}; };
}, },
watch: { watch: {
fitScreen: function(val) { doDownload: function(val) {
this.clearDragedTransform(this.getBigImgEl()); if (this.doDownload) {
this.clearDragedTransform(this.getSmallImgDragHandler()); // TODO(daming-lu): .svg is ugly and colorless.
}, let svg = this.$refs.graphSvg;
download: function(val) {
if (this.myCY) { // get svg source.
let aEl = document.createElement('a'); let serializer = new XMLSerializer();
aEl.href = this.myCY.png(); let source = serializer.serializeToString(svg);
aEl.download = 'graph.png';
aEl.click(); // add name spaces.
if (!source.match(/^<svg[^>]+xmlns="http\:\/\/www\.w3\.org\/2000\/svg"/)) {
source = source.replace(/^<svg/, '<svg xmlns="http://www.w3.org/2000/svg"');
}
if (!source.match(/^<svg[^>]+"http\:\/\/www\.w3\.org\/1999\/xlink"/)) {
source = source.replace(/^<svg/, '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
}
// add xml declaration
source = '<?xml version="1.0" standalone="no"?>\r\n' + source;
// convert svg source to URI data scheme.
let url = 'data:image/svg+xml;charset=utf-8,'+encodeURIComponent(source);
let a = document.createElement('a');
a.download = 'graph.svg';
a.href = url;
a.click();
this.$emit('triggerDownload', false);
} }
}, },
}, },
mounted() { mounted() {
this.getOriginChartsData();
let chartScope = this; let chartScope = this;
getPluginGraphsGraph().then(({errno, data}) => { getPluginGraphsGraph().then(({errno, data}) => {
let graphData = data.data; let graphData = data.data;
...@@ -183,94 +179,7 @@ export default { ...@@ -183,94 +179,7 @@ export default {
}); });
}, },
methods: { methods: {},
createChart() {
let el = this.el.getElementsByClassName('visual-dl-chart-box')[0];
this.myChart = echarts.init(el);
},
initChartOption(data) {
this.setChartOptions(data);
},
setChartOptions(data) {
this.myChart.setOption(data);
},
getOriginChartsData() {
getPluginGraphsGraph().then(({status, data}) => {
if (status === 0 && data.url) {
this.graphUrl = data.url;
this.addDragEventForImg();
}
});
},
clearDragedTransform(dragImgEl) {
dragImgEl.style.transform = 'none';
dragImgEl.setAttribute('data-x', 0);
dragImgEl.setAttribute('data-y', 0);
},
getBigImgEl() {
return this.$refs.draggable;
},
getSmallImgEl() {
return this.$refs.small_img;
},
getSmallImgDragHandler() {
return this.$refs.screen_handler;
},
addDragEventForImg() {
let chartScope = this;
// target elements with the "draggable" class
interact('.draggable').draggable({
// enable inertial throwing
inertia: true,
autoScroll: true,
// call this function on every dragmove event
onmove(event) {
dragMovelHandler(event, (target, x, y) => {
tansformElement(target, x, y);
// compute the proportional value
let triggerEl = chartScope.getBigImgEl();
let relativeEl = chartScope.getSmallImgDragHandler();
relativeMove({triggerEl, x, y}, relativeEl);
});
},
});
interact('.screen-handler').draggable({
// enable inertial throwing
inertia: true,
autoScroll: true,
restrict: {
restriction: 'parent',
endOnly: false,
elementRect: {
top: 0,
left: 0,
bottom: 1,
right: 1,
},
},
// call this function on every dragmove event
onmove(event) {
dragMovelHandler(event, (target, x, y) => {
tansformElement(target, x, y);
// compute the proportional value
let triggerEl = chartScope.getSmallImgEl();
let relativeEl = chartScope.getBigImgEl();
relativeMove({triggerEl, x, y}, relativeEl);
});
},
});
},
},
}; };
</script> </script>
<style lang="stylus"> <style lang="stylus">
......
<template> <template>
<div class="visual-dl-graph-config-com"> <div class="visual-dl-graph-config-com">
<div class="graph-config-upper"> <div class="graph-config-upper">
<v-btn
class="visual-dl-graph-config-button"
color="primary"
@click="handleFitScreen"
dark>
<v-icon
style="margin-right: 6px"
size="20">fullscreen</v-icon>
Fit &nbsp; to &nbsp; screen
</v-btn>
<v-btn <v-btn
class="visual-dl-graph-config-button" class="visual-dl-graph-config-button"
color="primary" color="primary"
...@@ -20,14 +9,6 @@ ...@@ -20,14 +9,6 @@
<v-icon style="margin-right: 6px">file_download</v-icon> <v-icon style="margin-right: 6px">file_download</v-icon>
Download image Download image
</v-btn> </v-btn>
<v-slider
label="Scale"
max="1"
min="0.1"
step="0.1"
v-model="config.scale"
dark/>
</div> </div>
<div class="node-info"> <div class="node-info">
<h3>Node Info: </h3> <h3>Node Info: </h3>
...@@ -55,21 +36,16 @@ ...@@ -55,21 +36,16 @@
export default { export default {
props: { props: {
curNode: { 'doDownload': {
type: Object, type: Boolean,
required: true, required: true,
}, },
config: { 'curNode': {
type: Object, type: Object,
required: true, default: {},
}, }}, methods: {
},
methods: {
handleFitScreen() {
this.$emit('fitScreen');
},
handleDownload() { handleDownload() {
this.$emit('download'); this.$emit('triggerDownload', true);
}, },
}, },
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册