Skip to content

Commit

Permalink
first pass at modularizing suave-charts so we only take up a single v…
Browse files Browse the repository at this point in the history
…ar in the global namespace
  • Loading branch information
jcarver committed Feb 15, 2016
1 parent 983d5ff commit 1d2515a
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 41 deletions.
8 changes: 7 additions & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env bash
coffee --bare --compile --output target/coffeescript/ src/coffeescript/
java -jar build/compiler.jar --js target/coffeescript/**.js --js_output_file dist/suave-charts.min.js
java \
-jar build/compiler.jar \
--js target/coffeescript/**.js \
--js_output_file dist/suave-charts.min.js \
--entry_point target/coffeescript/suave_charts \
--process_common_js_modules \
--output_wrapper "(function(){%output%})();"
Binary file modified build/compiler.jar
Binary file not shown.
53 changes: 29 additions & 24 deletions dist/suave-charts.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/basic-bar-chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h3>CSS</h3>
<script src="../dist/suave-charts.min.js"></script>
<script id="js1">
// Create a bar chart
var chart = new BarChart("#chart")
var chart = new Suave.BarChart("#chart")

// Draw the chart
chart.draw([
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-donut-chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h3>CSS</h3>
<script src="../dist/suave-charts.min.js"></script>
<script id="js1">
// Create a donut chart
var chart = new DonutChart("#chart", {
var chart = new Suave.DonutChart("#chart", {
// Controls how much of a donut this is (0 to 100%)
// For a pie chart, set this to 0
holeSize: 0.5
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-line-chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h3>CSS</h3>
}

// Create a line chart
chart = new LineChart("#chart")
chart = new Suave.LineChart("#chart")

// Draw the chart
chart.draw({
Expand Down
2 changes: 1 addition & 1 deletion examples/time-series-chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h3>CSS</h3>
var data2 = data.map(function(d) { return d * 3 })

// Create a line chart
chart = new LineChart("#chart", {
chart = new Suave.LineChart("#chart", {
xScale: "time",
xLabelInterval: "days",
xLabelFormat: "%d/%m/%Y"
Expand Down
7 changes: 6 additions & 1 deletion src/coffeescript/abstract_chart.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
defaults = require('./defaults')
Svg = require('./svg')

class AbstractChart
constructor: (selector, defaultOptions = {}, options = {}) ->
@options = mergeOptions(defaultOptions, options)
@options = defaults.mergeOptions(defaultOptions, options)
@svg = new Svg(selector, @options.aspectRatio, @options.margin)

module.exports = AbstractChart
2 changes: 2 additions & 0 deletions src/coffeescript/axes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ class Axes
.scale(scale)
.orient(orientation)
.tickPadding(@options.tickPadding)

module.exports = Axes
6 changes: 6 additions & 0 deletions src/coffeescript/bar_chart.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
AbstractChart = require('./abstract_chart')
MarginCalculator = require('./margin_calculator')
Tooltip = require('./tooltip')
defaultBarOptions = require('./defaults').barOptions

class BarChart extends AbstractChart
constructor: (selector, options = {}) ->
super(selector, defaultBarOptions, options)
Expand Down Expand Up @@ -58,3 +63,4 @@ class BarChart extends AbstractChart
@bars.on("mouseout", (d) -> tip.hide())
@render()

module.exports = BarChart
7 changes: 6 additions & 1 deletion src/coffeescript/defaults.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ defaultDonutOptions = {
}
}


module.exports = {
mergeOptions: mergeOptions
lineOptions: defaultLineOptions
barOptions: defaultBarOptions
donutOptions: defaultDonutOptions
}
9 changes: 5 additions & 4 deletions src/coffeescript/donut_chart.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AbstractChart = require('./abstract_chart')
defaultDonutOptions = require('./defaults').donutOptions

class DonutChart extends AbstractChart
constructor: (selector, options = {}) ->
super(selector, defaultDonutOptions, options)
Expand Down Expand Up @@ -37,7 +40,5 @@ class DonutChart extends AbstractChart

@render()

#g.append("text")
#.attr("transform", (d) => "translate(#{arc.centroid(d)})")
#.attr("dy", ".35em")
#.text((d) -> d[1])

module.exports = DonutChart
13 changes: 8 additions & 5 deletions src/coffeescript/line_chart.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# TODOS:
# multi axis
# Grouped bar charts
# Column charts
# transitions/animations
AbstractChart = require('./abstract_chart')
Axes = require('./axes')
MarginCalculator = require('./margin_calculator')
Scales = require('./scales')
Tooltip = require('./tooltip')
defaultLineOptions = require('./defaults').lineOptions

class LineChart extends AbstractChart
constructor: (selector, options = {}) ->
Expand Down Expand Up @@ -138,3 +139,5 @@ class LineChart extends AbstractChart

@createTooltip() if @options.tooltips
@render()

module.exports = LineChart
2 changes: 2 additions & 0 deletions src/coffeescript/margin_calculator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ class MarginCalculator

fauxSelection.remove()
margin

module.exports = MarginCalculator
2 changes: 2 additions & 0 deletions src/coffeescript/scales.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ class Scales
when "log" then d3.scale.log()
when "time" then d3.time.scale()
when "ordinal" then d3.scale.ordinal()

module.exports = Scales
5 changes: 5 additions & 0 deletions src/coffeescript/suave_charts.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
m = {}
m.LineChart = require('./line_chart')
m.BarChart = require('./bar_chart')
m.DonutChart = require('./donut_chart')
window.Suave = m
2 changes: 2 additions & 0 deletions src/coffeescript/svg.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ class Svg
.attr("height", newHeight)

@chart.attr("transform", "translate(#{margin.left},#{margin.top})")

module.exports = Svg
2 changes: 1 addition & 1 deletion src/coffeescript/tooltip.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class Tooltip
{ top: nodeCoords.top - (tipHeight + 10) + window.scrollY, left: nodeCenter - (tipWidth / 2) + window.scrollX }



module.exports = Tooltip

0 comments on commit 1d2515a

Please sign in to comment.