UNPKG

react-financial-charts

Version:
39 lines 1.56 kB
import * as React from "react"; export function withDeviceRatio() { return (OriginalComponent) => { return class WithRatio extends React.Component { constructor() { super(...arguments); this.canvasRef = React.createRef(); } componentDidMount() { const { current } = this.canvasRef; if (current === null) { this.setState({ ratio: 1, }); } else { const context = current.getContext("2d"); const { devicePixelRatio } = window; const backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1; this.setState({ ratio: devicePixelRatio / backingStoreRatio, }); } } render() { const state = this.state; if (state !== null) { return (React.createElement(OriginalComponent, Object.assign({}, this.props, { ratio: state.ratio }))); } return (React.createElement("canvas", { ref: this.canvasRef })); } }; }; } //# sourceMappingURL=withDeviceRatio.js.map