Files
threetwo/src/client/components/shared/Canvas.tsx
Rishi Ghan c03f706e9d Dark mode 2 (#100)
* 🗂️ Added tab icons and styles

* 🪑 Styled download panel table

* 🪑 Cleaned up the DC++ search results table

* 🪑 Many changes to DC++ downloads table

* 🏗️ Wired up search with RQ

* 🏗️ Changes to ComicDetail section

* 🔧 Fixing table styes

* 🏗 Fixed the archive ops panel

* 🔧 Tweaked Archive ops further

* 🃏 Styling the action menu

* 🧩 CV Match panel refactor WIP

* 🏗️ Refactored the action menu

* 🤼 Cleaning up CV match panel

* 🏗️ Refactored the scored matches

* 🤼 Revamped CV match panel UX

* 🖌️ Styling tweaks to the side panel

* 🖌️ Cleaned up the form

* 🏗️ Refactored the search form

* 🤐 Added a uncompress indicator

* 🏗️ Fix for encoding # in URIs

* 🔧 Fixed # symbol handling in URLs

* 🔧 Started work on Edit Metadata panel

* 🔎 Added a check for existing uncompressed archives

* 🏗️ Settings styling tweaks

* 🏗️ Fixed invalidation of archiveOps

* 🏗️ Fixed an invalidation query on DC++ download panel

* 🏗️ Fixed CV-sourced Volume info panel

* 🏗️ Fixed volume group card stacks on Dashboard

* 🔍 Fixing CV search page

* 🏗️ Refactoring Volume groups and wanted panel

* 🏗️ Cleaning up useless files

* 🛝 Added keen-slider for pull list

* 🏗️ Abstracted heading/subheading into Header

* 🏗️ Continued refactoring of PullList, Volumes etc.

* 📆 Wired up the datepicker to LoCG pull list
2024-02-06 05:58:56 -05:00

74 lines
2.0 KiB
TypeScript

import React, { useEffect, useRef } from "react";
export const Canvas = ({ data }) => {
const { colorHistogramData } = data;
const width = 559;
const height = 200;
const pixelRatio = window.devicePixelRatio;
const canvas = useRef(null);
useEffect(() => {
const context = canvas.current?.getContext("2d");
if (!context) {
return;
}
context.scale(pixelRatio, pixelRatio);
const guideHeight = 8;
const startY = height - guideHeight;
const dx = width / 256;
const dy = startY / colorHistogramData.maxBrightness;
context.lineWidth = dx;
context.fillStyle = "transparent";
context.fillRect(0, 0, width, height);
for (let i = 0; i < 256; i++) {
const x = i * dx;
// Red
context.strokeStyle = "rgba(220,0,0,0.5)";
context.beginPath();
context.moveTo(x, startY);
context.lineTo(x, startY - colorHistogramData.r[i] / 10);
context.closePath();
context.stroke();
// Green
context.strokeStyle = "rgba(0,210,0,0.5)";
context.beginPath();
context.moveTo(x, startY);
context.lineTo(x, startY - colorHistogramData.g[i] / 10);
context.closePath();
context.stroke();
// Blue
context.strokeStyle = "rgba(0,0,255,0.5)";
context.beginPath();
context.moveTo(x, startY);
context.lineTo(x, startY - colorHistogramData.b[i] / 10);
context.closePath();
context.stroke();
// Guide
context.strokeStyle = `rgb(${i}, ${i}, ${i})`;
context.beginPath();
context.moveTo(x, startY);
context.lineTo(x, height);
context.closePath();
context.stroke();
}
// Cleanup function
return () => {
// Perform cleanup actions here
};
}, [colorHistogramData, pixelRatio]);
const dw = Math.floor(pixelRatio * width);
const dh = Math.floor(pixelRatio * height);
const style = { width, height };
return <canvas ref={canvas} width={dw} height={dh} style={style} />;
};
export default Canvas;