Skip to content

Commit f877b65

Browse files
authored
Merge pull request #111 from Kitware/ondataavailable-callback
feat: onDataAvailable representation callback
2 parents 22a4948 + 0863e96 commit f877b65

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/core/Geometry2DRepresentation.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ export interface Geometry2DRepresentationProps extends PropsWithChildren {
6565
* The coordinate system in which the input dataset resides.
6666
*/
6767
transformCoordinate?: ICoordinateInitialValues;
68+
69+
/**
70+
* Event callback for when data is made available.
71+
*
72+
* By the time this callback is invoked, you can be sure that:
73+
* - the mapper has the input data
74+
* - the actor is visible (unless explicitly marked as not visible)
75+
* - initial properties are set
76+
*/
77+
onDataAvailable?: () => void;
6878
}
6979

7080
const DefaultProps = {
@@ -141,6 +151,16 @@ export default forwardRef(function Geometry2DRepresentation(
141151
([cur], [prev]) => compareShallowObject(cur, prev)
142152
);
143153

154+
// --- events --- //
155+
156+
const { onDataAvailable } = props;
157+
useEffect(() => {
158+
if (dataAvailable) {
159+
// trigger onDataAvailable after making updates to the actor and mapper
160+
onDataAvailable?.();
161+
}
162+
}, [dataAvailable, onDataAvailable]);
163+
144164
// --- //
145165

146166
const renderer = useRendererContext();

src/core/GeometryRepresentation.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export interface GeometryRepresentationProps extends PropsWithChildren {
8888
* TODO fix type
8989
*/
9090
scalarBarStyle?: Record<string, unknown>;
91+
92+
/**
93+
* Event callback for when data is made available.
94+
*
95+
* By the time this callback is invoked, you can be sure that:
96+
* - the mapper has the input data
97+
* - the actor is visible (unless explicitly marked as not visible)
98+
* - initial properties are set
99+
*/
100+
onDataAvailable?: () => void;
91101
}
92102

93103
const DefaultProps = {
@@ -154,6 +164,16 @@ export default forwardRef(function GeometryRepresentation(
154164
([cur], [prev]) => compareShallowObject(cur, prev)
155165
);
156166

167+
// --- events --- //
168+
169+
const { onDataAvailable } = props;
170+
useEffect(() => {
171+
if (dataAvailable) {
172+
// trigger onDataAvailable after making updates to the actor and mapper
173+
onDataAvailable?.();
174+
}
175+
}, [dataAvailable, onDataAvailable]);
176+
157177
// --- //
158178

159179
const renderer = useRendererContext();

src/core/SliceRepresentation.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ export interface SliceRepresentationProps extends PropsWithChildren {
9797
* index of the slice along z
9898
*/
9999
zSlice?: number;
100+
101+
/**
102+
* Event callback for when data is made available.
103+
*
104+
* By the time this callback is invoked, you can be sure that:
105+
* - the mapper has the input data
106+
* - the actor is visible (unless explicitly marked as not visible)
107+
* - initial properties are set
108+
*/
109+
onDataAvailable?: () => void;
100110
}
101111

102112
const DefaultProps = {
@@ -135,8 +145,6 @@ export default forwardRef(function SliceRepresentation(
135145
trackModified
136146
);
137147

138-
// --- PWF --- //
139-
140148
// --- mapper --- //
141149

142150
const getInternalMapper = useMapper(
@@ -243,6 +251,16 @@ export default forwardRef(function SliceRepresentation(
243251
}
244252
}, [kSlice, getMapper, trackModified]);
245253

254+
// --- events --- //
255+
256+
const { onDataAvailable } = props;
257+
useEffect(() => {
258+
if (dataAvailable) {
259+
// trigger onDataAvailable after making updates to the actor and mapper
260+
onDataAvailable?.();
261+
}
262+
}, [dataAvailable, onDataAvailable]);
263+
246264
// --- //
247265

248266
const renderer = useRendererContext();

0 commit comments

Comments
 (0)