td-plots 1.11.3 → 1.11.5

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