td-plots 1.3.2 → 1.4.0
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
package/dist/index.js
CHANGED
|
@@ -77,6 +77,18 @@ function calculateMean(arr) {
|
|
|
77
77
|
return sum / arr.length;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
// Utilities for rounding dates to the nearest day.
|
|
81
|
+
// Helpful for making nice bins
|
|
82
|
+
var roundToNextDay = function (timestamp) {
|
|
83
|
+
var date = new Date(timestamp);
|
|
84
|
+
date.setHours(23, 59, 59, 999); // End of day
|
|
85
|
+
return date.toISOString();
|
|
86
|
+
};
|
|
87
|
+
var roundToPrevDay = function (timestamp) {
|
|
88
|
+
var date = new Date(timestamp);
|
|
89
|
+
date.setHours(0, 0, 0, 0); // Start of day
|
|
90
|
+
return date.toISOString();
|
|
91
|
+
};
|
|
80
92
|
|
|
81
93
|
function getDefaultExportFromCjs (x) {
|
|
82
94
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -5860,7 +5872,7 @@ var Loading = function () {
|
|
|
5860
5872
|
var Plot$2 = React.lazy(function () { return import('react-plotly.js'); });
|
|
5861
5873
|
var HistogramPlot = function (props) {
|
|
5862
5874
|
var _a, _b;
|
|
5863
|
-
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;
|
|
5875
|
+
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;
|
|
5864
5876
|
// Ref for plot container
|
|
5865
5877
|
var containerRef = React.useRef(null);
|
|
5866
5878
|
// Track any selections made in this plot so we can style the selection box.
|
|
@@ -6043,10 +6055,59 @@ var HistogramPlot = function (props) {
|
|
|
6043
6055
|
layer: 'above' // Ensure the selection box is above the bars
|
|
6044
6056
|
}];
|
|
6045
6057
|
}, [selectedRange, unselectedData]);
|
|
6058
|
+
// Calculate the mean of the selected data using normalized data
|
|
6059
|
+
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6060
|
+
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6061
|
+
var meanLine = (showMeanLines && data.length > 0) ? [{
|
|
6062
|
+
type: 'line',
|
|
6063
|
+
x0: meanValue,
|
|
6064
|
+
y0: 1 - meanLineRadius,
|
|
6065
|
+
x1: meanValue,
|
|
6066
|
+
yref: 'paper',
|
|
6067
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6068
|
+
line: {
|
|
6069
|
+
color: barColor,
|
|
6070
|
+
width: 1.5,
|
|
6071
|
+
}
|
|
6072
|
+
}] : [];
|
|
6073
|
+
// Draw mean line for all data
|
|
6074
|
+
var allData = tslib.__spreadArray(tslib.__spreadArray([], data, true), unselectedData, true);
|
|
6075
|
+
var allDataMeanValue = (_b = calculateMean(allData)) !== null && _b !== void 0 ? _b : 0;
|
|
6076
|
+
var allDataMeanLine = (showMeanLines && unselectedData.length > 0 && data.length > 0) ? [{
|
|
6077
|
+
type: 'line',
|
|
6078
|
+
x0: allDataMeanValue,
|
|
6079
|
+
y0: 1 - meanLineRadius,
|
|
6080
|
+
x1: allDataMeanValue,
|
|
6081
|
+
yref: 'paper',
|
|
6082
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6083
|
+
line: {
|
|
6084
|
+
color: unselectedBarColor,
|
|
6085
|
+
width: 1.5,
|
|
6086
|
+
}
|
|
6087
|
+
}] : [];
|
|
6088
|
+
// If binSizeOverride is provided, use it to set the bin size and range explicitly.
|
|
6089
|
+
// Plotly does a better job of setting bins and ending them at nice numbers, so only use
|
|
6090
|
+
// this prop when necessary.
|
|
6091
|
+
var xBins = binSizeOverride
|
|
6092
|
+
? (isDateArray(allData)
|
|
6093
|
+
? {
|
|
6094
|
+
start: roundToPrevDay(Math.min.apply(Math, allData.map(function (d) { return d.getTime(); }))), // Find a nice round number as a starting point.
|
|
6095
|
+
end: roundToNextDay(Math.max.apply(Math, allData.map(function (d) { return d.getTime(); }))),
|
|
6096
|
+
size: binSizeOverride * 86400000 // bin size in milliseconds
|
|
6097
|
+
}
|
|
6098
|
+
: isNumberArray(allData)
|
|
6099
|
+
? {
|
|
6100
|
+
start: Math.floor(Math.min.apply(Math, allData)),
|
|
6101
|
+
end: Math.ceil(Math.max.apply(Math, allData)),
|
|
6102
|
+
size: binSizeOverride
|
|
6103
|
+
}
|
|
6104
|
+
: undefined)
|
|
6105
|
+
: undefined;
|
|
6046
6106
|
var unselectedTrace = {
|
|
6047
6107
|
x: unselectedData,
|
|
6048
6108
|
type: 'histogram',
|
|
6049
6109
|
autobinx: false,
|
|
6110
|
+
xbins: xBins,
|
|
6050
6111
|
// nbinsx is valid but not included in the type definition
|
|
6051
6112
|
//@ts-ignore
|
|
6052
6113
|
nbinsx: nBins, // Maximum number of bins. Plotly may adjust to make bins "nicer".
|
|
@@ -6064,6 +6125,7 @@ var HistogramPlot = function (props) {
|
|
|
6064
6125
|
x: data,
|
|
6065
6126
|
type: 'histogram',
|
|
6066
6127
|
autobinx: false,
|
|
6128
|
+
xbins: xBins,
|
|
6067
6129
|
// nbinsx is valid but not included in the type definition
|
|
6068
6130
|
//@ts-ignore
|
|
6069
6131
|
nbinsx: nBins, // Maximum number of bins. Plotly may adjust to make bins "nicer".
|
|
@@ -6078,36 +6140,6 @@ var HistogramPlot = function (props) {
|
|
|
6078
6140
|
},
|
|
6079
6141
|
unselectedTrace,
|
|
6080
6142
|
];
|
|
6081
|
-
// Calculate the mean of the selected data using normalized data
|
|
6082
|
-
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6083
|
-
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6084
|
-
var meanLine = (showMeanLines && data.length > 0) ? [{
|
|
6085
|
-
type: 'line',
|
|
6086
|
-
x0: meanValue,
|
|
6087
|
-
y0: 1 - meanLineRadius,
|
|
6088
|
-
x1: meanValue,
|
|
6089
|
-
yref: 'paper',
|
|
6090
|
-
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6091
|
-
line: {
|
|
6092
|
-
color: barColor,
|
|
6093
|
-
width: 1.5,
|
|
6094
|
-
}
|
|
6095
|
-
}] : [];
|
|
6096
|
-
// Draw mean line for all data
|
|
6097
|
-
var allData = tslib.__spreadArray(tslib.__spreadArray([], data, true), unselectedData, true);
|
|
6098
|
-
var allDataMeanValue = (_b = calculateMean(allData)) !== null && _b !== void 0 ? _b : 0;
|
|
6099
|
-
var allDataMeanLine = (showMeanLines && unselectedData.length > 0 && data.length > 0) ? [{
|
|
6100
|
-
type: 'line',
|
|
6101
|
-
x0: allDataMeanValue,
|
|
6102
|
-
y0: 1 - meanLineRadius,
|
|
6103
|
-
x1: allDataMeanValue,
|
|
6104
|
-
yref: 'paper',
|
|
6105
|
-
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6106
|
-
line: {
|
|
6107
|
-
color: unselectedBarColor,
|
|
6108
|
-
width: 1.5,
|
|
6109
|
-
}
|
|
6110
|
-
}] : [];
|
|
6111
6143
|
var layout = {
|
|
6112
6144
|
title: {
|
|
6113
6145
|
text: title,
|
|
@@ -6331,4 +6363,6 @@ var TestPlot = function (props) {
|
|
|
6331
6363
|
exports.HistogramPlot = HistogramPlot;
|
|
6332
6364
|
exports.RadialHistogramPlot = RadialHistogramPlot;
|
|
6333
6365
|
exports.TestPlot = TestPlot;
|
|
6366
|
+
exports.isDateArray = isDateArray;
|
|
6367
|
+
exports.isNumberArray = isNumberArray;
|
|
6334
6368
|
//# sourceMappingURL=index.js.map
|