td-plots 1.11.2 → 1.11.3

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
@@ -2170,6 +2164,7 @@ const SummaryComparisonPlot = (props) => {
2170
2164
  };
2171
2165
  const comparedLines = [];
2172
2166
  const comparedAnnotations = [];
2167
+ console.log("d3FormatValueString:", d3FormatValueString);
2173
2168
  // Transform the data into a format suitable for a plotly scatterplot
2174
2169
  const plotlyData = groups.flatMap((group, groupIndex) => {
2175
2170
  const traces = [];
@@ -2227,7 +2222,7 @@ const SummaryComparisonPlot = (props) => {
2227
2222
  y: 1.1,
2228
2223
  xref: "x",
2229
2224
  yref: "paper",
2230
- text: `${group.data.userValue.toFixed(2)} ${unit}`,
2225
+ text: `${format$1(d3FormatValueString)(group.data.userValue)} ${unit}`,
2231
2226
  showarrow: false,
2232
2227
  xanchor: "center",
2233
2228
  yanchor: "bottom",
@@ -2269,7 +2264,7 @@ const SummaryComparisonPlot = (props) => {
2269
2264
  height: height,
2270
2265
  autosize: true,
2271
2266
  margin: {
2272
- l: 130,
2267
+ l: 100,
2273
2268
  r: 35, // Balance between ensuring the mean annotation doesn't get cut off and having too much margin.
2274
2269
  t: title ? 70 : 40,
2275
2270
  b: 50,
@@ -2310,6 +2305,7 @@ const SummaryComparisonPlot = (props) => {
2310
2305
  zerolinewidth: 1,
2311
2306
  linecolor: "#bababa",
2312
2307
  linewidth: 1,
2308
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2313
2309
  },
2314
2310
  yaxis: {
2315
2311
  title: {
@@ -2647,7 +2643,7 @@ const BarPlot = (props) => {
2647
2643
  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
2644
  barGroups = [], // Optional array of bar groups for grouping bars by color
2649
2645
  barGroupTooltipTitle = "Group", // Default title for the bar group tooltip
2650
- } = props;
2646
+ d3FormatValueString = ".1f", } = props;
2651
2647
  // Ref for plot container
2652
2648
  const containerRef = useRef(null);
2653
2649
  const plotMetaRef = useRef(null);
@@ -2783,8 +2779,8 @@ const BarPlot = (props) => {
2783
2779
  xref: "paper",
2784
2780
  yref: "paper",
2785
2781
  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
2782
+ y0: y2AxisPosition - 0.11, // Position behind the primary title
2783
+ x1: 0.02 + title.length * 0.01, // Approximate width based on title length 0.3/
2788
2784
  y1: y2AxisPosition - 0.01,
2789
2785
  fillcolor: "rgba(255, 255, 255, 0.5)",
2790
2786
  line: {
@@ -2922,6 +2918,7 @@ const BarPlot = (props) => {
2922
2918
  text: xAxisTitle,
2923
2919
  },
2924
2920
  anchor: "y", // Anchor to primary y-axis
2921
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
2925
2922
  showgrid: true,
2926
2923
  zeroline: false,
2927
2924
  showline: true,
@@ -2938,6 +2935,7 @@ const BarPlot = (props) => {
2938
2935
  ? BAR_GROUP_SHAPE_TOP_PX + BAR_GROUP_SHAPE_HEIGHT_PX
2939
2936
  : 8, // tick length in px.
2940
2937
  tickcolor: "white",
2938
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2941
2939
  } }, (data2 && {
2942
2940
  xaxis2: {
2943
2941
  title: {
@@ -2959,6 +2957,7 @@ const BarPlot = (props) => {
2959
2957
  fixedrange: true,
2960
2958
  automargin: true,
2961
2959
  matches: "x", // Match the range of xaxis to keep them synchronized
2960
+ tickformat: d3FormatValueString, // Format ticks using provided d3 format string
2962
2961
  },
2963
2962
  })), { yaxis: {
2964
2963
  title: {
@@ -2966,6 +2965,8 @@ const BarPlot = (props) => {
2966
2965
  standoff: 15, // Add space between title and axis
2967
2966
  },
2968
2967
  domain: data2 ? [0, y2AxisPosition - 0.01] : [0, 1], // Ensure primary y-axis takes full height
2968
+ hoverformat: d3FormatValueString, // Format hover values using provided d3 format string
2969
+ nticks: 7, // Limit number of ticks to prevent overcrowding with the histogram
2969
2970
  automargin: true, // Required for standoff to work properly
2970
2971
  showgrid: true,
2971
2972
  zeroline: false,