import { HistoryNodeEvent , nodeEvent } from '@/store/history/types' ; import Visualization from './visualization' ; import { SubsetSelection } from '@/data/package' ; import { getNode } from '@/store/dataflow/helper' ; enum VisualizationEventType { INTERACTIVE_SELECTION = 'interactive-selection' } export const interactiveSelectionEvent = ( node , selection , prevSelection , message ? ) => { const count = selection . numItems ( ) ; return nodeEvent ( VisualizationEventType . INTERACTIVE_SELECTION , ! message ? `select ${ count } item${ count !== 1 ? 's' : '' }` : message , node , { selection : selection . serialize ( ) , prevSelection : prevSelection . serialize ( ) } , { isNodeIcon : true , nodeType : node . nodeType } ) ; } ; const undoInteractiveSelection = ( evt ) => { ( getNode ( evt . nodeId ) as Visualization ) . setSelection ( evt . data . prevSelection ) ; } ; const redoInteractiveSelection = ( evt ) => { ( getNode ( evt . nodeId ) as Visualization ) . setSelection ( evt . data . selection ) ; } ; export const undo = ( evt ) => { switch ( evt . type ) { case VisualizationEventType . INTERACTIVE_SELECTION : undoInteractiveSelection ( evt ) ; break ; default : return false ; } return true ; } ; export const redo = ( evt ) => { switch ( evt . type ) { case VisualizationEventType . INTERACTIVE_SELECTION : redoInteractiveSelection ( evt ) ; break ; default : return false ; } return true ; } ;