td-plots 1.5.3 → 1.5.4
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 +4 -3
- package/dist/index.esm.js +228 -170
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +228 -170
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6072,11 +6072,17 @@ var Loading = function () {
|
|
|
6072
6072
|
var Plot$2 = React.lazy(function () { return import('react-plotly.js'); });
|
|
6073
6073
|
var HistogramPlot = function (props) {
|
|
6074
6074
|
var _a, _b, _c, _d;
|
|
6075
|
-
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _e = props.barColor, barColor = _e === void 0 ?
|
|
6075
|
+
var data = props.data, title = props.title, xAxisTitle = props.xAxisTitle, _e = props.barColor, barColor = _e === void 0 ? "rgb(72, 72, 74)" : _e, _f = props.unselectedBarColor, unselectedBarColor = _f === void 0 ? "rgba(203, 195, 195, 0.88)" : _f, _g = props.selectorsColor, selectorsColor = _g === void 0 ? "black" : _g, containerStyleOverrides = props.containerStyleOverrides, _h = props.unselectedData, unselectedData = _h === void 0 ? [] : _h, _j = props.handleClickOrSelection, handleClickOrSelection = _j === void 0 ? function () { } : _j, _k = props.onDeselect, onDeselect = _k === void 0 ? function () { } : _k, plotId = props.plotId, _l = props.selectByBin, selectByBin = _l === void 0 ? false : _l, dateTickFormat = props.dateTickFormat, binSizeOverride = props.binSizeOverride, _m = props.statsAnnotations, statsAnnotations = _m === void 0 ? ["mean"] : _m, _o = props.emptySelectedRange, emptySelectedRange = _o === void 0 ? false : _o;
|
|
6076
6076
|
// Ref for plot container
|
|
6077
6077
|
var containerRef = React.useRef(null);
|
|
6078
6078
|
// Track any selections made in this plot so we can style the selection box.
|
|
6079
|
-
var
|
|
6079
|
+
var _p = React.useState(null), selectedRange = _p[0], setSelectedRange = _p[1];
|
|
6080
|
+
// If the parent component wants to clear the selection, reset selectedRange to null.
|
|
6081
|
+
React.useEffect(function () {
|
|
6082
|
+
if (emptySelectedRange) {
|
|
6083
|
+
setSelectedRange(null);
|
|
6084
|
+
}
|
|
6085
|
+
}, [emptySelectedRange]);
|
|
6080
6086
|
// Combine all data into one for later calculations
|
|
6081
6087
|
var allData = tslib.__spreadArray(tslib.__spreadArray([], data, true), unselectedData, true);
|
|
6082
6088
|
// If all the data becomes selected, we should forget any old selections.
|
|
@@ -6086,13 +6092,15 @@ var HistogramPlot = function (props) {
|
|
|
6086
6092
|
}
|
|
6087
6093
|
}, [unselectedData]);
|
|
6088
6094
|
// Set the bins based on the entire data set.
|
|
6089
|
-
var nBins =
|
|
6095
|
+
var nBins = data.length + unselectedData.length >= 10
|
|
6096
|
+
? Math.ceil(Math.sqrt(data.length + unselectedData.length))
|
|
6097
|
+
: 0;
|
|
6090
6098
|
// Plotly determines "nice" bins which consequently means it internally decides the axis range. We need
|
|
6091
6099
|
// to access that information once the plot has been initialized so that we can prevent the
|
|
6092
6100
|
// axis range from changing during interaction. Dates use strings.
|
|
6093
|
-
var
|
|
6101
|
+
var _q = React.useState(undefined), fixedXAxisRange = _q[0], setFixedXAxisRange = _q[1];
|
|
6094
6102
|
// track xbins too
|
|
6095
|
-
var
|
|
6103
|
+
var _r = React.useState(undefined), binSize = _r[0], setBinSize = _r[1];
|
|
6096
6104
|
// Once the plot is drawn, record the initial axis range so we can keep it fixed.
|
|
6097
6105
|
// figure should be Readonly<Plotly.Figure> but react-plotly.js doesn't expose that type, so we use any.
|
|
6098
6106
|
var handlePlotUpdate = function (figure, graphDiv) {
|
|
@@ -6110,7 +6118,11 @@ var HistogramPlot = function (props) {
|
|
|
6110
6118
|
}
|
|
6111
6119
|
if (!binSize) {
|
|
6112
6120
|
// Get the bin size from the first trace. Both traces should have the same bin size.
|
|
6113
|
-
if (figure &&
|
|
6121
|
+
if (figure &&
|
|
6122
|
+
figure.data &&
|
|
6123
|
+
figure.data.length > 0 &&
|
|
6124
|
+
figure.data[0].xbins &&
|
|
6125
|
+
figure.data[0].xbins.size) {
|
|
6114
6126
|
setBinSize(figure.data[0].xbins.size);
|
|
6115
6127
|
}
|
|
6116
6128
|
}
|
|
@@ -6120,22 +6132,22 @@ var HistogramPlot = function (props) {
|
|
|
6120
6132
|
// Add keyboard event listeners to track shift key
|
|
6121
6133
|
React.useEffect(function () {
|
|
6122
6134
|
var handleKeyDown = function (e) {
|
|
6123
|
-
if (e.key ===
|
|
6135
|
+
if (e.key === "Shift") {
|
|
6124
6136
|
isShiftPressed.current = true;
|
|
6125
6137
|
}
|
|
6126
6138
|
};
|
|
6127
6139
|
var handleKeyUp = function (e) {
|
|
6128
|
-
if (e.key ===
|
|
6140
|
+
if (e.key === "Shift") {
|
|
6129
6141
|
isShiftPressed.current = false;
|
|
6130
6142
|
}
|
|
6131
6143
|
};
|
|
6132
6144
|
// Add event listeners to document to catch shift key globally
|
|
6133
|
-
document.addEventListener(
|
|
6134
|
-
document.addEventListener(
|
|
6145
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
6146
|
+
document.addEventListener("keyup", handleKeyUp);
|
|
6135
6147
|
// Cleanup
|
|
6136
6148
|
return function () {
|
|
6137
|
-
document.removeEventListener(
|
|
6138
|
-
document.removeEventListener(
|
|
6149
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
6150
|
+
document.removeEventListener("keyup", handleKeyUp);
|
|
6139
6151
|
};
|
|
6140
6152
|
}, []);
|
|
6141
6153
|
// Create handler for click event that can use event data to update the plot if desired.
|
|
@@ -6145,11 +6157,12 @@ var HistogramPlot = function (props) {
|
|
|
6145
6157
|
return;
|
|
6146
6158
|
}
|
|
6147
6159
|
// Use the bin number to determine which bar was clicked and determine the range of the clicked bar.
|
|
6148
|
-
if ("binNumber" in event.points[0] &&
|
|
6160
|
+
if ("binNumber" in event.points[0] &&
|
|
6161
|
+
typeof event.points[0].binNumber === "number") {
|
|
6149
6162
|
// Get the index of the clicked bar with respect to the trace. So if
|
|
6150
6163
|
// my trace has only one bar (0, 1] but another trace has bars (-1, 0], (0, 1], (1, 2], etc.
|
|
6151
6164
|
// then when I click on (0, 1] in my trace the index will be 0, even thought it would be
|
|
6152
|
-
// the second bar in the other trace. Because of this, we can't use data.xbins to
|
|
6165
|
+
// the second bar in the other trace. Because of this, we can't use data.xbins to
|
|
6153
6166
|
// find the clicked bar, because its start and end values are based on all traces, not just the clicked trace.
|
|
6154
6167
|
var clickedBinIndex = event.points[0].binNumber;
|
|
6155
6168
|
// Handle dates and numbers separately
|
|
@@ -6159,26 +6172,35 @@ var HistogramPlot = function (props) {
|
|
|
6159
6172
|
var globalFirstBinStart = void 0;
|
|
6160
6173
|
if (isDateArray(data)) {
|
|
6161
6174
|
// Date bins are represented as strings (sometimes). We'll need to convert whatever plotly gives us to timestamps.
|
|
6162
|
-
globalFirstBinStart = fixedXAxisRange
|
|
6163
|
-
|
|
6175
|
+
globalFirstBinStart = fixedXAxisRange
|
|
6176
|
+
? new Date(fixedXAxisRange[0]).getTime()
|
|
6177
|
+
: new Date(event.points[0].data.xbins.start).getTime();
|
|
6178
|
+
minTraceValue =
|
|
6179
|
+
event.points[0].curveNumber === 0
|
|
6180
|
+
? Math.min.apply(Math, data.map(function (d) { return d.getTime(); })) : Math.min.apply(Math, unselectedData.map(function (d) { return d.getTime(); }));
|
|
6164
6181
|
}
|
|
6165
6182
|
else {
|
|
6166
6183
|
// Get the min value of the trace and the beginning of the first bin (globally)
|
|
6167
|
-
minTraceValue =
|
|
6168
|
-
|
|
6184
|
+
minTraceValue =
|
|
6185
|
+
event.points[0].curveNumber === 0
|
|
6186
|
+
? Math.min.apply(Math, data) : Math.min.apply(Math, unselectedData);
|
|
6187
|
+
globalFirstBinStart = fixedXAxisRange
|
|
6188
|
+
? fixedXAxisRange[0]
|
|
6189
|
+
: event.points[0].data.xbins.start;
|
|
6169
6190
|
}
|
|
6170
6191
|
// Finally, we need to calculate the min and max values of the clicked bin.
|
|
6171
6192
|
// If the bin size is a month or more, plotly records it in their "mstring" format like "M3" for 3 months.
|
|
6172
6193
|
// We then must convert it back to milliseconds. Otherwise, it's always ms.
|
|
6173
6194
|
var size = binSize !== null && binSize !== void 0 ? binSize : (_d = (_c = (_b = (_a = event.points) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.xbins) === null || _d === void 0 ? void 0 : _d.size;
|
|
6174
|
-
var convertedBinSize = typeof size ===
|
|
6195
|
+
var convertedBinSize = typeof size === "string"
|
|
6175
6196
|
? plotlyMToMilliseconds(size)
|
|
6176
6197
|
: size;
|
|
6177
6198
|
// This minTraceValue is in the 0th bin of this trace. Find the index of this bin in the whole plot.
|
|
6178
|
-
var clickedBinGlobalIndex = clickedBinIndex +
|
|
6199
|
+
var clickedBinGlobalIndex = clickedBinIndex +
|
|
6200
|
+
Math.floor((minTraceValue - globalFirstBinStart) / convertedBinSize);
|
|
6179
6201
|
var _e = [
|
|
6180
6202
|
globalFirstBinStart + clickedBinGlobalIndex * convertedBinSize,
|
|
6181
|
-
globalFirstBinStart + (clickedBinGlobalIndex + 1) * convertedBinSize
|
|
6203
|
+
globalFirstBinStart + (clickedBinGlobalIndex + 1) * convertedBinSize,
|
|
6182
6204
|
], minBinValue = _e[0], maxBinValue = _e[1];
|
|
6183
6205
|
if (isDateArray(data)) {
|
|
6184
6206
|
var minDate = new Date(minBinValue);
|
|
@@ -6211,7 +6233,8 @@ var HistogramPlot = function (props) {
|
|
|
6211
6233
|
}
|
|
6212
6234
|
var minValue;
|
|
6213
6235
|
var maxValue;
|
|
6214
|
-
if (typeof event.range.x[0] ===
|
|
6236
|
+
if (typeof event.range.x[0] === "string" &&
|
|
6237
|
+
typeof event.range.x[1] === "string") {
|
|
6215
6238
|
// Then we are must be dealing with dates
|
|
6216
6239
|
if (selectByBin) {
|
|
6217
6240
|
// Set selected range to include the whole bin if at least half the bin is within the explicit range
|
|
@@ -6222,7 +6245,7 @@ var HistogramPlot = function (props) {
|
|
|
6222
6245
|
var lastBinMidPoint = new Date(event.points[event.points.length - 1].x).getTime();
|
|
6223
6246
|
// If the bin size is a month or more, plotly records it in their "mstring" format like "M3" for 3 months.
|
|
6224
6247
|
// We then must convert it back to milliseconds. Otherwise, it's always ms.
|
|
6225
|
-
var convertedBinSize = typeof binSize ===
|
|
6248
|
+
var convertedBinSize = typeof binSize === "string"
|
|
6226
6249
|
? plotlyMToMilliseconds(binSize)
|
|
6227
6250
|
: binSize;
|
|
6228
6251
|
minValue = new Date(firstBinMidPoint - convertedBinSize / 2);
|
|
@@ -6269,7 +6292,7 @@ var HistogramPlot = function (props) {
|
|
|
6269
6292
|
}
|
|
6270
6293
|
if (minValue !== undefined && maxValue !== undefined) {
|
|
6271
6294
|
// Update selected range. Have to be strict about types.
|
|
6272
|
-
if (typeof minValue ===
|
|
6295
|
+
if (typeof minValue === "number" && typeof maxValue === "number") {
|
|
6273
6296
|
var newMinMax = [minValue, maxValue];
|
|
6274
6297
|
if (isShiftPressed.current && selectedRange) {
|
|
6275
6298
|
setSelectedRange(tslib.__spreadArray(tslib.__spreadArray([], selectedRange, true), [newMinMax], false));
|
|
@@ -6297,128 +6320,146 @@ var HistogramPlot = function (props) {
|
|
|
6297
6320
|
if (unselectedData.length === 0)
|
|
6298
6321
|
return []; // Don't show the box if the entire dataset is selected.
|
|
6299
6322
|
// Create a multiply-like effect by using a semi-transparent dark overlay
|
|
6300
|
-
var multiplyColor =
|
|
6323
|
+
var multiplyColor = "rgba(29, 104, 185, 0.1)";
|
|
6301
6324
|
return selectedRange.map(function (maxMin) { return ({
|
|
6302
|
-
type:
|
|
6325
|
+
type: "rect",
|
|
6303
6326
|
x0: isDateArray(maxMin) ? maxMin[0].getTime() : maxMin[0],
|
|
6304
6327
|
x1: isDateArray(maxMin) ? maxMin[1].getTime() : maxMin[1],
|
|
6305
6328
|
y0: 0,
|
|
6306
6329
|
y1: 1,
|
|
6307
|
-
yref:
|
|
6330
|
+
yref: "paper",
|
|
6308
6331
|
fillcolor: multiplyColor,
|
|
6309
6332
|
line: {
|
|
6310
6333
|
width: 1,
|
|
6311
|
-
color: multiplyColor
|
|
6334
|
+
color: multiplyColor,
|
|
6312
6335
|
},
|
|
6313
|
-
layer:
|
|
6336
|
+
layer: "above", // Ensure the selection box is above the bars
|
|
6314
6337
|
}); });
|
|
6315
6338
|
}, [selectedRange, unselectedData]);
|
|
6316
6339
|
// Calculate the mean of the selected data using normalized data
|
|
6317
6340
|
var meanValue = (_a = calculateMean(data)) !== null && _a !== void 0 ? _a : 0; // Default to 0 if no data
|
|
6318
6341
|
var stdevValue = (_b = calculateStandardDeviation(data)) !== null && _b !== void 0 ? _b : 0;
|
|
6319
6342
|
var meanLineRadius = 0.01; // distance from the top of the y axis to the top/bottom end of the mean line
|
|
6320
|
-
var meanLine =
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6343
|
+
var meanLine = statsAnnotations.includes("mean") && data.length > 0
|
|
6344
|
+
? [
|
|
6345
|
+
{
|
|
6346
|
+
type: "line",
|
|
6347
|
+
x0: meanValue,
|
|
6348
|
+
y0: 1 - meanLineRadius,
|
|
6349
|
+
x1: meanValue,
|
|
6350
|
+
yref: "paper",
|
|
6351
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6352
|
+
line: {
|
|
6353
|
+
color: barColor,
|
|
6354
|
+
width: 1.5,
|
|
6355
|
+
},
|
|
6356
|
+
},
|
|
6357
|
+
]
|
|
6358
|
+
: [];
|
|
6332
6359
|
// Draw mean line for all data
|
|
6333
6360
|
var allDataMeanValue = (_c = calculateMean(allData)) !== null && _c !== void 0 ? _c : 0;
|
|
6334
|
-
var allDataMeanLine =
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6361
|
+
var allDataMeanLine = statsAnnotations.includes("mean") &&
|
|
6362
|
+
unselectedData.length > 0 &&
|
|
6363
|
+
data.length > 0
|
|
6364
|
+
? [
|
|
6365
|
+
{
|
|
6366
|
+
type: "line",
|
|
6367
|
+
x0: allDataMeanValue,
|
|
6368
|
+
y0: 1 - meanLineRadius,
|
|
6369
|
+
x1: allDataMeanValue,
|
|
6370
|
+
yref: "paper",
|
|
6371
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6372
|
+
line: {
|
|
6373
|
+
color: unselectedBarColor,
|
|
6374
|
+
width: 1.5,
|
|
6375
|
+
},
|
|
6376
|
+
},
|
|
6377
|
+
]
|
|
6378
|
+
: [];
|
|
6379
|
+
var stdevLines = statsAnnotations.includes("stdev") && data.length > 0
|
|
6380
|
+
? [
|
|
6381
|
+
{
|
|
6382
|
+
type: "line",
|
|
6383
|
+
x0: meanValue - stdevValue,
|
|
6384
|
+
y0: 1 - meanLineRadius,
|
|
6385
|
+
x1: meanValue - stdevValue,
|
|
6386
|
+
yref: "paper",
|
|
6387
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6388
|
+
line: {
|
|
6389
|
+
color: barColor,
|
|
6390
|
+
width: 1.5,
|
|
6391
|
+
dash: "dot",
|
|
6392
|
+
},
|
|
6393
|
+
},
|
|
6394
|
+
{
|
|
6395
|
+
type: "line",
|
|
6396
|
+
x0: meanValue + stdevValue,
|
|
6397
|
+
y0: 1 - meanLineRadius,
|
|
6398
|
+
x1: meanValue + stdevValue,
|
|
6399
|
+
yref: "paper",
|
|
6400
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6401
|
+
line: {
|
|
6402
|
+
color: barColor,
|
|
6403
|
+
width: 1.5,
|
|
6404
|
+
dash: "dot",
|
|
6405
|
+
},
|
|
6406
|
+
},
|
|
6407
|
+
]
|
|
6372
6408
|
: [];
|
|
6373
6409
|
var allDataStdevValue = (_d = calculateStandardDeviation(allData)) !== null && _d !== void 0 ? _d : 0;
|
|
6374
|
-
var allDataStdevLines =
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6410
|
+
var allDataStdevLines = statsAnnotations.includes("stdev") &&
|
|
6411
|
+
unselectedData.length > 0 &&
|
|
6412
|
+
data.length > 0
|
|
6413
|
+
? [
|
|
6414
|
+
{
|
|
6415
|
+
type: "line",
|
|
6416
|
+
x0: allDataMeanValue - allDataStdevValue,
|
|
6417
|
+
y0: 1 - meanLineRadius,
|
|
6418
|
+
x1: allDataMeanValue - allDataStdevValue,
|
|
6419
|
+
yref: "paper",
|
|
6420
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6421
|
+
line: {
|
|
6422
|
+
color: unselectedBarColor,
|
|
6423
|
+
width: 1.5,
|
|
6424
|
+
dash: "dot",
|
|
6425
|
+
},
|
|
6426
|
+
},
|
|
6427
|
+
{
|
|
6428
|
+
type: "line",
|
|
6429
|
+
x0: allDataMeanValue + allDataStdevValue,
|
|
6430
|
+
y0: 1 - meanLineRadius,
|
|
6431
|
+
x1: allDataMeanValue + allDataStdevValue,
|
|
6432
|
+
yref: "paper",
|
|
6433
|
+
y1: 1 + meanLineRadius + 0.04, // Add extra length above to make the line look centered on the y-axis top.
|
|
6434
|
+
line: {
|
|
6435
|
+
color: unselectedBarColor,
|
|
6436
|
+
width: 1.5,
|
|
6437
|
+
dash: "dot",
|
|
6438
|
+
},
|
|
6439
|
+
},
|
|
6440
|
+
]
|
|
6400
6441
|
: [];
|
|
6401
|
-
// If binSizeOverride is provided, use it to set the bin size and range explicitly.
|
|
6442
|
+
// If binSizeOverride is provided, use it to set the bin size and range explicitly.
|
|
6402
6443
|
// Plotly does a better job of setting bins and ending them at nice numbers, so only use
|
|
6403
6444
|
// this prop when necessary.
|
|
6404
|
-
var xBins =
|
|
6405
|
-
?
|
|
6445
|
+
var xBins = binSizeOverride && allData.length > 0
|
|
6446
|
+
? isDateArray(allData)
|
|
6406
6447
|
? {
|
|
6407
6448
|
start: roundToPrevDay(Math.min.apply(Math, allData.map(function (d) { return d.getTime(); }))), // Find a nice round number as a starting point.
|
|
6408
6449
|
end: roundToNextDay(Math.max.apply(Math, allData.map(function (d) { return d.getTime(); }))),
|
|
6409
|
-
size: binSizeOverride // bin size in milliseconds
|
|
6450
|
+
size: binSizeOverride, // bin size in milliseconds
|
|
6410
6451
|
}
|
|
6411
6452
|
: isNumberArray(allData)
|
|
6412
6453
|
? {
|
|
6413
6454
|
start: Math.floor(Math.min.apply(Math, allData)),
|
|
6414
6455
|
end: Math.ceil(Math.max.apply(Math, allData)),
|
|
6415
|
-
size: binSizeOverride
|
|
6456
|
+
size: binSizeOverride,
|
|
6416
6457
|
}
|
|
6417
|
-
: undefined
|
|
6458
|
+
: undefined
|
|
6418
6459
|
: undefined;
|
|
6419
6460
|
var unselectedTrace = {
|
|
6420
6461
|
x: unselectedData,
|
|
6421
|
-
type:
|
|
6462
|
+
type: "histogram",
|
|
6422
6463
|
autobinx: false,
|
|
6423
6464
|
xbins: xBins,
|
|
6424
6465
|
// nbinsx is valid but not included in the type definition
|
|
@@ -6431,59 +6472,73 @@ var HistogramPlot = function (props) {
|
|
|
6431
6472
|
width: 0.5,
|
|
6432
6473
|
},
|
|
6433
6474
|
},
|
|
6434
|
-
hovertemplate:
|
|
6475
|
+
hovertemplate: "[%{x})<br>Count: %{y}<extra></extra>",
|
|
6435
6476
|
};
|
|
6436
|
-
var meanAnnotation =
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6477
|
+
var meanAnnotation = statsAnnotations.includes("mean") && meanLine && data.length > 0
|
|
6478
|
+
? [
|
|
6479
|
+
{
|
|
6480
|
+
x: meanValue,
|
|
6481
|
+
y: 1 + meanLineRadius + 0.04, // Position above the mean line. Value set with respect to the paper coordinates.
|
|
6482
|
+
yref: "paper",
|
|
6483
|
+
text: "<span style=\"font-weight:300\">AVG </span><span style=\"font-weight:600\">".concat(isDateArray(data)
|
|
6484
|
+
? new Date(meanValue).toLocaleDateString("en-US", {
|
|
6485
|
+
month: "2-digit",
|
|
6486
|
+
day: "2-digit",
|
|
6487
|
+
year: "2-digit",
|
|
6488
|
+
})
|
|
6489
|
+
: meanValue.toFixed(2), "</span>"),
|
|
6490
|
+
xanchor: "center",
|
|
6491
|
+
yanchor: "bottom",
|
|
6492
|
+
showarrow: false,
|
|
6493
|
+
font: {
|
|
6494
|
+
color: barColor,
|
|
6495
|
+
size: 12,
|
|
6496
|
+
},
|
|
6451
6497
|
},
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6456
|
-
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6498
|
+
]
|
|
6499
|
+
: [];
|
|
6500
|
+
var stdevAnnotation = statsAnnotations.includes("stdev") && stdevLines && data.length > 0
|
|
6501
|
+
? [
|
|
6502
|
+
{
|
|
6503
|
+
x: meanValue, // Draw above the mean annotation
|
|
6504
|
+
y: 1 +
|
|
6505
|
+
meanLineRadius +
|
|
6506
|
+
(statsAnnotations.includes("mean") ? 0.11 : 0.04),
|
|
6507
|
+
yref: "paper",
|
|
6508
|
+
text: "<span style=\"font-weight:300\">\u03C3 </span><span style=\"font-weight:600\">±".concat(isDateArray(data)
|
|
6509
|
+
? new Date(stdevValue).toLocaleDateString("en-US", {
|
|
6510
|
+
month: "2-digit",
|
|
6511
|
+
day: "2-digit",
|
|
6512
|
+
year: "2-digit",
|
|
6513
|
+
})
|
|
6514
|
+
: stdevValue.toFixed(2), "</span>"),
|
|
6515
|
+
xanchor: "center",
|
|
6516
|
+
yanchor: "bottom",
|
|
6517
|
+
showarrow: false,
|
|
6518
|
+
font: {
|
|
6519
|
+
color: barColor,
|
|
6520
|
+
size: 12,
|
|
6521
|
+
},
|
|
6468
6522
|
},
|
|
6469
|
-
|
|
6523
|
+
]
|
|
6524
|
+
: [];
|
|
6470
6525
|
var plotlyData = [
|
|
6471
6526
|
{
|
|
6472
6527
|
x: data,
|
|
6473
|
-
type:
|
|
6528
|
+
type: "histogram",
|
|
6474
6529
|
autobinx: false,
|
|
6475
6530
|
xbins: xBins,
|
|
6476
6531
|
// nbinsx is valid but not included in the type definition
|
|
6477
6532
|
//@ts-ignore
|
|
6478
6533
|
nbinsx: nBins, // Maximum number of bins. Plotly may adjust to make bins "nicer".
|
|
6479
6534
|
marker: {
|
|
6480
|
-
color: barColor !== null && barColor !== void 0 ? barColor :
|
|
6535
|
+
color: barColor !== null && barColor !== void 0 ? barColor : "blue",
|
|
6481
6536
|
line: {
|
|
6482
6537
|
color: "white",
|
|
6483
6538
|
width: 0.5,
|
|
6484
6539
|
},
|
|
6485
6540
|
},
|
|
6486
|
-
hovertemplate:
|
|
6541
|
+
hovertemplate: "[%{x})<br>Count: %{y}<extra></extra>", // Custom hover text
|
|
6487
6542
|
},
|
|
6488
6543
|
unselectedTrace,
|
|
6489
6544
|
];
|
|
@@ -6491,63 +6546,66 @@ var HistogramPlot = function (props) {
|
|
|
6491
6546
|
title: {
|
|
6492
6547
|
text: title,
|
|
6493
6548
|
},
|
|
6494
|
-
barmode:
|
|
6549
|
+
barmode: "stack", // Stack unselected bars on top of selected bars
|
|
6495
6550
|
showlegend: false,
|
|
6496
6551
|
autosize: true,
|
|
6497
6552
|
width: undefined, // Let autosize handle width
|
|
6498
6553
|
height: undefined, // Let autosize handle height
|
|
6499
6554
|
margin: {
|
|
6500
6555
|
l: 50,
|
|
6501
|
-
r: 35, // Balance between ensuring the mean annotation doesn't get cut off and having too much margin.
|
|
6556
|
+
r: 35, // Balance between ensuring the mean annotation doesn't get cut off and having too much margin.
|
|
6502
6557
|
t: 40 + (title ? 50 : 0), // Add extra top margin if there is a title
|
|
6503
6558
|
b: 50,
|
|
6504
|
-
pad: 4
|
|
6559
|
+
pad: 4,
|
|
6505
6560
|
},
|
|
6506
6561
|
xaxis: {
|
|
6507
6562
|
title: {
|
|
6508
|
-
text: xAxisTitle
|
|
6563
|
+
text: xAxisTitle,
|
|
6509
6564
|
},
|
|
6510
6565
|
range: fixedXAxisRange, // Fixed range prevents axis shifting during interaction or data updates
|
|
6511
6566
|
showgrid: true,
|
|
6512
6567
|
zeroline: false,
|
|
6513
6568
|
showline: true,
|
|
6514
|
-
mirror:
|
|
6515
|
-
gridcolor:
|
|
6569
|
+
mirror: "ticks",
|
|
6570
|
+
gridcolor: "#efefef",
|
|
6516
6571
|
gridwidth: 0.2,
|
|
6517
|
-
zerolinecolor:
|
|
6572
|
+
zerolinecolor: "#969696",
|
|
6518
6573
|
zerolinewidth: 1,
|
|
6519
|
-
linecolor:
|
|
6574
|
+
linecolor: "#bababa",
|
|
6520
6575
|
linewidth: 1,
|
|
6521
6576
|
fixedrange: true, // Disable zooming
|
|
6522
|
-
ticklabelposition:
|
|
6577
|
+
ticklabelposition: "outside",
|
|
6523
6578
|
tickformat: isDateArray(data) ? dateTickFormat : undefined, // Format ticks for dates
|
|
6524
6579
|
automargin: true, // Adjust margin if tick labels rotate
|
|
6525
|
-
hoverformat:
|
|
6580
|
+
hoverformat: isNumberArray(allData) &&
|
|
6581
|
+
Math.max.apply(Math, allData) - Math.min.apply(Math, allData) > 3
|
|
6582
|
+
? ".1~f"
|
|
6583
|
+
: undefined,
|
|
6526
6584
|
},
|
|
6527
6585
|
yaxis: {
|
|
6528
6586
|
title: {
|
|
6529
|
-
text:
|
|
6587
|
+
text: "Count",
|
|
6530
6588
|
standoff: 12, // Add space between title and axis
|
|
6531
6589
|
},
|
|
6532
6590
|
automargin: true, // Required for standoff to work properly
|
|
6533
6591
|
showgrid: true,
|
|
6534
6592
|
zeroline: false,
|
|
6535
6593
|
showline: true,
|
|
6536
|
-
mirror:
|
|
6537
|
-
gridcolor:
|
|
6594
|
+
mirror: "ticks",
|
|
6595
|
+
gridcolor: "#efefef",
|
|
6538
6596
|
gridwidth: 0.2,
|
|
6539
|
-
zerolinecolor:
|
|
6597
|
+
zerolinecolor: "#969696",
|
|
6540
6598
|
zerolinewidth: 1,
|
|
6541
|
-
linecolor:
|
|
6599
|
+
linecolor: "#bababa",
|
|
6542
6600
|
linewidth: 1,
|
|
6543
6601
|
fixedrange: true, // Disable zooming
|
|
6544
|
-
ticksuffix:
|
|
6602
|
+
ticksuffix: " ", // Add space between y axis and ticks
|
|
6545
6603
|
},
|
|
6546
6604
|
bargap: 0.03, // Gap between bars
|
|
6547
|
-
dragmode:
|
|
6548
|
-
selectdirection:
|
|
6605
|
+
dragmode: "select", // Enable drag to select
|
|
6606
|
+
selectdirection: "h", // User can select in horizontal direction only
|
|
6549
6607
|
shapes: tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray(tslib.__spreadArray([], allDataMeanLine, true), meanLine, true), selectedRangeBox, true), stdevLines, true), allDataStdevLines, true), // Add the mean line and selection box
|
|
6550
|
-
annotations: tslib.__spreadArray(tslib.__spreadArray([], meanAnnotation, true), stdevAnnotation, true)
|
|
6608
|
+
annotations: tslib.__spreadArray(tslib.__spreadArray([], meanAnnotation, true), stdevAnnotation, true),
|
|
6551
6609
|
};
|
|
6552
6610
|
var config = {
|
|
6553
6611
|
responsive: true, // Make the plot responsive
|
|
@@ -6557,14 +6615,14 @@ var HistogramPlot = function (props) {
|
|
|
6557
6615
|
staticPlot: false, // Enable interactivity
|
|
6558
6616
|
};
|
|
6559
6617
|
var containerStyles = tslib.__assign({ width: "100%", height: "100%", position: "relative" }, containerStyleOverrides);
|
|
6560
|
-
return (jsxRuntime.jsx("div", { ref: containerRef, className: "plot-container ".concat(plotId), style: tslib.__assign({
|
|
6618
|
+
return (jsxRuntime.jsx("div", { ref: containerRef, className: "plot-container ".concat(plotId), style: tslib.__assign({ "--selection-color": selectorsColor }, containerStyles), children: jsxRuntime.jsx(React.Suspense, { fallback: jsxRuntime.jsx(Loading, {}), children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(Plot$2, { data: plotlyData, layout: layout, config: config, onSelected: handleSelection, onClick: handleClick, onDeselect: function () {
|
|
6561
6619
|
onDeselect();
|
|
6562
6620
|
setSelectedRange(null); // Remove selected box
|
|
6563
6621
|
}, onUpdate: handlePlotUpdate, useResizeHandler: true, style: {
|
|
6564
6622
|
width: "100%",
|
|
6565
6623
|
height: "100%",
|
|
6566
|
-
display: "block"
|
|
6567
|
-
} }, "histogram-".concat(plotId ||
|
|
6624
|
+
display: "block",
|
|
6625
|
+
} }, "histogram-".concat(plotId || "default")) }) }) }));
|
|
6568
6626
|
};
|
|
6569
6627
|
|
|
6570
6628
|
var Plot$1 = React.lazy(function () { return import('react-plotly.js'); });
|