grgw_old_java/heatsupply2/WebContent/static/echarts/4.2.1/test/hoverStyle.html

632 lines
21 KiB
HTML

<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/facePrint.js"></script>
<script src="lib/testHelper.js"></script>
<link rel="stylesheet" href="lib/reset.css" />
</head>
<body>
<style>
.test-title {
background: #146402;
color: #fff;
}
#info {
position: fixed;
left: 0;
top: 0;
background: #333;
color: #fff;
padding: 2px 5px;
z-index: 9999;
box-shadow: 0 0 2px #333;
}
</style>
<br>
<br>
<br>
<div id="info"></div>
<div id="mainb1"></div>
<div id="mainb2"></div>
<div id="mainb3"></div>
<div id="main0"></div>
<div id="main1"></div>
<div id="main2"></div>
<div id="main3"></div>
<div id="main4"></div>
<div id="main5"></div>
<script>
var USE_HOVER_LAYER_KEY = '__EC_TEST_USE_HOVER_LAYER_KEY___';
var useHoverLayer = getUseHoverLayer();
var hoverLayerThreshold = useHoverLayer ? 0 : null;
var infoEl = document.getElementById('info');
genInfo();
function setUseHoverLayer(useHoverLayer) {
window.localStorage.setItem(USE_HOVER_LAYER_KEY, useHoverLayer ? 'true' : '');
}
function getUseHoverLayer() {
return !!window.localStorage.getItem(USE_HOVER_LAYER_KEY);
}
function genInfo(zrRefreshTimestamp) {
infoEl.innerHTML = [
'<span style="color:yellow">'
+ (useHoverLayer ? 'Using HoverLayer' : 'NOT using HoverLayer')
+ '</span>',
'hoverLayerThreshold: ' + hoverLayerThreshold,
'zr refresh base layer at: <span style="color:yellow">' + (zrRefreshTimestamp || null) + '</span>'
].join('<br>');
}
function genHoverLayerBtns() {
return [{
text: 'NOT use hoverLayer',
onclick: function () {
setUseHoverLayer(false);
location.reload();
}
}, {
text: 'Use hoverLayer',
onclick: function () {
setUseHoverLayer(true);
location.reload();
}
}]
}
var originalCreate = testHelper.create;
testHelper.create = function (echarts, dom, opt) {
if (opt.option.hoverLayerThreshold === void 0) {
throw new Error('"hoverLayerThreshold" should be set');
}
var buttons = opt.buttons || [];
opt.buttons = buttons = genHoverLayerBtns().concat(buttons);
var chart = originalCreate.call(this, echarts, dom, opt);
var zr = chart.getZr();
var originalRefreshImmediately = zr.refreshImmediately;
zr.refreshImmediately = function () {
var result = originalRefreshImmediately.apply(this, arguments);
// Make sure refreshImmediately is not called when `useHoverLayer`.
genInfo(+new Date());
return result;
};
return chart;
}
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
xAxis: {
},
yAxis: {
},
grid: {
right: 120
},
visualMap: {
min: 100,
max: 800,
top: 10,
right: 10,
splitNumber: 3,
type: 'piecewise',
// demension: 1,
// hoverLink: true,
inRange: {
color: ['blue', 'red']
},
outOfRange: {
color: 'black'
}
},
series: [{
type: 'scatter',
symbolSize: 30,
data: [
[12, 331],
[55, 131],
[55, 531]
]
}]
};
testHelper.create(echarts, 'mainb1', {
title: [
'visualMap should be normal (and hoverLink should be normal)',
'(inRange: has color, outOfRange: "black")'
],
option: option,
height: 200
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
xAxis: {
},
yAxis: {
},
series: [{
type: 'scatter',
symbolSize: 30,
data: [
[12, 131],
[55, 431],
[55, 331]
]
}]
};
var chart = testHelper.create(echarts, 'mainb2', {
title: [
'setOption onclick and hover animation should be normal:',
'click any symbol, all symbols should become blue'
],
option: option,
height: 200
});
chart.on('click', function () {
chart.setOption({
color: ['blue']
});
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
xAxis: {
},
yAxis: {
},
series: [{
type: 'scatter',
symbolSize: 100,
data: [
{value: [0, 0], itemStyle: {color: 'blue'}},
{value: [0, 1], itemStyle: {color: 'red'}}
]
}]
};
var chart = testHelper.create(echarts, 'mainb3', {
title: [
'hover the blue symbol, the z2 can be top',
'unhover, **z2 should be back** to bottom'
],
option: option,
height: 200
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'scatter',
symbolSize: 30,
emphasis: {
label: {
show: true
}
},
data: [[12, 331221], [55, 331221]]
}]
};
testHelper.create(echarts, 'main0', {
title: [
'normal no label, hover show label inside',
'TEST: hover twice, should be normal',
'zrBaseLayer should not be refreshed if NOT using hoverLayer'
],
option: option,
height: 200
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'scatter',
symbolSize: 30,
label: {
show: true
},
itemStyle: {
color: 'green',
opacity: 1
},
emphasis: {
label: {
position: 'top'
}
},
data: [[12, 331221], [20, 331221], [55, 331221]]
}]
};
testHelper.create(echarts, 'main1', {
title: [
'normal label inside, hover label outside top.',
'lifted color should be able to restore after hover twice.'
],
option: option,
height: 200
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'scatter',
symbolSize: 30,
label: {
show: true
},
itemStyle: {
color: 'green',
opacity: 1
},
emphasis: {
itemStyle: {
color: 'red'
},
label: {
position: 'top'
}
},
data: [[12, 331221], [55, 331221]]
}]
};
var chart = testHelper.create(echarts, 'main2', {
title: [
'normal style: green',
'trigger hover by API (red, text top).',
'Test mouse hover and leave, should NOT return to normal.',
'Only click downplay to return normal'
],
option: option,
height: 200,
buttons: [{
text: 'highlight dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
});
}
}, {
text: 'downplay dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: 0
});
}
}]
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'scatter',
id: 's',
symbolSize: 30,
label: {
show: true
},
itemStyle: {
color: 'green',
opacity: 1
},
emphasis: {
itemStyle: {
color: 'red'
},
label: {
position: 'top'
}
},
data: [[12, 331221], [55, 331221]]
}]
};
var chart = testHelper.create(echarts, 'main3', {
title: [
'trigger hover by API (red, text top).',
'setOption to change hoverStyle.'
],
option: option,
height: 200,
buttons: [{
text: 'highlight dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
});
}
}, {
text: 'setOption to modify hoverStyle yellow',
onclick: function () {
chart.setOption({
series: [{
id: 's',
emphasis: {
itemStyle: {
color: 'yellow'
},
label: {
fontSize: 30
}
}
}]
});
}
}, {
text: 'setOption to modify hoverStyle blue',
onclick: function () {
chart.setOption({
series: [{
id: 's',
emphasis: {
itemStyle: {
color: 'blue'
},
label: {
fontSize: 50
}
}
}]
});
}
}, {
text: 'downplay dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: 0
});
}
}]
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'custom',
renderItem: function (params, api) {
return {
type: 'group',
children: [{
type: 'rect',
shape: {x: 100, y: 30, width: 100, height: 50},
style: {fill: '#333'}
}, {
type: 'rect',
shape: {x: 130, y: 50, width: 100, height: 50},
style: {fill: '#555'}
}, {
type: 'rect',
shape: {x: 160, y: 70, width: 100, height: 50},
style: {fill: '#777'}
}]
};
},
data: [[12, 331221], [55, 331221]]
}]
};
testHelper.create(echarts, 'main4', {
title: [
'custom series: all highlighted when hover, keep z correct'
],
option: option,
height: 200
});
});
</script>
<script>
require(['echarts'], function (echarts) {
var option = {
hoverLayerThreshold: hoverLayerThreshold,
tooltip: {},
xAxis: {
},
yAxis: {
splitNumber: 2,
scale: true
},
series: [{
type: 'line',
symbolSize: 20,
data: [[21, 22], [44, 11]]
}]
};
var chart = testHelper.create(echarts, 'main5', {
title: [
'Test default symbol hover style (scale) (Only test **Not use hoverLayer**)',
'trigger hover by API: **should scaled**.',
'Test mouse hover and leave, should NOT return to normal.',
'Only click downplay to return normal'
],
option: option,
height: 200,
buttons: [{
text: 'highlight dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'highlight',
seriesIndex: 0,
dataIndex: 0
});
}
}, {
text: 'downplay dataIndex 0',
onclick: function () {
chart.dispatchAction({
type: 'downplay',
seriesIndex: 0,
dataIndex: 0
});
}
}]
});
});
</script>
</body>
</html>