@lunit/oui 3.1.0 → 3.1.1

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.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box } from '@mui/material';
3
3
  import { AnalysisBarSegmentContainer, AnalysisBarOuter, AxisLabels, GraphAxisLabel, GraphScoreIndicator, GraphSegment, } from './AnalysisBar.styled';
4
- import { parseStringValToNumber, normalizeSegmentWidths } from './AnalysisBar.utils';
4
+ import { resolveExpressionLevel, normalizeSegmentWidths } from './AnalysisBar.utils';
5
5
  import HeatmapGraphSVG from './HeatmapGraphIcon/HeatmapGraphSVG';
6
6
  const Segments = ({ segments, isCutoff }) => {
7
7
  if (!segments) {
@@ -40,7 +40,8 @@ const AnalysisBar = ({ componentType = 'analysisBar', isCutoff = false, expressi
40
40
  const normalizedSegments = normalizeSegmentWidths(segments, isCutoff);
41
41
  return (_jsxs(AnalysisBarOuter, { className: "analysis-bar", isDimmed: isDimmed, children: [_jsxs(AnalysisBarSegmentContainer, { children: [expressionValue && (_jsx(GraphScoreIndicator, { value: expressionValue, isCutoff: isCutoff, isJet: normalizedSegments?.[0]?.color === 'jet' })), _jsx(Segments, { segments: normalizedSegments, isCutoff: isCutoff })] }), (expressionLevels.length > 0 || caption) && (_jsxs(AxisLabels, { children: [expressionLevels.length > 0 &&
42
42
  expressionLevels.map((val, i) => {
43
- return (_jsx(GraphAxisLabel, { label: expressionLabels[i] || val, isCutoff: isCutoff, leftPos: parseStringValToNumber(val) }, i));
43
+ const { label, position } = resolveExpressionLevel(val);
44
+ return (_jsx(GraphAxisLabel, { label: expressionLabels[i] || label, isCutoff: isCutoff, leftPos: position }, i));
44
45
  }), caption && (_jsx(GraphAxisLabel, { label: caption, isCutoff: isCutoff, leftPos: 50 }))] }))] }));
45
46
  };
46
47
  export default AnalysisBar;
@@ -2,6 +2,17 @@ export function parseStringValToNumber(val) {
2
2
  const value = val.endsWith('%') ? val.slice(0, -1) : val;
3
3
  return parseInt(value, 10);
4
4
  }
5
+ /**
6
+ * @description resolveExpressionLevel normalizes an expression level into a label and its position on the bar.
7
+ * @param level - A numeric string ('20', '20%') used as both label and position, or an object with an explicit label and position.
8
+ * @returns The label to display and its position on the bar.
9
+ */
10
+ export function resolveExpressionLevel(level) {
11
+ if (typeof level === 'string') {
12
+ return { label: level, position: parseStringValToNumber(level) };
13
+ }
14
+ return level;
15
+ }
5
16
  export function clampNumericalPercentage(value) {
6
17
  if (value >= 100)
7
18
  return 100;
@@ -1,7 +1,16 @@
1
+ /** A label placed at an explicit position on the bar */
2
+ export interface AnalysisBarLevel {
3
+ /** Text displayed under the bar */
4
+ label: string;
5
+ /** Horizontal position on the bar, 0-100 (%) */
6
+ position: number;
7
+ }
8
+ /** Either a numeric string ('20', '20%') that doubles as its own label, or an explicitly positioned label */
9
+ export type AnalysisBarExpressionLevel = string | AnalysisBarLevel;
1
10
  export interface AnalysisBarProps {
2
11
  componentType: 'analysisBar';
3
12
  isCutoff?: boolean;
4
- expressionLevels?: string[];
13
+ expressionLevels?: AnalysisBarExpressionLevel[];
5
14
  caption?: string;
6
15
  segments?: {
7
16
  color: 'jet' | string;
@@ -1,4 +1,11 @@
1
+ import type { AnalysisBarExpressionLevel, AnalysisBarLevel } from './AnalysisBar.types';
1
2
  export declare function parseStringValToNumber(val: string): number;
3
+ /**
4
+ * @description resolveExpressionLevel normalizes an expression level into a label and its position on the bar.
5
+ * @param level - A numeric string ('20', '20%') used as both label and position, or an object with an explicit label and position.
6
+ * @returns The label to display and its position on the bar.
7
+ */
8
+ export declare function resolveExpressionLevel(level: AnalysisBarExpressionLevel): AnalysisBarLevel;
2
9
  export declare function clampNumericalPercentage(value: number): number;
3
10
  export declare function clampBarLabelPosition(value: number): number;
4
11
  /**
@@ -1,4 +1,4 @@
1
1
  import AnalysisBar from './AnalysisBar';
2
- import type { AnalysisBarProps } from './AnalysisBar.types';
2
+ import type { AnalysisBarProps, AnalysisBarLevel, AnalysisBarExpressionLevel } from './AnalysisBar.types';
3
3
  export { AnalysisBar };
4
- export type { AnalysisBarProps };
4
+ export type { AnalysisBarProps, AnalysisBarLevel, AnalysisBarExpressionLevel };
@@ -99,6 +99,34 @@ Exported together from `@lunit/oui`. Composite components for the oncology analy
99
99
 
100
100
  `Accordion`, `AnalysisBar`, `FreeText`, `Histogram`, `HorizonDivider`, `ModelType`, `Preview`, `Score`, `Statistic`, `Threshold`, `ToggleControl`, `ToggleControlGroup`
101
101
 
102
+ ### AnalysisBar — `expressionLevels`
103
+
104
+ Axis labels under the bar. Each item is either a numeric string, which is both the label and its position, or an object that places arbitrary text at an explicit position.
105
+
106
+ ```tsx
107
+ // numeric strings: label and position are the same value
108
+ <AnalysisBar componentType="analysisBar" expressionLevels={['0', '20', '100']} segments={segments} />
109
+
110
+ // text labels at explicit positions (0-100)
111
+ <AnalysisBar
112
+ componentType="analysisBar"
113
+ expressionLevels={[
114
+ { label: 'Low', position: 0 },
115
+ { label: 'High', position: 100 },
116
+ ]}
117
+ segments={segments}
118
+ />
119
+
120
+ // the two forms can be mixed
121
+ <AnalysisBar
122
+ componentType="analysisBar"
123
+ expressionLevels={['0', { label: 'Cutoff', position: 20 }, '100']}
124
+ segments={segments}
125
+ />
126
+ ```
127
+
128
+ `expressionLabels[i]`, when present, still overrides the displayed text of the i-th level while its position is unchanged.
129
+
102
130
  ---
103
131
 
104
132
  ## Usage examples
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunit/oui",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "validate-branch-name": {
5
5
  "pattern": "^(main|develop)|(feature|fix|release|hotfix|qe)/.+$",
6
6
  "errorMsg": "The branch name is not correct. Please check the pattern. (ex. feature/add-something)"