@cratis/components 0.1.14 → 0.1.16
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.
- package/dist/cjs/PivotViewer/PivotViewer.css +16 -3
- package/dist/cjs/PivotViewer/PivotViewer.js +34 -5
- package/dist/cjs/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotCanvas.js +0 -2
- package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js +4 -2
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/visibility.js +0 -20
- package/dist/cjs/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/cjs/PivotViewer/hooks/usePivotEngine.js +79 -75
- package/dist/cjs/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/cjs/PivotViewer/types.js.map +1 -1
- package/dist/cjs/PivotViewer/utils/animations.js +0 -16
- package/dist/cjs/PivotViewer/utils/animations.js.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.css +16 -3
- package/dist/esm/PivotViewer/PivotViewer.d.ts +1 -1
- package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.js +34 -5
- package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.stories.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.stories.js +5 -2
- package/dist/esm/PivotViewer/PivotViewer.stories.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.js +0 -2
- package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts +2 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.js +4 -2
- package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.js +0 -20
- package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.d.ts.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.js +0 -8
- package/dist/esm/PivotViewer/engine/pivot.worker.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePivotEngine.d.ts.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePivotEngine.js +80 -76
- package/dist/esm/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/esm/PivotViewer/types.d.ts +16 -0
- package/dist/esm/PivotViewer/types.d.ts.map +1 -1
- package/dist/esm/PivotViewer/types.js.map +1 -1
- package/dist/esm/PivotViewer/utils/animations.d.ts.map +1 -1
- package/dist/esm/PivotViewer/utils/animations.js +0 -16
- package/dist/esm/PivotViewer/utils/animations.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PivotViewerMain.js","sources":["../../../../PivotViewer/components/PivotViewerMain.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { ReactNode } from 'react';\nimport type { ItemId, LayoutResult, GroupingResult } from '../engine/types';\nimport type { ViewMode } from './Toolbar';\nimport type { PivotDimensionFilter } from '../hooks/useDimensionState';\nimport { Spinner } from './Spinner';\nimport { PivotCanvas } from './PivotCanvas';\nimport { AxisLabels } from './AxisLabels';\nimport { DetailPanel } from './DetailPanel';\n\nexport interface PivotViewerMainProps<TItem extends object> {\n data: TItem[];\n ready: boolean;\n isLoading: boolean;\n visibleIds: Uint32Array;\n grouping: GroupingResult;\n layout: LayoutResult;\n cardWidth: number;\n cardHeight: number;\n zoomLevel: number;\n scrollPosition: { x: number; y: number };\n containerDimensions: { width: number; height: number };\n selectedItem: TItem | null;\n hoveredGroupIndex: number | null;\n isZooming: boolean;\n viewMode: ViewMode;\n cardRenderer?: (item: TItem) => ReactNode;\n resolveId: (item: TItem, index: number) => ItemId;\n emptyContent?: ReactNode;\n dimensionFilter: PivotDimensionFilter;\n onCardClick: (item: TItem, e: MouseEvent, id: number | string) => void;\n onPanStart: (e: React.MouseEvent) => void;\n onPanMove: (e: React.MouseEvent) => void;\n onPanEnd: () => void;\n onGroupHover: (index: number | null) => void;\n onAxisLabelClick: (value: string) => void;\n onCloseDetail: () => void;\n containerRef: React.RefObject<HTMLDivElement | null>;\n axisLabelsRef: React.RefObject<HTMLDivElement | null>;\n spacerRef: React.RefObject<HTMLDivElement | null>;\n}\n\nexport function PivotViewerMain<TItem extends object>({\n data,\n ready,\n isLoading,\n visibleIds,\n grouping,\n layout,\n cardWidth,\n cardHeight,\n zoomLevel,\n scrollPosition,\n containerDimensions,\n selectedItem,\n hoveredGroupIndex,\n isZooming,\n viewMode,\n cardRenderer,\n resolveId,\n emptyContent,\n dimensionFilter,\n onCardClick,\n onPanStart,\n onPanMove,\n onPanEnd,\n onGroupHover,\n onAxisLabelClick,\n onCloseDetail,\n containerRef,\n axisLabelsRef,\n spacerRef,\n}: PivotViewerMainProps<TItem>) {\n const handleViewportClick = (e: React.MouseEvent) => {\n if (isZooming || !containerRef.current) return;\n\n const container = containerRef.current;\n const rect = container.getBoundingClientRect();\n // Use live DOM scroll position for accurate hit testing\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const clickX = e.clientX - rect.left + scrollLeft;\n const clickY = e.clientY - rect.top + scrollTop;\n\n const worldX = clickX / zoomLevel;\n const worldY = clickY / zoomLevel;\n\n // Check visible items\n for (let i = 0; i < visibleIds.length; i++) {\n const id = visibleIds[i];\n const pos = layout.positions.get(id);\n if (pos) {\n if (worldX >= pos.x && worldX <= pos.x + cardWidth &&\n worldY >= pos.y && worldY <= pos.y + cardHeight) {\n const item = data[id];\n if (item) {\n onCardClick(item, e.nativeEvent as unknown as MouseEvent, id);\n }\n return;\n }\n }\n }\n };\n\n const handleViewportMouseMove = (e: React.MouseEvent) => {\n if (isZooming || !containerRef.current) return;\n\n const container = containerRef.current;\n const rect = container.getBoundingClientRect();\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const mouseX = e.clientX - rect.left + scrollLeft;\n const mouseY = e.clientY - rect.top + scrollTop;\n\n const worldX = mouseX / zoomLevel;\n const worldY = mouseY / zoomLevel;\n\n let isOverCard = false;\n for (let i = 0; i < visibleIds.length; i++) {\n const id = visibleIds[i];\n const pos = layout.positions.get(id);\n if (pos) {\n if (worldX >= pos.x && worldX <= pos.x + cardWidth &&\n worldY >= pos.y && worldY <= pos.y + cardHeight) {\n isOverCard = true;\n break;\n }\n }\n }\n\n container.style.cursor = isOverCard ? 'pointer' : 'default';\n };\n\n return isLoading ? (\n <Spinner />\n ) : (\n <div className=\"pv-groups-wrapper\">\n <div style={{ position: 'relative', flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}>\n <div\n className={`pv-viewport ${isZooming ? 'pv-zooming' : ''}`}\n ref={containerRef}\n style={{ overflow: 'auto', position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}\n onClick={handleViewportClick}\n onMouseMove={handleViewportMouseMove}\n >\n {/* Spacer for scrolling - explicitly rendered to allow synchronous updates during animation */}\n <div\n ref={spacerRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: layout.totalWidth * zoomLevel,\n height: layout.totalHeight * zoomLevel,\n pointerEvents: 'none'\n }}\n />\n\n {!ready && (\n <div className=\"pv-loading\">Building indexes...</div>\n )}\n\n {ready && visibleIds.length === 0 && (\n <div className=\"pv-empty\">\n {emptyContent ?? 'No items to display.'}\n </div>\n )}\n\n {ready && visibleIds.length > 0 && (\n <PivotCanvas\n items={data}\n layout={layout}\n grouping={grouping}\n visibleIds={visibleIds}\n cardWidth={cardWidth}\n cardHeight={cardHeight}\n zoomLevel={zoomLevel}\n panX={scrollPosition.x}\n panY={scrollPosition.y}\n viewportWidth={containerDimensions.width}\n viewportHeight={containerDimensions.height}\n selectedId={selectedItem ? resolveId(selectedItem, 0) : null}\n hoveredGroupIndex={hoveredGroupIndex}\n isZooming={isZooming}\n cardRenderer={cardRenderer}\n resolveId={resolveId}\n onCardClick={onCardClick}\n onPanStart={onPanStart}\n onPanMove={onPanMove}\n onPanEnd={onPanEnd}\n containerRef={containerRef}\n viewMode={viewMode}\n />\n )}\n </div>\n <DetailPanel\n selectedItem={selectedItem}\n onClose={onCloseDetail}\n />\n </div>\n\n {viewMode === 'grouped' && grouping.groups.length > 0 && (\n <AxisLabels\n groups={grouping.groups.map((g) => ({\n key: g.key,\n value: g.value,\n label: String(g.value),\n items: [],\n count: g.ids.length,\n }))}\n bucketWidths={layout.bucketWidths || []}\n zoomLevel={zoomLevel}\n dimensionFilter={dimensionFilter}\n hoveredGroup={hoveredGroupIndex !== null ? String(grouping.groups[hoveredGroupIndex]?.value) : null}\n onHover={(label) => {\n const index = grouping.groups.findIndex(g => String(g.value) === label);\n onGroupHover(index >= 0 ? index : null);\n }}\n onClick={onAxisLabelClick}\n containerRef={axisLabelsRef}\n />\n )}\n </div>\n );\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;AA4CM,SAAU,eAAe,CAAuB,EACpD,IAAI,EACJ,KAAK,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAA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iBACpB,CAAC,CAAC,EACH,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE,EACvC,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,EACnG,OAAO,EAAE,CAAC,KAAK,KAAI;oBACjB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AACvE,oBAAA,YAAY,CAAC,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;AACzC,gBAAA,CAAC,EACD,OAAO,EAAE,gBAAgB,EACzB,YAAY,EAAE,aAAa,EAAA,CAC3B,CACH,CAAA,EAAA,CACG,CACP;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"PivotViewerMain.js","sources":["../../../../PivotViewer/components/PivotViewerMain.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { ReactNode } from 'react';\nimport type { ItemId, LayoutResult, GroupingResult } from '../engine/types';\nimport type { ViewMode } from './Toolbar';\nimport type { PivotDimensionFilter } from '../hooks/useDimensionState';\nimport { Spinner } from './Spinner';\nimport { PivotCanvas } from './PivotCanvas';\nimport { AxisLabels } from './AxisLabels';\nimport { DetailPanel } from './DetailPanel';\n\nexport interface PivotViewerMainProps<TItem extends object> {\n data: TItem[];\n ready: boolean;\n isLoading: boolean;\n visibleIds: Uint32Array;\n grouping: GroupingResult;\n layout: LayoutResult;\n cardWidth: number;\n cardHeight: number;\n zoomLevel: number;\n scrollPosition: { x: number; y: number };\n containerDimensions: { width: number; height: number };\n selectedItem: TItem | null;\n hoveredGroupIndex: number | null;\n isZooming: boolean;\n viewMode: ViewMode;\n cardRenderer?: (item: TItem) => ReactNode;\n /** Optional renderer for a custom details panel when a card is selected */\n detailRenderer?: (item: TItem, onClose: () => void) => ReactNode;\n resolveId: (item: TItem, index: number) => ItemId;\n emptyContent?: ReactNode;\n dimensionFilter: PivotDimensionFilter;\n onCardClick: (item: TItem, e: MouseEvent, id: number | string) => void;\n onPanStart: (e: React.MouseEvent) => void;\n onPanMove: (e: React.MouseEvent) => void;\n onPanEnd: () => void;\n onGroupHover: (index: number | null) => void;\n onAxisLabelClick: (value: string) => void;\n onCloseDetail: () => void;\n containerRef: React.RefObject<HTMLDivElement | null>;\n axisLabelsRef: React.RefObject<HTMLDivElement | null>;\n spacerRef: React.RefObject<HTMLDivElement | null>;\n}\n\nexport function PivotViewerMain<TItem extends object>({\n data,\n ready,\n isLoading,\n visibleIds,\n grouping,\n layout,\n cardWidth,\n cardHeight,\n zoomLevel,\n scrollPosition,\n containerDimensions,\n selectedItem,\n hoveredGroupIndex,\n isZooming,\n viewMode,\n cardRenderer,\n detailRenderer,\n resolveId,\n emptyContent,\n dimensionFilter,\n onCardClick,\n onPanStart,\n onPanMove,\n onPanEnd,\n onGroupHover,\n onAxisLabelClick,\n onCloseDetail,\n containerRef,\n axisLabelsRef,\n spacerRef,\n}: PivotViewerMainProps<TItem>) {\n const handleViewportClick = (e: React.MouseEvent) => {\n if (isZooming || !containerRef.current) return;\n\n const container = containerRef.current;\n const rect = container.getBoundingClientRect();\n // Use live DOM scroll position for accurate hit testing\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const clickX = e.clientX - rect.left + scrollLeft;\n const clickY = e.clientY - rect.top + scrollTop;\n\n const worldX = clickX / zoomLevel;\n const worldY = clickY / zoomLevel;\n\n // Check visible items\n for (let i = 0; i < visibleIds.length; i++) {\n const id = visibleIds[i];\n const pos = layout.positions.get(id);\n if (pos) {\n if (worldX >= pos.x && worldX <= pos.x + cardWidth &&\n worldY >= pos.y && worldY <= pos.y + cardHeight) {\n const item = data[id];\n if (item) {\n onCardClick(item, e.nativeEvent as unknown as MouseEvent, id);\n }\n return;\n }\n }\n }\n };\n\n const handleViewportMouseMove = (e: React.MouseEvent) => {\n if (isZooming || !containerRef.current) return;\n\n const container = containerRef.current;\n const rect = container.getBoundingClientRect();\n const scrollLeft = container.scrollLeft;\n const scrollTop = container.scrollTop;\n\n const mouseX = e.clientX - rect.left + scrollLeft;\n const mouseY = e.clientY - rect.top + scrollTop;\n\n const worldX = mouseX / zoomLevel;\n const worldY = mouseY / zoomLevel;\n\n let isOverCard = false;\n for (let i = 0; i < visibleIds.length; i++) {\n const id = visibleIds[i];\n const pos = layout.positions.get(id);\n if (pos) {\n if (worldX >= pos.x && worldX <= pos.x + cardWidth &&\n worldY >= pos.y && worldY <= pos.y + cardHeight) {\n isOverCard = true;\n break;\n }\n }\n }\n\n container.style.cursor = isOverCard ? 'pointer' : 'default';\n };\n\n return isLoading ? (\n <Spinner />\n ) : (\n <div className=\"pv-groups-wrapper\">\n <div style={{ position: 'relative', flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}>\n <div\n className={`pv-viewport ${isZooming ? 'pv-zooming' : ''}`}\n ref={containerRef}\n style={{ overflow: 'auto', position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}\n onClick={handleViewportClick}\n onMouseMove={handleViewportMouseMove}\n >\n {/* Spacer for scrolling - explicitly rendered to allow synchronous updates during animation */}\n <div\n ref={spacerRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: layout.totalWidth * zoomLevel,\n height: layout.totalHeight * zoomLevel,\n pointerEvents: 'none'\n }}\n />\n\n {!ready && (\n <div className=\"pv-loading\">Building indexes...</div>\n )}\n\n {ready && visibleIds.length === 0 && (\n <div className=\"pv-empty\">\n {emptyContent ?? 'No items to display.'}\n </div>\n )}\n\n {ready && visibleIds.length > 0 && (\n <PivotCanvas\n items={data}\n layout={layout}\n grouping={grouping}\n visibleIds={visibleIds}\n cardWidth={cardWidth}\n cardHeight={cardHeight}\n zoomLevel={zoomLevel}\n panX={scrollPosition.x}\n panY={scrollPosition.y}\n viewportWidth={containerDimensions.width}\n viewportHeight={containerDimensions.height}\n selectedId={selectedItem ? resolveId(selectedItem, 0) : null}\n hoveredGroupIndex={hoveredGroupIndex}\n isZooming={isZooming}\n cardRenderer={cardRenderer}\n resolveId={resolveId}\n onCardClick={onCardClick}\n onPanStart={onPanStart}\n onPanMove={onPanMove}\n onPanEnd={onPanEnd}\n containerRef={containerRef}\n viewMode={viewMode}\n />\n )}\n </div>\n {detailRenderer\n ? (selectedItem ? detailRenderer(selectedItem, onCloseDetail) : null)\n : (\n <DetailPanel\n selectedItem={selectedItem}\n onClose={onCloseDetail}\n />\n )}\n </div>\n\n {viewMode === 'grouped' && grouping.groups.length > 0 && (\n <AxisLabels\n groups={grouping.groups.map((g) => ({\n key: g.key,\n value: g.value,\n label: String(g.value),\n items: [],\n count: g.ids.length,\n }))}\n bucketWidths={layout.bucketWidths || []}\n zoomLevel={zoomLevel}\n dimensionFilter={dimensionFilter}\n hoveredGroup={hoveredGroupIndex !== null ? String(grouping.groups[hoveredGroupIndex]?.value) : null}\n onHover={(label) => {\n const index = grouping.groups.findIndex(g => String(g.value) === label);\n onGroupHover(index >= 0 ? index : null);\n }}\n onClick={onAxisLabelClick}\n containerRef={axisLabelsRef}\n />\n )}\n </div>\n );\n}\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;AA8CM,SAAU,eAAe,CAAuB,EACpD,IAAI,EACJ,KAAK,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,WAAW,EACX,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,aA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KAAK,EAAE,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,UAAU,CAAC;IAC5E,iBAAiB,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,KAAK,IAAI,CAAC;IAC7D,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,QA0SrE"}
|
|
@@ -5,14 +5,6 @@ function syncSpritesToViewport(params) {
|
|
|
5
5
|
const { root, container, sprites, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;
|
|
6
6
|
if (!root || !container)
|
|
7
7
|
return;
|
|
8
|
-
console.log('[syncSpritesToViewport] Called with', {
|
|
9
|
-
layoutPositionsSize: layout.positions.size,
|
|
10
|
-
visibleIdsSize: visibleIds.length,
|
|
11
|
-
spritesSize: sprites.size,
|
|
12
|
-
itemsLength: items.length,
|
|
13
|
-
isViewTransition,
|
|
14
|
-
zoomLevel
|
|
15
|
-
});
|
|
16
8
|
if (isViewTransition && (panDeltaX || panDeltaY)) {
|
|
17
9
|
const dx = (panDeltaX || 0) / (zoomLevel || 1);
|
|
18
10
|
const dy = (panDeltaY || 0) / (zoomLevel || 1);
|
|
@@ -163,22 +155,17 @@ function syncSpritesToViewport(params) {
|
|
|
163
155
|
}
|
|
164
156
|
const MAX_SPRITES_PER_FRAME = 50;
|
|
165
157
|
let createdCount = 0;
|
|
166
|
-
console.log('[syncSpritesToViewport] About to create sprites for inViewportIds:', inViewportIds.length);
|
|
167
|
-
console.log('[syncSpritesToViewport] layout.positions IDs:', Array.from(layout.positions.keys()));
|
|
168
158
|
for (const id of inViewportIds) {
|
|
169
159
|
const position = layout.positions.get(id);
|
|
170
160
|
if (!position) {
|
|
171
|
-
console.log('[syncSpritesToViewport] No position for id:', id, 'in layout.positions');
|
|
172
161
|
continue;
|
|
173
162
|
}
|
|
174
163
|
let sprite = sprites.get(id);
|
|
175
164
|
if (!sprite) {
|
|
176
165
|
if (createdCount >= MAX_SPRITES_PER_FRAME) {
|
|
177
|
-
console.log('[syncSpritesToViewport] Max sprites per frame reached');
|
|
178
166
|
continue;
|
|
179
167
|
}
|
|
180
168
|
createdCount++;
|
|
181
|
-
console.log('[syncSpritesToViewport] Creating sprite for id:', id, 'at position:', position);
|
|
182
169
|
let startX = position.x;
|
|
183
170
|
let startY = position.y;
|
|
184
171
|
let shouldAnimate = false;
|
|
@@ -214,10 +201,6 @@ function syncSpritesToViewport(params) {
|
|
|
214
201
|
}
|
|
215
202
|
}
|
|
216
203
|
if (sprite.targetX !== position.x || sprite.targetY !== position.y) {
|
|
217
|
-
console.log('[syncSpritesToViewport] Updating sprite target position for id:', id, 'from', {
|
|
218
|
-
oldX: sprite.targetX,
|
|
219
|
-
oldY: sprite.targetY
|
|
220
|
-
}, 'to', position);
|
|
221
204
|
if (isViewTransition) {
|
|
222
205
|
sprite.startX = sprite.currentX;
|
|
223
206
|
sprite.startY = sprite.currentY;
|
|
@@ -233,9 +216,6 @@ function syncSpritesToViewport(params) {
|
|
|
233
216
|
delete sprite.animationDelay;
|
|
234
217
|
}
|
|
235
218
|
}
|
|
236
|
-
else {
|
|
237
|
-
console.log('[syncSpritesToViewport] Sprite position unchanged for id:', id, 'at', position);
|
|
238
|
-
}
|
|
239
219
|
const item = items[Number(id)];
|
|
240
220
|
if (item) {
|
|
241
221
|
updateCardContent(sprite, item);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visibility.js","sources":["../../../../../PivotViewer/components/pivot/visibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as PIXI from 'pixi.js';\nimport type { CardSprite } from './constants';\nimport { CARD_GAP } from './constants';\nimport type { LayoutResult } from '../../engine/types';\nimport { destroySprite } from './sprites';\n\nexport interface SyncParams<TItem> {\n root: PIXI.Container | null;\n container: HTMLDivElement | null;\n sprites: Map<string | number, CardSprite>;\n layout: LayoutResult;\n visibleIds: Uint32Array;\n items: TItem[];\n cardWidth: number;\n cardHeight: number;\n panX: number;\n panY: number;\n panDeltaX?: number;\n panDeltaY?: number;\n viewportWidth: number;\n viewportHeight: number;\n zoomLevel: number;\n createCardSprite: (id: string | number, x: number, y: number) => CardSprite;\n updateCardContent: (sprite: CardSprite, item: TItem) => void;\n isViewTransition?: boolean;\n prevLayout?: LayoutResult | null;\n}\n\nexport function syncSpritesToViewport<TItem>(params: SyncParams<TItem>) {\n const { root, container, sprites, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;\n if (!root || !container) return;\n\n console.log('[syncSpritesToViewport] Called with', {\n layoutPositionsSize: layout.positions.size,\n visibleIdsSize: visibleIds.length,\n spritesSize: sprites.size,\n itemsLength: items.length,\n isViewTransition,\n zoomLevel\n });\n\n // `visibleIds` comes from callers but this module iterates `layout.positions`.\n // Keep a reference to avoid unused variable lint errors when callers include it.\n void visibleIds;\n\n // Apply pan delta to animating sprites to keep them visually stable during camera jumps\n if (isViewTransition && (panDeltaX || panDeltaY)) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n\n for (const sprite of sprites.values()) {\n if (sprite.animationStartTime !== undefined) {\n if (sprite.startX !== undefined) sprite.startX += dx;\n if (sprite.startY !== undefined) sprite.startY += dy;\n sprite.currentX += dx;\n sprite.currentY += dy;\n sprite.container?.position?.set(sprite.currentX, sprite.currentY);\n }\n }\n }\n\n const visibleSet = new Set<string | number>();\n\n // Increase buffer (in world units) to reduce edge cases where rapid\n // scrolling skips sprite creation. Keep buffer in world units and convert\n // DOM pixel measurements into world coordinates below to avoid mixing\n // coordinate spaces which can cause precision drift at browser zooms.\n const baseBufferWorld = Math.max(cardWidth, cardHeight) * 4;\n // Ensure buffer scales with viewport size (in world units) so that when\n // zoomed out we still pre-create enough sprites ahead of the viewport.\n const invScale = zoomLevel && zoomLevel !== 0 ? 1 / zoomLevel : 1;\n // The layout positions are in world units; when the root container is scaled\n // (zoomed) the rendered pixel position = position * zoomLevel. The DOM\n // scroll positions (`container.scrollLeft/Top`) are the authoritative pixel\n // camera offsets; prefer them over the passed `panX/panY` to avoid stale\n // values or race conditions between React state and direct DOM updates.\n const effectivePanX = typeof container.scrollLeft === 'number' ? container.scrollLeft : (panX || 0);\n const effectivePanY = typeof container.scrollTop === 'number' ? container.scrollTop : (panY || 0);\n\n // Convert pixel-based DOM measurements into world units so we compare like\n // with like. root.position is set using -pixels, so the mapping\n // from DOM scroll (pixels) to world units is: world = pixels / zoomLevel.\n const panWorldX = effectivePanX * invScale;\n const panWorldY = effectivePanY * invScale;\n\n // Use the container's measured client size for the viewport dimensions\n // (in pixels). The passed `viewportWidth`/`viewportHeight` can be stale\n // when the browser/device zoom changes; `clientWidth/clientHeight` are\n // authoritative for the actual visible pixel area.\n const viewportPxWidth = container.clientWidth || viewportWidth;\n const viewportPxHeight = container.clientHeight || viewportHeight;\n\n const viewportWorldWidth = viewportPxWidth * invScale;\n const viewportWorldHeight = viewportPxHeight * invScale;\n\n // Ensure bufferWorld is calculated from the actual measured viewport\n // in world units (after converting client pixel dims using invScale).\n // Make buffer adaptive to zoom: when zoomed out (invScale > 1) a small\n // pixel scroll maps to a larger world delta, so increase the buffer.\n // Use the larger of width/height to ensure we buffer enough in both directions.\n const bufferWorld = Math.max(baseBufferWorld * invScale, Math.max(viewportWorldWidth, viewportWorldHeight) * 2.0, baseBufferWorld);\n\n // Do not clamp viewport edges to 0 — allow negative top/left values so the\n // visible window correctly follows the scroll even when the buffer is\n // larger than the current scroll offset.\n const viewportLeftWorld = panWorldX - bufferWorld;\n const viewportRightWorld = panWorldX + viewportWorldWidth + bufferWorld;\n const viewportTopWorld = panWorldY - bufferWorld;\n const viewportBottomWorld = panWorldY + viewportWorldHeight + bufferWorld;\n\n const inViewportIds: (string | number)[] = [];\n // Small tolerance in world units to avoid floating-point edge cases when\n // browser/device zoom or high scroll values produce tiny rounding errors.\n // Scale epsilon with invScale so tolerance grows when zoomed out.\n const worldEpsilon = Math.max(0.5, 0.5 * invScale);\n\n // Iterate layout positions directly to avoid depending on `visibleIds`\n // which may be calculated in a different coordinate space or with\n // different assumptions about zoom. Looping the positions map is\n // deterministic and uses world coordinates directly.\n for (const [id, position] of layout.positions) {\n if (!position) continue;\n const worldX = position.x;\n const worldY = position.y;\n const worldCardW = cardWidth;\n const worldCardH = cardHeight;\n\n if (\n worldX + worldCardW >= viewportLeftWorld - worldEpsilon &&\n worldX <= viewportRightWorld + worldEpsilon &&\n worldY + worldCardH >= viewportTopWorld - worldEpsilon &&\n worldY <= viewportBottomWorld + worldEpsilon\n ) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n\n // Ensure last rows are present when the user scrolls near the bottom.\n // Compute slot/row information and force-insert IDs from the last few\n // rows to avoid missing tiles due to rounding/precision at zoom levels.\n try {\n const slotHeight = cardHeight + (CARD_GAP || 8);\n const totalRows = Math.ceil((layout.totalHeight || 0) / slotHeight) || 0;\n // Determine how many rows are visible in the viewport (world units),\n // then prefetch a fraction of that adjusted by zoom (invScale).\n const rowsVisible = Math.max(1, Math.ceil(viewportWorldHeight / slotHeight));\n const prefetchMultiplier = 0.75; // fraction of viewport to prefetch\n const prefetchRows = Math.max(2, Math.ceil(rowsVisible * prefetchMultiplier * Math.max(1, invScale)));\n const lastRowThresholdY = Math.max(0, (totalRows - prefetchRows) * slotHeight);\n for (const [id, position] of layout.positions) {\n if (position.y >= lastRowThresholdY) {\n if (!visibleSet.has(id)) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n }\n } catch (e) {\n void e;\n }\n\n // If we detect a very large discrepancy between created sprites and the\n // computed in-viewport count, that's a signal our culling math may be\n // unstable (especially at non-100% zoom). In that case, skip hiding this\n // frame as a conservative safeguard to avoid mass disappearing tiles.\n // However, disable this safeguard during view transitions to ensure old sprites are cleaned up.\n // EXCEPT: During view transitions, if scroll position hasn't stabilized yet (e.g., switching to grouped\n // mode triggers a scroll-to-bottom), keep all sprites visible to prevent flickering\n const scrollStabilized = Math.abs(panWorldY - (container.scrollTop * invScale)) < 10;\n const aggressiveCull = (!isViewTransition && sprites.size > Math.max(120, Math.ceil(inViewportIds.length * 1.5))) || \n (isViewTransition && !scrollStabilized);\n\n for (const [id, sprite] of sprites) {\n if (!visibleSet.has(id)) {\n // If view transition is active, check if this sprite has a valid target in the new layout\n // If so, keep it visible and animate it to the new position (even if off-screen)\n if (isViewTransition && layout.positions.has(id)) {\n const newPos = layout.positions.get(id);\n if (newPos) {\n sprite.targetX = newPos.x;\n sprite.targetY = newPos.y;\n\n // Trigger animation if not already animating\n if (sprite.animationStartTime === undefined) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n // Don't mark as hidden, so it won't be swept\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n continue;\n }\n }\n\n if (aggressiveCull) {\n // Keep sprite visible this frame to avoid visual holes\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n continue;\n }\n\n try {\n if (sprite.container) {\n sprite.container.visible = false;\n }\n (sprite as unknown as { __lastHiddenAt: number }).__lastHiddenAt = Date.now();\n } catch (e) {\n void e;\n }\n } else {\n try {\n if (sprite.container) {\n sprite.container.visible = true;\n }\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n } catch (e) { void e; }\n }\n }\n\n // Sweep: actually destroy sprites that have been hidden longer than threshold\n try {\n const SWEEP_MS = 100; // keep hidden sprites for 100ms before destruction (reduced from 500ms for faster mode transitions)\n const now = Date.now();\n for (const [id, sprite] of sprites) {\n const lastHidden = (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n if (lastHidden && now - lastHidden > SWEEP_MS) {\n try {\n // remove from parent if present\n if (sprite.container && sprite.container.parent) sprite.container.parent.removeChild(sprite.container);\n } catch (e) {\n void e;\n }\n try {\n destroySprite(sprite);\n } catch (e) {\n void e;\n }\n sprites.delete(id);\n }\n }\n } catch (e) {\n void e;\n }\n\n // Limit the number of sprites created per frame to avoid choking the GPU/CPU\n // when scrolling rapidly or zooming out significantly.\n const MAX_SPRITES_PER_FRAME = 50;\n let createdCount = 0;\n\n console.log('[syncSpritesToViewport] About to create sprites for inViewportIds:', inViewportIds.length);\n console.log('[syncSpritesToViewport] layout.positions IDs:', Array.from(layout.positions.keys()));\n\n for (const id of inViewportIds) {\n const position = layout.positions.get(id);\n if (!position) {\n console.log('[syncSpritesToViewport] No position for id:', id, 'in layout.positions');\n continue;\n }\n\n let sprite = sprites.get(id);\n if (!sprite) {\n if (createdCount >= MAX_SPRITES_PER_FRAME) {\n console.log('[syncSpritesToViewport] Max sprites per frame reached');\n continue;\n }\n createdCount++;\n\n console.log('[syncSpritesToViewport] Creating sprite for id:', id, 'at position:', position);\n\n let startX = position.x;\n let startY = position.y;\n let shouldAnimate = false;\n\n // If view transition, try to find old position to fly in from\n if (isViewTransition && prevLayout && prevLayout.positions.has(id)) {\n const oldPos = prevLayout.positions.get(id);\n if (oldPos) {\n startX = oldPos.x;\n startY = oldPos.y;\n\n // If we have a pan delta (camera jump), we need to adjust the start position\n // so that the sprite appears at the same visual location relative to the NEW camera.\n // StartWorld = OldWorld + PanDelta\n if (panDeltaX || panDeltaY) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n startX += dx;\n startY += dy;\n }\n\n shouldAnimate = true;\n }\n }\n\n sprite = createCardSprite(id, startX, startY);\n sprites.set(id, sprite);\n if (sprite.container) {\n root.addChild(sprite.container);\n sprite.currentX = startX;\n sprite.currentY = startY;\n // Keep sprite.container positioned in world units; animation/update\n // loop will apply root.scale/position to convert to pixels.\n sprite.container.position.set(startX, startY);\n }\n\n if (shouldAnimate) {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.startX = startX;\n sprite.startY = startY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n }\n\n // Check if target changed to trigger animation\n if (sprite.targetX !== position.x || sprite.targetY !== position.y) {\n console.log('[syncSpritesToViewport] Updating sprite target position for id:', id, 'from', {\n oldX: sprite.targetX,\n oldY: sprite.targetY\n }, 'to', position);\n if (isViewTransition) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.animationStartTime = Date.now();\n // Add random delay for \"organic\" fly effect\n sprite.animationDelay = Math.random() * 300;\n } else {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n delete sprite.animationStartTime;\n delete sprite.animationDelay;\n }\n } else {\n console.log('[syncSpritesToViewport] Sprite position unchanged for id:', id, 'at', position);\n }\n\n const item = items[Number(id)];\n if (item) {\n updateCardContent(sprite, item);\n }\n }\n}\n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AC3B,gBAAA,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE;gBAEtC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG;YAC/C;iBAAO;AACH,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;gBAC3B,OAAO,MAAM,CAAC,kBAAkB;gBAChC,OAAO,MAAM,CAAC,cAAc;YAChC;QACJ;aAAO;YACH,OAAO,CAAC,GAAG,CAAC,2DAA2D,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC;QAChG;QAEA,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,IAAI,EAAE;AACN,YAAA,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;QACnC;IACJ;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"visibility.js","sources":["../../../../../PivotViewer/components/pivot/visibility.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport * as PIXI from 'pixi.js';\nimport type { CardSprite } from './constants';\nimport { CARD_GAP } from './constants';\nimport type { LayoutResult } from '../../engine/types';\nimport { destroySprite } from './sprites';\n\nexport interface SyncParams<TItem> {\n root: PIXI.Container | null;\n container: HTMLDivElement | null;\n sprites: Map<string | number, CardSprite>;\n layout: LayoutResult;\n visibleIds: Uint32Array;\n items: TItem[];\n cardWidth: number;\n cardHeight: number;\n panX: number;\n panY: number;\n panDeltaX?: number;\n panDeltaY?: number;\n viewportWidth: number;\n viewportHeight: number;\n zoomLevel: number;\n createCardSprite: (id: string | number, x: number, y: number) => CardSprite;\n updateCardContent: (sprite: CardSprite, item: TItem) => void;\n isViewTransition?: boolean;\n prevLayout?: LayoutResult | null;\n}\n\nexport function syncSpritesToViewport<TItem>(params: SyncParams<TItem>) {\n const { root, container, sprites, layout, visibleIds, items, cardWidth, cardHeight, panX, panY, panDeltaX, panDeltaY, viewportWidth, viewportHeight, createCardSprite, updateCardContent, zoomLevel, isViewTransition, prevLayout } = params;\n if (!root || !container) return;\n\n // `visibleIds` comes from callers but this module iterates `layout.positions`.\n // Keep a reference to avoid unused variable lint errors when callers include it.\n void visibleIds;\n\n // Apply pan delta to animating sprites to keep them visually stable during camera jumps\n if (isViewTransition && (panDeltaX || panDeltaY)) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n\n for (const sprite of sprites.values()) {\n if (sprite.animationStartTime !== undefined) {\n if (sprite.startX !== undefined) sprite.startX += dx;\n if (sprite.startY !== undefined) sprite.startY += dy;\n sprite.currentX += dx;\n sprite.currentY += dy;\n sprite.container?.position?.set(sprite.currentX, sprite.currentY);\n }\n }\n }\n\n const visibleSet = new Set<string | number>();\n\n // Increase buffer (in world units) to reduce edge cases where rapid\n // scrolling skips sprite creation. Keep buffer in world units and convert\n // DOM pixel measurements into world coordinates below to avoid mixing\n // coordinate spaces which can cause precision drift at browser zooms.\n const baseBufferWorld = Math.max(cardWidth, cardHeight) * 4;\n // Ensure buffer scales with viewport size (in world units) so that when\n // zoomed out we still pre-create enough sprites ahead of the viewport.\n const invScale = zoomLevel && zoomLevel !== 0 ? 1 / zoomLevel : 1;\n // The layout positions are in world units; when the root container is scaled\n // (zoomed) the rendered pixel position = position * zoomLevel. The DOM\n // scroll positions (`container.scrollLeft/Top`) are the authoritative pixel\n // camera offsets; prefer them over the passed `panX/panY` to avoid stale\n // values or race conditions between React state and direct DOM updates.\n const effectivePanX = typeof container.scrollLeft === 'number' ? container.scrollLeft : (panX || 0);\n const effectivePanY = typeof container.scrollTop === 'number' ? container.scrollTop : (panY || 0);\n\n // Convert pixel-based DOM measurements into world units so we compare like\n // with like. root.position is set using -pixels, so the mapping\n // from DOM scroll (pixels) to world units is: world = pixels / zoomLevel.\n const panWorldX = effectivePanX * invScale;\n const panWorldY = effectivePanY * invScale;\n\n // Use the container's measured client size for the viewport dimensions\n // (in pixels). The passed `viewportWidth`/`viewportHeight` can be stale\n // when the browser/device zoom changes; `clientWidth/clientHeight` are\n // authoritative for the actual visible pixel area.\n const viewportPxWidth = container.clientWidth || viewportWidth;\n const viewportPxHeight = container.clientHeight || viewportHeight;\n\n const viewportWorldWidth = viewportPxWidth * invScale;\n const viewportWorldHeight = viewportPxHeight * invScale;\n\n // Ensure bufferWorld is calculated from the actual measured viewport\n // in world units (after converting client pixel dims using invScale).\n // Make buffer adaptive to zoom: when zoomed out (invScale > 1) a small\n // pixel scroll maps to a larger world delta, so increase the buffer.\n // Use the larger of width/height to ensure we buffer enough in both directions.\n const bufferWorld = Math.max(baseBufferWorld * invScale, Math.max(viewportWorldWidth, viewportWorldHeight) * 2.0, baseBufferWorld);\n\n // Do not clamp viewport edges to 0 — allow negative top/left values so the\n // visible window correctly follows the scroll even when the buffer is\n // larger than the current scroll offset.\n const viewportLeftWorld = panWorldX - bufferWorld;\n const viewportRightWorld = panWorldX + viewportWorldWidth + bufferWorld;\n const viewportTopWorld = panWorldY - bufferWorld;\n const viewportBottomWorld = panWorldY + viewportWorldHeight + bufferWorld;\n\n const inViewportIds: (string | number)[] = [];\n // Small tolerance in world units to avoid floating-point edge cases when\n // browser/device zoom or high scroll values produce tiny rounding errors.\n // Scale epsilon with invScale so tolerance grows when zoomed out.\n const worldEpsilon = Math.max(0.5, 0.5 * invScale);\n\n // Iterate layout positions directly to avoid depending on `visibleIds`\n // which may be calculated in a different coordinate space or with\n // different assumptions about zoom. Looping the positions map is\n // deterministic and uses world coordinates directly.\n for (const [id, position] of layout.positions) {\n if (!position) continue;\n const worldX = position.x;\n const worldY = position.y;\n const worldCardW = cardWidth;\n const worldCardH = cardHeight;\n\n if (\n worldX + worldCardW >= viewportLeftWorld - worldEpsilon &&\n worldX <= viewportRightWorld + worldEpsilon &&\n worldY + worldCardH >= viewportTopWorld - worldEpsilon &&\n worldY <= viewportBottomWorld + worldEpsilon\n ) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n\n // Ensure last rows are present when the user scrolls near the bottom.\n // Compute slot/row information and force-insert IDs from the last few\n // rows to avoid missing tiles due to rounding/precision at zoom levels.\n try {\n const slotHeight = cardHeight + (CARD_GAP || 8);\n const totalRows = Math.ceil((layout.totalHeight || 0) / slotHeight) || 0;\n // Determine how many rows are visible in the viewport (world units),\n // then prefetch a fraction of that adjusted by zoom (invScale).\n const rowsVisible = Math.max(1, Math.ceil(viewportWorldHeight / slotHeight));\n const prefetchMultiplier = 0.75; // fraction of viewport to prefetch\n const prefetchRows = Math.max(2, Math.ceil(rowsVisible * prefetchMultiplier * Math.max(1, invScale)));\n const lastRowThresholdY = Math.max(0, (totalRows - prefetchRows) * slotHeight);\n for (const [id, position] of layout.positions) {\n if (position.y >= lastRowThresholdY) {\n if (!visibleSet.has(id)) {\n inViewportIds.push(id);\n visibleSet.add(id);\n }\n }\n }\n } catch (e) {\n void e;\n }\n\n // If we detect a very large discrepancy between created sprites and the\n // computed in-viewport count, that's a signal our culling math may be\n // unstable (especially at non-100% zoom). In that case, skip hiding this\n // frame as a conservative safeguard to avoid mass disappearing tiles.\n // However, disable this safeguard during view transitions to ensure old sprites are cleaned up.\n // EXCEPT: During view transitions, if scroll position hasn't stabilized yet (e.g., switching to grouped\n // mode triggers a scroll-to-bottom), keep all sprites visible to prevent flickering\n const scrollStabilized = Math.abs(panWorldY - (container.scrollTop * invScale)) < 10;\n const aggressiveCull = (!isViewTransition && sprites.size > Math.max(120, Math.ceil(inViewportIds.length * 1.5))) || \n (isViewTransition && !scrollStabilized);\n\n for (const [id, sprite] of sprites) {\n if (!visibleSet.has(id)) {\n // If view transition is active, check if this sprite has a valid target in the new layout\n // If so, keep it visible and animate it to the new position (even if off-screen)\n if (isViewTransition && layout.positions.has(id)) {\n const newPos = layout.positions.get(id);\n if (newPos) {\n sprite.targetX = newPos.x;\n sprite.targetY = newPos.y;\n\n // Trigger animation if not already animating\n if (sprite.animationStartTime === undefined) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n // Don't mark as hidden, so it won't be swept\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n continue;\n }\n }\n\n if (aggressiveCull) {\n // Keep sprite visible this frame to avoid visual holes\n try { if (sprite.container) sprite.container.visible = true; } catch (e) { void e; }\n continue;\n }\n\n try {\n if (sprite.container) {\n sprite.container.visible = false;\n }\n (sprite as unknown as { __lastHiddenAt: number }).__lastHiddenAt = Date.now();\n } catch (e) {\n void e;\n }\n } else {\n try {\n if (sprite.container) {\n sprite.container.visible = true;\n }\n if ((sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt) delete (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n } catch (e) { void e; }\n }\n }\n\n // Sweep: actually destroy sprites that have been hidden longer than threshold\n try {\n const SWEEP_MS = 100; // keep hidden sprites for 100ms before destruction (reduced from 500ms for faster mode transitions)\n const now = Date.now();\n for (const [id, sprite] of sprites) {\n const lastHidden = (sprite as unknown as { __lastHiddenAt?: number }).__lastHiddenAt;\n if (lastHidden && now - lastHidden > SWEEP_MS) {\n try {\n // remove from parent if present\n if (sprite.container && sprite.container.parent) sprite.container.parent.removeChild(sprite.container);\n } catch (e) {\n void e;\n }\n try {\n destroySprite(sprite);\n } catch (e) {\n void e;\n }\n sprites.delete(id);\n }\n }\n } catch (e) {\n void e;\n }\n\n // Limit the number of sprites created per frame to avoid choking the GPU/CPU\n // when scrolling rapidly or zooming out significantly.\n const MAX_SPRITES_PER_FRAME = 50;\n let createdCount = 0;\n\n\n for (const id of inViewportIds) {\n const position = layout.positions.get(id);\n if (!position) {\n continue;\n }\n\n let sprite = sprites.get(id);\n if (!sprite) {\n if (createdCount >= MAX_SPRITES_PER_FRAME) {\n continue;\n }\n createdCount++;\n\n let startX = position.x;\n let startY = position.y;\n let shouldAnimate = false;\n\n // If view transition, try to find old position to fly in from\n if (isViewTransition && prevLayout && prevLayout.positions.has(id)) {\n const oldPos = prevLayout.positions.get(id);\n if (oldPos) {\n startX = oldPos.x;\n startY = oldPos.y;\n\n // If we have a pan delta (camera jump), we need to adjust the start position\n // so that the sprite appears at the same visual location relative to the NEW camera.\n // StartWorld = OldWorld + PanDelta\n if (panDeltaX || panDeltaY) {\n const dx = (panDeltaX || 0) / (zoomLevel || 1);\n const dy = (panDeltaY || 0) / (zoomLevel || 1);\n startX += dx;\n startY += dy;\n }\n\n shouldAnimate = true;\n }\n }\n\n sprite = createCardSprite(id, startX, startY);\n sprites.set(id, sprite);\n if (sprite.container) {\n root.addChild(sprite.container);\n sprite.currentX = startX;\n sprite.currentY = startY;\n // Keep sprite.container positioned in world units; animation/update\n // loop will apply root.scale/position to convert to pixels.\n sprite.container.position.set(startX, startY);\n }\n\n if (shouldAnimate) {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.startX = startX;\n sprite.startY = startY;\n sprite.animationStartTime = Date.now();\n sprite.animationDelay = Math.random() * 300;\n }\n }\n\n // Check if target changed to trigger animation\n if (sprite.targetX !== position.x || sprite.targetY !== position.y) {\n if (isViewTransition) {\n sprite.startX = sprite.currentX;\n sprite.startY = sprite.currentY;\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n sprite.animationStartTime = Date.now();\n // Add random delay for \"organic\" fly effect\n sprite.animationDelay = Math.random() * 300;\n } else {\n sprite.targetX = position.x;\n sprite.targetY = position.y;\n delete sprite.animationStartTime;\n delete sprite.animationDelay;\n }\n }\n\n const item = items[Number(id)];\n if (item) {\n updateCardContent(sprite, item);\n }\n }\n}\n"],"names":[],"mappings":";;;AA+BM,SAAU,qBAAqB,CAAQ,MAAyB,EAAA;AAClE,IA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AQ,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,EAAE;YAChE,IAAI,gBAAgB,EAAE;AAClB,gBAAA,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;AAC/B,gBAAA,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ;AAC/B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE;gBAEtC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG;YAC/C;iBAAO;AACH,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;AAC3B,gBAAA,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC;gBAC3B,OAAO,MAAM,CAAC,kBAAkB;gBAChC,OAAO,MAAM,CAAC,cAAc;YAChC;QACJ;QAEA,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,IAAI,EAAE;AACN,YAAA,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC;QACnC;IACJ;AACJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pivot.worker.d.ts","sourceRoot":"","sources":["../../../../PivotViewer/engine/pivot.worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pivot.worker.d.ts","sourceRoot":"","sources":["../../../../PivotViewer/engine/pivot.worker.ts"],"names":[],"mappings":"AA+FA,OAAO,EAAE,CAAC"}
|
|
@@ -3,25 +3,20 @@ let store = null;
|
|
|
3
3
|
let indexes = null;
|
|
4
4
|
self.onmessage = (e) => {
|
|
5
5
|
const message = e.data;
|
|
6
|
-
console.log('[Worker] Received message:', message.type);
|
|
7
6
|
switch (message.type) {
|
|
8
7
|
case 'buildIndexes': {
|
|
9
|
-
console.log('[Worker] Building indexes for', message.store.items.length, 'items');
|
|
10
8
|
const fieldsArray = message.store.fields;
|
|
11
9
|
const fieldsMap = new Map(fieldsArray);
|
|
12
10
|
store = {
|
|
13
11
|
...message.store,
|
|
14
12
|
fields: fieldsMap,
|
|
15
13
|
};
|
|
16
|
-
console.log('[Worker] Store converted, fields:', Array.from(fieldsMap.keys()));
|
|
17
14
|
if (store) {
|
|
18
15
|
indexes = buildIndexes(store, message.fields);
|
|
19
|
-
console.log('[Worker] Indexes built');
|
|
20
16
|
const response = {
|
|
21
17
|
type: 'indexesReady',
|
|
22
18
|
indexes,
|
|
23
19
|
};
|
|
24
|
-
console.log('[Worker] Posting indexesReady');
|
|
25
20
|
self.postMessage(response);
|
|
26
21
|
}
|
|
27
22
|
break;
|
|
@@ -44,14 +39,11 @@ self.onmessage = (e) => {
|
|
|
44
39
|
console.error('[Worker] Store or indexes not initialized');
|
|
45
40
|
return;
|
|
46
41
|
}
|
|
47
|
-
console.log('[Worker] Computing grouping for', message.visibleIds.length, 'items, groupBy:', message.groupBy);
|
|
48
42
|
const result = computeGrouping(store, indexes, message.visibleIds, message.groupBy);
|
|
49
|
-
console.log('[Worker] Grouping computed:', result.groups.length, 'groups');
|
|
50
43
|
const response = {
|
|
51
44
|
type: 'groupingResult',
|
|
52
45
|
result,
|
|
53
46
|
};
|
|
54
|
-
console.log('[Worker] Posting groupingResult');
|
|
55
47
|
self.postMessage(response);
|
|
56
48
|
break;
|
|
57
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pivot.worker.js","sourceRoot":"","sources":["../../../../PivotViewer/engine/pivot.worker.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE/E,IAAI,KAAK,GAAsB,IAAI,CAAC;AACpC,IAAI,OAAO,GAAwB,I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AAC;IACf,YAAY,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC/D,eAAe,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1F,OAAO,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,CAAC;CAC5E;AAED,wBAAgB,cAAc,CAAC,KAAK,SAAS,MAAM,EAAE,EACnD,IAAI,EACJ,eAAe,EACf,WAAW,GACZ,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAAG,oBAAoB,CAiQrD"}
|
|
@@ -1,94 +1,106 @@
|
|
|
1
1
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { buildStore, buildIndexes, applyFilters, computeGrouping, sortIds } from '../engine/store.js';
|
|
3
3
|
|
|
4
4
|
function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
5
5
|
const [ready, setReady] = useState(false);
|
|
6
|
+
const [workerAvailable, setWorkerAvailable] = useState(false);
|
|
6
7
|
const workerRef = useRef(null);
|
|
7
8
|
const indexesRef = useRef(null);
|
|
8
9
|
const fallbackRef = useRef(false);
|
|
9
10
|
const storeRef = useRef(null);
|
|
10
11
|
const pendingCallbacksRef = useRef(new Map());
|
|
11
12
|
useEffect(() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.warn('[PivotEngine] No callback registered for filter result - ignoring duplicate message');
|
|
13
|
+
if (typeof window === 'undefined' || typeof Worker === 'undefined') {
|
|
14
|
+
fallbackRef.current = true;
|
|
15
|
+
setWorkerAvailable(false);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const workerUrl = new URL('../engine/pivot.worker.js', import.meta.url);
|
|
19
|
+
let disposed = false;
|
|
20
|
+
const enableFallback = () => {
|
|
21
|
+
fallbackRef.current = true;
|
|
22
|
+
workerRef.current = null;
|
|
23
|
+
setWorkerAvailable(false);
|
|
24
|
+
};
|
|
25
|
+
const setupWorker = async () => {
|
|
26
|
+
try {
|
|
27
|
+
if (typeof fetch === 'function') {
|
|
28
|
+
const response = await fetch(workerUrl, { method: 'HEAD' });
|
|
29
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
30
|
+
if (!response.ok || !contentType.includes('javascript')) {
|
|
31
|
+
enableFallback();
|
|
32
|
+
return;
|
|
33
33
|
}
|
|
34
|
-
break;
|
|
35
34
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
enableFallback();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (disposed) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const worker = new Worker(workerUrl, { type: 'module' });
|
|
44
|
+
workerRef.current = worker;
|
|
45
|
+
setWorkerAvailable(true);
|
|
46
|
+
worker.onmessage = (e) => {
|
|
47
|
+
const message = e.data;
|
|
48
|
+
switch (message.type) {
|
|
49
|
+
case 'indexesReady':
|
|
50
|
+
setReady(true);
|
|
51
|
+
break;
|
|
52
|
+
case 'filterResult': {
|
|
53
|
+
const callback = pendingCallbacksRef.current.get('filter');
|
|
54
|
+
if (callback) {
|
|
55
|
+
callback(message.result);
|
|
56
|
+
pendingCallbacksRef.current.delete('filter');
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'groupingResult': {
|
|
61
|
+
const callback = pendingCallbacksRef.current.get('grouping');
|
|
62
|
+
if (callback) {
|
|
63
|
+
callback(message.result);
|
|
64
|
+
pendingCallbacksRef.current.delete('grouping');
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
43
67
|
}
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
case 'sortResult': {
|
|
69
|
+
const callback = pendingCallbacksRef.current.get('sort');
|
|
70
|
+
if (callback) {
|
|
71
|
+
callback(message.result);
|
|
72
|
+
pendingCallbacksRef.current.delete('sort');
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
46
75
|
}
|
|
47
|
-
break;
|
|
48
76
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
};
|
|
78
|
+
worker.onerror = (error) => {
|
|
79
|
+
console.error('[PivotEngine] Worker error:', error);
|
|
80
|
+
enableFallback();
|
|
81
|
+
if (storeRef.current) {
|
|
82
|
+
try {
|
|
83
|
+
indexesRef.current = buildIndexes(storeRef.current, indexFields);
|
|
55
84
|
}
|
|
56
|
-
|
|
57
|
-
console.
|
|
85
|
+
catch (e) {
|
|
86
|
+
console.error('[PivotEngine] Failed to build indexes in fallback:', e);
|
|
87
|
+
indexesRef.current = null;
|
|
58
88
|
}
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
worker.onerror = (error) => {
|
|
64
|
-
console.error('[PivotEngine] Worker error:', error);
|
|
65
|
-
fallbackRef.current = true;
|
|
66
|
-
workerRef.current = null;
|
|
67
|
-
if (storeRef.current) {
|
|
68
|
-
try {
|
|
69
|
-
indexesRef.current = buildIndexes(storeRef.current, indexFields);
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
console.error('[PivotEngine] Failed to build indexes in fallback:', e);
|
|
73
|
-
indexesRef.current = null;
|
|
89
|
+
setReady(true);
|
|
74
90
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
91
|
+
};
|
|
77
92
|
};
|
|
93
|
+
void setupWorker();
|
|
78
94
|
return () => {
|
|
79
|
-
|
|
95
|
+
disposed = true;
|
|
96
|
+
workerRef.current?.terminate();
|
|
97
|
+
workerRef.current = null;
|
|
80
98
|
};
|
|
81
|
-
}, []);
|
|
99
|
+
}, [indexFields]);
|
|
82
100
|
useEffect(() => {
|
|
83
|
-
if (!workerRef.current) {
|
|
84
|
-
console.warn('[PivotEngine] Worker not available in data effect');
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
console.log('[PivotEngine] Building indexes for', data.length, 'items');
|
|
88
101
|
setReady(false);
|
|
89
102
|
const store = buildStore(data, fieldExtractors);
|
|
90
103
|
storeRef.current = store;
|
|
91
|
-
console.log('[PivotEngine] Store built with', store.items.length, 'items and', store.fields.size, 'fields');
|
|
92
104
|
try {
|
|
93
105
|
indexesRef.current = buildIndexes(store, indexFields);
|
|
94
106
|
}
|
|
@@ -96,7 +108,7 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
|
96
108
|
console.error('[PivotEngine] buildIndexes failed:', e);
|
|
97
109
|
indexesRef.current = null;
|
|
98
110
|
}
|
|
99
|
-
if (workerRef.current) {
|
|
111
|
+
if (workerRef.current && !fallbackRef.current) {
|
|
100
112
|
const fieldsArray = Array.from(store.fields.entries());
|
|
101
113
|
const serializableStore = {
|
|
102
114
|
...store,
|
|
@@ -107,13 +119,12 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
|
107
119
|
store: serializableStore,
|
|
108
120
|
fields: indexFields,
|
|
109
121
|
};
|
|
110
|
-
console.log('[PivotEngine] Posting buildIndexes with', fieldsArray.length, 'fields');
|
|
111
122
|
workerRef.current.postMessage(message);
|
|
112
123
|
}
|
|
113
124
|
else {
|
|
114
125
|
setReady(true);
|
|
115
126
|
}
|
|
116
|
-
}, [data, fieldExtractors, indexFields]);
|
|
127
|
+
}, [data, fieldExtractors, indexFields, workerAvailable]);
|
|
117
128
|
const applyFiltersCallback = useCallback((filters) => {
|
|
118
129
|
return new Promise((resolve) => {
|
|
119
130
|
if (!workerRef.current || fallbackRef.current) {
|
|
@@ -141,20 +152,16 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
|
141
152
|
});
|
|
142
153
|
}, [ready]);
|
|
143
154
|
const computeGroupingCallback = useCallback((visibleIds, groupBy) => {
|
|
144
|
-
console.log('[PivotEngine] computeGroupingCallback called with', visibleIds.length, 'visibleIds');
|
|
145
155
|
if (pendingCallbacksRef.current.has('grouping')) {
|
|
146
|
-
console.warn('[PivotEngine] Grouping already in progress, ignoring duplicate request');
|
|
147
156
|
return Promise.resolve({ groups: [] });
|
|
148
157
|
}
|
|
149
158
|
return new Promise((resolve) => {
|
|
150
159
|
if (!workerRef.current || fallbackRef.current) {
|
|
151
|
-
console.log('[PivotEngine] Using synchronous fallback for grouping');
|
|
152
160
|
try {
|
|
153
161
|
const store = storeRef.current;
|
|
154
162
|
const indexes = indexesRef.current;
|
|
155
163
|
if (store && indexes) {
|
|
156
164
|
const result = computeGrouping(store, indexes, visibleIds, groupBy);
|
|
157
|
-
console.log('[PivotEngine] Fallback grouping result:', result);
|
|
158
165
|
resolve(result);
|
|
159
166
|
return;
|
|
160
167
|
}
|
|
@@ -162,11 +169,9 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
|
162
169
|
catch (e) {
|
|
163
170
|
console.error('[PivotEngine] fallback computeGrouping error:', e);
|
|
164
171
|
}
|
|
165
|
-
console.warn('[PivotEngine] No store/indexes for fallback, returning empty');
|
|
166
172
|
resolve({ groups: [] });
|
|
167
173
|
return;
|
|
168
174
|
}
|
|
169
|
-
console.log('[PivotEngine] Setting grouping callback and posting to worker');
|
|
170
175
|
pendingCallbacksRef.current.set('grouping', resolve);
|
|
171
176
|
const message = {
|
|
172
177
|
type: 'computeGrouping',
|
|
@@ -174,7 +179,6 @@ function usePivotEngine({ data, fieldExtractors, indexFields, }) {
|
|
|
174
179
|
groupBy,
|
|
175
180
|
};
|
|
176
181
|
workerRef.current.postMessage(message);
|
|
177
|
-
console.log('[PivotEngine] Message posted to worker');
|
|
178
182
|
});
|
|
179
183
|
}, [ready]);
|
|
180
184
|
const sortIdsCallback = useCallback((visibleIds, sortBy) => {
|