Skip to content

Commit 8f0453d

Browse files
committed
make surface system in graph optional
1 parent 734859c commit 8f0453d

File tree

6 files changed

+75
-32
lines changed

6 files changed

+75
-32
lines changed

annotation-tool/src/App/Tabs/SVG.purs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Effect.Class (class MonadEffect)
1313
import Halogen as H
1414
import Halogen.HTML as HH
1515
import Halogen.HTML.Core as HC
16+
import Halogen.HTML.Events as HE
1617
import Halogen.HTML.Properties as HP
1718
import Halogen.Query.Input (Input(..))
1819
import Halogen.Svg.Attributes as SA
@@ -38,11 +39,13 @@ type SVGInput = { modelInfo :: ModelInfo, settings :: AppSettings }
3839
data SVGAction
3940
= SVGRegisterElt Element
4041
| SVGReceive SVGInput
42+
| SVGToggleSurface
4143

4244
type SVGState =
4345
{ scoreElt :: Maybe Element
4446
, modelInfo :: ModelInfo
4547
, settings :: AppSettings
48+
, showSurface :: Boolean
4649
}
4750

4851
svgComponent
@@ -58,35 +61,53 @@ svgComponent = H.mkComponent
5861
}
5962
}
6063
where
61-
initialState { modelInfo, settings } = { modelInfo, settings, scoreElt: Nothing }
64+
initialState { modelInfo, settings } = { modelInfo, settings, scoreElt: Nothing, showSurface: true }
6265

63-
render { modelInfo, settings } = HH.div [ class_ "wide" ]
64-
[ svgContainer settings modelInfo ]
66+
render :: SVGState -> _
67+
render { modelInfo, settings, showSurface } = HH.div_
68+
[ HH.div [ class_ "content-np tab pure-form pure-g" ]
69+
[ HH.div [ class_ "pure-u-3-4" ]
70+
[ HH.input
71+
[ HP.type_ $ HP.InputCheckbox
72+
, HP.checked showSurface
73+
, HE.onChange \_ -> SVGToggleSurface
74+
, HP.id "showSurface"
75+
]
76+
, HH.label [ HP.for "showSurface" ] [ HH.text " show full surface below graph" ]
77+
]
78+
]
79+
, HH.div [ class_ "wide" ]
80+
[ svgContainer settings showSurface modelInfo ]
81+
]
6582

6683
handleSVGAction action = do
6784
case action of
68-
SVGRegisterElt elt -> do
85+
SVGRegisterElt elt ->
6986
H.modify_ \st -> st { scoreElt = Just elt }
7087
SVGReceive { modelInfo, settings } ->
7188
H.modify_ \st -> st { modelInfo = modelInfo, settings = settings }
89+
SVGToggleSurface ->
90+
H.modify_ \st -> st { showSurface = not st.showSurface }
7291
redrawGraph
7392

7493
svgContainer
7594
:: forall p
7695
. AppSettings
96+
-> Boolean
7797
-> ModelInfo
7898
-> HH.HTML p SVGAction
79-
svgContainer sett { model, graph } =
99+
svgContainer sett showSurface { model, graph } =
80100
let
81101
isComplete = L.length model.reduction.segments == 1
82102
width = scalex sett (graph.maxx + 1.0) + sliceDistance / 2.0
83103
staff = model.styles.staff
84104
systemHeight = if staff == GrandStaff then scoreHeightGrand else scoreHeightSingle
85105
extraRows = if isComplete then 0.0 else 1.0
86-
height = systemHeight * (graph.maxd + 1.0 + extraRows) + axisHeight
106+
surfaceRows = if showSurface then 1.0 else 0.0
107+
height = systemHeight * (graph.maxd + surfaceRows + extraRows) + axisHeight
87108
in
88109
HH.div
89-
[ HP.style "overflow: scroll; position: relative; left: 50%; transform: translateX(-50%); width: auto;"
110+
[ HP.style "overflow: scroll;"
90111
]
91112
[ SE.svg
92113
[ SA.width width
@@ -105,7 +126,7 @@ svgContainer sett { model, graph } =
105126

106127
redrawGraph :: forall o m s. (MonadEffect m) => H.HalogenM SVGState SVGAction s o m Unit
107128
redrawGraph = do
108-
{ modelInfo: { model, graph, surface }, settings, scoreElt } <- H.get
129+
{ modelInfo: { model, graph, surface }, settings, scoreElt, showSurface } <- H.get
109130
case scoreElt of
110131
Nothing -> pure unit
111132
Just elt ->
@@ -114,4 +135,4 @@ redrawGraph = do
114135
toX x = scalex settings x -- - (noteSize / 2.0)
115136
in
116137
H.liftEffect $ do
117-
insertScore elt $ renderGraph graph model.piece surface model.styles Nothing Nothing toX totalWidth scoreScale
138+
insertScore elt $ renderGraph graph model.piece surface model.styles Nothing Nothing toX totalWidth scoreScale showSurface

model/src/ProtoVoices/RenderSVG.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ function drawTimeLabel(time, y) {
391391
return label;
392392
}
393393

394-
export const drawGraph = (graph) => (totalWidth) => (scale) => {
394+
export const drawGraph = (graph) => (totalWidth) => (scale) => (showScore) => {
395395
// The graph is drawn in several steps:
396396
// - create a container element, add marker defs and CSS
397397
// - add a separator element to be able to sort element into foreground and background
@@ -475,13 +475,17 @@ export const drawGraph = (graph) => (totalWidth) => (scale) => {
475475
});
476476

477477
// draw score
478-
let score = drawScore(graph.surfaceSlices)(graph.surfaceTransitions)(graph.styles.staffType)(totalWidth)(scale);
479-
score.setAttribute(
480-
"transform",
481-
`translate(0 ${(graph.maxd - minLevel + 1) * levelOffset})`,
482-
);
483-
graphContainer.appendChild(score);
484-
let yoff = (graph.maxd - minLevel + 2) * levelOffset + 20;
478+
if (showScore) {
479+
let score = drawScore(graph.surfaceSlices)(graph.surfaceTransitions)(graph.styles.staffType)(totalWidth)(scale);
480+
score.setAttribute(
481+
"transform",
482+
`translate(0 ${(graph.maxd - minLevel + 1) * levelOffset})`,
483+
);
484+
graphContainer.appendChild(score);
485+
}
486+
487+
// draw time labels
488+
let yoff = (graph.maxd - minLevel + (showScore ? 2 : 1)) * levelOffset + 20;
485489
graph.times.forEach((time) => {
486490
graphContainer.appendChild(drawTimeLabel(time, yoff));
487491
});

model/src/ProtoVoices/RenderSVG.purs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ foreign import drawGraph
7979
, select :: Nullable (Nullable SelectionInfo -> Effect Unit)
8080
, styles :: StylesJSON
8181
}
82-
-> Number
83-
-> Number
82+
-> Number -- | total width
83+
-> Number -- | scaling
84+
-> Boolean -- | show score?
8485
-> DOMScore
8586

8687
renderGraph
@@ -93,6 +94,7 @@ renderGraph
9394
-> (Number -> Number)
9495
-> Number
9596
-> Number
97+
-> Boolean
9698
-> DOMScore
9799
renderGraph graph piece surface styles selection selectCallback toX = drawGraph
98100
{ slices: A.fromFoldable $ mkGraphSlice <$> M.values graph.slices

viewer/src/Common.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data ViewerAction
3232
| ToggleInner
3333
| ToggleOuter
3434
| ToggleScore
35+
| ToggleSurface
3536
| SetXScale String
3637
| SetYScale String
3738

@@ -43,6 +44,7 @@ type AppSettings =
4344
, showInner :: Boolean
4445
, showOuter :: Boolean
4546
, showScore :: Boolean
47+
, showSurface :: Boolean
4648
}
4749

4850
defaultSettings :: AppSettings
@@ -54,6 +56,7 @@ defaultSettings =
5456
, showInner: false
5557
, showOuter: false
5658
, showScore: true
59+
, showSurface: true
5760
}
5861

5962
readOptions :: F.Foreign -> AppSettings
@@ -65,6 +68,7 @@ readOptions obj =
6568
, showInner: fromRight defaultSettings.showInner $ runExcept $ obj FI.! "showInner" >>= F.readBoolean
6669
, showOuter: fromRight defaultSettings.showOuter $ runExcept $ obj FI.! "showOuter" >>= F.readBoolean
6770
, showScore: fromRight defaultSettings.showScore $ runExcept $ obj FI.! "showScore" >>= F.readBoolean
71+
, showSurface: fromRight defaultSettings.showSurface $ runExcept $ obj FI.! "showSurface" >>= F.readBoolean
6872
}
6973

7074
type Selection = Maybe { note :: Note, expl :: NoteExplanation }

viewer/src/Main.purs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,26 @@ viewerComponent prefix { listener, emitter } =
202202
]
203203
, HH.label [ HP.for $ prefix <> "showInnerGraph" ] [ HH.text "show inner graph" ]
204204
]
205-
, HH.div [ class_ "pv-control-box" ]
206-
[ HH.input
207-
[ HP.type_ $ HP.InputCheckbox
208-
, HP.checked st.settings.showScore
209-
, HE.onChange \_ -> ToggleScore
210-
, HP.id $ prefix <> "showScore"
205+
, HH.div [ class_ "pure-g" ]
206+
[ HH.div [ class_ "pure-u-1-2 pv-control-box" ]
207+
[ HH.input
208+
[ HP.type_ $ HP.InputCheckbox
209+
, HP.checked st.settings.showScore
210+
, HE.onChange \_ -> ToggleScore
211+
, HP.id $ prefix <> "showScore"
212+
]
213+
, HH.label [ HP.for $ prefix <> "showScore" ] [ HH.text "show score" ]
214+
]
215+
, HH.div [ class_ "pure-u-1-2 pv-control-box" ]
216+
[ HH.input
217+
[ HP.type_ $ HP.InputCheckbox
218+
, HP.checked st.settings.showSurface
219+
, HP.enabled st.settings.showScore
220+
, HE.onChange \_ -> ToggleSurface
221+
, HP.id $ prefix <> "showSurface"
222+
]
223+
, HH.label [ HP.for $ prefix <> "showSurface" ] [ HH.text "show surface below graph" ]
211224
]
212-
, HH.label [ HP.for $ prefix <> "showScore" ] [ HH.text "show score" ]
213225
]
214226
, HH.div [ class_ "pv-control-box" ]
215227
[ HH.input
@@ -280,6 +292,9 @@ viewerComponent prefix { listener, emitter } =
280292
ToggleInner -> H.modify_ \st -> st { settings { showInner = not st.settings.showInner } }
281293
ToggleOuter -> H.modify_ \st -> st { settings { showOuter = not st.settings.showOuter } }
282294
ToggleScore -> H.modify_ \st -> st { settings { showScore = not st.settings.showScore } }
295+
ToggleSurface -> do
296+
H.modify_ \st -> st { settings { showSurface = not st.settings.showSurface } }
297+
redrawScore
283298
SetXScale s -> case fromString s of
284299
Nothing -> pure unit
285300
Just n -> do
@@ -304,5 +319,5 @@ redrawScore = do
304319
HS.notify st.eventListener $ Select sel
305320
toX x = scalex st.settings x -- - (noteSize / 2.0)
306321
pure $ H.liftEffect $ do
307-
insertScore scoreElt $ renderGraph graph model.piece surface model.styles st.selected (Just select) toX totalWidth scoreScale
322+
insertScore scoreElt $ renderGraph graph model.piece surface model.styles st.selected (Just select) toX totalWidth scoreScale st.settings.showSurface
308323
fromMaybe (pure unit) update

viewer/src/Render.purs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,11 @@ renderScoreSVG sett graph isComplete staffType =
455455
-- <> (A.mapWithIndex (renderTime sett ((graph.maxd + 1.0 + extraRows) * systemHeight)) piece)
456456
]
457457
where
458-
459458
width = scalex sett (graph.maxx + 1.0) + sliceWidth / 2.0
460-
461459
systemHeight = if staffType == GrandStaff then scoreHeightGrand else scoreHeightSingle
462-
463460
extraRows = if isComplete then 0.0 else 1.0
464-
465-
height = systemHeight * (graph.maxd + 1.0 + extraRows) + axisHeight
461+
surfaceRows = if sett.showSurface then 1.0 else 0.0
462+
height = systemHeight * (graph.maxd + surfaceRows + extraRows) + axisHeight
466463

467464
renderReduction :: forall p. AppSettings -> Graph -> Selection -> HH.HTML p ViewerAction
468465
renderReduction sett graph selection =

0 commit comments

Comments
 (0)