Skip to content

Commit

Permalink
Adds support for wordtree chart type, fixes #173 (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesalvaro committed Dec 22, 2016
1 parent 955586a commit f11a3cc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
26 changes: 25 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ <h2>Chart gallery</h2>

<google-chart
type="sankey"
options='{"title": "Distribution of days in 2001H1"}'
cols='[{"label": "From", "type": "string"},
{"label": "To", "type": "string"},
{"label": "Weight", "type": "number"}]'
Expand Down Expand Up @@ -444,6 +443,31 @@ <h2>Chart gallery</h2>
}());
</script>

<p>Here's a wordtree:</p>

<google-chart
type="wordtree"
data='[["Phrases"],
["cats are better than dogs"],
["cats eat kibble"],
["cats are better than hamsters"],
["cats are awesome"],
["cats are people too"],
["cats eat mice"],
["cats meowing"],
["cats in the cradle"],
["cats eat mice"],
["cats in the cradle lyrics"],
["cats eat kibble"],
["cats for adoption"],
["cats are family"],
["cats eat mice"],
["cats are better than kittens"],
["cats are evil"],
["cats are weird"],
["cats eat mice"]
]'></google-chart>

<p>Here are three gauges:</p>

<google-chart
Expand Down
32 changes: 22 additions & 10 deletions google-chart-loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
/** @type {string} Most charts use this package. */
var DEFACTO_CHART_PACKAGE = 'corechart';

/** @enum {string} Namespaces that contain chart constructors. */
var Namespace = {
CHARTS: 'charts',
VIS: 'visualization'
};

/**
* A collection of chart type details.
*
Expand All @@ -28,6 +34,10 @@
'bubble': {
ctor: 'BubbleChart',
},
'calendar': {
ctor: 'Calendar',
pkg: 'calendar',
},
'candlestick': {
ctor: 'CandlestickChart',
},
Expand All @@ -37,6 +47,10 @@
'combo': {
ctor: 'ComboChart',
},
'gauge': {
ctor: 'Gauge',
pkg: 'gauge',
},
'geo': {
ctor: 'GeoChart',
},
Expand Down Expand Up @@ -79,27 +93,24 @@
ctor: 'Timeline',
pkg: 'timeline',
},
'gauge': {
ctor: 'Gauge',
pkg: 'gauge',
},
'treemap': {
ctor: 'TreeMap',
pkg: 'treemap',
},
'calendar': {
ctor: 'Calendar',
pkg: 'calendar',
'wordtree': {
ctor: 'WordTree',
namespace: Namespace.VIS,
pkg: 'wordtree',
}
};

/**
* Returns the namespace for the given chart type.
* The Google Charts constructor namespace inferred from the given chart type.
* @param {string} type the type of the chart
* @return {!Object} the namespace that contains the chart's constructor
*/
function namespaceForType(type) {
return google[type.indexOf('md-') === 0 ? 'charts' : 'visualization'];
return google[type.indexOf('md-') === 0 ? Namespace.CHARTS : Namespace.VIS];
}

/** @type {!Object<string, boolean>} set-like object of gviz packages to load */
Expand Down Expand Up @@ -216,7 +227,8 @@
}
return this._loadPackages([chartData.pkg || DEFACTO_CHART_PACKAGE])
.then(function() {
return namespaceForType(type)[chartData.ctor];
var namespace = google[chartData.namespace] || namespaceForType(type);
return namespace[chartData.ctor];
});
},

Expand Down
1 change: 1 addition & 0 deletions google-chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
* - `table`
* - `timeline`
* - `treemap`
* - `wordtree`
*
* See <a href="https://google-developers.appspot.com/chart/interactive/docs/gallery">Google Visualization API reference (Chart Gallery)</a>
* for details.
Expand Down

0 comments on commit f11a3cc

Please sign in to comment.