UNPKG

react-pixi-plot

Version:

A React component rendering a zoomable and draggable PIXI.js scene. Intended to render 2d plots

28 lines 1.09 kB
import React from 'react'; const defaultState = { draggablePosition: { x: 0, y: 0 }, zoomablePosition: { x: 0, y: 0 }, zoomableScale: { x: 1, y: 1 }, appHeight: 0, appWidth: 0, }; const reducer = (state = defaultState, action) => { switch (action.type) { case 'drag': return Object.assign({}, state, { draggablePosition: action.payload.position }); case 'zoom': return Object.assign({}, state, { zoomablePosition: action.payload.position, zoomableScale: action.payload.scale }); } return state; }; const DomPlotContext = React.createContext({}); const PlotContextProvider = (props) => { const [state, dispatch] = React.useReducer(reducer, defaultState); state.appHeight = props.appHeight; state.appWidth = props.appWidth; const value = { state, dispatch }; return React.createElement(DomPlotContext.Provider, { value: value }, props.children); }; const PixiPlotContext = React.createContext({}); export { DomPlotContext, PlotContextProvider, PixiPlotContext }; //# sourceMappingURL=PlotContext.js.map