{"id":23779297,"url":"https://github.com/kubohiroya/webgpu-react-bitmap-viewport","last_synced_at":"2026-03-09T15:33:13.650Z","repository":{"id":244667716,"uuid":"815893845","full_name":"kubohiroya/webgpu-react-bitmap-viewport","owner":"kubohiroya","description":"a React component that uses WebGPU to render bitmap data within a set of viewports synchronously, including Schelling's Segregation Model simulator as its example","archived":false,"fork":false,"pushed_at":"2025-03-14T19:27:23.000Z","size":8960,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-17T20:49:53.733Z","etag":null,"topics":["bitmap-image","mit","react","reactjs","reactjs-components","schelling-model","viewport","webgpu","wgsl"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kubohiroya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-16T12:58:48.000Z","updated_at":"2025-08-02T13:34:28.000Z","dependencies_parsed_at":"2024-06-28T14:57:06.899Z","dependency_job_id":"50e6771b-051e-4052-ac75-aad5fb7a0b0a","html_url":"https://github.com/kubohiroya/webgpu-react-bitmap-viewport","commit_stats":null,"previous_names":["kubohiroya/webgpu-react-grid","kubohiroya/webgpu-react-bitmap-viewport"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kubohiroya/webgpu-react-bitmap-viewport","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubohiroya%2Fwebgpu-react-bitmap-viewport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubohiroya%2Fwebgpu-react-bitmap-viewport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubohiroya%2Fwebgpu-react-bitmap-viewport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubohiroya%2Fwebgpu-react-bitmap-viewport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubohiroya","download_url":"https://codeload.github.com/kubohiroya/webgpu-react-bitmap-viewport/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubohiroya%2Fwebgpu-react-bitmap-viewport/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30301109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T14:33:48.460Z","status":"ssl_error","status_checked_at":"2026-03-09T14:33:48.027Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitmap-image","mit","react","reactjs","reactjs-components","schelling-model","viewport","webgpu","wgsl"],"created_at":"2025-01-01T10:16:30.614Z","updated_at":"2026-03-09T15:33:13.623Z","avatar_url":"https://github.com/kubohiroya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebGPU-React-Bitmap-Viewport - a React component that uses WebGPU to render bitmap data within a set of viewports synchronously\n\n[![npm version](https://badge.fury.io/js/webgpu-react-bitmap-viewport.svg)](https://badge.fury.io/js/webgpu-react-bitmap-viewport)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n![animation](https://kubohiroya.github.io/webgpu-react-bitmap-viewport/examples/hokusai_demo_movie.gif)\n\n![animation](https://kubohiroya.github.io/webgpu-react-bitmap-viewport/examples/schelling_demo_movie.gif)\n\n- A React component displaying bitmap data as a set of viewport contents with use of WebGPU API, without dependencies other than React.\n- Dynamic synchronization of GPUBuffers from JavaScript image data (e.g., Uint32Array of RGBA color values).\n- Dynamic extraction and rendering a set of (one or more) viewport contents from GPUBuffers.\n- Interactive viewport navigation via mouse drag and scrollbar handling, as well as zoom in and out via the mouse wheel.\n- Customizable for bitmap image size, viewport display size, canvas size, header area size, and scrollbar size through React component props.\n- Highlights the column and row under the current mouse pointer.\n- Allows toggling the selected state of each column and row, and highlight the selected ones.\n\n# Download and Installation\n\nDownload the latest version of webgpu-react-bitmap-viewport from the npm repository:\n\n```bash\npnpm install webgpu-react-bitmap-viewport\n```\n# API\n\n[doc](https://kubohiroya.github.io/webgpu-react-bitmap-viewport/modules.html)\n\n# Live Demo\n\n```bash\ncd examples\npnpm install \u0026\u0026 pnpm dev\n```\n\n[Live demo](https://kubohiroya.github.io/webgpu-react-bitmap-viewport/examples/index.html)\n- Synchronized Viewports of Static Image: \"The Grate Wave off Kanagawa\" from the series Thirty-six Views of Mount Fuji by Hokusai\n- Synchronized Viewports of Dynamic Image: Randomly generated data\n- Viewport of Multi Agent Simulation: Schelling's model of segregation implemented with Vanilla-JS/WebGPU/WebAssembly\n\n# Code Example\n\n```tsx\nimport { Grid, GridHandles } from \"webgpu-react-bitmap-viewport\";\nimport { useRef } from \"react\";\n\nconst gridSize = { numColumns: 128, numRows: 128 };\n\nconst data =  new Float32Array(gridSize.numRows * gridSize.numColumns);\nfor (let i = 0; i \u003c data.length; i++) {\n  if (Math.random() \u003c 0.99) {\n    data[i] = i / data.length;\n  } else {\n    data[i] = Infinity;\n  }\n}\n\nconst focusedCellPosition = new Uint32Array([-1, -1]);\nconst selectedStates = new Uint32Array(Math.ceil(gridSize.numRows * gridSize.numColumns / 32));\n\nconst viewportStates = new Float32Array([\n  0.0, 0.0, 16.0, 16.0, // viewport index 0: left, top, right, bottom\n  8.0, 8.0, 24.0, 24.0, // viewport index 1: left, top, right, bottom\n]);\n\nexport const Index = () =\u003e {\n  const gridHandlerRefs =\n    [\n      useRef\u003cGridHandles\u003e(null),\n      useRef\u003cGridHandles\u003e(null)\n    ];\n\n  return (\n    \u003c\u003e\n      \u003cGrid\n        index={0}\n        ref={gridHandlerRefs[0]}\n        numViewports={2}\n        headerOffset={{ left: 10, top: 10 }}\n        canvasSize={{ width: 138, height: 138 }}\n        numColumns={gridSize.numColumns}\n        numRows={gridSize.numRows}\n        scrollBar={{\n          radius: 5.0,\n          margin: 2.0,\n        }}\n        data={data}\n        focusedCellPosition={focusedCellPosition}\n        selectedStates={selectedStates}\n        viewportStates={viewportStates}\n        onFocusedCellPositionChange={(sourceIndex: number, columnIndex: number, rowIndex: number) =\u003e {\n          gridHandlerRefs[1].current?.refreshFocusedCellPosition(sourceIndex, columnIndex, rowIndex);\n        }}\n        onSelectedStateChange={(sourceIndex:number, columnIndex: number, rowIndex: number) =\u003e {\n          gridHandlerRefs[1].current?.refreshSelectedState(sourceIndex, columnIndex, rowIndex);\n        }}\n        onViewportStateChange={(sourceIndex: number) =\u003e {\n          gridHandlerRefs[1].current?.refreshViewportState(sourceIndex);\n        }}\n      /\u003e\n      \u003cGrid\n        index={1}\n        ref={gridHandlerRefs[1]}\n        numViewports={2}\n        headerOffset={{ left: 10, top: 10 }}\n        canvasSize={{ width: 138, height: 138 }}\n        numColumns={gridSize.numColumns}\n        numRows={gridSize.numRows}\n        scrollBar={{\n          radius: 5.0,\n          margin: 2.0,\n        }}\n        data={data}\n        focusedCellPosition={focusedCellPosition}\n        selectedStates={selectedStates}\n        viewportStates={viewportStates}\n        onFocusedCellPositionChange={(sourceIndex: number, columnIndex: number, rowIndex: number) =\u003e {\n          gridHandlerRefs[0].current?.refreshFocusedCellPosition(sourceIndex, columnIndex, rowIndex);\n        }}\n        onSelectedStateChange={(sourceIndex: number, columnIndex: number, rowIndex: number) =\u003e {\n          gridHandlerRefs[0].current?.refreshSelectedState(sourceIndex, columnIndex, rowIndex);\n        }}\n        onViewportStateChange={(sourceIndex: number) =\u003e {\n          gridHandlerRefs[0].current?.refreshViewportState(sourceIndex);\n        }}\n      /\u003e\n    \u003c/\u003e\n  );\n}\n```\n# Design\n\n```mermaid\ngraph TD;\n        Application((Application))\n        Application --\u003e |width,height|canvasSize\n        Application --\u003e |numColumns,numRows|GridSize --\u003e GridProps\n        Application ==\u003e |numColumns*numRows|data\n        Application ==\u003e |left,top,right,bottom|viewportStates\n        Application ==\u003e focusedStates\n        Application ==\u003e selectedStates\n    data --\u003e|Float32Array| GridProps[GridProps]\n    focusedStates --\u003e |Uint32Array| GridProps\n    selectedStates --\u003e |Uint32Array| GridProps\n    viewportStates --\u003e |Float32Array| GridProps\n    canvasSize --\u003e GridProps\n    GridProps --\u003e |React Component Property| Grid\n    Application --\u003e |React Component|Grid\n```\n\n```mermaid\ngraph TD;\n        Application((Application)) --\u003e |refreshFocusedState|Grid\n        Application --\u003e |refreshSelectedState|Grid\n        Application --\u003e |refreshViewportState|Grid\n        Grid -.-\u003e |onFocusedStateChange|Application\n        Grid -.-\u003e |onSelectedStateChange|Application\n        Grid -.-\u003e |onViewportStateChange|Application\n```\n\n```mermaid\ngraph TD;\n    subgraph Inside React Component: part 1\n    GridProps ---\u003e |React Component Property| Grid\n        refreshFocusedState[/refreshFocusedState\\] -.-\u003e |React Component Method| Grid\n        refreshSelectedState[/refreshSelectedState\\] -.-\u003e |React Component Method| Grid\n        refreshViewportState[/refreshViewportState\\] -.-\u003e |React Component Method| Grid\n    Grid --\u003e |canvasSize|CanvasElementContext --\u003e GridUI\n    CanvasElementContext --\u003e |width,height|canvas\n    Grid --\u003e |refreshFocusedState,refreshSelectedState,refreshViewportState|GridUI\n    Grid --\u003e |gridSize|GridContext --\u003e GridUI\n    Grid --\u003e |viewportStates|ViewportGroupContext --\u003e GridUI     \n    Grid --\u003e WebGPUContext --\u003e |device,canvasContext,format,texture| GridUI\n    GridContext --\u003e GridUI\n    CanvasElementContext --\u003e WebGPUContext\n    GridContext --\u003e WebGPUContext\n    onMouseEnter[/onMouseEnter\\] -.-\u003e canvas\n    onMouseOut[/onMouseLeave\\] -.-\u003e canvas\n    onMouseDown[/onMouseDown\\] -.-\u003e canvas\n    onMouseMove[/onMouseMove\\] -.-\u003e canvas\n    end\n```\n```mermaid\ngraph TD;\n    subgraph Inside React Component: part 2    \n    GridUI --\u003e F32UniformBufferSource --\u003e GPUBuffer\n    GridUI --\u003e U32UniformBufferSource --\u003e GPUBuffer\n    GridUI --\u003e data --\u003e GPUBuffer\n    GridUI --\u003e focusedCellPosition --\u003e GPUBuffer\n    GridUI --\u003e selectedStates --\u003e GPUBuffer\n    GPUBindGroupLayout --\u003e GPUPipelineLayout\n    GPUPipelineLayout --\u003e GPURenderPipeline\n    WGSL[[WGSLGridShader]] --\u003e GPUShaderModule\n    GPUShaderModule --\u003e GPURenderPipeline\n    Vertices --\u003e GPUBuffer\n    GPUBuffer --\u003e GPUBindGroup\n    GPUBindGroupLayout --\u003e GPUBindGroup\n    GPURenderPipeline --\u003e GPURenderBundle\n    GPUBindGroup --\u003e GPURenderBundle\n    GridUI --\u003e GPUBindGroupLayout\n    GridUI --\u003e Vertices\n    GridUI --\u003e GPURenderPassEncoder\n    GPURenderBundle --\u003e GPURenderPassEncoder\n    GPURenderPassEncoder --\u003e |submit|GPUDevice\n    end\n```\n\n# Prerequisites:\n- WebGPU compatible browser (e.g. Chrome with WebGPU enabled)\n- react: `^18.2.0`\n- react-dom: `^18.2.0`\n\n# Licensing\n\nwebgpu-react-bitmap-viewport is published under the MIT License (MIT).\n\n(c) 2024 Hiroya Kubo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n# Author\n\nHiroya Kubo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubohiroya%2Fwebgpu-react-bitmap-viewport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubohiroya%2Fwebgpu-react-bitmap-viewport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubohiroya%2Fwebgpu-react-bitmap-viewport/lists"}