@@ -44,6 +44,39 @@ exports.p2c = function (axArray, v) {
4444 return out ;
4545} ;
4646
47+ /*
48+ * Given an array of calcdata values and an array of axes corresponding to each value,
49+ * convert the calcdata values to data values by calling the `c2d` method of each axis.
50+ *
51+ * This function is intended to be used in constructing hover and click events,
52+ * for converting x/y values from calc space to data space. axArray and valArray are arrays
53+ * rather than single values because in the case of stacked subplots, there may be multiple axes
54+ * (and therefore multiple data values) corresponding to a single hover or click event.
55+ *
56+ * For linear and log axes, this conversion has no effect beyond validating the inputs.
57+ * However, for some axes types, the converted values may be of a different type than the
58+ * inputs:
59+ * - For category axes, `c2d` converts calcdata values (numeric) into category labels (strings)
60+ * - For date axes, `c2d` converts calcdata values (numeric values in ms) into date strings
61+ *
62+ * For axes which don't define `c2d` (e.g. geo, map), the inputs are passed through untouched.
63+ *
64+ * @param {Array } axArray : axes corresponding to each value in valArray
65+ * @param {Array } valArray : calcdata values
66+ * @return {Array } : data values, computed by calling `ax.c2d` (if defined) on each input value
67+ */
68+ exports . c2dApply = function ( axArray , valArray ) {
69+ if ( axArray . length !== valArray . length ) {
70+ Lib . warn ( 'c2dApply: axArray and valArray must be the same length' ) ;
71+ }
72+ var out = new Array ( valArray . length ) ;
73+ for ( var i = 0 ; i < valArray . length ; i ++ ) {
74+ var ax = axArray && axArray [ i ] ;
75+ out [ i ] = ax && ax . c2d ? ax . c2d ( valArray [ i ] ) : valArray [ i ] ;
76+ }
77+ return out ;
78+ } ;
79+
4780exports . getDistanceFunction = function ( mode , dx , dy , dxy ) {
4881 if ( mode === 'closest' ) return dxy || exports . quadrature ( dx , dy ) ;
4982 return mode . charAt ( 0 ) === 'x' ? dx : dy ;
0 commit comments