* Filter a set of candidate tick values, ensuring that only tick values * that lie within the scale range are included. * @param {Scale} scale - The scale for which to generate tick values. * @param {Array<*>} ticks - The candidate tick values. * @param {*} count - The tick count or interval fun
(scale9, ticks, count)
| 127139 | * @param {*} count - The tick count or interval function. |
| 127140 | * @return {Array<*>} - The filtered tick values. |
| 127141 | */ function validTicks(scale9, ticks, count) { |
| 127142 | let range = scale9.range(), lo = range[0], hi = (0, _vegaUtil.peek)(range), cmp = ascending; |
| 127143 | if (lo > hi) { |
| 127144 | range = hi; |
| 127145 | hi = lo; |
| 127146 | lo = range; |
| 127147 | cmp = descending; |
| 127148 | } |
| 127149 | lo = Math.floor(lo); |
| 127150 | hi = Math.ceil(hi); // filter ticks to valid values within the range |
| 127151 | // additionally sort ticks in range order (#2579) |
| 127152 | ticks = ticks.map((v)=>[ |
| 127153 | v, |
| 127154 | scale9(v) |
| 127155 | ]).filter((_)=>lo <= _[1] && _[1] <= hi).sort(cmp).map((_)=>_[0]); |
| 127156 | if (count > 0 && ticks.length > 1) { |
| 127157 | const endpoints = [ |
| 127158 | ticks[0], |
| 127159 | (0, _vegaUtil.peek)(ticks) |
| 127160 | ]; |
| 127161 | while(ticks.length > count && ticks.length >= 3)ticks = ticks.filter((_, i)=>!(i % 2)); |
| 127162 | if (ticks.length < 3) ticks = endpoints; |
| 127163 | } |
| 127164 | return ticks; |
| 127165 | } |
| 127166 | /** |
| 127167 | * Generate tick values for the given scale and approximate tick count or |
| 127168 | * interval value. If the scale has a 'ticks' method, it will be used to |