Skip to content

Commit e72fde4

Browse files
A proper handler of general mouse interactions.
1 parent 0f5f556 commit e72fde4

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • Graphics/Dynamic/Plot

Graphics/Dynamic/Plot/R2.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,22 @@ clickThrough (v:vs) = addInterrupt $ plot v
18921892
interac@(Interactions [] _) -> fmap addInterrupt $ anim interac
18931893
Interactions (_:_) _ -> Just $ clickThrough vs
18941894

1895+
mouseInteractive :: Plottable p
1896+
=> (MouseEvent (,) -> s -> s)
1897+
-> s
1898+
-> (s -> p)
1899+
-> DynamicPlottable
1900+
mouseInteractive upd initl f = go initl
1901+
where go s = addInterrupt . plot $ f s
1902+
where addInterrupt :: DynamicPlottable -> DynamicPlottable
1903+
addInterrupt pl = pl
1904+
& futurePlots %~ \anim -> \case
1905+
Interactions _ Nothing
1906+
-> fmap addInterrupt $ anim mempty
1907+
Interactions _ (Just drag)
1908+
-> pure . go $ upd drag s
1909+
1910+
18951911

18961912
atExtendOf :: PlainGraphicsR2 -> PlainGraphicsR2 -> PlainGraphicsR2
18971913
atExtendOf d₁ = atExtendOf' d₁ 1

0 commit comments

Comments
 (0)