cx 24.10.4 → 24.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/charts.js CHANGED
@@ -37,6 +37,32 @@ import {
37
37
  getCursorPos,
38
38
  } from "cx/widgets";
39
39
 
40
+ function _arrayLikeToArray(r, a) {
41
+ (null == a || a > r.length) && (a = r.length);
42
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
43
+ return n;
44
+ }
45
+ function _createForOfIteratorHelperLoose(r, e) {
46
+ var t = ("undefined" != typeof Symbol && r[Symbol.iterator]) || r["@@iterator"];
47
+ if (t) return (t = t.call(r)).next.bind(t);
48
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
49
+ t && (r = t);
50
+ var o = 0;
51
+ return function () {
52
+ return o >= r.length
53
+ ? {
54
+ done: !0,
55
+ }
56
+ : {
57
+ done: !1,
58
+ value: r[o++],
59
+ };
60
+ };
61
+ }
62
+ throw new TypeError(
63
+ "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.",
64
+ );
65
+ }
40
66
  function _extends() {
41
67
  return (
42
68
  (_extends = Object.assign
@@ -64,6 +90,20 @@ function _setPrototypeOf(t, e) {
64
90
  _setPrototypeOf(t, e)
65
91
  );
66
92
  }
93
+ function _unsupportedIterableToArray(r, a) {
94
+ if (r) {
95
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
96
+ var t = {}.toString.call(r).slice(8, -1);
97
+ return (
98
+ "Object" === t && r.constructor && (t = r.constructor.name),
99
+ "Map" === t || "Set" === t
100
+ ? Array.from(r)
101
+ : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)
102
+ ? _arrayLikeToArray(r, a)
103
+ : void 0
104
+ );
105
+ }
106
+ }
67
107
 
68
108
  var Rect = /*#__PURE__*/ (function () {
69
109
  function Rect(config) {
@@ -270,7 +310,7 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
270
310
  return instance.calculator;
271
311
  };
272
312
  _proto.reportData = function reportData(context, instance) {};
273
- _proto.renderTicksAndLabels = function renderTicksAndLabels(context, instance, valueFormatter) {
313
+ _proto.renderTicksAndLabels = function renderTicksAndLabels(context, instance, valueFormatter, minLabelDistance) {
274
314
  var _this = this;
275
315
  if (this.hidden) return false;
276
316
  var data = instance.data,
@@ -279,14 +319,15 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
279
319
  var bounds = data.bounds;
280
320
  var CSS = this.CSS,
281
321
  baseClass = this.baseClass;
282
- var size = calculator.findTickSize(this.minLabelDistance);
322
+ var size = calculator.findTickSize(minLabelDistance);
283
323
  var labelClass = CSS.expand(CSS.element(baseClass, "label"), data.labelClass);
284
324
  var offsetClass = CSS.element(baseClass, "label-offset");
285
325
  var x1,
286
326
  y1,
287
327
  x2,
288
328
  y2,
289
- tickSize = this.tickSize;
329
+ tickSize = this.tickSize,
330
+ tickOffset = this.tickOffset;
290
331
  if (this.vertical) {
291
332
  x1 = x2 = this.secondary ? bounds.r : bounds.l;
292
333
  y1 = bounds.b;
@@ -312,23 +353,23 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
312
353
  );
313
354
  }
314
355
  var t = [];
315
- if (size > 0 && !data.hideLabels) {
356
+ if (!!size && !data.hideLabels) {
316
357
  var ticks = calculator.getTicks([size]);
317
358
  ticks.forEach(function (serie, si) {
318
359
  serie.forEach(function (v, i) {
319
360
  var s = calculator.map(v);
320
361
  if (_this.secondary) {
321
- x1 = _this.vertical ? bounds.r : s;
322
- y1 = _this.vertical ? s : bounds.t;
323
- x2 = _this.vertical ? bounds.r + tickSize : s;
324
- y2 = _this.vertical ? s : bounds.t - tickSize;
362
+ x1 = _this.vertical ? bounds.r + tickOffset : s;
363
+ y1 = _this.vertical ? s : bounds.t - tickOffset;
364
+ x2 = _this.vertical ? bounds.r + tickOffset + tickSize : s;
365
+ y2 = _this.vertical ? s : bounds.t - tickOffset - tickSize;
325
366
  } else {
326
- x1 = _this.vertical ? bounds.l : s;
327
- y1 = _this.vertical ? s : bounds.b;
328
- x2 = _this.vertical ? bounds.l - tickSize : s;
329
- y2 = _this.vertical ? s : bounds.b + tickSize;
367
+ x1 = _this.vertical ? bounds.l - tickOffset : s;
368
+ y1 = _this.vertical ? s : bounds.b + tickOffset;
369
+ x2 = _this.vertical ? bounds.l - tickOffset - tickSize : s;
370
+ y2 = _this.vertical ? s : bounds.b + tickOffset + tickSize;
330
371
  }
331
- t.push("M " + x1 + " " + y1 + " L " + x2 + " " + y2);
372
+ if (!_this.useGridlineTicks) t.push("M " + x1 + " " + y1 + " L " + x2 + " " + y2);
332
373
  var x, y;
333
374
  var labelOffset =
334
375
  _this.alternateLabelOffset != null && i % 2 == 1 ? _this.alternateLabelOffset : _this.labelOffset;
@@ -366,6 +407,23 @@ var Axis = /*#__PURE__*/ (function (_BoundedObject) {
366
407
  });
367
408
  }
368
409
  if (!data.hideTicks) {
410
+ if (this.useGridlineTicks) {
411
+ var gridlines = calculator.mapGridlines();
412
+ gridlines.forEach(function (s, i) {
413
+ if (_this.secondary) {
414
+ x1 = _this.vertical ? bounds.r + tickOffset : s;
415
+ y1 = _this.vertical ? s : bounds.t - tickOffset;
416
+ x2 = _this.vertical ? bounds.r + tickOffset + tickSize : s;
417
+ y2 = _this.vertical ? s : bounds.t - tickOffset - tickSize;
418
+ } else {
419
+ x1 = _this.vertical ? bounds.l - tickOffset : s;
420
+ y1 = _this.vertical ? s : bounds.b + tickOffset;
421
+ x2 = _this.vertical ? bounds.l - tickOffset - tickSize : s;
422
+ y2 = _this.vertical ? s : bounds.b + tickOffset + tickSize;
423
+ }
424
+ t.push("M " + x1 + " " + y1 + " L " + x2 + " " + y2);
425
+ });
426
+ }
369
427
  res[1] = /*#__PURE__*/ jsx(
370
428
  "path",
371
429
  {
@@ -466,6 +524,7 @@ Axis.prototype.hideLabels = false;
466
524
  Axis.prototype.hideTicks = false;
467
525
  Axis.prototype.hideLine = false;
468
526
  Axis.prototype.tickSize = 3;
527
+ Axis.prototype.tickOffset = 0;
469
528
  Axis.prototype.minTickDistance = 25;
470
529
  Axis.prototype.minLabelDistanceVertical = 40;
471
530
  Axis.prototype.minLabelDistanceHorizontal = 50;
@@ -4239,7 +4298,7 @@ var NumericAxis = /*#__PURE__*/ (function (_Axis) {
4239
4298
  {
4240
4299
  className: data.classNames,
4241
4300
  style: data.style,
4242
- children: this.renderTicksAndLabels(context, instance, formatter),
4301
+ children: this.renderTicksAndLabels(context, instance, formatter, this.minLabelDistance),
4243
4302
  },
4244
4303
  key,
4245
4304
  );
@@ -4566,7 +4625,7 @@ var CategoryAxis = /*#__PURE__*/ (function (_Axis) {
4566
4625
  inverted = _instance$data.inverted,
4567
4626
  uniform = _instance$data.uniform,
4568
4627
  minSize = _instance$data.minSize;
4569
- instance.calculator.reset(inverted, uniform, values, names, minSize);
4628
+ instance.calculator.reset(inverted, uniform, values, names, minSize, this.minTickDistance, this.minLabelDistance);
4570
4629
  };
4571
4630
  _proto.reportData = function reportData(context, instance) {
4572
4631
  instance.set("categoryCount", instance.calculator.valueList.length);
@@ -4601,11 +4660,14 @@ CategoryAxis.prototype.labelAnchor = "auto";
4601
4660
  CategoryAxis.prototype.labelDx = "auto";
4602
4661
  CategoryAxis.prototype.labelDy = "auto";
4603
4662
  CategoryAxis.prototype.minSize = 1;
4663
+ CategoryAxis.prototype.minLabelDistanceHorizontal = 0;
4664
+ CategoryAxis.prototype.minLabelDistanceVertical = 0;
4665
+ CategoryAxis.prototype.minTickDistance = 0;
4604
4666
  Axis.alias("category", CategoryAxis);
4605
4667
  var CategoryScale = /*#__PURE__*/ (function () {
4606
4668
  function CategoryScale() {}
4607
4669
  var _proto2 = CategoryScale.prototype;
4608
- _proto2.reset = function reset(inverted, uniform, values, names, minSize) {
4670
+ _proto2.reset = function reset(inverted, uniform, values, names, minSize, minTickDistance, minLabelDistance) {
4609
4671
  var _this = this;
4610
4672
  this.padding = 0.5;
4611
4673
  delete this.min;
@@ -4619,6 +4681,8 @@ var CategoryScale = /*#__PURE__*/ (function () {
4619
4681
  this.uniform = uniform;
4620
4682
  this.valueStacks = {};
4621
4683
  this.names = {};
4684
+ this.minTickDistance = minTickDistance;
4685
+ this.minLabelDistance = minLabelDistance;
4622
4686
  if (values) {
4623
4687
  if (isArray(values))
4624
4688
  values.forEach(function (v) {
@@ -4666,6 +4730,19 @@ var CategoryScale = /*#__PURE__*/ (function () {
4666
4730
  this.factor = (sign * (this.b - this.a)) / (this.max - this.min + 2 * this.padding);
4667
4731
  this.origin = (this.a * (1 + sign)) / 2 + (this.b * (1 - sign)) / 2; //a || b
4668
4732
  }
4733
+ this.tickSizes = [];
4734
+ var tickMultiplier = [1, 2, 5];
4735
+ var absFactor = Math.abs(this.factor);
4736
+ for (var base = 1; base < 10000 && this.tickSizes.length < 2; base *= 10) {
4737
+ for (var _iterator = _createForOfIteratorHelperLoose(tickMultiplier), _step; !(_step = _iterator()).done; ) {
4738
+ var m = _step.value;
4739
+ if (base * m * absFactor >= this.minTickDistance && this.tickSizes.length == 0) this.tickSizes.push(base * m);
4740
+ if (base * m * absFactor >= this.minLabelDistance) {
4741
+ this.tickSizes.push(base * m);
4742
+ break;
4743
+ }
4744
+ }
4745
+ }
4669
4746
  };
4670
4747
  _proto2.hash = function hash() {
4671
4748
  return {
@@ -4736,28 +4813,35 @@ var CategoryScale = /*#__PURE__*/ (function () {
4736
4813
  return this.valueList[index];
4737
4814
  };
4738
4815
  _proto2.findTickSize = function findTickSize(minPxDist) {
4816
+ for (var _iterator2 = _createForOfIteratorHelperLoose(this.tickSizes), _step2; !(_step2 = _iterator2()).done; ) {
4817
+ var tickSize = _step2.value;
4818
+ if (tickSize * Math.abs(this.factor) >= minPxDist) return tickSize;
4819
+ }
4739
4820
  return 1;
4740
4821
  };
4741
4822
  _proto2.getTickSizes = function getTickSizes() {
4742
- return [1];
4823
+ return this.tickSizes;
4743
4824
  };
4744
4825
  _proto2.getTicks = function getTicks(tickSizes) {
4745
4826
  var _this2 = this;
4746
4827
  return tickSizes.map(function (size) {
4747
- return _this2.valueList;
4828
+ return _this2.valueList.filter(function (_, i) {
4829
+ return i % size == 0;
4830
+ });
4748
4831
  });
4749
4832
  };
4750
4833
  _proto2.mapGridlines = function mapGridlines() {
4751
- var _this3 = this;
4752
- return Array.from({
4753
- length: this.valueList.length + 1,
4754
- }).map(function (_, index) {
4755
- return _this3.origin + (index - 0.5 - _this3.min + _this3.padding) * _this3.factor;
4756
- });
4834
+ var result = [];
4835
+ if (this.tickSizes.length == 0) return result;
4836
+ var step = this.tickSizes[0];
4837
+ for (var index = this.min; index <= this.max + 1; index += step)
4838
+ result.push(this.origin + (index - 0.5 - this.min + this.padding) * this.factor);
4839
+ return result;
4757
4840
  };
4758
4841
  return CategoryScale;
4759
4842
  })();
4760
4843
 
4844
+ var _TimeAxis$prototype$m;
4761
4845
  Format$1.registerFactory("yearOrMonth", function (format) {
4762
4846
  var year = Format$1.parse("datetime;yyyy");
4763
4847
  var month = Format$1.parse("datetime;MMM");
@@ -4787,8 +4871,13 @@ var TimeAxis = /*#__PURE__*/ (function (_Axis) {
4787
4871
  if (this.labelDx == "auto") this.labelDx = this.vertical ? 0 : "5px";
4788
4872
  if (this.deadZone) {
4789
4873
  this.lowerDeadZone = this.deadZone;
4790
- this.upperDeadZone = this.deadZone;
4874
+ pperDeadZone = this.deadZone;
4791
4875
  }
4876
+ this.minLabelDistanceFormatOverride = _extends(
4877
+ {},
4878
+ this.minLabelDistanceFormatOverrideDefaults,
4879
+ this.minLabelDistanceFormatOverride,
4880
+ );
4792
4881
  _Axis.prototype.init.call(this);
4793
4882
  };
4794
4883
  _proto.declareData = function declareData() {
@@ -4824,14 +4913,16 @@ var TimeAxis = /*#__PURE__*/ (function (_Axis) {
4824
4913
  max,
4825
4914
  this.snapToTicks,
4826
4915
  this.tickDivisions,
4827
- this.minTickDistance,
4828
- this.minLabelDistance,
4916
+ Math.max(1, this.minTickDistance),
4917
+ Math.max(1, this.minLabelDistance),
4829
4918
  normalized,
4830
4919
  inverted,
4831
4920
  this.minTickUnit,
4832
4921
  lowerDeadZone,
4833
4922
  upperDeadZone,
4834
4923
  this.decode,
4924
+ this.useLabelDistanceFormatOverrides ? this.minLabelDistanceFormatOverride : {},
4925
+ this.format,
4835
4926
  );
4836
4927
  };
4837
4928
  _proto.render = function render(context, instance, key) {
@@ -4840,14 +4931,15 @@ var TimeAxis = /*#__PURE__*/ (function (_Axis) {
4840
4931
  calculator = instance.calculator;
4841
4932
  cached.axis = calculator.hash();
4842
4933
  if (!data.bounds.valid()) return null;
4843
- var format = this.format || calculator.getFormat();
4934
+ var format = calculator.resolvedFormat;
4935
+ var minLabelDistance = calculator.resolvedMinLabelDistance;
4844
4936
  var formatter = Format$1.parse(format);
4845
4937
  return /*#__PURE__*/ jsx(
4846
4938
  "g",
4847
4939
  {
4848
4940
  className: data.classNames,
4849
4941
  style: data.style,
4850
- children: this.renderTicksAndLabels(context, instance, formatter),
4942
+ children: this.renderTicksAndLabels(context, instance, formatter, minLabelDistance),
4851
4943
  },
4852
4944
  key,
4853
4945
  );
@@ -4873,11 +4965,21 @@ TimeAxis.prototype.tickDivisions = {
4873
4965
  [10, 50, 100],
4874
4966
  ],
4875
4967
  };
4968
+ var TimeFormats = {
4969
+ fullDateAndTime: "datetime;yyyy MMM dd HH mm ss n",
4970
+ shortMonthDate: "datetime;yyyy MMM dd",
4971
+ };
4876
4972
  TimeAxis.prototype.snapToTicks = 0;
4877
4973
  TimeAxis.prototype.tickSize = 15;
4878
4974
  TimeAxis.prototype.minLabelDistance = 60;
4879
4975
  TimeAxis.prototype.minTickDistance = 60;
4880
4976
  TimeAxis.prototype.minTickUnit = "second";
4977
+ TimeAxis.prototype.useLabelDistanceFormatOverrides = false;
4978
+ TimeAxis.prototype.minLabelDistanceFormatOverrideDefaults =
4979
+ ((_TimeAxis$prototype$m = {}),
4980
+ (_TimeAxis$prototype$m[TimeFormats.fullDateAndTime] = 150),
4981
+ (_TimeAxis$prototype$m[TimeFormats.shortMonthDate] = 90),
4982
+ _TimeAxis$prototype$m);
4881
4983
  function monthNumber(date) {
4882
4984
  return date.getFullYear() * 12 + date.getMonth() + (date.getDate() - 1) / 31;
4883
4985
  }
@@ -4909,6 +5011,8 @@ var TimeScale = /*#__PURE__*/ (function () {
4909
5011
  lowerDeadZone,
4910
5012
  upperDeadZone,
4911
5013
  decode,
5014
+ minLabelDistanceFormatOverride,
5015
+ format,
4912
5016
  ) {
4913
5017
  this.dateCache = {};
4914
5018
  this.min = min != null ? this.decodeValue(min) : null;
@@ -4929,6 +5033,8 @@ var TimeScale = /*#__PURE__*/ (function () {
4929
5033
  delete this.maxValuePadded;
4930
5034
  this.stacks = {};
4931
5035
  this.decode = decode;
5036
+ this.minLabelDistanceFormatOverride = minLabelDistanceFormatOverride;
5037
+ this.format = format;
4932
5038
  };
4933
5039
  _proto2.decodeValue = function decodeValue(date) {
4934
5040
  if (date instanceof Date) return date.getTime();
@@ -4947,22 +5053,22 @@ var TimeScale = /*#__PURE__*/ (function () {
4947
5053
  _proto2.encodeValue = function encodeValue(v) {
4948
5054
  return new Date(v).toISOString();
4949
5055
  };
4950
- _proto2.getFormat = function getFormat() {
4951
- switch (this.tickMeasure) {
5056
+ _proto2.getFormat = function getFormat(unit, scale) {
5057
+ switch (unit) {
4952
5058
  case "year":
4953
5059
  return "datetime;yyyy";
4954
5060
  case "month":
4955
- if (new Date(this.scale.min).getFullYear() != new Date(this.scale.max).getFullYear()) return "yearOrMonth";
5061
+ if (new Date(scale.min).getFullYear() != new Date(scale.max).getFullYear()) return "yearOrMonth";
4956
5062
  return "datetime;yyyy MMM";
4957
5063
  case "week":
4958
5064
  return "datetime;MMMdd";
4959
5065
  case "day":
4960
5066
  if (
4961
- new Date(this.scale.min).getFullYear() != new Date(this.scale.max).getFullYear() ||
4962
- new Date(this.scale.min).getMonth() != new Date(this.scale.max).getMonth()
5067
+ new Date(scale.min).getFullYear() != new Date(scale.max).getFullYear() ||
5068
+ new Date(scale.min).getMonth() != new Date(scale.max).getMonth()
4963
5069
  )
4964
5070
  return "monthOrDay";
4965
- return "datetime;yyyy MMM dd";
5071
+ return TimeFormats.shortMonthDate;
4966
5072
  case "hour":
4967
5073
  return "datetime;HH mm n";
4968
5074
  case "minute":
@@ -4970,7 +5076,7 @@ var TimeScale = /*#__PURE__*/ (function () {
4970
5076
  case "second":
4971
5077
  return "datetime;mm ss";
4972
5078
  default:
4973
- return "datetime;yyyy MMM dd HH mm ss n";
5079
+ return TimeFormats.fullDateAndTime;
4974
5080
  }
4975
5081
  };
4976
5082
  _proto2.map = function map(v, offset) {
@@ -5041,27 +5147,28 @@ var TimeScale = /*#__PURE__*/ (function () {
5041
5147
  else this.max = this.normalized ? 1 : 100;
5042
5148
  }
5043
5149
  this.origin = this.inverted ? this.b : this.a;
5044
- this.scale = this.getScale();
5045
5150
  this.calculateTicks();
5151
+ if (this.scale == null) {
5152
+ this.scale = this.getScale();
5153
+ }
5046
5154
  };
5047
5155
  _proto2.getTimezoneOffset = function getTimezoneOffset(date) {
5048
5156
  return date.getTimezoneOffset() * 60 * 1000;
5049
5157
  };
5050
- _proto2.getScale = function getScale(tickSizes, measure) {
5158
+ _proto2.getScale = function getScale(tickSize, measure) {
5051
5159
  var min = this.min,
5052
5160
  max = this.max,
5053
5161
  upperDeadZone = this.upperDeadZone,
5054
5162
  lowerDeadZone = this.lowerDeadZone;
5055
5163
  var smin = min;
5056
5164
  var smax = max;
5057
- if (isNumber(this.snapToTicks) && measure && tickSizes && 0 <= this.snapToTicks && tickSizes.length > 0) {
5058
- var tickSize = tickSizes[Math.min(tickSizes.length - 1, this.snapToTicks)];
5165
+ if (tickSize) {
5059
5166
  var minDate = new Date(min);
5060
5167
  var maxDate = new Date(max);
5061
5168
  switch (measure) {
5062
5169
  case "second":
5063
5170
  case "minute":
5064
- case "hours":
5171
+ case "hour":
5065
5172
  case "day":
5066
5173
  default:
5067
5174
  var minOffset = this.getTimezoneOffset(minDate);
@@ -5145,8 +5252,9 @@ var TimeScale = /*#__PURE__*/ (function () {
5145
5252
  };
5146
5253
  _proto2.findTickSize = function findTickSize(minPxDist) {
5147
5254
  var _this2 = this;
5148
- return this.tickSizes.find(function (a) {
5149
- return a * Math.abs(_this2.scale.factor) >= minPxDist;
5255
+ return this.tickSizes.find(function (_ref) {
5256
+ var size = _ref.size;
5257
+ return size * Math.abs(_this2.scale.factor) >= minPxDist;
5150
5258
  });
5151
5259
  };
5152
5260
  _proto2.getTickSizes = function getTickSizes() {
@@ -5155,7 +5263,7 @@ var TimeScale = /*#__PURE__*/ (function () {
5155
5263
  _proto2.calculateTicks = function calculateTicks() {
5156
5264
  var _this3 = this;
5157
5265
  var minReached = false;
5158
- var _loop = function _loop() {
5266
+ var _loop = function _loop(unit) {
5159
5267
  if (!minReached) {
5160
5268
  if (unit == _this3.minTickUnit) minReached = true;
5161
5269
  else return 0; // continue
@@ -5168,73 +5276,147 @@ var TimeScale = /*#__PURE__*/ (function () {
5168
5276
  (_this3$tickSizes = _this3.tickSizes).push.apply(
5169
5277
  _this3$tickSizes,
5170
5278
  divisions[0].map(function (s) {
5171
- return s * unitSize;
5279
+ return {
5280
+ size: s * unitSize,
5281
+ measure: unit,
5282
+ };
5172
5283
  }),
5173
5284
  );
5174
- return 0; // continue
5285
+ return 1; // break
5175
5286
  }
5176
5287
  var bestLabelDistance = Infinity;
5288
+ var bestMinLabelDistance = _this3.minLabelDistance;
5177
5289
  var bestTicks = [];
5178
- var bestScale = _this3.scale;
5290
+ var bestScale = null;
5291
+ var bestFormat = null;
5179
5292
  _this3.tickMeasure = unit;
5180
- var _loop2 = function _loop2() {
5181
- var divs = divisions[i];
5182
- var tickSizes = divs.map(function (s) {
5183
- return s * unitSize;
5184
- });
5185
- var scale = _this3.getScale(tickSizes, unit);
5186
- tickSizes.forEach(function (size, level) {
5187
- var tickDistance = size * Math.abs(scale.factor);
5188
- if (tickDistance >= _this3.minTickDistance && tickDistance < bestLabelDistance) {
5293
+ for (var _i = 0; _i < divisions.length; _i++) {
5294
+ var _divs = divisions[_i];
5295
+ for (var _d = 0; _d < _divs.length; _d++) {
5296
+ var _this3$format, _this3$minLabelDistan;
5297
+ //if (useSnapToTicks && d < Math.min(divs.length - 1, this.snapToTicks)) continue;
5298
+ var _tickSize2 = _divs[_d] * unitSize;
5299
+ var scale = _this3.getScale(null, unit);
5300
+ var format = (_this3$format = _this3.format) != null ? _this3$format : _this3.getFormat(unit, scale);
5301
+ var minLabelDistance =
5302
+ (_this3$minLabelDistan = _this3.minLabelDistanceFormatOverride[format]) != null
5303
+ ? _this3$minLabelDistan
5304
+ : _this3.minLabelDistance;
5305
+ var labelDistance = _tickSize2 * Math.abs(scale.factor);
5306
+ if (labelDistance >= minLabelDistance && labelDistance < bestLabelDistance) {
5189
5307
  bestScale = scale;
5190
- bestTicks = tickSizes;
5191
- bestLabelDistance = tickDistance;
5308
+ bestTicks = _divs.map(function (s) {
5309
+ return s * unitSize;
5310
+ });
5311
+ bestLabelDistance = labelDistance;
5312
+ bestFormat = format;
5313
+ bestMinLabelDistance = minLabelDistance;
5192
5314
  }
5193
- });
5194
- };
5195
- for (var i = 0; i < divisions.length; i++) {
5196
- _loop2();
5315
+ }
5197
5316
  }
5198
5317
  _this3.scale = bestScale;
5199
- _this3.tickSizes = bestTicks.filter(function (ts) {
5200
- return ts * Math.abs(bestScale.factor) >= _this3.minTickDistance;
5201
- });
5318
+ _this3.tickSizes = bestTicks
5319
+ .filter(function (ts) {
5320
+ return ts * Math.abs(bestScale.factor) >= _this3.minTickDistance;
5321
+ })
5322
+ .map(function (size) {
5323
+ return {
5324
+ size: size,
5325
+ measure: _this3.tickMeasure,
5326
+ };
5327
+ });
5328
+ _this3.resolvedFormat = bestFormat;
5329
+ _this3.resolvedMinLabelDistance = bestMinLabelDistance;
5202
5330
  },
5203
5331
  _ret;
5204
5332
  for (var unit in miliSeconds) {
5205
- _ret = _loop();
5333
+ _ret = _loop(unit);
5206
5334
  if (_ret === 0) continue;
5335
+ if (_ret === 1) break;
5336
+ }
5337
+ var lowerTickUnit = null;
5338
+ switch (this.tickMeasure) {
5339
+ case "year":
5340
+ lowerTickUnit = "month";
5341
+ break;
5342
+ case "month":
5343
+ lowerTickUnit = "day";
5344
+ break;
5345
+ case "week":
5346
+ lowerTickUnit = "day";
5347
+ break;
5348
+ case "day":
5349
+ lowerTickUnit = "hour";
5350
+ break;
5351
+ case "hour":
5352
+ lowerTickUnit = "minute";
5353
+ break;
5354
+ case "minute":
5355
+ lowerTickUnit = "second";
5356
+ break;
5357
+ }
5358
+ if (lowerTickUnit != null && this.scale) {
5359
+ var bestMinorTickSize = Infinity;
5360
+ var divisions = this.tickDivisions[lowerTickUnit];
5361
+ var unitSize = miliSeconds[lowerTickUnit];
5362
+ for (var i = 0; i < divisions.length; i++) {
5363
+ var divs = divisions[i];
5364
+ for (var d = 0; d < divs.length; d++) {
5365
+ var tickSize = divs[d] * unitSize;
5366
+ if (tickSize * Math.abs(this.scale.factor) >= this.minTickDistance && tickSize < bestMinorTickSize) {
5367
+ bestMinorTickSize = tickSize;
5368
+ }
5369
+ }
5370
+ }
5371
+ if (bestMinorTickSize != Infinity) {
5372
+ this.tickSizes.unshift({
5373
+ size: bestMinorTickSize,
5374
+ measure: lowerTickUnit,
5375
+ });
5376
+ if (this.tickSizes.length > 1) {
5377
+ var labelStep = this.tickSizes[1].size;
5378
+ var lowerScale = this.getScale(null, lowerTickUnit);
5379
+ if (lowerScale.max - lowerScale.min >= labelStep) this.scale = lowerScale;
5380
+ }
5381
+ }
5382
+ }
5383
+ if (isNumber(this.snapToTicks) && this.snapToTicks >= 0) {
5384
+ var _tickSize = this.tickSizes[Math.min(this.tickSizes.length - 1, this.snapToTicks)];
5385
+ this.scale = this.getScale(_tickSize.size, _tickSize.measure);
5207
5386
  }
5208
5387
  };
5209
5388
  _proto2.getTicks = function getTicks(tickSizes) {
5210
5389
  var _this4 = this;
5211
- return tickSizes.map(function (size) {
5390
+ return tickSizes.map(function (_ref2) {
5391
+ var size = _ref2.size,
5392
+ measure = _ref2.measure;
5212
5393
  var result = [],
5213
5394
  start,
5214
5395
  end,
5215
5396
  minDate,
5216
5397
  maxDate;
5217
- if (_this4.tickMeasure == "year") {
5398
+ if (measure == "year") {
5218
5399
  size /= miliSeconds.year;
5219
5400
  minDate = new Date(_this4.scale.min - _this4.scale.minPadding);
5220
5401
  maxDate = new Date(_this4.scale.max + _this4.scale.maxPadding);
5221
5402
  start = Math.ceil(yearNumber(minDate) / size) * size;
5222
5403
  end = Math.floor(yearNumber(maxDate) / size) * size;
5223
5404
  for (var i = start; i <= end; i += size) result.push(new Date(i, 0, 1).getTime());
5224
- } else if (_this4.tickMeasure == "month") {
5405
+ } else if (measure == "month") {
5225
5406
  size /= miliSeconds.month;
5226
5407
  minDate = new Date(_this4.scale.min - _this4.scale.minPadding);
5227
5408
  maxDate = new Date(_this4.scale.max + _this4.scale.maxPadding);
5228
5409
  start = Math.ceil(monthNumber(minDate) / size) * size;
5229
5410
  end = Math.floor(monthNumber(maxDate) / size) * size;
5230
- for (var _i = start; _i <= end; _i += size) result.push(new Date(Math.floor(_i / 12), _i % 12, 1).getTime());
5231
- } else if (_this4.tickMeasure == "day" || _this4.tickMeasure == "week") {
5232
- var multiplier = _this4.tickMeasure == "week" ? 7 : 1;
5411
+ for (var _i2 = start; _i2 <= end; _i2 += size)
5412
+ result.push(new Date(Math.floor(_i2 / 12), _i2 % 12, 1).getTime());
5413
+ } else if (measure == "day" || measure == "week") {
5414
+ var multiplier = measure == "week" ? 7 : 1;
5233
5415
  size /= miliSeconds.day;
5234
5416
  minDate = new Date(_this4.scale.min - _this4.scale.minPadding);
5235
5417
  maxDate = new Date(_this4.scale.max + _this4.scale.maxPadding);
5236
5418
  var date = zeroTime(minDate);
5237
- if (_this4.tickMeasure == "week") {
5419
+ if (measure == "week") {
5238
5420
  //start on monday
5239
5421
  while (date.getDay() != 1) {
5240
5422
  date.setDate(date.getDate() + 1);