You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2019/11/26 17:45:47 UTC

[GitHub] [incubator-echarts] 100pah commented on a change in pull request #11684: WIP(axisPointer): snapping logic WIP.

100pah commented on a change in pull request #11684: WIP(axisPointer): snapping logic WIP.
URL: https://github.com/apache/incubator-echarts/pull/11684#discussion_r350717249
 
 

 ##########
 File path: src/component/axisPointer/axisTrigger.js
 ##########
 @@ -97,19 +97,92 @@ export default function (payload, ecModel, api) {
 
     // Process for triggered axes.
     each(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
+        /**
+         * If both x and y axes are snapping and one and only one of them is
+         * of category type, then the category axis is used as primary
+         * snapping, otherwise the baseAxis is used as primary snapping.
+         * The snapped value of the other axis is calculated from it.
+         *
+         *  4 |                 *
+         *  3 |       *
+         *  2 |            *
+         *  1 |  *     +
+         *    ---------------------
+         *       a    b    c    d
+         *
+         * In the above example, the x axis is in category type, and y axis
+         *     value.
+         * The *'s are data items, + is the mouse position.
+         *
+         * If both x and y axes are using snapping, then:
+         * 1. x axis is used as primary snapping axis because it's the only
+         *     category axis.
+         * 2. The nearest x value to the mouse is 'b', so 'b' is used as
+         *     snapped x value.
+         * 3. The corresponding y value of 'b' is 3, so 3 is used as snapped y
+         *     value.
+         * 4. So the axisPointer should be at ('b', 3).
+         *
+         * If only x is snapping, then the axisPointer should be at ('b', 1).
+         * If only y is snapping, then the axisPointer should be at the
+         *     position of +.
+         */
+
         // If a point given, it must be contained by the coordinate system.
         var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
 
+        var snapXor; // One and only one of the axes is snapping
+        var snapBoth = true; // Both axes are snapping
+        var primarySnapAxis;
+        each(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo) {
+            if (snapXor === undefined) {
+                snapXor = axisInfo.snap;
+            }
+            else {
+                snapXor = snapXor && !axisInfo.snap || !snapXor && axisInfo.snap;
+            }
+            snapBoth = snapBoth && axisInfo.snap;
+            axisInfo.snap && (primarySnapAxis = axisInfo.axis);
+        });
+
+        if (!snapBoth && !snapXor) {
+            // Snap none
+            return;
+        }
+
+        if (!snapXor) {
+            // Snap both
+            var coord = coordSys.getCartesians()[0];
 
 Review comment:
   Might no cartesian coord sys. e.g., only polar?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org