@vizzly/dashboard 0.14.4-dev-e7e7c15c8b3927aa9908c4690679a21c39ce6088 → 0.14.4-dev-1af2412194f87504caed1b603c0df3686a016863

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.
@@ -43512,25 +43512,30 @@ function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
43512
43512
  }
43513
43513
  return fittedTicks.length;
43514
43514
  }
43515
- function howManyTicksFitInHeight(ticks, height) {
43516
- if (height > 180) return undefined;
43517
- var currentHeight = 0;
43518
- var fittedTicks = 0;
43519
- var ASSUMED_AVERAGE_CHAR_HEIGHT = 28;
43520
- for (var i = 0; i < ticks.length; i++) {
43521
- var wordHeight = ASSUMED_AVERAGE_CHAR_HEIGHT;
43522
- if (currentHeight + wordHeight <= height) {
43523
- fittedTicks++;
43524
- currentHeight += wordHeight;
43525
- } else {
43526
- break;
43527
- }
43528
- }
43529
- return fittedTicks;
43515
+ function determineYTicks(ticks, height) {
43516
+ if (ticks.length === 0) return [];
43517
+ if (height > 224) return ticks; // No restriction if enough space
43518
+
43519
+ var ASSUMED_AVERAGE_CHAR_HEIGHT = 24;
43520
+ var maxFittingTicks = Math.floor(height / ASSUMED_AVERAGE_CHAR_HEIGHT);
43521
+ if (maxFittingTicks < 2) return ticks.slice(0, maxFittingTicks);
43522
+ var evenTicks = ticks.filter(function (t) {
43523
+ return t.value % 2 === 0;
43524
+ });
43525
+ var oddTicks = ticks.filter(function (t) {
43526
+ return t.value % 2 === 1;
43527
+ });
43528
+ var favorEven = evenTicks.length >= oddTicks.length;
43529
+ var selectedList = favorEven ? evenTicks : oddTicks;
43530
+ var selectedTicks = pickEquallySpaced(selectedList, maxFittingTicks);
43531
+ if (selectedTicks.length && selectedTicks[selectedTicks.length - 1] === ticks[ticks.length - 1]) {
43532
+ selectedTicks.pop();
43533
+ }
43534
+ return selectedTicks;
43530
43535
  }
43531
43536
  function pickEquallySpaced(arr, numPicks) {
43532
43537
  if (numPicks >= arr.length) {
43533
- return arr; // If numPicks is greater than or equal to the array length, return the whole array
43538
+ return arr;
43534
43539
  }
43535
43540
  var result = [];
43536
43541
  var interval = (arr.length - 1) / (numPicks - 1);
@@ -43540,22 +43545,87 @@ function pickEquallySpaced(arr, numPicks) {
43540
43545
  }
43541
43546
  return result;
43542
43547
  }
43543
- function adjustTicks(representation, width, height) {
43548
+ function adjustTicks(representation, width, height, xKeyField) {
43544
43549
  representation = cloneDeep(representation);
43545
43550
 
43546
43551
  // TODO; take this from the theme override...
43547
43552
  var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
43548
43553
  var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks || [], width, averageCharacterWidth);
43549
- var numberOfYTicksFittingIntoSpace = howManyTicksFitInHeight(representation.y.ticks || [], height);
43550
43554
 
43551
43555
  // @ts-ignore
43552
- representation.x.ticks = pickEquallySpaced(representation.x.ticks, numberOfXTicksFittingIntoSpace);
43553
- if (numberOfYTicksFittingIntoSpace) {
43554
- // @ts-ignore
43555
- representation.y.ticks = pickEquallySpaced(representation.y.ticks, numberOfYTicksFittingIntoSpace);
43556
- }
43556
+ representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
43557
+ // @ts-ignore
43558
+ representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
43557
43559
  return representation;
43558
43560
  }
43561
+ function toNumeric(value) {
43562
+ if (value == null) return null;
43563
+ if (value instanceof Date) return value.getTime();
43564
+ if (typeof value === 'number') return value;
43565
+ var parsed = Date.parse(value);
43566
+ if (!isNaN(parsed)) {
43567
+ return parsed; // treat as timestamp
43568
+ }
43569
+ var numeric = Number(value);
43570
+ return Number.isFinite(numeric) ? numeric : null;
43571
+ }
43572
+ function getEvenlySpacedNumericTicks(sorted, count) {
43573
+ var _toNumeric, _toNumeric2;
43574
+ if (sorted.length <= count) return sorted;
43575
+ var minVal = (_toNumeric = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric : 0;
43576
+ var maxVal = (_toNumeric2 = toNumeric(sorted[sorted.length - 1].scaleValue)) != null ? _toNumeric2 : 0;
43577
+ var range = maxVal - minVal;
43578
+ if (range <= 0) {
43579
+ return [sorted[0]];
43580
+ }
43581
+ var targets = Array.from({
43582
+ length: count
43583
+ }, function (_, i) {
43584
+ var fraction = i / (count - 1);
43585
+ return minVal + fraction * range;
43586
+ });
43587
+ return targets.map(function (target) {
43588
+ var _toNumeric3;
43589
+ var closest = sorted[0];
43590
+ var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
43591
+ for (var _iterator2 = _createForOfIteratorHelperLoose(sorted), _step2; !(_step2 = _iterator2()).done;) {
43592
+ var _toNumeric4;
43593
+ var tick = _step2.value;
43594
+ var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
43595
+ var diff = Math.abs(numericVal - target);
43596
+ if (diff < minDiff) {
43597
+ closest = tick;
43598
+ minDiff = diff;
43599
+ }
43600
+ }
43601
+ return closest;
43602
+ });
43603
+ }
43604
+ function getEvenlySpacedStringTicks(ticks, count) {
43605
+ if (ticks.length <= count) return ticks;
43606
+ var result = [];
43607
+ var step = (ticks.length - 1) / (count - 1);
43608
+ for (var i = 0; i < count; i++) {
43609
+ var index = Math.round(i * step);
43610
+ result.push(ticks[index]);
43611
+ }
43612
+ return result;
43613
+ }
43614
+ function getEvenlySpacedTicks(ticks, count, xKeyField) {
43615
+ if (count === void 0) {
43616
+ count = 4;
43617
+ }
43618
+ if (ticks.length === 0) return [];
43619
+ if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
43620
+ var sorted = [].concat(ticks).sort(function (a, b) {
43621
+ var _toNumeric5, _toNumeric6;
43622
+ return ((_toNumeric5 = toNumeric(a.scaleValue)) != null ? _toNumeric5 : 0) - ((_toNumeric6 = toNumeric(b.scaleValue)) != null ? _toNumeric6 : 0);
43623
+ });
43624
+ return getEvenlySpacedNumericTicks(sorted, count);
43625
+ } else {
43626
+ return getEvenlySpacedStringTicks(ticks, count);
43627
+ }
43628
+ }
43559
43629
 
43560
43630
  var buildMargin = function buildMargin(yTicks, showYAxisLabels, hasYAxisTitle, hasXAxisTitle, showDetailedSubGroupingLabels) {
43561
43631
  if (showDetailedSubGroupingLabels === void 0) {
@@ -46392,6 +46462,10 @@ var LineChartV2View = function LineChartV2View(props) {
46392
46462
  }
46393
46463
  });
46394
46464
  }
46465
+ var xKeyField = useMemo(function () {
46466
+ var _props$result$fields, _props$result;
46467
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
46468
+ }, [pivotConfig, props.result]);
46395
46469
 
46396
46470
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
46397
46471
  if (!LineChartV2Component.isRunnable(props.attributes)) {
@@ -46427,7 +46501,7 @@ var LineChartV2View = function LineChartV2View(props) {
46427
46501
  return jsx(LineChart$5, {
46428
46502
  width: parent.width,
46429
46503
  height: parent.height,
46430
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
46504
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
46431
46505
  options: {
46432
46506
  lineCurve: props.attributes.lineCurve,
46433
46507
  removeStroke: false,
@@ -50412,6 +50486,10 @@ var BarChartV2View = function BarChartV2View(props) {
50412
50486
  });
50413
50487
  setSelectedBar(undefined);
50414
50488
  }, [props.onDrilldownChange, selectedBar]);
50489
+ var xKeyField = useMemo(function () {
50490
+ var _props$result$fields, _props$result;
50491
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
50492
+ }, [pivotConfig, props.result]);
50415
50493
 
50416
50494
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
50417
50495
  if (!BarChartV2Component.isRunnable(props.attributes)) {
@@ -50460,7 +50538,7 @@ var BarChartV2View = function BarChartV2View(props) {
50460
50538
  return jsx(BarChart$5, {
50461
50539
  width: parent.width,
50462
50540
  height: parent.height,
50463
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
50541
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
50464
50542
  options: {
50465
50543
  stacked: !!props.attributes.stacked,
50466
50544
  removeStroke: false,
@@ -51716,6 +51794,7 @@ var AreaChartV2View = function AreaChartV2View(props) {
51716
51794
  var theme = useTheme();
51717
51795
  var AreaChartV2Component = getComponentInterface(props.attributes.type);
51718
51796
  var pivotConfig = init$d(props.attributes);
51797
+ console.log(props.attributes, pivotConfig);
51719
51798
  var chartRepresentation = null;
51720
51799
  if (!isLoading(props.result) && !hasFailed(props.result) && !isEmpty(props.result) && AreaChartV2Component.isRunnable(props.attributes)) {
51721
51800
  var _theme$charts$colors, _theme$charts, _props$attributes$goa;
@@ -51761,6 +51840,10 @@ var AreaChartV2View = function AreaChartV2View(props) {
51761
51840
  stacked: props.attributes.stacked
51762
51841
  });
51763
51842
  }
51843
+ var xKeyField = useMemo(function () {
51844
+ var _props$result$fields, _props$result;
51845
+ return getXKeyField(pivotConfig, (_props$result$fields = (_props$result = props.result) == null ? void 0 : _props$result.fields) != null ? _props$result$fields : []);
51846
+ }, [pivotConfig, props.result]);
51764
51847
 
51765
51848
  // When these are triggered they don't render the chart after they're resolved, potentially because component did no re-render?
51766
51849
  if (!AreaChartV2Component.isRunnable(props.attributes)) {
@@ -51797,7 +51880,7 @@ var AreaChartV2View = function AreaChartV2View(props) {
51797
51880
  return jsx(AreaChart$5, {
51798
51881
  width: parent.width,
51799
51882
  height: parent.height,
51800
- chart: adjustTicks(chartRepresentation, parent.width, parent.height),
51883
+ chart: adjustTicks(chartRepresentation, parent.width, parent.height, xKeyField),
51801
51884
  uniqueId: (_props$attributes$vie2 = props.attributes.viewId) != null ? _props$attributes$vie2 : 'area-chart',
51802
51885
  options: {
51803
51886
  stacked: (_props$attributes$sta = props.attributes.stacked) != null ? _props$attributes$sta : false,
@@ -52795,16 +52878,15 @@ var ComboChartViewV2 = function ComboChartViewV2(props) {
52795
52878
  children: function children(parent) {
52796
52879
  var _props$attributes$sta2;
52797
52880
  var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(comboChartRepresentation.x.ticks || [], parent.width);
52798
- var numberOfYTicksFittingIntoSpace = howManyTicksFitInHeight(comboChartRepresentation.y.ticks, parent.height);
52799
52881
  return jsx(ComboChart$4, {
52800
52882
  width: parent.width,
52801
52883
  height: parent.height,
52802
52884
  chart: _extends({}, comboChartRepresentation, {
52803
52885
  y: _extends({}, comboChartRepresentation.y, {
52804
- ticks: numberOfYTicksFittingIntoSpace ? pickEquallySpaced(comboChartRepresentation.y.ticks, numberOfYTicksFittingIntoSpace) : comboChartRepresentation.y.ticks
52886
+ ticks: determineYTicks(comboChartRepresentation.y.ticks, parent.height)
52805
52887
  }),
52806
52888
  x: _extends({}, comboChartRepresentation == null ? void 0 : comboChartRepresentation.x, {
52807
- ticks: pickEquallySpaced(comboChartRepresentation.x.ticks, numberOfXTicksFittingIntoSpace)
52889
+ ticks: getEvenlySpacedTicks(comboChartRepresentation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField)
52808
52890
  })
52809
52891
  }),
52810
52892
  options: {
@@ -1,6 +1,9 @@
1
+ import { Result } from '../Result/types';
1
2
  import { BaseChartRepresentation, Tick } from './types';
2
3
  export declare const ASSUMED_AVERAGE_CHAR_WIDTH = 4;
3
4
  export declare function howManyTicksFitInWidth(ticks: Tick<string | Number | Date>[], maxWidth: number, avgCharWidth?: number): number;
4
5
  export declare function howManyTicksFitInHeight(ticks: Tick<string | number | Date>[], height: number): number | undefined;
5
- export declare function pickEquallySpaced(arr: Tick<string | Number | Date>[], numPicks: number): Tick<string | Number | Date>[];
6
- export declare function adjustTicks<T extends BaseChartRepresentation>(representation: T, width: number, height: number): T;
6
+ export declare function determineYTicks(ticks: Tick<number>[], height: number): Tick<number>[];
7
+ export declare function pickEquallySpaced<T>(arr: Tick<T>[], numPicks: number): Tick<T>[];
8
+ export declare function adjustTicks<T extends BaseChartRepresentation>(representation: T, width: number, height: number, xKeyField: Result.Field | undefined): T;
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.14.4-dev-e7e7c15c8b3927aa9908c4690679a21c39ce6088",
4
+ "version": "0.14.4-dev-1af2412194f87504caed1b603c0df3686a016863",
5
5
  "source": "src/index.tsx",
6
6
  "types": "./dist/dashboard/src/index.d.ts",
7
7
  "module": "./dist/dashboard.esm.js",
@@ -53,10 +53,10 @@
53
53
  "@react-hook/window-size": "^3.1.1",
54
54
  "@react-spring/web": "9.6.1",
55
55
  "@visx/visx": "^3.10.2",
56
- "@vizzly/api-client": "0.0.45",
56
+ "@vizzly/api-client": "0.0.46",
57
57
  "@vizzly/joi": "^17.7.0",
58
- "@vizzly/semantic-layer-public": "0.0.228",
59
- "@vizzly/sqlbuilder-public": "0.1.31",
58
+ "@vizzly/semantic-layer-public": "0.0.229",
59
+ "@vizzly/sqlbuilder-public": "0.1.33",
60
60
  "chroma-js": "2.4.2",
61
61
  "copy-to-clipboard": "^3.3.3",
62
62
  "cross-fetch": "^4.0.0",