@vizzly/dashboard 0.15.0-dev-be496789be553817e5a66f91e70d9233188e33b0 → 0.15.0-dev-ec22f31a049b4f844d3ea606a85bd487c4553b03

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,33 +43662,64 @@ var Legend$1 = function Legend(_ref) {
43662
43662
  });
43663
43663
  };
43664
43664
 
43665
- var ASSUMED_AVERAGE_CHAR_WIDTH = 4;
43665
+ var ASSUMED_AVERAGE_CHAR_WIDTH = 7.1;
43666
+
43666
43667
  function calculateWordWidth(word, avgCharWidth) {
43667
43668
  return word.length * avgCharWidth;
43668
43669
  }
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
- };
43670
+ function getTicksIntervals(numElements) {
43671
+ var divisors = [];
43672
+ for (var i = 1; i <= Math.sqrt(numElements - 1); i++) {
43673
+ if ((numElements - 1) % i !== 0) {
43674
+ continue;
43675
+ }
43676
+ divisors.push(i);
43677
+ var divisor = (numElements - 1) / i;
43678
+ if (i === divisor) {
43679
+ continue;
43680
+ }
43681
+ divisors.push(divisor);
43682
+ }
43683
+ divisors.sort(function (a, b) {
43684
+ return b - a;
43685
+ });
43686
+ return divisors;
43687
+ }
43688
+ function isTickIntervalValid(interval, maxWidth, wordWidths) {
43689
+ var totalWidth = 0;
43690
+ for (var i = 0; i < wordWidths.length; i += interval) {
43691
+ var spacing = i > 0 ? 12 : 0; // Add spacing only after the first tick
43692
+ totalWidth += wordWidths[i] + spacing;
43693
+ }
43694
+ return totalWidth <= maxWidth;
43695
+ }
43675
43696
  function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
43676
43697
  if (avgCharWidth === void 0) {
43677
43698
  avgCharWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43678
43699
  }
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
43700
+ var ticksIntervals = getTicksIntervals(ticks.length);
43701
+ var ticksWidths = ticks.map(function (tick) {
43702
+ var _tick$formattedValue;
43703
+ return calculateWordWidth((_tick$formattedValue = tick == null ? void 0 : tick.formattedValue) != null ? _tick$formattedValue : '', avgCharWidth);
43704
+ });
43705
+ var optimalInterval = ticksIntervals[ticksIntervals.length - 1]; // Default to showing only first and last marks if none fit
43706
+ var left = 0;
43707
+ var right = ticksIntervals.length - 1;
43708
+
43709
+ // Binary search for the largest step that fits all elements
43710
+ while (left <= right) {
43711
+ var mid = Math.floor((left + right) / 2);
43712
+ var step = ticksIntervals[mid];
43713
+ if (isTickIntervalValid(step, maxWidth, ticksWidths)) {
43714
+ optimalInterval = step; // Found a valid step, try to find a larger one
43715
+ left = mid + 1;
43688
43716
  } else {
43689
- break; // Stop if adding the word exceeds maxWidth
43717
+ right = mid - 1;
43690
43718
  }
43691
43719
  }
43720
+ var fittedTicks = ticks.filter(function (_, index) {
43721
+ return index % optimalInterval === 0;
43722
+ });
43692
43723
  return fittedTicks.length;
43693
43724
  }
43694
43725
  function determineYTicks(ticks, height) {
@@ -43725,16 +43756,14 @@ function pickEquallySpaced(arr, numPicks) {
43725
43756
  return result;
43726
43757
  }
43727
43758
  function adjustTicks(representation, width, height, xKeyField) {
43759
+ var _representation$x$tic, _representation$y$tic;
43728
43760
  representation = cloneDeep(representation);
43729
43761
 
43730
43762
  // TODO; take this from the theme override...
43731
43763
  var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43732
- var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks || [], width, averageCharacterWidth);
43733
-
43734
- // @ts-ignore
43764
+ var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_representation$x$tic = representation.x.ticks) != null ? _representation$x$tic : [], width, averageCharacterWidth);
43735
43765
  representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
43736
- // @ts-ignore
43737
- representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
43766
+ representation.y.ticks = determineYTicks((_representation$y$tic = representation.y.ticks) != null ? _representation$y$tic : [], height);
43738
43767
  return representation;
43739
43768
  }
43740
43769
  function toNumeric(value) {
@@ -43767,9 +43796,9 @@ function getEvenlySpacedNumericTicks(sorted, count) {
43767
43796
  var _toNumeric3;
43768
43797
  var closest = sorted[0];
43769
43798
  var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
43770
- for (var _iterator2 = _createForOfIteratorHelperLoose(sorted), _step2; !(_step2 = _iterator2()).done;) {
43799
+ for (var _iterator = _createForOfIteratorHelperLoose(sorted), _step; !(_step = _iterator()).done;) {
43771
43800
  var _toNumeric4;
43772
- var tick = _step2.value;
43801
+ var tick = _step.value;
43773
43802
  var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
43774
43803
  var diff = Math.abs(numericVal - target);
43775
43804
  if (diff < minDiff) {
@@ -43791,16 +43820,9 @@ function getEvenlySpacedStringTicks(ticks, count) {
43791
43820
  return result;
43792
43821
  }
43793
43822
  function getEvenlySpacedTicks(ticks, count, xKeyField) {
43794
- if (count === void 0) {
43795
- count = 4;
43796
- }
43797
43823
  if (ticks.length === 0) return [];
43798
43824
  if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
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);
43825
+ return getEvenlySpacedNumericTicks(ticks, count);
43804
43826
  } else {
43805
43827
  return getEvenlySpacedStringTicks(ticks, count);
43806
43828
  }
@@ -53091,8 +53113,10 @@ var SunburstChartView = function SunburstChartView(props) {
53091
53113
  setTooltipLabel = _useState5[1];
53092
53114
  var xScale = scaleLinear$1().domain(xDomain).range(xRange);
53093
53115
  var yScale = scaleSqrt().domain(yDomain).range(yRange);
53094
- var width = props.width * 3 / 5;
53095
- var height = 500;
53116
+ var width = props.width * 3 / 6;
53117
+ var height = props.height * 0.9;
53118
+ var minDimension = Math.min(props.width, props.height);
53119
+ var centeredRatio = minDimension / 2.5;
53096
53120
  var sunburstChartComponent = getComponentInterface(props.attributes.type);
53097
53121
  var headerProps = {
53098
53122
  displayTitle: props.attributes.displayTitle,
@@ -53112,8 +53136,8 @@ var SunburstChartView = function SunburstChartView(props) {
53112
53136
  order: props.attributes.order
53113
53137
  };
53114
53138
  useEffect(function () {
53115
- setYRange([yRange[0], width / 2]);
53116
- }, [width]);
53139
+ setYRange([yRange[0], centeredRatio]);
53140
+ }, [centeredRatio]);
53117
53141
  var arc$1 = arc().startAngle(function (d) {
53118
53142
  return Math.max(0, Math.min(2 * Math.PI, xScale(d.x0)));
53119
53143
  }).endAngle(function (d) {
@@ -53126,7 +53150,7 @@ var SunburstChartView = function SunburstChartView(props) {
53126
53150
  var handleClick = function handleClick(d) {
53127
53151
  setXDomain([d.x0, d.x1]);
53128
53152
  setYDomain([d.y0, 1]);
53129
- setYRange([d.y0 ? 20 : 0, width / 2]);
53153
+ setYRange([d.y0 ? 20 : 0, centeredRatio]);
53130
53154
  };
53131
53155
  var handleUpdate = function handleUpdate(t, xd, yd, yr) {
53132
53156
  xScale.domain(xd(t));
@@ -53213,7 +53237,7 @@ var SunburstChartView = function SunburstChartView(props) {
53213
53237
  height: height,
53214
53238
  children: jsx(Partition, {
53215
53239
  top: 0,
53216
- left: centerX * 2 / 3,
53240
+ left: centerX + DEFAULT_MARGINS.left,
53217
53241
  root: root,
53218
53242
  children: jsx(Spring, {
53219
53243
  reset: true,
@@ -53339,7 +53363,7 @@ function calculateWordWidth$1(word, avgCharWidth) {
53339
53363
  }
53340
53364
 
53341
53365
  /** Reduce width proportionally to simulate spacing / padding between ticks. */
53342
- var widthWithSpacing$1 = function widthWithSpacing(width) {
53366
+ var widthWithSpacing = function widthWithSpacing(width) {
53343
53367
  var THIRTY_PERCENT = 0.3;
53344
53368
  return width - width * THIRTY_PERCENT;
53345
53369
  };
@@ -53353,7 +53377,7 @@ function howManyTicksFitInWidth$1(ticks, maxWidth, avgCharWidth) {
53353
53377
  var tick = _step.value;
53354
53378
  var word = (tick == null ? void 0 : tick.formattedValue) || '';
53355
53379
  var wordWidth = calculateWordWidth$1(word, avgCharWidth);
53356
- if (currentWidth + wordWidth <= widthWithSpacing$1(maxWidth)) {
53380
+ if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
53357
53381
  fittedTicks.push(tick);
53358
53382
  currentWidth += wordWidth + avgCharWidth; // Add space between words
53359
53383
  } 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 = 4;
4
- export declare function howManyTicksFitInWidth(ticks: Tick<string | Number | Date>[], maxWidth: number, avgCharWidth?: number): number;
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;
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 | undefined, xKeyField: Result.Field | undefined): Tick<DataType>[];
9
+ export declare function getEvenlySpacedTicks<DataType extends string | number | Date>(ticks: Tick<DataType>[], count: number, 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-be496789be553817e5a66f91e70d9233188e33b0",
4
+ "version": "0.15.0-dev-ec22f31a049b4f844d3ea606a85bd487c4553b03",
5
5
  "source": "src/index.tsx",
6
6
  "types": "./dist/dashboard/src/index.d.ts",
7
7
  "module": "./dist/dashboard.esm.js",