mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-04 13:58:11 +08:00
* Added TS. Updated build and linting config. Added types. * [ts-migrate][.] Rename files from JS/JSX to TS/TSX Co-authored-by: ts-migrate <> * [ts-migrate][.] Run TS Migrate Co-authored-by: ts-migrate <> * Corrected files mangled by ts-migrate. * Updated lint config, minor linting. * Re-enabled Husky. * Updated tests and config. * Reverted webpack devtool config. * Removed obsolete snapshots. * Added annotations snap. * Updated tsconfig includes wrt linting. * Removed ts-migrate. Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
This commit is contained in:
co-authored by
ts-migrate
Timmy Huang
parent
7328cbdbd5
commit
934cc5c69b
@@ -1,72 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
export default class MiniStackedBar extends React.PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.canvasRef = React.createRef();
|
||||
}
|
||||
|
||||
drawStacks = () => {
|
||||
const {
|
||||
domainValues,
|
||||
scale,
|
||||
domain,
|
||||
colorTable,
|
||||
occupancy,
|
||||
width,
|
||||
height,
|
||||
} = this.props;
|
||||
|
||||
if (!colorTable || !domainValues) return;
|
||||
|
||||
const { scale: colorScale } = colorTable;
|
||||
|
||||
const ctx = this.canvasRef?.current.getContext("2d");
|
||||
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
let currentOffset = 0;
|
||||
|
||||
let occupancyValue;
|
||||
let scaledValue;
|
||||
let value;
|
||||
|
||||
for (let i = 0, { length } = domainValues; i < length; i += 1) {
|
||||
value = domainValues[i];
|
||||
occupancyValue = occupancy.get(value);
|
||||
scaledValue = scale(occupancyValue);
|
||||
ctx.fillStyle = occupancyValue
|
||||
? colorScale(domain.indexOf(value))
|
||||
: "rgb(255,255,255)";
|
||||
ctx.fillRect(currentOffset, 0, occupancyValue ? scaledValue : 0, height);
|
||||
currentOffset += occupancyValue ? scaledValue : 0;
|
||||
}
|
||||
};
|
||||
|
||||
componentDidUpdate = (prevProps) => {
|
||||
const { occupancy } = this.props;
|
||||
if (occupancy !== prevProps.occupancy) this.drawStacks();
|
||||
};
|
||||
|
||||
componentDidMount = () => {
|
||||
this.drawStacks();
|
||||
};
|
||||
|
||||
render() {
|
||||
const { width, height } = this.props;
|
||||
const { canvas } = this;
|
||||
if (canvas) canvas.getContext("2d").clearRect(0, 0, width, height);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
style={{
|
||||
marginRight: 5,
|
||||
width,
|
||||
height,
|
||||
}}
|
||||
width={width}
|
||||
height={height}
|
||||
ref={this.canvasRef}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user