You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by ov...@apache.org on 2022/03/22 09:23:51 UTC
[echarts] branch feat-toolbar-snap created (now 25b0b2f)
This is an automated email from the ASF dual-hosted git repository.
ovilia pushed a change to branch feat-toolbar-snap
in repository https://gitbox.apache.org/repos/asf/echarts.git.
at 25b0b2f feat(tooltip): tooltip with snap
This branch includes the following new commits:
new 41e45dd test(tooltip): add test case
new 25b0b2f feat(tooltip): tooltip with snap
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[echarts] 01/02: test(tooltip): add test case
Posted by ov...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ovilia pushed a commit to branch feat-toolbar-snap
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 41e45dd6b968aa7ef719fce7f6fd89ac9cd20d68
Author: Ovilia <zw...@gmail.com>
AuthorDate: Mon Mar 21 14:26:04 2022 +0800
test(tooltip): add test case
---
test/tooltip-snap.html | 162 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 162 insertions(+)
diff --git a/test/tooltip-snap.html b/test/tooltip-snap.html
new file mode 100644
index 0000000..285c7b7
--- /dev/null
+++ b/test/tooltip-snap.html
@@ -0,0 +1,162 @@
+<!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="ut/lib/canteen.js"></script> -->
+ <link rel="stylesheet" href="lib/reset.css" />
+ </head>
+ <body>
+ <style>
+ .test-chart {
+ border: 1px solid red;
+ }
+ </style>
+
+
+
+ <div id="main0"></div>
+ <div id="main1"></div>
+ <div id="main2"></div>
+ <div id="main3"></div>
+
+
+
+ <script>
+ require([
+ 'echarts',
+ // 'map/js/china',
+ // './data/nutrients.json'
+ ], function (echarts) {
+ var testNames = [
+ 'Tooltip default snapping',
+ 'Tooltip with axisPointer (neither snap)',
+ 'Tooltip with axisPointer (x/radius snap)',
+ 'Tooltip with axisPointer (both snap)'
+ ];
+
+ for (var testId = 0; testId < testNames.length; ++testId) {
+ (function () {
+ var option = {
+ xAxis: {
+ axisPointer: {
+ show: testId > 0,
+ snap: testId > 1
+ }
+ },
+ yAxis: {
+ axisPointer: {
+ show: testId > 0,
+ snap: testId > 2
+ }
+ },
+ grid: {
+ left: 50,
+ width: 800
+ },
+ polar: {
+ center: [1200, 200],
+ radius: [50, 150]
+ },
+ radiusAxis: {
+ axisPointer: {
+ show: testId > 0,
+ snap: testId > 1
+ }
+ },
+ angleAxis: {
+ axisPointer: {
+ show: testId > 0,
+ snap: testId > 2
+ }
+ },
+ series: [{
+ type: 'line',
+ data: [[15, 2], [16, 44]]
+ }, {
+ type: 'scatter',
+ data: [[6, 33], [12, 13]]
+ }, {
+ type: 'line',
+ data: [[15, 2], [16, 44]],
+ coordinateSystem: 'polar'
+ }, {
+ type: 'scatter',
+ data: [[6, 33], [12, 13]],
+ coordinateSystem: 'polar'
+ }],
+ tooltip: {
+ show: true,
+ hideDelay: 1000,
+ snap: true
+ }
+ };
+
+ var cnt = 0;
+
+ var chart = testHelper.create(echarts, 'main' + testId, {
+ title: [
+ '**' + testNames[testId] + '**',
+ 'Click "Run Next" button and it should test the following cases one by one',
+ '1. Grid: Move mouse around (6, 30) and should be snapped by data "33"',
+ '2. Grid: Move mouse around (15, 0) and should be snapped by data "2"',
+ '3. Grid: Move mouse around (16, 0) and should not be snapped',
+ '4. Polar: Move mouse around (3, 33) and should be snapped by data "33"',
+ '5. Polar: Move mouse around (13, 2.5) and should be snapped by data "2"',
+ '6. Polar: Move mouse around (9, 0) and should not be snapped'
+ ],
+ option: option,
+ button: {
+ text: 'Run Next',
+ onclick: function () {
+ var position = [
+ [319, 172],
+ [719, 331],
+ [762, 327],
+ [1131, 209],
+ [1237, 81],
+ [1202, 101]
+ ];
+ if (cnt < position.length) {
+ chart.dispatchAction({
+ type: 'showTip',
+ x: position[cnt][0],
+ y: position[cnt][1]
+ });
+ }
+ ++cnt;
+ }
+ }
+ // height: 300
+ });
+ })();
+ }
+ });
+ </script>
+ </body>
+</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org
[echarts] 02/02: feat(tooltip): tooltip with snap
Posted by ov...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ovilia pushed a commit to branch feat-toolbar-snap
in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 25b0b2fc6c1fbf58ecfc42249bda36d1d86da8cf
Author: Ovilia <zw...@gmail.com>
AuthorDate: Tue Mar 22 17:22:38 2022 +0800
feat(tooltip): tooltip with snap
---
src/component/tooltip/TooltipModel.ts | 6 +++++-
src/component/tooltip/TooltipView.ts | 37 +++++++++++++++++++++++++++++++++--
test/tooltip-snap.html | 2 +-
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/src/component/tooltip/TooltipModel.ts b/src/component/tooltip/TooltipModel.ts
index 413b52f..3264a20 100644
--- a/src/component/tooltip/TooltipModel.ts
+++ b/src/component/tooltip/TooltipModel.ts
@@ -73,6 +73,8 @@ export interface TooltipOption extends CommonTooltipOption<TopLevelFormatterPara
className?: string
order?: TooltipOrderMode
+
+ snapSize?: number
}
class TooltipModel extends ComponentModel<TooltipOption> {
@@ -171,7 +173,9 @@ class TooltipModel extends ComponentModel<TooltipOption> {
textStyle: {
color: '#666',
fontSize: 14
- }
+ },
+
+ snapSize: 25
};
}
diff --git a/src/component/tooltip/TooltipView.ts b/src/component/tooltip/TooltipView.ts
index 51b5200..ded1c2f 100644
--- a/src/component/tooltip/TooltipView.ts
+++ b/src/component/tooltip/TooltipView.ts
@@ -497,11 +497,44 @@ class TooltipView extends ComponentView {
}
}
else {
- this._lastDataByCoordSys = null;
- this._hide(dispatchAction);
+ const snapSize = tooltipModel.get('snapSize');
+ const nearestEl = this._findNearestData(this._lastX, this._lastY, snapSize);
+ if (!nearestEl) {
+ this._lastDataByCoordSys = null;
+ this._hide(dispatchAction);
+ }
+ else {
+ this._showSeriesItemTooltip(e, nearestEl, dispatchAction);
+ }
}
}
+ private _findNearestData(x: number, y: number, snapSize: number): Element {
+ let minDistance = snapSize * snapSize;
+ let minDataEl: Element = null;
+ this._ecModel.eachSeries(seriesModel => {
+ const data = seriesModel.getData();
+ const coordSys = seriesModel.coordinateSystem;
+ // TODO: also consider snapSize as tolerance?
+ if (coordSys.containPoint([x, y])) {
+ let minDataId: number = null;
+ data.each(id => {
+ const values = data.getValues(id);
+ const pts = coordSys.dataToPoint(values);
+ const distance = (pts[0] - x) * (pts[0] - x) + (pts[1] - y) * (pts[1] - y);
+ if (distance < minDistance) {
+ minDistance = distance;
+ minDataId = id;
+ }
+ });
+ if (minDataId != null) {
+ minDataEl = data.getItemGraphicEl(minDataId);
+ }
+ }
+ });
+ return minDataEl;
+ }
+
private _showOrMove(
tooltipModel: Model<TooltipOption>,
cb: () => void
diff --git a/test/tooltip-snap.html b/test/tooltip-snap.html
index 285c7b7..b5136d5 100644
--- a/test/tooltip-snap.html
+++ b/test/tooltip-snap.html
@@ -112,7 +112,7 @@ under the License.
}],
tooltip: {
show: true,
- hideDelay: 1000,
+ // hideDelay: 1000,
snap: true
}
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org