minorTicks.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { round } from '../util/number.js';
  41. import { getScaleBreakHelper } from './break.js';
  42. import { getIntervalPrecision } from './helper.js';
  43. export function getMinorTicks(scale, splitNumber, breaks, scaleInterval) {
  44. var ticks = scale.getTicks({
  45. expandToNicedExtent: true
  46. });
  47. // NOTE: In log-scale, do not support minor ticks when breaks exist.
  48. // because currently log-scale minor ticks is calculated based on raw values
  49. // rather than log-transformed value, due to an odd effect when breaks exist.
  50. var minorTicks = [];
  51. var extent = scale.getExtent();
  52. for (var i = 1; i < ticks.length; i++) {
  53. var nextTick = ticks[i];
  54. var prevTick = ticks[i - 1];
  55. if (prevTick["break"] || nextTick["break"]) {
  56. // Do not build minor ticks to the adjacent ticks to breaks ticks,
  57. // since the interval might be irregular.
  58. continue;
  59. }
  60. var count = 0;
  61. var minorTicksGroup = [];
  62. var interval = nextTick.value - prevTick.value;
  63. var minorInterval = interval / splitNumber;
  64. var minorIntervalPrecision = getIntervalPrecision(minorInterval);
  65. while (count < splitNumber - 1) {
  66. var minorTick = round(prevTick.value + (count + 1) * minorInterval, minorIntervalPrecision);
  67. // For the first and last interval. The count may be less than splitNumber.
  68. if (minorTick > extent[0] && minorTick < extent[1]) {
  69. minorTicksGroup.push(minorTick);
  70. }
  71. count++;
  72. }
  73. var scaleBreakHelper = getScaleBreakHelper();
  74. scaleBreakHelper && scaleBreakHelper.pruneTicksByBreak('auto', minorTicksGroup, breaks, function (value) {
  75. return value;
  76. }, scaleInterval, extent);
  77. minorTicks.push(minorTicksGroup);
  78. }
  79. return minorTicks;
  80. }