Skip to content

与iscroll同用时无法点击图表(pointer事件兼容性判断和chrome更新所致) #6928

Description

@4Percent

One-line summary [问题简述]

在chrome 61中,使用iscroll创建自定义滚动条时,如果内容区包含echarts图表,则echarts图表中的图例等点击无效。

<div id="container">
    <div class="content">
        <div id="chart"></div>
        <div class="pad"></div>
    </div>
</div>
// iscroll 5.2
var scroller = new IScroll(container);

问题原因:

        // iscroll.js 1659行
        // iscroll处理pointerdown和mousedown的_start函数使用了preventDefault()
        // 在有pointer事件的浏览器中mousedown事件不触发
        // code...
	handleEvent: function (e) {
		switch ( e.type ) {
			case 'touchstart':
			case 'pointerdown':
			case 'MSPointerDown':
			case 'mousedown':
				this._start(e);
				break;
        // code...
                    // echarts 3.7.2 2252行判断pointerEventsSupported的逻辑没有考虑Chrome从55之后对poiner事件的支持
                    // 后面加事件的时候仍然给Chrome加了mouse事件,但是因为iscroll的缘故,mousedown不会触发,导致图表点击无效
                    // code...
	            pointerEventsSupported: 'onpointerdown' in window
	                // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
	                // events currently. So we dont use that on other browsers unless tested sufficiently.
	                // Although IE 10 supports pointer event, it use old style and is different from the
	                // standard. So we exclude that. (IE 10 is hardly used on touch device)
	                && (browser.edge || (browser.ie && browser.version >= 11))
                    // code...

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]: 3.7.2
  • Browser version [浏览器类型和版本]: Chrome 61.0.3163.100
  • OS Version [操作系统类型和版本]: Windows 10

Expected behaviour [期望结果]

本地测试不太方便,随便改改虽然好使,但是怕不全面。希望能改进pointer事件的兼容性判断逻辑。

ECharts option [ECharts配置项]

直接用了官网实例中option

option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b}: {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'left',
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
            series: [
                {
                    name: '访问来源',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        normal: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                fontSize: '30',
                                fontWeight: 'bold'
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data: [
                        { value: 335, name: '直接访问' },
                        { value: 310, name: '邮件营销' },
                        { value: 234, name: '联盟广告' },
                        { value: 135, name: '视频广告' },
                        { value: 1548, name: '搜索引擎' }
                    ]
                }
            ]
}

Other comments [其他信息]

感谢! (代码缩进什么的就请不要吐槽了)

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleInactive for a long time. Will be closed in 7 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions