SVG rerenders each time the model changes and ChartType.renderChart() is called.
authordeclerambaul <fabian.kaelin@gmail.com>
Mon, 2 Jul 2012 13:49:28 +0000 (15:49 +0200)
committerdeclerambaul <fabian.kaelin@gmail.com>
Mon, 2 Jul 2012 13:49:28 +0000 (15:49 +0200)
lib/chart/type/d3-chart.co

index d9ba175..3e968d6 100644 (file)
@@ -74,10 +74,13 @@ class exports.D3ChartType extends ChartType
             .domain d3.extent allValues
             .range [ height - margin.top - margin.bottom, 0 ]
         
+        
+        # Hack. Remove svg if it exists. If @model changes, the graph will be redrawn
+        svg = d3.select viewport.0 .selectAll "svg"            
+            .remove()
         # Select the svg element, if it exists.
         svg = d3.select viewport.0 .selectAll "svg"
             .data [cols]
-        
         # ...Otherwise, create the skeletal chart.
         enterFrame = svg.enter()
             .append "svg" .append "g"
@@ -121,7 +124,7 @@ class exports.D3ChartType extends ChartType
                     # FOR NOW take line as default
                     chartElement ?= 'd3-line' # @model.get "chartElement"                 
                     # create d3 chart element and render it
-                    chEl = D3ChartElement.create chartElement
+                    chEl = D3ChartElement.create chartElement                
 
                     chEl.renderChartElement d, frame ,xScale, yScale