@vizzly/dashboard 0.14.4-dev-88903b8e28588c7d1639449a7dce0f9119640190 → 0.14.4-dev-83542b4d3e5dc5752bc27c826e2f23e6251ee415

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.
@@ -43460,25 +43460,30 @@ function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
43460
43460
  }
43461
43461
  return fittedTicks.length;
43462
43462
  }
43463
- function howManyTicksFitInHeight(ticks, height) {
43464
- if (height > 180) return undefined;
43465
- var currentHeight = 0;
43466
- var fittedTicks = 0;
43467
- var ASSUMED_AVERAGE_CHAR_HEIGHT = 28;
43468
- for (var i = 0; i < ticks.length; i++) {
43469
- var wordHeight = ASSUMED_AVERAGE_CHAR_HEIGHT;
43470
- if (currentHeight + wordHeight <= height) {
43471
- fittedTicks++;
43472
- currentHeight += wordHeight;
43473
- } else {
43474
- break;
43475
- }
43476
- }
43477
- return fittedTicks;
43463
+ function determineYTicks(ticks, height) {
43464
+ if (ticks.length === 0) return [];
43465
+ if (height > 224) return ticks; // No restriction if enough space
43466
+
43467
+ var ASSUMED_AVERAGE_CHAR_HEIGHT = 24;
43468
+ var maxFittingTicks = Math.floor(height / ASSUMED_AVERAGE_CHAR_HEIGHT);
43469
+ if (maxFittingTicks < 2) return ticks.slice(0, maxFittingTicks);
43470
+ var evenTicks = ticks.filter(function (t) {
43471
+ return t.value % 2 === 0;
43472
+ });
43473
+ var oddTicks = ticks.filter(function (t) {
43474
+ return t.value % 2 === 1;
43475
+ });
43476
+ var favorEven = evenTicks.length >= oddTicks.length;
43477
+ var selectedList = favorEven ? evenTicks : oddTicks;
43478
+ var selectedTicks = pickEquallySpaced(selectedList, maxFittingTicks);
43479
+ if (selectedTicks.length && selectedTicks[selectedTicks.length - 1] === ticks[ticks.length - 1]) {
43480
+ selectedTicks.pop();
43481
+ }
43482
+ return selectedTicks;
43478
43483
  }
43479
43484
  function pickEquallySpaced(arr, numPicks) {
43480
43485
  if (numPicks >= arr.length) {
43481
- return arr; // If numPicks is greater than or equal to the array length, return the whole array
43486
+ return arr;
43482
43487
  }
43483
43488
  var result = [];
43484
43489
  var interval = (arr.length - 1) / (numPicks - 1);
@@ -43488,22 +43493,87 @@ function pickEquallySpaced(arr, numPicks) {
43488
43493
  }
43489
43494
  return result;
43490
43495
  }
43491
- function adjustTicks(representation, width, height) {
43496
+ function adjustTicks(representation, width, height, xKeyField) {
43492
43497
  representation = _.cloneDeep(representation);
43493
43498
 
43494
43499
  // TODO; take this from the theme override...
43495
43500
  var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43496
43501
  var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks || [], width, averageCharacterWidth);
43497
- var numberOfYTicksFittingIntoSpace = howManyTicksFitInHeight(representation.y.ticks || [], height);
43498
43502
 
43499
43503
  // @ts-ignore
43500
- representation.x.ticks = pickEquallySpaced(representation.x.ticks, numberOfXTicksFittingIntoSpace);
43501
- if (numberOfYTicksFittingIntoSpace) {
43502
- // @ts-ignore
43503
- representation.y.ticks = pickEquallySpaced(representation.y.ticks, numberOfYTicksFittingIntoSpace);
43504
- }
43504
+ representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
43505
+ // @ts-ignore
43506
+ representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
43505
43507
  return representation;
43506
43508
  }
43509
+ function toNumeric(value) {
43510
+ if (value == null) return null;
43511
+ if (value instanceof Date) return value.getTime();
43512
+ if (typeof value === 'number') return value;
43513
+ var parsed = Date.parse(value);
43514
+ if (!isNaN(parsed)) {
43515
+ return parsed; // treat as timestamp
43516
+ }
43517
+ var numeric = Number(value);
43518
+ return Number.isFinite(numeric) ? numeric : null;
43519
+ }
43520
+ function getEvenlySpacedNumericTicks(sorted, count) {
43521
+ var _toNumeric, _toNumeric2;
43522
+ if (sorted.length <= count) return sorted;
43523
+ var minVal = (_toNumeric = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric : 0;
43524
+ var maxVal = (_toNumeric2 = toNumeric(sorted[sorted.length - 1].scaleValue)) != null ? _toNumeric2 : 0;
43525
+ var range = maxVal - minVal;
43526
+ if (range <= 0) {
43527
+ return [sorted[0]];
43528
+ }
43529
+ var targets = Array.from({
43530
+ length: count
43531
+ }, function (_, i) {
43532
+ var fraction = i / (count - 1);
43533
+ return minVal + fraction * range;
43534
+ });
43535
+ return targets.map(function (target) {
43536
+ var _toNumeric3;
43537
+ var closest = sorted[0];
43538
+ var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
43539
+ for (var _iterator2 = _createForOfIteratorHelperLoose(sorted), _step2; !(_step2 = _iterator2()).done;) {
43540
+ var _toNumeric4;
43541
+ var tick = _step2.value;
43542
+ var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
43543
+ var diff = Math.abs(numericVal - target);
43544
+ if (diff < minDiff) {
43545
+ closest = tick;
43546
+ minDiff = diff;
43547
+ }
43548
+ }
43549
+ return closest;
43550
+ });
43551
+ }
43552
+ function getEvenlySpacedStringTicks(ticks, count) {
43553
+ if (ticks.length <= count) return ticks;
43554
+ var result = [];
43555
+ var step = (ticks.length - 1) / (count - 1);
43556
+ for (var i = 0; i < count; i++) {
43557
+ var index = Math.round(i * step);
43558
+ result.push(ticks[index]);
43559
+ }
43560
+ return result;
43561
+ }
43562
+ function getEvenlySpacedTicks(ticks, count, xKeyField) {
43563
+ if (count === void 0) {
43564
+ count = 4;
43565
+ }
43566
+ if (ticks.length === 0) return [];
43567
+ if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
43568
+ var sorted = [].concat(ticks).sort(function (a, b) {
43569
+ var _toNumeric5, _toNumeric6;
43570
+ return ((_toNumeric5 = toNumeric(a.scaleValue)) != null ? _toNumeric5 : 0) - ((_toNumeric6 = toNumeric(b.scaleValue)) != null ? _toNumeric6 : 0);
43571
+ });
43572
+ return getEvenlySpacedNumericTicks(sorted, count);
43573
+ } else {
43574
+ return getEvenlySpacedStringTicks(ticks, count);
43575
+ }
43576
+ }
43507
43577
 
43508
43578
  var buildMargin = function buildMargin(yTicks, showYAxisLabels, hasYAxisTitle, hasXAxisTitle, showDetailedSubGroupingLabels) {
43509
43579
  if (showDetailedSubGroupingLabels === void 0) {
@@ -46334,6 +46404,10 @@ var LineChartV2View = function LineChartV2View(props) {
46334
46404
  }
46335
46405
  });
46336
46406
  }
46407
+ var xKeyField = React.useMemo(function () {
46408
+ var _props$result$fields, _props$result;
46409
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
46410
+ }, [pivotConfig, props.result]);
46337
46411
 
46338
46412
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
46339
46413
  if (!LineChartV2Component.isRunnable(props.attributes)) {
@@ -46369,7 +46443,7 @@ var LineChartV2View = function LineChartV2View(props) {
46369
46443
  return jsxRuntime.jsx(LineChart$5, {
46370
46444
  width: parent.width,
46371
46445
  height: parent.height,
46372
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
46446
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
46373
46447
  options: {
46374
46448
  lineCurve: props.attributes.lineCurve,
46375
46449
  removeStroke: false,
@@ -50354,6 +50428,10 @@ var BarChartV2View = function BarChartV2View(props) {
50354
50428
  });
50355
50429
  setSelectedBar(undefined);
50356
50430
  }, [props.onDrilldownChange, selectedBar]);
50431
+ var xKeyField = React.useMemo(function () {
50432
+ var _props$result$fields, _props$result;
50433
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
50434
+ }, [pivotConfig, props.result]);
50357
50435
 
50358
50436
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
50359
50437
  if (!BarChartV2Component.isRunnable(props.attributes)) {
@@ -50402,7 +50480,7 @@ var BarChartV2View = function BarChartV2View(props) {
50402
50480
  return jsxRuntime.jsx(BarChart$5, {
50403
50481
  width: parent.width,
50404
50482
  height: parent.height,
50405
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
50483
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
50406
50484
  options: {
50407
50485
  stacked: !!props.attributes.stacked,
50408
50486
  removeStroke: false,
@@ -51658,6 +51736,7 @@ var AreaChartV2View = function AreaChartV2View(props) {
51658
51736
  var theme = useTheme();
51659
51737
  var AreaChartV2Component = getComponentInterface(props.attributes.type);
51660
51738
  var pivotConfig = init$d(props.attributes);
51739
+ console.log(props.attributes, pivotConfig);
51661
51740
  var chartRepresentation = null;
51662
51741
  if (!isLoading(props.result) && !hasFailed(props.result) && !isEmpty(props.result) && AreaChartV2Component.isRunnable(props.attributes)) {
51663
51742
  var _theme$charts$colors, _theme$charts, _props$attributes$goa;
@@ -51703,6 +51782,10 @@ var AreaChartV2View = function AreaChartV2View(props) {
51703
51782
  stacked: props.attributes.stacked
51704
51783
  });
51705
51784
  }
51785
+ var xKeyField = React.useMemo(function () {
51786
+ var _props$result$fields, _props$result;
51787
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
51788
+ }, [pivotConfig, props.result]);
51706
51789
 
51707
51790
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
51708
51791
  if (!AreaChartV2Component.isRunnable(props.attributes)) {
@@ -51739,7 +51822,7 @@ var AreaChartV2View = function AreaChartV2View(props) {
51739
51822
  return jsxRuntime.jsx(AreaChart$5, {
51740
51823
  width: parent.width,
51741
51824
  height: parent.height,
51742
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
51825
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
51743
51826
  uniqueId: (_props$attributes$vie2 = props.attributes.viewId) != null ? _props$attributes$vie2 : 'area-chart',
51744
51827
  options: {
51745
51828
  stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
@@ -52737,16 +52820,15 @@ var ComboChartViewV2 = function ComboChartViewV2(props) {
52737
52820
  children: function children(parent) {
52738
52821
  var _props$attributes$sta2;
52739
52822
  var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(comboChartRepresentation.x.ticks || [], parent.width);
52740
- var numberOfYTicksFittingIntoSpace = howManyTicksFitInHeight(comboChartRepresentation.y.ticks, parent.height);
52741
52823
  return jsxRuntime.jsx(ComboChart$4, {
52742
52824
  width: parent.width,
52743
52825
  height: parent.height,
52744
52826
  chart: _extends({}, comboChartRepresentation, {
52745
52827
  y: _extends({}, comboChartRepresentation.y, {
52746
- ticks: numberOfYTicksFittingIntoSpace ? pickEquallySpaced(comboChartRepresentation.y.ticks, numberOfYTicksFittingIntoSpace) : comboChartRepresentation.y.ticks
52828
+ ticks: determineYTicks(comboChartRepresentation.y.ticks, parent.height)
52747
52829
  }),
52748
52830
  x: _extends({}, comboChartRepresentation == null ? void 0 : comboChartRepresentation.x, {
52749
- ticks: pickEquallySpaced(comboChartRepresentation.x.ticks, numberOfXTicksFittingIntoSpace)
52831
+ ticks: getEvenlySpacedTicks(comboChartRepresentation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField)
52750
52832
  })
52751
52833
  }),
52752
52834
  options: {