td-plots 1.3.2 → 1.4.1
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/components/Histogram.d.ts +1 -0
- package/dist/components/Utils.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +64 -32
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +65 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ export type HistogramPlotProps = {
|
|
|
15
15
|
plotId?: string;
|
|
16
16
|
selectByBin?: boolean;
|
|
17
17
|
dateTickFormat?: string;
|
|
18
|
+
binSizeOverride?: number;
|
|
18
19
|
};
|
|
19
20
|
export declare const HistogramPlot: (props: HistogramPlotProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
21
|
export default HistogramPlot;
|
|
@@ -2,3 +2,5 @@ export declare const isNumberArray: (arr: unknown[]) => arr is number[];
|
|
|
2
2
|
export declare const isDateArray: (arr: unknown[]) => arr is Date[];
|
|
3
3
|
export declare function calculateMean(arr: number[] | Date[]): number | undefined;
|
|
4
4
|
export declare const formatDateMDY: (timestamp: number) => string;
|
|
5
|
+
export declare const roundToNextDay: (timestamp: number) => string;
|
|
6
|
+
export declare const roundToPrevDay: (timestamp: number) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export type { HistogramPlotProps } from './components/Histogram';
|
|
|
4
4
|
export { RadialHistogramPlot } from './components/RadialHistogram';
|
|
5
5
|
export type { RadialHistogramPlotProps } from './components/RadialHistogram';
|
|
6
6
|
export { default as TestPlot } from './components/TestPlot';
|
|
7
|
+
export { isDateArray, isNumberArray } from './components/Utils';
|
|
7
8
|
export type { PlotParams } from 'react-plotly.js';
|
package/dist/index.esm.js
CHANGED
|
@@ -57,6 +57,18 @@ function calculateMean(arr) {
|
|
|
57
57
|
return sum / arr.length;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// Utilities for rounding dates to the nearest day.
|
|
61
|
+
// Helpful for making nice bins
|
|
62
|
+
var roundToNextDay = function (timestamp) {
|
|
63
|
+
var date = new Date(timestamp);
|
|
64
|
+
date.setHours(23, 59, 59, 999); // End of day
|
|
65
|
+
return date.toISOString();
|
|
66
|
+
};
|
|
67
|
+
var roundToPrevDay = function (timestamp) {
|
|
68
|
+
var date = new Date(timestamp);
|
|
69
|
+
date.setHours(0, 0, 0, 0); // Start of day
|
|
70
|
+
return date.toISOString();
|
|
71
|
+
};
|
|
60
72
|
|
|
61
73
|
function getDefaultExportFromCjs (x) {
|
|
62
74
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -5840,7 +5852,7 @@ var Loading = function () {
|
|
|
5840
5852
|
var Plot$2 = lazy(function () { return import('react-plotly.js'); });
|
|
5841
5853
|
var HistogramPlot = function (props) {
|
|
5842
5854
|
var _a, _b;
|
|
5843
|
-
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _c = props.barColor, barColor = _c === void 0 ? 'rgb(72, 72, 74)' : _c, _d = props.unselectedBarColor, unselectedBarColor = _d === void 0 ? 'rgba(203, 195, 195, 0.88)' : _d, _e = props.selectorsColor, selectorsColor = _e === void 0 ? 'black' : _e, _f = props.showMeanLines, showMeanLines = _f === void 0 ? true : _f, containerStyleOverrides = props.containerStyleOverrides, _g = props.unselectedData, unselectedData = _g === void 0 ? [] : _g, _h = props.handleClickOrSelection, handleClickOrSelection = _h === void 0 ? function () { } : _h, _j = props.onDeselect, onDeselect = _j === void 0 ? function () { } : _j, plotId = props.plotId, _k = props.selectByBin, selectByBin = _k === void 0 ? false : _k, dateTickFormat = props.dateTickFormat;
|
|
5855
|
+
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _c = props.barColor, barColor = _c === void 0 ? 'rgb(72, 72, 74)' : _c, _d = props.unselectedBarColor, unselectedBarColor = _d === void 0 ? 'rgba(203, 195, 195, 0.88)' : _d, _e = props.selectorsColor, selectorsColor = _e === void 0 ? 'black' : _e, _f = props.showMeanLines, showMeanLines = _f === void 0 ? true : _f, containerStyleOverrides = props.containerStyleOverrides, _g = props.unselectedData, unselectedData = _g === void 0 ? [] : _g, _h = props.handleClickOrSelection, handleClickOrSelection = _h === void 0 ? function () { } : _h, _j = props.onDeselect, onDeselect = _j === void 0 ? function () { } : _j, plotId = props.plotId, _k = props.selectByBin, selectByBin = _k === void 0 ? false : _k, dateTickFormat = props.dateTickFormat, binSizeOverride = props.binSizeOverride;
|
|
5844
5856
|
// Ref for plot container
|
|
5845
5857
|
var containerRef = useRef(null);
|
|
5846
5858
|
// Track any selections made in this plot so we can style the selection box.
|
|
@@ -6023,10 +6035,59 @@ var HistogramPlot = function (props) {
|
|
|
6023
6035
|
layer: 'above' // Ensure the selection box is above the bars
|
|
6024
6036
|
}];
|
|
6025
6037
|
}, [selectedRange, unselectedData]);
|
|
6038
|
+
// Calculate the mean of the selected data using normalized data
|
|
6039
|
+
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6040
|
+
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6041
|
+
var meanLine = (showMeanLines && data.length > 0) ? [{
|
|
6042
|
+
type: 'line',
|
|
6043
|
+
x0: meanValue,
|
|
6044
|
+
y0: 1 - meanLineRadius,
|
|
6045
|
+
x1: meanValue,
|
|
6046
|
+
yref: 'paper',
|
|
6047
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6048
|
+
line: {
|
|
6049
|
+
color: barColor,
|
|
6050
|
+
width: 1.5,
|
|
6051
|
+
}
|
|
6052
|
+
}] : [];
|
|
6053
|
+
// Draw mean line for all data
|
|
6054
|
+
var allData = __spreadArray(__spreadArray([], data, true), unselectedData, true);
|
|
6055
|
+
var allDataMeanValue = (_b = calculateMean(allData)) !== null && _b !== void 0 ? _b : 0;
|
|
6056
|
+
var allDataMeanLine = (showMeanLines && unselectedData.length > 0 && data.length > 0) ? [{
|
|
6057
|
+
type: 'line',
|
|
6058
|
+
x0: allDataMeanValue,
|
|
6059
|
+
y0: 1 - meanLineRadius,
|
|
6060
|
+
x1: allDataMeanValue,
|
|
6061
|
+
yref: 'paper',
|
|
6062
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6063
|
+
line: {
|
|
6064
|
+
color: unselectedBarColor,
|
|
6065
|
+
width: 1.5,
|
|
6066
|
+
}
|
|
6067
|
+
}] : [];
|
|
6068
|
+
// If binSizeOverride is provided, use it to set the bin size and range explicitly.
|
|
6069
|
+
// Plotly does a better job of setting bins and ending them at nice numbers, so only use
|
|
6070
|
+
// this prop when necessary.
|
|
6071
|
+
var xBins = binSizeOverride
|
|
6072
|
+
? (isDateArray(allData)
|
|
6073
|
+
? {
|
|
6074
|
+
start: roundToPrevDay(Math.min.apply(Math, allData.map(function (d) { return d.getTime(); }))), // Find a nice round number as a starting point.
|
|
6075
|
+
end: roundToNextDay(Math.max.apply(Math, allData.map(function (d) { return d.getTime(); }))),
|
|
6076
|
+
size: binSizeOverride // bin size in milliseconds
|
|
6077
|
+
}
|
|
6078
|
+
: isNumberArray(allData)
|
|
6079
|
+
? {
|
|
6080
|
+
start: Math.floor(Math.min.apply(Math, allData)),
|
|
6081
|
+
end: Math.ceil(Math.max.apply(Math, allData)),
|
|
6082
|
+
size: binSizeOverride
|
|
6083
|
+
}
|
|
6084
|
+
: undefined)
|
|
6085
|
+
: undefined;
|
|
6026
6086
|
var unselectedTrace = {
|
|
6027
6087
|
x: unselectedData,
|
|
6028
6088
|
type: 'histogram',
|
|
6029
6089
|
autobinx: false,
|
|
6090
|
+
xbins: xBins,
|
|
6030
6091
|
// nbinsx is valid but not included in the type definition
|
|
6031
6092
|
//@ts-ignore
|
|
6032
6093
|
nbinsx: nBins, // Maximum number of bins. Plotly may adjust to make bins "nicer".
|
|
@@ -6044,6 +6105,7 @@ var HistogramPlot = function (props) {
|
|
|
6044
6105
|
x: data,
|
|
6045
6106
|
type: 'histogram',
|
|
6046
6107
|
autobinx: false,
|
|
6108
|
+
xbins: xBins,
|
|
6047
6109
|
// nbinsx is valid but not included in the type definition
|
|
6048
6110
|
//@ts-ignore
|
|
6049
6111
|
nbinsx: nBins, // Maximum number of bins. Plotly may adjust to make bins "nicer".
|
|
@@ -6058,36 +6120,6 @@ var HistogramPlot = function (props) {
|
|
|
6058
6120
|
},
|
|
6059
6121
|
unselectedTrace,
|
|
6060
6122
|
];
|
|
6061
|
-
// Calculate the mean of the selected data using normalized data
|
|
6062
|
-
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6063
|
-
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6064
|
-
var meanLine = (showMeanLines && data.length > 0) ? [{
|
|
6065
|
-
type: 'line',
|
|
6066
|
-
x0: meanValue,
|
|
6067
|
-
y0: 1 - meanLineRadius,
|
|
6068
|
-
x1: meanValue,
|
|
6069
|
-
yref: 'paper',
|
|
6070
|
-
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6071
|
-
line: {
|
|
6072
|
-
color: barColor,
|
|
6073
|
-
width: 1.5,
|
|
6074
|
-
}
|
|
6075
|
-
}] : [];
|
|
6076
|
-
// Draw mean line for all data
|
|
6077
|
-
var allData = __spreadArray(__spreadArray([], data, true), unselectedData, true);
|
|
6078
|
-
var allDataMeanValue = (_b = calculateMean(allData)) !== null && _b !== void 0 ? _b : 0;
|
|
6079
|
-
var allDataMeanLine = (showMeanLines && unselectedData.length > 0 && data.length > 0) ? [{
|
|
6080
|
-
type: 'line',
|
|
6081
|
-
x0: allDataMeanValue,
|
|
6082
|
-
y0: 1 - meanLineRadius,
|
|
6083
|
-
x1: allDataMeanValue,
|
|
6084
|
-
yref: 'paper',
|
|
6085
|
-
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6086
|
-
line: {
|
|
6087
|
-
color: unselectedBarColor,
|
|
6088
|
-
width: 1.5,
|
|
6089
|
-
}
|
|
6090
|
-
}] : [];
|
|
6091
6123
|
var layout = {
|
|
6092
6124
|
title: {
|
|
6093
6125
|
text: title,
|
|
@@ -6308,5 +6340,5 @@ var TestPlot = function (props) {
|
|
|
6308
6340
|
return jsx(Plot, { data: data, layout: layout });
|
|
6309
6341
|
};
|
|
6310
6342
|
|
|
6311
|
-
export { HistogramPlot, RadialHistogramPlot, TestPlot };
|
|
6343
|
+
export { HistogramPlot, RadialHistogramPlot, TestPlot, isDateArray, isNumberArray };
|
|
6312
6344
|
//# sourceMappingURL=index.esm.js.map
|