   initialize: (messageManager, @editor) ->
     messageManager.onDidReceiveMessage (message) => @handleMessage(message)
     messageManager.onGraphCreationRequest (request) => @handleGraphCreationRequest(request)
+    messageManager.onGraphDrawingRequest (request) => @handleGraphDrawingRequest(request)
 
   getTitle: ->
     @editor.getTitle() + ' Csound output'
 
   handleGraphCreationRequest: ({name, data}) ->
+    graphElement = document.createElement 'div'
+    @divsForGraphIDs ?= {}
+    @divsForGraphIDs[data.windid] = graphElement
+
+    @handleGraphDrawingRequest data
+
+    nextSibling = @nextSiblingsForGraphCaptions?[data.caption.trim()]
+    if nextSibling
+      @insertBefore graphElement, nextSibling
+    else
+      @appendChild graphElement
+    @scrollTop += graphElement.clientHeight
+
+  handleGraphDrawingRequest: (data) ->
     margin = {top: 20, right: 20, bottom: 30, left: 50}
     width = 650 - margin.left - margin.right
     height = 340 - margin.top - margin.bottom

        span.classList.add className
    span.appendChild document.createTextNode string

    if needsScroll
      @scrollTop = @scrollHeight - @clientHeight

module.exports = MessageHistoryElement = document.registerElement 'csound-message-history', prototype: MessageHistoryElement.prototype

        .attr('class', 'line')
        .attr('d', line)

    graphElement = @divsForGraphIDs?[data.windid]
    graphElement?.innerHTML = svgElement.outerHTML

  handleMessage: ({string, attributes}) ->
    if @lastChild?.localName isnt 'pre'
      @messageContainer = @appendChild document.createElement 'pre'

    messageType = attributes & csound.CSOUNDMSG_TYPE_MASK
    if messageType is csound.CSOUNDMSG_DEFAULT
