td-plots 1.2.3 → 1.3.2
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 +2 -2
- package/dist/index.esm.js +20 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +19 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5860,17 +5860,23 @@ var Loading = function () {
|
|
|
5860
5860
|
var Plot$2 = React.lazy(function () { return import('react-plotly.js'); });
|
|
5861
5861
|
var HistogramPlot = function (props) {
|
|
5862
5862
|
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.
|
|
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;
|
|
5864
5864
|
// Ref for plot container
|
|
5865
5865
|
var containerRef = React.useRef(null);
|
|
5866
5866
|
// Track any selections made in this plot so we can style the selection box.
|
|
5867
|
-
var
|
|
5867
|
+
var _l = React.useState(null), selectedRange = _l[0], setSelectedRange = _l[1];
|
|
5868
|
+
// If all the data becomes selected, we should forget any old selections.
|
|
5869
|
+
React.useEffect(function () {
|
|
5870
|
+
if (unselectedData.length === 0) {
|
|
5871
|
+
setSelectedRange(null); // Clear selection box if all data is selected
|
|
5872
|
+
}
|
|
5873
|
+
}, [unselectedData]);
|
|
5868
5874
|
// Set the bins based on the entire data set.
|
|
5869
|
-
var nBins = Math.ceil(Math.sqrt(data.length + unselectedData.length));
|
|
5875
|
+
var nBins = (data.length + unselectedData.length) >= 10 ? Math.ceil(Math.sqrt(data.length + unselectedData.length)) : 0;
|
|
5870
5876
|
// Plotly determines "nice" bins which consequently means it internally decides the axis range. We need
|
|
5871
5877
|
// to access that information once the plot has been initialized so that we can prevent the
|
|
5872
5878
|
// axis range from changing during interaction. Dates use strings.
|
|
5873
|
-
var
|
|
5879
|
+
var _m = React.useState(undefined), fixedXAxisRange = _m[0], setFixedXAxisRange = _m[1];
|
|
5874
5880
|
// Once the plot is drawn, record the initial axis range so we can keep it fixed.
|
|
5875
5881
|
// figure should be Readonly<Plotly.Figure> but react-plotly.js doesn't expose that type, so we use any.
|
|
5876
5882
|
var handlePlotUpdate = function (figure, graphDiv) {
|
|
@@ -5883,11 +5889,7 @@ var HistogramPlot = function (props) {
|
|
|
5883
5889
|
if (range[0] === -1 && range[1] === 1) {
|
|
5884
5890
|
return;
|
|
5885
5891
|
}
|
|
5886
|
-
|
|
5887
|
-
? [new Date(range[0]), new Date(range[1])]
|
|
5888
|
-
: [range[0], range[1]];
|
|
5889
|
-
console.log('Captured range from onUpdate:', computedRange);
|
|
5890
|
-
setFixedXAxisRange(computedRange);
|
|
5892
|
+
setFixedXAxisRange(range);
|
|
5891
5893
|
}
|
|
5892
5894
|
}
|
|
5893
5895
|
};
|
|
@@ -6018,11 +6020,12 @@ var HistogramPlot = function (props) {
|
|
|
6018
6020
|
handleClickOrSelection(minValue, maxValue);
|
|
6019
6021
|
}
|
|
6020
6022
|
};
|
|
6021
|
-
console.log('fixed range', fixedXAxisRange);
|
|
6022
6023
|
// Create the selected range box
|
|
6023
6024
|
var selectedRangeBox = React.useMemo(function () {
|
|
6024
6025
|
if (!selectedRange)
|
|
6025
6026
|
return [];
|
|
6027
|
+
if (unselectedData.length === 0)
|
|
6028
|
+
return []; // Don't show the box if the entire dataset is selected.
|
|
6026
6029
|
// Create a multiply-like effect by using a semi-transparent dark overlay
|
|
6027
6030
|
var multiplyColor = 'rgba(29, 104, 185, 0.1)';
|
|
6028
6031
|
return [{
|
|
@@ -6039,7 +6042,7 @@ var HistogramPlot = function (props) {
|
|
|
6039
6042
|
},
|
|
6040
6043
|
layer: 'above' // Ensure the selection box is above the bars
|
|
6041
6044
|
}];
|
|
6042
|
-
}, [selectedRange]);
|
|
6045
|
+
}, [selectedRange, unselectedData]);
|
|
6043
6046
|
var unselectedTrace = {
|
|
6044
6047
|
x: unselectedData,
|
|
6045
6048
|
type: 'histogram',
|
|
@@ -6078,7 +6081,7 @@ var HistogramPlot = function (props) {
|
|
|
6078
6081
|
// Calculate the mean of the selected data using normalized data
|
|
6079
6082
|
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6080
6083
|
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6081
|
-
var meanLine =
|
|
6084
|
+
var meanLine = (showMeanLines && data.length > 0) ? [{
|
|
6082
6085
|
type: 'line',
|
|
6083
6086
|
x0: meanValue,
|
|
6084
6087
|
y0: 1 - meanLineRadius,
|
|
@@ -6093,7 +6096,7 @@ var HistogramPlot = function (props) {
|
|
|
6093
6096
|
// Draw mean line for all data
|
|
6094
6097
|
var allData = tslib.__spreadArray(tslib.__spreadArray([], data, true), unselectedData, true);
|
|
6095
6098
|
var allDataMeanValue = (_b = calculateMean(allData)) !== null && _b !== void 0 ? _b : 0;
|
|
6096
|
-
var allDataMeanLine = (
|
|
6099
|
+
var allDataMeanLine = (showMeanLines && unselectedData.length > 0 && data.length > 0) ? [{
|
|
6097
6100
|
type: 'line',
|
|
6098
6101
|
x0: allDataMeanValue,
|
|
6099
6102
|
y0: 1 - meanLineRadius,
|
|
@@ -6138,6 +6141,8 @@ var HistogramPlot = function (props) {
|
|
|
6138
6141
|
linewidth: 1,
|
|
6139
6142
|
fixedrange: true, // Disable zooming
|
|
6140
6143
|
ticklabelposition: 'outside',
|
|
6144
|
+
tickformat: isDateArray(data) ? dateTickFormat : undefined, // Format ticks for dates
|
|
6145
|
+
automargin: true, // Adjust margin if tick labels rotate
|
|
6141
6146
|
},
|
|
6142
6147
|
yaxis: {
|
|
6143
6148
|
title: {
|
|
@@ -6162,7 +6167,7 @@ var HistogramPlot = function (props) {
|
|
|
6162
6167
|
dragmode: 'select', // Enable drag to select
|
|
6163
6168
|
selectdirection: 'h', // User can select in horizontal direction only
|
|
6164
6169
|
shapes: tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], allDataMeanLine, true), meanLine, true), selectedRangeBox, true), // Add the mean line and selection box
|
|
6165
|
-
annotations: (
|
|
6170
|
+
annotations: (showMeanLines && meanLine && data.length > 0) ? [{
|
|
6166
6171
|
x: meanValue,
|
|
6167
6172
|
y: 1 + meanLineRadius + 0.04, // Position above the mean line. Value set with respect to the paper coordinates.
|
|
6168
6173
|
yref: 'paper',
|