@vizzly/dashboard 0.15.0-dev-40c479fdafffb16cba288545eceac8ea5f1efddb → 0.15.0-dev-4815d6f8b96f6aef5270f29e0b642f190891df6b

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