@vizzly/dashboard 0.15.0-dev-abd38c3135e9c81774564b32bbe7750a29cc6448 → 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.
package/dist/dashboard.esm.js
CHANGED
|
@@ -43662,33 +43662,62 @@ var Legend$1 = function Legend(_ref) {
|
|
|
43662
43662
|
});
|
|
43663
43663
|
};
|
|
43664
43664
|
|
|
43665
|
-
var ASSUMED_AVERAGE_CHAR_WIDTH =
|
|
43665
|
+
var ASSUMED_AVERAGE_CHAR_WIDTH = 7.1;
|
|
43666
43666
|
function calculateWordWidth(word, avgCharWidth) {
|
|
43667
43667
|
return word.length * avgCharWidth;
|
|
43668
43668
|
}
|
|
43669
|
-
|
|
43670
|
-
|
|
43671
|
-
var
|
|
43672
|
-
|
|
43673
|
-
|
|
43674
|
-
}
|
|
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
|
+
}
|
|
43675
43694
|
function howManyTicksFitInWidth(ticks, maxWidth, avgCharWidth) {
|
|
43676
43695
|
if (avgCharWidth === void 0) {
|
|
43677
43696
|
avgCharWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
|
|
43678
43697
|
}
|
|
43679
|
-
var
|
|
43680
|
-
var
|
|
43681
|
-
|
|
43682
|
-
|
|
43683
|
-
|
|
43684
|
-
|
|
43685
|
-
|
|
43686
|
-
|
|
43687
|
-
|
|
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;
|
|
43688
43714
|
} else {
|
|
43689
|
-
|
|
43715
|
+
right = mid - 1;
|
|
43690
43716
|
}
|
|
43691
43717
|
}
|
|
43718
|
+
var fittedTicks = ticks.filter(function (_, index) {
|
|
43719
|
+
return index % optimalInterval === 0;
|
|
43720
|
+
});
|
|
43692
43721
|
return fittedTicks.length;
|
|
43693
43722
|
}
|
|
43694
43723
|
function determineYTicks(ticks, height) {
|
|
@@ -43725,16 +43754,14 @@ function pickEquallySpaced(arr, numPicks) {
|
|
|
43725
43754
|
return result;
|
|
43726
43755
|
}
|
|
43727
43756
|
function adjustTicks(representation, width, height, xKeyField) {
|
|
43757
|
+
var _representation$x$tic, _representation$y$tic;
|
|
43728
43758
|
representation = cloneDeep(representation);
|
|
43729
43759
|
|
|
43730
43760
|
// TODO; take this from the theme override...
|
|
43731
43761
|
var averageCharacterWidth = ASSUMED_AVERAGE_CHAR_WIDTH;
|
|
43732
|
-
var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(representation.x.ticks
|
|
43733
|
-
|
|
43734
|
-
// @ts-ignore
|
|
43762
|
+
var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_representation$x$tic = representation.x.ticks) != null ? _representation$x$tic : [], width, averageCharacterWidth);
|
|
43735
43763
|
representation.x.ticks = getEvenlySpacedTicks(representation.x.ticks, numberOfXTicksFittingIntoSpace, xKeyField);
|
|
43736
|
-
|
|
43737
|
-
representation.y.ticks = determineYTicks(representation.y.ticks || [], height);
|
|
43764
|
+
representation.y.ticks = determineYTicks((_representation$y$tic = representation.y.ticks) != null ? _representation$y$tic : [], height);
|
|
43738
43765
|
return representation;
|
|
43739
43766
|
}
|
|
43740
43767
|
function toNumeric(value) {
|
|
@@ -43767,9 +43794,9 @@ function getEvenlySpacedNumericTicks(sorted, count) {
|
|
|
43767
43794
|
var _toNumeric3;
|
|
43768
43795
|
var closest = sorted[0];
|
|
43769
43796
|
var minDiff = Math.abs(((_toNumeric3 = toNumeric(sorted[0].scaleValue)) != null ? _toNumeric3 : 0) - target);
|
|
43770
|
-
for (var
|
|
43797
|
+
for (var _iterator = _createForOfIteratorHelperLoose(sorted), _step; !(_step = _iterator()).done;) {
|
|
43771
43798
|
var _toNumeric4;
|
|
43772
|
-
var tick =
|
|
43799
|
+
var tick = _step.value;
|
|
43773
43800
|
var numericVal = (_toNumeric4 = toNumeric(tick.scaleValue)) != null ? _toNumeric4 : 0;
|
|
43774
43801
|
var diff = Math.abs(numericVal - target);
|
|
43775
43802
|
if (diff < minDiff) {
|
|
@@ -43791,16 +43818,9 @@ function getEvenlySpacedStringTicks(ticks, count) {
|
|
|
43791
43818
|
return result;
|
|
43792
43819
|
}
|
|
43793
43820
|
function getEvenlySpacedTicks(ticks, count, xKeyField) {
|
|
43794
|
-
if (count === void 0) {
|
|
43795
|
-
count = 4;
|
|
43796
|
-
}
|
|
43797
43821
|
if (ticks.length === 0) return [];
|
|
43798
43822
|
if ((xKeyField == null ? void 0 : xKeyField.dataType) === 'number' || (xKeyField == null ? void 0 : xKeyField.dataType) === 'date_time') {
|
|
43799
|
-
|
|
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);
|
|
43823
|
+
return getEvenlySpacedNumericTicks(ticks, count);
|
|
43804
43824
|
} else {
|
|
43805
43825
|
return getEvenlySpacedStringTicks(ticks, count);
|
|
43806
43826
|
}
|
|
@@ -49267,8 +49287,8 @@ var ComboChartViewV2 = function ComboChartViewV2(props) {
|
|
|
49267
49287
|
overflowX: 'hidden'
|
|
49268
49288
|
},
|
|
49269
49289
|
children: function children(parent) {
|
|
49270
|
-
var _props$attributes$sta2;
|
|
49271
|
-
var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth(comboChartRepresentation.x.ticks
|
|
49290
|
+
var _comboChartRepresenta, _props$attributes$sta2;
|
|
49291
|
+
var numberOfXTicksFittingIntoSpace = howManyTicksFitInWidth((_comboChartRepresenta = comboChartRepresentation.x.ticks) != null ? _comboChartRepresenta : [], parent.width);
|
|
49272
49292
|
return jsx(ComboChart$4, {
|
|
49273
49293
|
width: parent.width,
|
|
49274
49294
|
height: parent.height,
|
|
@@ -53339,7 +53359,7 @@ function calculateWordWidth$1(word, avgCharWidth) {
|
|
|
53339
53359
|
}
|
|
53340
53360
|
|
|
53341
53361
|
/** Reduce width proportionally to simulate spacing / padding between ticks. */
|
|
53342
|
-
var widthWithSpacing
|
|
53362
|
+
var widthWithSpacing = function widthWithSpacing(width) {
|
|
53343
53363
|
var THIRTY_PERCENT = 0.3;
|
|
53344
53364
|
return width - width * THIRTY_PERCENT;
|
|
53345
53365
|
};
|
|
@@ -53353,7 +53373,7 @@ function howManyTicksFitInWidth$1(ticks, maxWidth, avgCharWidth) {
|
|
|
53353
53373
|
var tick = _step.value;
|
|
53354
53374
|
var word = (tick == null ? void 0 : tick.formattedValue) || '';
|
|
53355
53375
|
var wordWidth = calculateWordWidth$1(word, avgCharWidth);
|
|
53356
|
-
if (currentWidth + wordWidth <= widthWithSpacing
|
|
53376
|
+
if (currentWidth + wordWidth <= widthWithSpacing(maxWidth)) {
|
|
53357
53377
|
fittedTicks.push(tick);
|
|
53358
53378
|
currentWidth += wordWidth + avgCharWidth; // Add space between words
|
|
53359
53379
|
} 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
|
-
export declare function howManyTicksFitInWidth(ticks: Tick<string |
|
|
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
|
|
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-
|
|
4
|
+
"version": "0.15.0-dev-4815d6f8b96f6aef5270f29e0b642f190891df6b",
|
|
5
5
|
"source": "src/index.tsx",
|
|
6
6
|
"types": "./dist/dashboard/src/index.d.ts",
|
|
7
7
|
"module": "./dist/dashboard.esm.js",
|