| <!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/simpleRequire.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> |
| <script src="data/basicChartsOptions.js"></script> |
| <script src="lib/dat.gui.min.js"></script> |
| <!-- <script src="ut/lib/canteen.js"></script> --> |
| <link rel="stylesheet" href="lib/reset.css" /> |
| </head> |
| <body> |
| <style> |
| body { |
| background: #eee; |
| margin: 0; |
| text-align: center; |
| } |
| #main { |
| box-sizing: border-box; |
| margin: 0 auto; |
| width: 800px; |
| max-width: 100%; |
| text-align: center; |
| } |
| .chart { |
| height: 400px; |
| border-radius: 5px; |
| margin: 20px 0; |
| box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); |
| background: #fff; |
| } |
| .dg.ac { |
| text-align: left; |
| } |
| </style> |
| |
| |
| |
| <div id="main"> |
| <h1>Tests for focus and blurScope</h1> |
| </div> |
| |
| |
| <script> |
| require(['echarts'/*, 'map/js/china' */], function (echarts) { |
| const charts = []; |
| const seriesFocusType = { |
| pie: 'self', |
| funnel: 'self', |
| themeRiver: 'self', |
| graph: 'adjacency', |
| sankey: 'adjacency', |
| sunburst: 'descendant', |
| treemap: 'descendant', |
| tree: 'ancestor' |
| } |
| allChartsOptions.forEach(function (chartOption) { |
| chartOption.series.forEach(function (series) { |
| series.emphasis = series.emphasis || {}; |
| series.emphasis.focus = series.emphasis.focus || seriesFocusType[series.type] || 'series'; |
| |
| if (series.renderItem) { |
| const oldRenderItem = series.renderItem; |
| series.renderItem = function () { |
| const ret = oldRenderItem.apply(this, arguments); |
| ret.focus = 'self'; |
| ret.blur = { |
| style: { |
| stroke: null |
| } |
| } |
| return ret; |
| } |
| } |
| |
| if (series.type === 'treemap') { |
| series.itemStyle = { |
| borderColor: 'rgba(100, 100, 200, 0.1)', |
| borderWidth: 5 |
| }; |
| series.upperLabel = { |
| show: true, |
| height: 15, |
| fontSize: 10 |
| }; |
| } |
| else if (series.type === 'line') { |
| series.endLabel = { |
| show: true |
| }; |
| series.labelLayout = { |
| hideOverlap: true |
| } |
| } |
| }); |
| const dom = document.createElement('div'); |
| dom.className = 'chart'; |
| document.querySelector('#main').appendChild(dom); |
| |
| const chart = echarts.init(dom); |
| chart.setOption(chartOption); |
| charts.push(chart); |
| }); |
| |
| // testcases about dispatchAction: 'highlight' |
| (function addDispatchActionHighlightChart(){ |
| // Basic options for all charts |
| var polarData = []; |
| for (var i = 0; i <= 100; i++) { |
| var theta = (i / 100) * 360; |
| var r = 5 * (1 + Math.sin((theta / 180) * Math.PI)); |
| polarData.push([r, theta]); |
| } |
| |
| var seriesBlurEmphasis = { |
| focus: 'self', |
| blurScope: "series" |
| }; |
| var globalBlurEmphasis = { |
| focus: "series", |
| blurScope: "global", |
| }; |
| var coordinateSystemBlurEmphasis = { |
| focus: 'series', |
| blurScope: "coordinateSystem", |
| }; |
| |
| const options = [ |
| ////////////// Hightlight multilple series(blurScope = 'series') ////////////// |
| { |
| id: "highlightMultipleSeries(blurScope='series', focus='self')", |
| name: "Dispatch action to hightlight multiple series (with blurScope='series', focus='self')", |
| legend: { |
| top: 30, |
| data: [ |
| "Direct", |
| "Mail Ad", |
| "Affiliate Ad", |
| "Video Ad", |
| "Search Engine", |
| ], |
| }, |
| xAxis: { |
| type: "category", |
| data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| }, |
| yAxis: { |
| type: "value", |
| }, |
| series: [ |
| { |
| name: "Direct", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| emphasis: seriesBlurEmphasis, |
| data: [320, 302, 301, 334, 390, 330, 320], |
| }, |
| { |
| name: "Mail Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| emphasis: seriesBlurEmphasis, |
| data: [120, 132, 101, 134, 90, 230, 210], |
| }, |
| { |
| name: "Affiliate Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| emphasis: seriesBlurEmphasis, |
| data: [220, 182, 191, 234, 290, 330, 310], |
| }, |
| { |
| name: "Video Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| emphasis: seriesBlurEmphasis, |
| data: [150, 212, 201, 154, 190, 330, 410], |
| }, |
| ], |
| }, |
| ////////////// Hightlight multilple series(blurScope = 'global') ////////////// |
| { |
| id: "highlightMultipleSeries(blurScope='global', focus='series')", |
| name: "Dispatch action to hightlight multiple series (with blurScope='global', focus='series')", |
| legend: { |
| top: 30, |
| data: [ |
| "Direct", |
| "Mail Ad", |
| "Affiliate Ad", |
| "Video Ad", |
| "Search Engine", |
| ], |
| }, |
| xAxis: { |
| type: "category", |
| data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| }, |
| yAxis: { |
| type: "value", |
| }, |
| series: [ |
| { |
| name: "Direct", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [320, 302, 301, 334, 390, 330, 320], |
| emphasis: globalBlurEmphasis, |
| }, |
| { |
| name: "Mail Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [120, 132, 101, 134, 90, 230, 210], |
| emphasis: globalBlurEmphasis, |
| }, |
| { |
| name: "Affiliate Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [220, 182, 191, 234, 290, 330, 310], |
| emphasis: globalBlurEmphasis, |
| }, |
| { |
| name: "Video Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [150, 212, 201, 154, 190, 330, 410], |
| emphasis: globalBlurEmphasis, |
| }, |
| ], |
| }, |
| ////////////// Hightlight multilple series(blurScope = 'coordinateSystem') ////////////// |
| { |
| id: "highlightMultipleSeries(blurScope='coordinateSystem', focus='series')", |
| name: "Dispatch action to hightlight multiple series (with blurScope='coordinateSystem', focus='series')", |
| legend: { |
| top: 30, |
| data: [ |
| "polar", |
| "Direct", |
| "Mail Ad", |
| "Affiliate Ad", |
| "Video Ad", |
| "Search Engine", |
| ], |
| }, |
| xAxis: { |
| type: "category", |
| data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], |
| }, |
| yAxis: { |
| type: "value", |
| }, |
| polar: {}, |
| |
| angleAxis: { |
| type: 'value', |
| startAngle: 0 |
| }, |
| radiusAxis: { |
| }, |
| series: [ |
| { |
| coordinateSystem: 'polar', |
| name: 'polar', |
| type: 'line', |
| data: polarData, |
| emphasis: coordinateSystemBlurEmphasis, |
| }, |
| { |
| name: "Direct", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [320, 302, 301, 334, 390, 330, 320], |
| emphasis: coordinateSystemBlurEmphasis, |
| }, |
| { |
| name: "Mail Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [120, 132, 101, 134, 90, 230, 210], |
| emphasis: coordinateSystemBlurEmphasis, |
| }, |
| { |
| name: "Affiliate Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [220, 182, 191, 234, 290, 330, 310], |
| emphasis: coordinateSystemBlurEmphasis, |
| }, |
| { |
| name: "Video Ad", |
| type: "line", |
| label: { |
| show: true, |
| }, |
| data: [150, 212, 201, 154, 190, 330, 410], |
| emphasis: coordinateSystemBlurEmphasis, |
| }, |
| ], |
| },] |
| for(const chartOption of options){ |
| const dom = document.createElement('div'); |
| dom.className = 'chart'; |
| document.querySelector('#main').appendChild(dom); |
| const chart = testHelper.create(echarts, dom, { |
| title: chartOption.name, |
| option: chartOption, |
| buttons: [ |
| { |
| text: 'Dispatch highlight action({seriesIndex: [1, 2], dataIndex: [0,1,2]})', |
| onclick: function () { |
| chart.dispatchAction({ |
| type: "highlight", |
| seriesIndex: [1, 2], |
| dataIndex: [0,1,2], |
| }); |
| } |
| }, |
| ], |
| }); |
| charts.push(chart); |
| } |
| })(); |
| |
| const blurOpts = { |
| opacity: 0.1, |
| grayColor: false |
| } |
| |
| function update() { |
| allChartsOptions.forEach(function (chartOption, idx) { |
| chartOption.series.forEach(function (series) { |
| series.blur = { |
| itemStyle: { |
| color: blurOpts.grayColor ? '#aaa' : null, |
| opacity: blurOpts.opacity |
| }, |
| lineStyle: { |
| color: blurOpts.grayColor ? '#aaa' : null, |
| opacity: blurOpts.opacity |
| }, |
| areaStyle: { |
| color: blurOpts.grayColor ? '#aaa' : null, |
| opacity: blurOpts.opacity |
| }, |
| label: { |
| color: blurOpts.grayColor ? '#aaa' : null, |
| opacity: blurOpts.opacity |
| } |
| } |
| }); |
| charts[idx].setOption(chartOption); |
| }); |
| } |
| |
| var gui = new dat.GUI(); |
| gui.add(blurOpts, 'opacity', 0, 1).onFinishChange(update); |
| gui.add(blurOpts, 'grayColor').onChange(update); |
| |
| window.addEventListener('resize', function () { |
| charts.forEach(function (chart) { |
| chart.resize(); |
| }); |
| }); |
| }); |
| </script> |
| |
| |
| </body> |
| </html> |
| |