Skip to content

Commit

Permalink
initial support for C3 charting #193
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaskruchten committed Feb 25, 2015
1 parent 600f3ea commit 3cae6b0
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 21 deletions.
36 changes: 17 additions & 19 deletions c3_renderers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ callWithJQuery = (pivotModule) ->

callWithJQuery ($) ->

makeGoogleChart = (chartType, extraOptions) -> (pivotData, opts) ->
makeC3Chart = (chartType) -> (pivotData, opts) ->
defaults =
localeStrings:
vs: "vs"
Expand All @@ -22,37 +22,35 @@ callWithJQuery ($) ->
colKeys = pivotData.getColKeys()
colKeys.push [] if colKeys.length == 0

headers = (h.join("-") for h in rowKeys)
headers.unshift ""
headers = (h.join("-") for h in colKeys)

numCharsInHAxis = 0
dataArray = [headers]
for colKey in colKeys
row = [colKey.join("-")]
numCharsInHAxis += row[0].length
for rowKey in rowKeys
columns = []
for rowKey in rowKeys
rowHeader = rowKey.join("-")
row = [if rowHeader == "" then pivotData.aggregatorName else rowHeader]
for colKey in colKeys
agg = pivotData.getAggregator(rowKey, colKey)
if agg.value()?
row.push agg.value()
else row.push null
dataArray.push row
console.log dataArray
columns.push row

result = $("<div>")
c3.generate
title: "blah"
params =
bindto: result[0]
size:
height: ($(window).height() / 1.4),
width: ($(window).width() / 1.4)
axis: x:
type: 'category',
categories: dataArray.pop()
data: columns: dataArray
categories: headers
data:
columns: columns
if chartType?
params.data.type = chartType
c3.generate params
return result

$.pivotUtilities.c3_renderers =
"Line Chart": makeGoogleChart("LineChart")
"Bar Chart": makeGoogleChart("ColumnChart")
"Stacked Bar Chart": makeGoogleChart("ColumnChart", isStacked: true)
"Area Chart": makeGoogleChart("AreaChart", isStacked: true)
"Line Chart C3": makeC3Chart()
"Bar Chart C3": makeC3Chart("bar")
91 changes: 91 additions & 0 deletions dist/c3_renderers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/c3_renderers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/c3_renderers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/c3_renderers.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/c3.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
return mp["Gender"] == "Male" ? 1 : -1;
}
},
cols: [], rows: ["Province"],
rendererName: "Line Chart"
cols: ["Age Bin"], rows: ["Gender"],
rendererName: "Line Chart C3"
});
});
});
Expand Down
1 change: 1 addition & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h3 align="center">Canadian Parliament 2012 Dataset <small>(<a href="mps.csv">CS
<li><a href="mps_export.html">pivotUI() with export renderers</a></li>
<li><a href="gchart.html">pivotUI() with Google Charts renderers</a></li>
<li><a href="d3.html">pivotUI() with D3 renderers</a></li>
<li><a href="c3.html">pivotUI() with C3 chart renderers</a></li>
<li><a href="fully_loaded.html">pivotUI() mobile-enabled and with all renderers</a></li>
</ul>
<h3 align="center">Bring your own dataset</h3>
Expand Down

0 comments on commit 3cae6b0

Please sign in to comment.