td-plots 1.11.4 → 1.11.6

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.
@@ -14,7 +14,6 @@ export interface BarPlotProps {
14
14
  data2?: number[];
15
15
  data2Selected?: [number, number];
16
16
  data2SelectedColor?: string;
17
- barDataWidth?: number;
18
17
  barWidth?: number;
19
18
  barColor?: string;
20
19
  barColor2?: string;
@@ -1,7 +1,7 @@
1
1
  type BracketData = {
2
- userValue?: number;
3
2
  populationMin: number;
4
3
  populationMax: number;
4
+ userValue?: number;
5
5
  };
6
6
  type BracketDataWithMeta = {
7
7
  groupLabel: string;
@@ -10,7 +10,6 @@ type BracketDataWithMeta = {
10
10
  };
11
11
  export type SummaryComparisonPlotProps = {
12
12
  groups: BracketDataWithMeta[];
13
- userColor?: string;
14
13
  width?: number;
15
14
  height?: number;
16
15
  title?: string;
@@ -21,6 +20,13 @@ export type SummaryComparisonPlotProps = {
21
20
  tooltipPosition?: "left" | "right";
22
21
  startXAxisAtZero?: boolean;
23
22
  unit?: string;
23
+ xAnnotations?: {
24
+ x: number;
25
+ text?: string;
26
+ label?: string;
27
+ color?: string;
28
+ markerY?: number;
29
+ }[];
24
30
  tooltipLabels?: {
25
31
  populationMinLabel?: string;
26
32
  populationMaxLabel?: string;
package/dist/index.esm.js CHANGED
@@ -2076,9 +2076,7 @@ const SplitBoxPlot = (props) => {
2076
2076
 
2077
2077
  const Plot$2 = lazy(() => Promise.resolve().then(function () { return reactPlotlyWrapper$1; }));
2078
2078
  const SummaryComparisonPlot = (props) => {
2079
- const { groups, userColor = "orange", height = 250, title = "", xAxisTitle, yAxisTitle, containerStyleOverrides, plotId = "summary-comparison-plot", tooltipPosition = "right", startXAxisAtZero = true, unit = "",
2080
- // xAnnotations = [], TO DO
2081
- tooltipLabels = {}, d3FormatValueString = ".1f", } = props;
2079
+ const { groups, height = 250, title = "", xAxisTitle, yAxisTitle, containerStyleOverrides, plotId = "summary-comparison-plot", tooltipPosition = "right", startXAxisAtZero = true, unit = "", xAnnotations = [], tooltipLabels = {}, d3FormatValueString = ".1f", } = props;
2082
2080
  // Ref for plot container
2083
2081
  const containerRef = useRef(null);
2084
2082
  // State for custom tooltip
@@ -2162,8 +2160,8 @@ const SummaryComparisonPlot = (props) => {
2162
2160
  const handleUnhover = () => {
2163
2161
  setTooltip((prev) => (Object.assign(Object.assign({}, prev), { visible: false })));
2164
2162
  };
2165
- const comparedLines = [];
2166
- const comparedAnnotations = [];
2163
+ const xAnnotationLines = [];
2164
+ const xAnnotationText = [];
2167
2165
  // Transform the data into a format suitable for a plotly scatterplot
2168
2166
  const plotlyData = groups.flatMap((group, groupIndex) => {
2169
2167
  const traces = [];
@@ -2180,22 +2178,26 @@ const SummaryComparisonPlot = (props) => {
2180
2178
  showlegend: false,
2181
2179
  hoverinfo: "none",
2182
2180
  });
2183
- if (group.data.userValue !== undefined) {
2181
+ return traces;
2182
+ });
2183
+ xAnnotations.forEach((annotation, annotationIndex) => {
2184
+ var _a, _b, _c, _d;
2185
+ if (xAnnotations.length > 0) {
2184
2186
  const CIRCLE_RADIUS_PX = 6;
2185
- comparedLines.push({
2187
+ xAnnotationLines.push({
2186
2188
  type: "line",
2187
- name: group.groupLabel,
2188
- x0: group.data.userValue,
2189
- x1: group.data.userValue,
2189
+ name: annotation.label || "Annotation",
2190
+ x0: annotation.x,
2191
+ x1: annotation.x,
2190
2192
  y0: 0,
2191
2193
  y1: 1.1,
2192
2194
  yref: "paper",
2193
2195
  line: {
2194
- color: colorToRGBA(userColor, 1),
2196
+ color: colorToRGBA((_a = annotation.color) !== null && _a !== void 0 ? _a : "orange", 1),
2195
2197
  width: 2,
2196
2198
  },
2197
2199
  });
2198
- comparedLines.push({
2200
+ xAnnotationLines.push({
2199
2201
  type: "circle",
2200
2202
  xref: "x",
2201
2203
  yref: "y",
@@ -2204,60 +2206,54 @@ const SummaryComparisonPlot = (props) => {
2204
2206
  // visual size regardless of the axis scale.
2205
2207
  xsizemode: "pixel",
2206
2208
  ysizemode: "pixel",
2207
- xanchor: group.data.userValue,
2208
- yanchor: groupIndex * 0.1,
2209
+ xanchor: annotation.x,
2210
+ yanchor: (_b = annotation.markerY) !== null && _b !== void 0 ? _b : annotationIndex * 0.1,
2209
2211
  x0: -CIRCLE_RADIUS_PX,
2210
2212
  x1: CIRCLE_RADIUS_PX,
2211
2213
  y0: -CIRCLE_RADIUS_PX,
2212
2214
  y1: CIRCLE_RADIUS_PX,
2213
- fillcolor: colorToRGBA(userColor, 1),
2215
+ fillcolor: colorToRGBA((_c = annotation.color) !== null && _c !== void 0 ? _c : "orange", 1),
2214
2216
  line: {
2215
2217
  color: "white",
2216
2218
  width: 1,
2217
2219
  },
2218
2220
  });
2219
- comparedAnnotations.push({
2220
- x: group.data.userValue,
2221
+ xAnnotationText.push({
2222
+ x: annotation.x,
2221
2223
  y: 1.1,
2222
2224
  xref: "x",
2223
2225
  yref: "paper",
2224
- text: `${format$1(d3FormatValueString)(group.data.userValue)} ${unit}`,
2226
+ text: `${format$1(d3FormatValueString)(annotation.x)} ${unit}`,
2225
2227
  showarrow: false,
2226
2228
  xanchor: "center",
2227
2229
  yanchor: "bottom",
2228
2230
  font: {
2229
- color: colorToRGBA(userColor, 1),
2231
+ color: colorToRGBA((_d = annotation.color) !== null && _d !== void 0 ? _d : "orange", 1),
2230
2232
  size: 12,
2231
2233
  },
2232
2234
  });
2233
2235
  }
2234
- return traces;
2235
- });
2236
- // Add tick label for the compared annotation value
2237
- if (comparedAnnotations.length > 0) {
2238
- comparedAnnotations.push({
2236
+ // Add "tick" label
2237
+ xAnnotationText.push({
2239
2238
  x: 0, // Position to the left of the y-axis
2240
2239
  y: 1.1, // Should match the y position of the compared median annotation
2241
2240
  xref: "paper",
2242
2241
  xshift: -10,
2243
2242
  yref: "paper",
2244
- text: "My AVG",
2243
+ text: annotation.label || annotation.text || "Annotation",
2245
2244
  showarrow: false,
2246
2245
  xanchor: "right",
2247
2246
  yanchor: "bottom",
2248
2247
  });
2249
- }
2248
+ });
2250
2249
  // xRangeMin a little funky because we want to ensure a non-zero value is calculated
2251
2250
  // in case startXAxisAtZero is false. populationMin is our anchor and
2252
2251
  // if that is not defined then we can fall back to a min of 0. If userValue is not defined
2253
2252
  // we want to listen to populationMin for computing xRangeMin.
2254
- const xRangeMin = groups.reduce((min, group) => { var _a; return Math.min(min, group.data.populationMin, (_a = group.data.userValue) !== null && _a !== void 0 ? _a : Infinity); }, Infinity);
2253
+ const xRangeMin = Math.min(groups.reduce((min, group) => Math.min(min, group.data.populationMin), Infinity), xAnnotations.reduce((min, annotation) => Math.min(min, annotation.x), Infinity));
2255
2254
  // Similar logic for xRangeMax. If nothing is defined, set the max to 0.
2256
2255
  // Otherwise, listen to populationMax and userValue if given.
2257
- const xRangeMax = groups.reduce((max, group) => {
2258
- var _a;
2259
- return Math.max(max, group.data.populationMax, (_a = group.data.userValue) !== null && _a !== void 0 ? _a : -Infinity);
2260
- }, -Infinity);
2256
+ const xRangeMax = Math.max(groups.reduce((max, group) => Math.max(max, group.data.populationMax), -Infinity), xAnnotations.reduce((max, annotation) => Math.max(max, annotation.x), -Infinity));
2261
2257
  const layout = {
2262
2258
  width: undefined,
2263
2259
  height: height,
@@ -2336,8 +2332,8 @@ const SummaryComparisonPlot = (props) => {
2336
2332
  ticklabelstandoff: 5,
2337
2333
  },
2338
2334
  hovermode: "y",
2339
- shapes: comparedLines,
2340
- annotations: comparedAnnotations,
2335
+ shapes: xAnnotationLines,
2336
+ annotations: xAnnotationText,
2341
2337
  };
2342
2338
  const containerStyles = Object.assign({ width: "100%", height: height, position: "relative", display: "flex", flexDirection: "column", gap: 0 }, containerStyleOverrides);
2343
2339
  const config = {
@@ -2635,7 +2631,7 @@ const LineWithHistogram = (props) => {
2635
2631
  const Plot = lazy(() => Promise.resolve().then(function () { return reactPlotlyWrapper$1; }));
2636
2632
  const BarPlot = (props) => {
2637
2633
  var _a, _b;
2638
- const { data, data2 = null, data2Selected = [], barDataWidth = 2, barWidth = 0.8, barColor = "rgb(205, 26, 154)", // Default bar color (red)
2634
+ const { data, data2 = null, data2Selected = [], barWidth = 2, barColor = "rgb(205, 26, 154)", // Default bar color (red)
2639
2635
  barColor2 = "rgba(100, 200, 255, 0.7)", // Default histogram bar color (blue)
2640
2636
  data2SelectedColor = "rgba(255, 0, 0, 0.5)", // Default color for the histogram selection box (red)
2641
2637
  width = 600, height = 400, title = "", title2 = "", // Default title for histogram subplot
@@ -2720,7 +2716,7 @@ const BarPlot = (props) => {
2720
2716
  {
2721
2717
  x: data.map((point) => xAccessor(point)),
2722
2718
  y: data.map((point) => yAccessor(point)),
2723
- customdata: data.map((point) => [xAccessor(point) + barDataWidth]),
2719
+ customdata: data.map((point) => [xAccessor(point) + barWidth]),
2724
2720
  yaxis: "y",
2725
2721
  type: "bar",
2726
2722
  marker: {
@@ -2752,7 +2748,7 @@ const BarPlot = (props) => {
2752
2748
  },
2753
2749
  ]
2754
2750
  : [];
2755
- const selectedHistogramShape = data2Selected.length === 2
2751
+ const selectedHistogramShape = data2Selected.length === 2 && data2Selected[0] < data2Selected[1]
2756
2752
  ? [
2757
2753
  {
2758
2754
  type: "rect",
@@ -2865,7 +2861,7 @@ const BarPlot = (props) => {
2865
2861
  ? {
2866
2862
  xref: "x",
2867
2863
  yref: "paper",
2868
- x: barGroups[0].min + barDataWidth / 2,
2864
+ x: barGroups[0].min + barWidth / 2,
2869
2865
  // Convert the pixel center of the shape band to a paper y coordinate using
2870
2866
  // the actual rendered plot area height so it stays inside the shape on any screen size.
2871
2867
  y: -18 /