@vizzly/dashboard 0.15.0-dev-4ac4ddba4b756843de06e0ef600c2aed9b8ef78f → 0.15.0-dev-a0c2e94601580e6492c72e10cbc684c57074babe

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.
@@ -43610,33 +43610,64 @@ var Legend$1 = function Legend(_ref) {
43610
43610
  });
43611
43611
  };
43612
43612
 
43613
- var ASSUMED_AVERAGE_CHAR_WIDTH = 4;
43613
+ var ASSUMED_AVERAGE_CHAR_WIDTH = 7.1;
43614
+
43614
43615
  function calculateWordWidth(word, avgCharWidth) {
43615
43616
  return word.length * avgCharWidth;
43616
43617
  }
43617
-
43618
- /** Reduce width proportionally to simulate spacing / padding between ticks. */
43619
- var widthWithSpacing = function widthWithSpacing(width) {
43620
- var THIRTY_PERCENT = 0.3;
43621
- return width - width * THIRTY_PERCENT;
43622
- };
43618
+ function getTicksIntervals(numElements) {
43619
+ var divisors = [];
43620
+ for (var i = 1; i <= Math.sqrt(numElements - 1); i++) {
43621
+ if ((numElements - 1) % i !== 0) {
43622
+ continue;
43623
+ }
43624
+ divisors.push(i);
43625
+ var divisor = (numElements - 1) / i;
43626
+ if (i === divisor) {
43627
+ continue;
43628
+ }
43629
+ divisors.push(divisor);
43630
+ }
43631
+ divisors.sort(function (a, b) {
43632
+ return b - a;
43633
+ });
43634
+ return divisors;
43635
+ }
43636
+ function isTickIntervalValid(interval, maxWidth, wordWidths) {
43637
+ var totalWidth = 0;
43638
+ for (var i = 0; i < wordWidths.length; i += interval) {
43639
+ var spacing = i > 0 ? 12 : 0; // Add spacing only after the first tick
43640
+ totalWidth += wordWidths[i] + spacing;
43641
+ }
43642
+ return totalWidth <= maxWidth;
43643
+ }
43623
43644
  function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
43624
43645
  if (avgCharWidth === void 0) {
43625
43646
  avgCharWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43626
43647
  }
43627
- var fittedTicks = [];
43628
- var currentWidth = 0;
43629
- for (var _iterator = _createForOfIteratorHelperLoose(ticks), _step; !(_step = _iterator()).done;) {
43630
- var tick = _step.value;
43631
- var word = (tick == null ? void 0 : tick.formattedValue) || '';
43632
- var wordWidth = calculateWordWidth(word, avgCharWidth);
43633
- if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
43634
- fittedTicks.push(tick);
43635
- currentWidth += wordWidth + avgCharWidth; // Add space between words
43648
+ var ticksIntervals = getTicksIntervals(ticks.length);
43649
+ var ticksWidths = ticks.map(function (tick) {
43650
+ var _tick$formattedValue;
43651
+ return calculateWordWidth((_tick$formattedValue = tick == null ? void 0 : tick.formattedValue) != null ? _tick$formattedValue : '', avgCharWidth);
43652
+ });
43653
+ var optimalInterval = ticksIntervals[ticksIntervals.length - 1]; // Default to showing only first and last marks if none fit
43654
+ var left = 0;
43655
+ var right = ticksIntervals.length - 1;
43656
+
43657
+ // Binary search for the largest step that fits all elements
43658
+ while (left <= right) {
43659
+ var mid = Math.floor((left + right) / 2);
43660
+ var step = ticksIntervals[mid];
43661
+ if (isTickIntervalValid(step, maxWidth, ticksWidths)) {
43662
+ optimalInterval = step; // Found a valid step, try to find a larger one
43663
+ left = mid + 1;
43636
43664
  } else {
43637
- break; // Stop if adding the word exceeds maxWidth
43665
+ right = mid - 1;
43638
43666
  }
43639
43667
  }
43668
+ var fittedTicks = ticks.filter(function (_, index) {
43669
+ return index % optimalInterval === 0;
43670
+ });
43640
43671
  return fittedTicks.length;
43641
43672
  }
43642
43673
  function determineYTicks(ticks, height) {
@@ -43673,16 +43704,14 @@ function pickEquallySpaced(arr, numPicks) {
43673
43704
  return result;
43674
43705
  }
43675
43706
  function adjustTicks(representation, width, height, xKeyField) {
43707
+ var _representation$x$tic, _representation$y$tic;
43676
43708
  representation = _.cloneDeep(representation);
43677
43709
 
43678
43710
  // TODO; take this from the theme override...
43679
43711
  var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43680
- var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks || [], width, averageCharacterWidth);
43681
-
43682
- // @ts-ignore
43712
+ var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_representation$x$tic = representation.x.ticks) != null ? _representation$x$tic : [], width, averageCharacterWidth);
43683
43713
  representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
43684
- // @ts-ignore
43685
- representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
43714
+ representation.y.ticks = determineYTicks((_representation$y$tic = representation.y.ticks) != null ? _representation$y$tic : [], height);
43686
43715
  return representation;
43687
43716
  }
43688
43717
  function toNumeric(value) {
@@ -43715,9 +43744,9 @@ function getEvenlySpacedNumericTicks(sorted, count) {
43715
43744
  var _toNumeric3;
43716
43745
  var closest = sorted[0];
43717
43746
  var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
43718
- for (var _iterator2 = _createForOfIteratorHelperLoose(sorted), _step2; !(_step2 = _iterator2()).done;) {
43747
+ for (var _iterator = _createForOfIteratorHelperLoose(sorted), _step; !(_step = _iterator()).done;) {
43719
43748
  var _toNumeric4;
43720
- var tick = _step2.value;
43749
+ var tick = _step.value;
43721
43750
  var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
43722
43751
  var diff = Math.abs(numericVal - target);
43723
43752
  if (diff < minDiff) {
@@ -43739,16 +43768,9 @@ function getEvenlySpacedStringTicks(ticks, count) {
43739
43768
  return result;
43740
43769
  }
43741
43770
  function getEvenlySpacedTicks(ticks, count, xKeyField) {
43742
- if (count === void 0) {
43743
- count = 4;
43744
- }
43745
43771
  if (ticks.length === 0) return [];
43746
43772
  if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
43747
- var sorted = [].concat(ticks).sort(function (a, b) {
43748
- var _toNumeric5, _toNumeric6;
43749
- return ((_toNumeric5 = toNumeric(a.scaleValue)) != null ? _toNumeric5 : 0) - ((_toNumeric6 = toNumeric(b.scaleValue)) != null ? _toNumeric6 : 0);
43750
- });
43751
- return getEvenlySpacedNumericTicks(sorted, count);
43773
+ return getEvenlySpacedNumericTicks(ticks, count);
43752
43774
  } else {
43753
43775
  return getEvenlySpacedStringTicks(ticks, count);
43754
43776
  }
@@ -53281,7 +53303,7 @@ function calculateWordWidth$1(word, avgCharWidth) {
53281
53303
  }
53282
53304
 
53283
53305
  /** Reduce width proportionally to simulate spacing / padding between ticks. */
53284
- var widthWithSpacing$1 = function widthWithSpacing(width) {
53306
+ var widthWithSpacing = function widthWithSpacing(width) {
53285
53307
  var THIRTY_PERCENT = 0.3;
53286
53308
  return width - width * THIRTY_PERCENT;
53287
53309
  };
@@ -53295,7 +53317,7 @@ function howManyTicksFitInWidth$1(ticks, maxWidth, avgCharWidth) {
53295
53317
  var tick = _step.value;
53296
53318
  var word = (tick == null ? void 0 : tick.formattedValue) || '';
53297
53319
  var wordWidth = calculateWordWidth$1(word, avgCharWidth);
53298
- if (currentWidth + wordWidth <= widthWithSpacing$1(maxWidth)) {
53320
+ if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
53299
53321
  fittedTicks.push(tick);
53300
53322
  currentWidth += wordWidth + avgCharWidth; // Add space between words
53301
53323
  } else {