td-plots 1.11.2 → 1.11.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.
@@ -38,6 +38,7 @@ export interface BarPlotProps {
38
38
  barHoverTemplate?: string;
39
39
  barGroups?: BarGroup[];
40
40
  barGroupTooltipTitle?: string;
41
+ d3FormatValueString?: string;
41
42
  }
42
43
  declare const BarPlot: (props: BarPlotProps) => import("react/jsx-runtime").JSX.Element;
43
44
  export default BarPlot;
@@ -18,6 +18,8 @@ export interface SplitBoxPlotProps {
18
18
  text?: string;
19
19
  color?: string;
20
20
  }[];
21
+ d3FormatValueString?: string;
22
+ addExtraYTitleRoom?: boolean;
21
23
  }
22
24
  declare const SplitBoxPlot: (props: SplitBoxPlotProps) => import("react/jsx-runtime").JSX.Element;
23
25
  export default SplitBoxPlot;
@@ -26,6 +26,7 @@ export type SummaryComparisonPlotProps = {
26
26
  populationMaxLabel?: string;
27
27
  userValueLabel?: string;
28
28
  };
29
+ d3FormatValueString?: string;
29
30
  };
30
31
  declare const SummaryComparisonPlot: (props: SummaryComparisonPlotProps) => import("react/jsx-runtime").JSX.Element;
31
32
  export default SummaryComparisonPlot;
package/dist/index.esm.js CHANGED
@@ -1818,7 +1818,7 @@ const PairedComparisonsBoxPlot = (props) => {
1818
1818
  // This component shows a set of main boxplots as one collection, then allowes for additional
1819
1819
  // boxes to be shown in a subplot above the main boxplots for comparison.
1820
1820
  const SplitBoxPlot = (props) => {
1821
- const { groups, additionalGroups = [], width = 600, height = 400, title = "", xAxisTitle, yAxisTitle, secondXAxisTitle, secondYAxisTitle, containerStyleOverrides, plotId = "paired-comparisons-boxplot", xAnnotations = [], } = props;
1821
+ const { groups, additionalGroups = [], width = 600, height = 400, title = "", xAxisTitle, yAxisTitle, secondXAxisTitle, secondYAxisTitle, containerStyleOverrides, plotId = "paired-comparisons-boxplot", xAnnotations = [], d3FormatValueString = ".1f", addExtraYTitleRoom = false, } = props;
1822
1822
  // Transform the grouped data into an array for BoxPlot
1823
1823
  const boxPlotData = [
1824
1824
  ...groups.flatMap((group, groupIndex) => {
@@ -1922,23 +1922,14 @@ const SplitBoxPlot = (props) => {
1922
1922
  });
1923
1923
  const totalGroups = groups.length + additionalGroups.length;
1924
1924
  const yAxisSplitProportion = additionalGroups.length > 0 ? groups.length / totalGroups : 1;
1925
- // Render y-axis titles as annotations so we can specifically set xshift in px from the axis.
1926
- // Calculating approximate label width in pixels to ensure the title is far enough away from the longest label,
1927
- // with a minimum distance to look good even with short labels.
1928
- const charWidth = 8; // ~px per character for Open Sans 14px (Plotly title font)
1929
- const primaryMaxChars = Math.max(0, ...groups.map((g) => g.label.length));
1930
- const secondaryMaxChars = additionalGroups.length > 0
1931
- ? Math.max(0, ...additionalGroups.map((g) => g.label.length))
1932
- : primaryMaxChars;
1933
- const maxLabelChars = Math.max(primaryMaxChars, secondaryMaxChars);
1934
- const approxLabelPx = maxLabelChars * charWidth;
1925
+ const xshift = addExtraYTitleRoom ? -140 : -130; // Add extra shift if we're adding extra room for y-axis titles
1935
1926
  const yAxisTitleAnnotations = [];
1936
1927
  if (yAxisTitle) {
1937
1928
  const domainTop = additionalGroups.length > 0 ? yAxisSplitProportion - 0.01 : 1;
1938
1929
  yAxisTitleAnnotations.push({
1939
1930
  text: yAxisTitle,
1940
1931
  x: 0,
1941
- xshift: -120,
1932
+ xshift: xshift,
1942
1933
  y: domainTop / 2,
1943
1934
  xref: "paper",
1944
1935
  yref: "paper",
@@ -1957,7 +1948,7 @@ const SplitBoxPlot = (props) => {
1957
1948
  yAxisTitleAnnotations.push({
1958
1949
  text: secondYAxisTitle,
1959
1950
  x: 0,
1960
- xshift: -120,
1951
+ xshift: xshift,
1961
1952
  y: (yAxisSplitProportion + 1) / 2,
1962
1953
  xref: "paper",
1963
1954
  yref: "paper",
@@ -1988,15 +1979,17 @@ const SplitBoxPlot = (props) => {
1988
1979
  ticklabelstandoff: 7,
1989
1980
  ticklabelposition: "outside left",
1990
1981
  title: { text: "" }, // rendered via annotation instead
1982
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
1991
1983
  }, xaxis: {
1992
1984
  anchor: "y", // Anchor to primary y-axis
1985
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
1986
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
1993
1987
  }, margin: {
1994
1988
  t: title ? 50 : 70,
1995
1989
  r: 20,
1996
- l: Math.max(130, approxLabelPx + 40),
1990
+ l: 80, // Got to complicated to calculate. Adjust if necessary.
1997
1991
  }, shapes: [
1998
1992
  ...separatorShapes,
1999
- // ...differenceBetweenMediansLines,
2000
1993
  ...xAnnotations.map((annotation, annotationIndex) => ({
2001
1994
  type: "line",
2002
1995
  x0: annotation.x,
@@ -2049,6 +2042,7 @@ const SplitBoxPlot = (props) => {
2049
2042
  fixedrange: true,
2050
2043
  automargin: true,
2051
2044
  matches: "x", // Match the range of xaxis to keep them synchronized
2045
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2052
2046
  },
2053
2047
  })), (additionalGroups.length > 0 && {
2054
2048
  yaxis2: {
@@ -2084,7 +2078,7 @@ const Plot$2 = lazy(() => Promise.resolve().then(function () { return reactPlotl
2084
2078
  const SummaryComparisonPlot = (props) => {
2085
2079
  const { groups, userColor = "orange", height = 250, title = "", xAxisTitle, yAxisTitle, containerStyleOverrides, plotId = "summary-comparison-plot", tooltipPosition = "right", startXAxisAtZero = true, unit = "",
2086
2080
  // xAnnotations = [], TO DO
2087
- tooltipLabels = {}, } = props;
2081
+ tooltipLabels = {}, d3FormatValueString = ".1f", } = props;
2088
2082
  // Ref for plot container
2089
2083
  const containerRef = useRef(null);
2090
2084
  // State for custom tooltip
@@ -2227,7 +2221,7 @@ const SummaryComparisonPlot = (props) => {
2227
2221
  y: 1.1,
2228
2222
  xref: "x",
2229
2223
  yref: "paper",
2230
- text: `${group.data.userValue.toFixed(2)} ${unit}`,
2224
+ text: `${format$1(d3FormatValueString)(group.data.userValue)} ${unit}`,
2231
2225
  showarrow: false,
2232
2226
  xanchor: "center",
2233
2227
  yanchor: "bottom",
@@ -2269,7 +2263,7 @@ const SummaryComparisonPlot = (props) => {
2269
2263
  height: height,
2270
2264
  autosize: true,
2271
2265
  margin: {
2272
- l: 130,
2266
+ l: 100,
2273
2267
  r: 35, // Balance between ensuring the mean annotation doesn't get cut off and having too much margin.
2274
2268
  t: title ? 70 : 40,
2275
2269
  b: 50,
@@ -2310,6 +2304,7 @@ const SummaryComparisonPlot = (props) => {
2310
2304
  zerolinewidth: 1,
2311
2305
  linecolor: "#bababa",
2312
2306
  linewidth: 1,
2307
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2313
2308
  },
2314
2309
  yaxis: {
2315
2310
  title: {
@@ -2647,7 +2642,7 @@ const BarPlot = (props) => {
2647
2642
  xAxisTitle = "X Axis", yAxisTitle = "Y Axis", xAxis2Title = "", yAxis2Title = "", xAccessor = (d) => d.x, yAccessor = (d) => d.y, containerStyleOverrides = {}, plotId = "bar-plot", xAnnotations = [], barHoverTemplate = "", // Default hover template for bars
2648
2643
  barGroups = [], // Optional array of bar groups for grouping bars by color
2649
2644
  barGroupTooltipTitle = "Group", // Default title for the bar group tooltip
2650
- } = props;
2645
+ d3FormatValueString = ".1f", } = props;
2651
2646
  // Ref for plot container
2652
2647
  const containerRef = useRef(null);
2653
2648
  const plotMetaRef = useRef(null);
@@ -2783,8 +2778,8 @@ const BarPlot = (props) => {
2783
2778
  xref: "paper",
2784
2779
  yref: "paper",
2785
2780
  x0: 0,
2786
- y0: y2AxisPosition - 0.3, // Position behind the primary title
2787
- x1: 0.02 + title.length * 0.015, // Approximate width based on title length
2781
+ y0: y2AxisPosition - 0.11, // Position behind the primary title
2782
+ x1: 0.02 + title.length * 0.01, // Approximate width based on title length 0.3/
2788
2783
  y1: y2AxisPosition - 0.01,
2789
2784
  fillcolor: "rgba(255, 255, 255, 0.5)",
2790
2785
  line: {
@@ -2922,6 +2917,7 @@ const BarPlot = (props) => {
2922
2917
  text: xAxisTitle,
2923
2918
  },
2924
2919
  anchor: "y", // Anchor to primary y-axis
2920
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
2925
2921
  showgrid: true,
2926
2922
  zeroline: false,
2927
2923
  showline: true,
@@ -2938,6 +2934,7 @@ const BarPlot = (props) => {
2938
2934
  ? BAR_GROUP_SHAPE_TOP_PX + BAR_GROUP_SHAPE_HEIGHT_PX
2939
2935
  : 8, // tick length in px.
2940
2936
  tickcolor: "white",
2937
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2941
2938
  } }, (data2 && {
2942
2939
  xaxis2: {
2943
2940
  title: {
@@ -2959,6 +2956,7 @@ const BarPlot = (props) => {
2959
2956
  fixedrange: true,
2960
2957
  automargin: true,
2961
2958
  matches: "x", // Match the range of xaxis to keep them synchronized
2959
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2962
2960
  },
2963
2961
  })), { yaxis: {
2964
2962
  title: {
@@ -2966,6 +2964,8 @@ const BarPlot = (props) => {
2966
2964
  standoff: 15, // Add space between title and axis
2967
2965
  },
2968
2966
  domain: data2 ? [0, y2AxisPosition - 0.01] : [0, 1], // Ensure primary y-axis takes full height
2967
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
2968
+ nticks: 7, // Limit number of ticks to prevent overcrowding with the histogram
2969
2969
  automargin: true, // Required for standoff to work properly
2970
2970
  showgrid: true,
2971
2971
  zeroline: false,