@vizzly/dashboard 0.15.0-dev-4815d6f8b96f6aef5270f29e0b642f190891df6b → 0.15.0-dev-7fc1f00d183f9b2ca9704405e39d6c5e03b100bb

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.
@@ -43662,62 +43662,33 @@ var Legend$1 = function Legend(_ref) {
43662
43662
  });
43663
43663
  };
43664
43664
 
43665
- var ASSUMED_AVERAGE_CHAR_WIDTH = 7.1;
43665
+ var ASSUMED_AVERAGE_CHAR_WIDTH = 4;
43666
43666
  function calculateWordWidth(word, avgCharWidth) {
43667
43667
  return word.length * avgCharWidth;
43668
43668
  }
43669
- function getTicksIntervals(numElements) {
43670
- var divisors = [];
43671
- for (var i = 1; i <= Math.sqrt(numElements - 1); i++) {
43672
- if ((numElements - 1) % i !== 0) {
43673
- continue;
43674
- }
43675
- divisors.push(i);
43676
- var divisor = (numElements - 1) / i;
43677
- if (i === divisor) {
43678
- continue;
43679
- }
43680
- divisors.push(divisor);
43681
- }
43682
- divisors.sort(function (a, b) {
43683
- return b - a;
43684
- });
43685
- return divisors;
43686
- }
43687
- function isTickIntervalValid(interval, maxWidth, wordWidths) {
43688
- var totalWidth = 0;
43689
- for (var i = 0; i < wordWidths.length; i += interval) {
43690
- totalWidth += wordWidths[i];
43691
- }
43692
- return totalWidth <= maxWidth;
43693
- }
43669
+
43670
+ /** Reduce width proportionally to simulate spacing / padding between ticks. */
43671
+ var widthWithSpacing = function widthWithSpacing(width) {
43672
+ var THIRTY_PERCENT = 0.3;
43673
+ return width - width * THIRTY_PERCENT;
43674
+ };
43694
43675
  function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
43695
43676
  if (avgCharWidth === void 0) {
43696
43677
  avgCharWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43697
43678
  }
43698
- var ticksIntervals = getTicksIntervals(ticks.length);
43699
- var ticksWidths = ticks.map(function (tick) {
43700
- var _tick$formattedValue;
43701
- return calculateWordWidth((_tick$formattedValue = tick == null ? void 0 : tick.formattedValue) != null ? _tick$formattedValue : '', avgCharWidth);
43702
- });
43703
- var optimalInterval = ticksIntervals[ticksIntervals.length - 1]; // Default to showing only first and last marks if none fit
43704
- var left = 0;
43705
- var right = ticksIntervals.length - 1;
43706
-
43707
- // Binary search for the largest step that fits all elements
43708
- while (left <= right) {
43709
- var mid = Math.floor((left + right) / 2);
43710
- var step = ticksIntervals[mid];
43711
- if (isTickIntervalValid(step, maxWidth, ticksWidths)) {
43712
- optimalInterval = step; // Found a valid step, try to find a larger one
43713
- left = mid + 1;
43679
+ var fittedTicks = [];
43680
+ var currentWidth = 0;
43681
+ for (var _iterator = _createForOfIteratorHelperLoose(ticks), _step; !(_step = _iterator()).done;) {
43682
+ var tick = _step.value;
43683
+ var word = (tick == null ? void 0 : tick.formattedValue) || '';
43684
+ var wordWidth = calculateWordWidth(word, avgCharWidth);
43685
+ if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
43686
+ fittedTicks.push(tick);
43687
+ currentWidth += wordWidth + avgCharWidth; // Add space between words
43714
43688
  } else {
43715
- right = mid - 1;
43689
+ break; // Stop if adding the word exceeds maxWidth
43716
43690
  }
43717
43691
  }
43718
- var fittedTicks = ticks.filter(function (_, index) {
43719
- return index % optimalInterval === 0;
43720
- });
43721
43692
  return fittedTicks.length;
43722
43693
  }
43723
43694
  function determineYTicks(ticks, height) {
@@ -43754,14 +43725,16 @@ function pickEquallySpaced(arr, numPicks) {
43754
43725
  return result;
43755
43726
  }
43756
43727
  function adjustTicks(representation, width, height, xKeyField) {
43757
- var _representation$x$tic, _representation$y$tic;
43758
43728
  representation = cloneDeep(representation);
43759
43729
 
43760
43730
  // TODO; take this from the theme override...
43761
43731
  var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43762
- var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_representation$x$tic = representation.x.ticks) != null ? _representation$x$tic : [], width, averageCharacterWidth);
43732
+ var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks || [], width, averageCharacterWidth);
43733
+
43734
+ // @ts-ignore
43763
43735
  representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
43764
- representation.y.ticks = determineYTicks((_representation$y$tic = representation.y.ticks) != null ? _representation$y$tic : [], height);
43736
+ // @ts-ignore
43737
+ representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
43765
43738
  return representation;
43766
43739
  }
43767
43740
  function toNumeric(value) {
@@ -43794,9 +43767,9 @@ function getEvenlySpacedNumericTicks(sorted, count) {
43794
43767
  var _toNumeric3;
43795
43768
  var closest = sorted[0];
43796
43769
  var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
43797
- for (var _iterator = _createForOfIteratorHelperLoose(sorted), _step; !(_step = _iterator()).done;) {
43770
+ for (var _iterator2 = _createForOfIteratorHelperLoose(sorted), _step2; !(_step2 = _iterator2()).done;) {
43798
43771
  var _toNumeric4;
43799
- var tick = _step.value;
43772
+ var tick = _step2.value;
43800
43773
  var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
43801
43774
  var diff = Math.abs(numericVal - target);
43802
43775
  if (diff < minDiff) {
@@ -43818,9 +43791,16 @@ function getEvenlySpacedStringTicks(ticks, count) {
43818
43791
  return result;
43819
43792
  }
43820
43793
  function getEvenlySpacedTicks(ticks, count, xKeyField) {
43794
+ if (count === void 0) {
43795
+ count = 4;
43796
+ }
43821
43797
  if (ticks.length === 0) return [];
43822
43798
  if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
43823
- return getEvenlySpacedNumericTicks(ticks, count);
43799
+ var sorted = [].concat(ticks).sort(function (a, b) {
43800
+ var _toNumeric5, _toNumeric6;
43801
+ return ((_toNumeric5 = toNumeric(a.scaleValue)) != null ? _toNumeric5 : 0) - ((_toNumeric6 = toNumeric(b.scaleValue)) != null ? _toNumeric6 : 0);
43802
+ });
43803
+ return getEvenlySpacedNumericTicks(sorted, count);
43824
43804
  } else {
43825
43805
  return getEvenlySpacedStringTicks(ticks, count);
43826
43806
  }
@@ -49287,8 +49267,8 @@ var ComboChartViewV2 = function ComboChartViewV2(props) {
49287
49267
  overflowX: 'hidden'
49288
49268
  },
49289
49269
  children: function children(parent) {
49290
- var _comboChartRepresenta, _props$attributes$sta2;
49291
- var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_comboChartRepresenta = comboChartRepresentation.x.ticks) != null ? _comboChartRepresenta : [], parent.width);
49270
+ var _props$attributes$sta2;
49271
+ var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(comboChartRepresentation.x.ticks || [], parent.width);
49292
49272
  return jsx(ComboChart$4, {
49293
49273
  width: parent.width,
49294
49274
  height: parent.height,
@@ -53359,7 +53339,7 @@ function calculateWordWidth$1(word, avgCharWidth) {
53359
53339
  }
53360
53340
 
53361
53341
  /** Reduce width proportionally to simulate spacing / padding between ticks. */
53362
- var widthWithSpacing = function widthWithSpacing(width) {
53342
+ var widthWithSpacing$1 = function widthWithSpacing(width) {
53363
53343
  var THIRTY_PERCENT = 0.3;
53364
53344
  return width - width * THIRTY_PERCENT;
53365
53345
  };
@@ -53373,7 +53353,7 @@ function howManyTicksFitInWidth$1(ticks, maxWidth, avgCharWidth) {
53373
53353
  var tick = _step.value;
53374
53354
  var word = (tick == null ? void 0 : tick.formattedValue) || '';
53375
53355
  var wordWidth = calculateWordWidth$1(word, avgCharWidth);
53376
- if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
53356
+ if (currentWidth + wordWidth <= widthWithSpacing$1(maxWidth)) {
53377
53357
  fittedTicks.push(tick);
53378
53358
  currentWidth += wordWidth + avgCharWidth; // Add space between words
53379
53359
  } else {
@@ -1,9 +1,9 @@
1
1
  import { Result } from '../Result/types';
2
2
  import { BaseChartRepresentation, Tick } from './types';
3
- export declare const ASSUMED_AVERAGE_CHAR_WIDTH = 7.1;
4
- export declare function howManyTicksFitInWidth(ticks: Tick<string | number | Date>[], maxWidth: number, avgCharWidth?: number): number;
3
+ export declare const ASSUMED_AVERAGE_CHAR_WIDTH = 4;
4
+ export declare function howManyTicksFitInWidth(ticks: Tick<string | Number | Date>[], maxWidth: number, avgCharWidth?: number): number;
5
5
  export declare function howManyTicksFitInHeight(ticks: Tick<string | number | Date>[], height: number): number | undefined;
6
6
  export declare function determineYTicks(ticks: Tick<number>[], height: number): Tick<number>[];
7
7
  export declare function pickEquallySpaced<T>(arr: Tick<T>[], numPicks: number): Tick<T>[];
8
8
  export declare function adjustTicks<T extends BaseChartRepresentation>(representation: T, width: number, height: number, xKeyField?: Result.Field): T;
9
- export declare function getEvenlySpacedTicks<DataType extends string | number | Date>(ticks: Tick<DataType>[], count: number, xKeyField: Result.Field | undefined): Tick<DataType>[];
9
+ export declare function getEvenlySpacedTicks<DataType extends string | number | Date>(ticks: Tick<DataType>[], count: number | undefined, xKeyField: Result.Field | undefined): Tick<DataType>[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vizzly/dashboard",
3
3
  "author": "james@vizzly.co",
4
- "version": "0.15.0-dev-4815d6f8b96f6aef5270f29e0b642f190891df6b",
4
+ "version": "0.15.0-dev-7fc1f00d183f9b2ca9704405e39d6c5e03b100bb",
5
5
  "source": "src/index.tsx",
6
6
  "types": "./dist/dashboard/src/index.d.ts",
7
7
  "module": "./dist/dashboard.esm.js",