(axis, ticksCoords, alignWithLabel, clamp)
| 38931 | // to displayed labels. (So we should not use `getBandWidth` in this |
| 38932 | // case). |
| 38933 | function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) { |
| 38934 | var ticksLen = ticksCoords.length; |
| 38935 | |
| 38936 | if (!axis.onBand || alignWithLabel || !ticksLen) { |
| 38937 | return; |
| 38938 | } |
| 38939 | |
| 38940 | var axisExtent = axis.getExtent(); |
| 38941 | var last; |
| 38942 | var diffSize; |
| 38943 | if (ticksLen === 1) { |
| 38944 | ticksCoords[0].coord = axisExtent[0]; |
| 38945 | last = ticksCoords[1] = {coord: axisExtent[0]}; |
| 38946 | } |
| 38947 | else { |
| 38948 | var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue; |
| 38949 | var shift = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen; |
| 38950 | |
| 38951 | each$1(ticksCoords, function (ticksItem) { |
| 38952 | ticksItem.coord -= shift / 2; |
| 38953 | }); |
| 38954 | |
| 38955 | var dataExtent = axis.scale.getExtent(); |
| 38956 | diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue; |
| 38957 | |
| 38958 | last = {coord: ticksCoords[ticksLen - 1].coord + shift * diffSize}; |
| 38959 | |
| 38960 | ticksCoords.push(last); |
| 38961 | } |
| 38962 | |
| 38963 | var inverse = axisExtent[0] > axisExtent[1]; |
| 38964 | |
| 38965 | // Handling clamp. |
| 38966 | if (littleThan(ticksCoords[0].coord, axisExtent[0])) { |
| 38967 | clamp ? (ticksCoords[0].coord = axisExtent[0]) : ticksCoords.shift(); |
| 38968 | } |
| 38969 | if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) { |
| 38970 | ticksCoords.unshift({coord: axisExtent[0]}); |
| 38971 | } |
| 38972 | if (littleThan(axisExtent[1], last.coord)) { |
| 38973 | clamp ? (last.coord = axisExtent[1]) : ticksCoords.pop(); |
| 38974 | } |
| 38975 | if (clamp && littleThan(last.coord, axisExtent[1])) { |
| 38976 | ticksCoords.push({coord: axisExtent[1]}); |
| 38977 | } |
| 38978 | |
| 38979 | function littleThan(a, b) { |
| 38980 | // Avoid rounding error cause calculated tick coord different with extent. |
| 38981 | // It may cause an extra unecessary tick added. |
| 38982 | a = round$1(a); |
| 38983 | b = round$1(b); |
| 38984 | return inverse ? a > b : a < b; |
| 38985 | } |
| 38986 | } |
| 38987 | |
| 38988 | /* |
| 38989 | * Licensed to the Apache Software Foundation (ASF) under one |
no test coverage detected