UNPKG

@domoinc/multi-metric-comparison-bar-chart

Version:

MultiMetricComparisonBarChart - Domo Widget

57 lines (45 loc) 1.82 kB
/*---------------------------------------------------------------------------------- Chart Auto Widget File © 2011 - 2015 DOMO, INC. ----------------------------------------------------------------------------------*/ // Add your chart to our the registry with your chart's unique name. AutoWidgets.register('DomoMultiMetricComparisonBarChartDomo', function(container) { // Use the bBox of the 'chartBounds' rect to find out // the size of the chart we need to render. var bBox = container.select('[id^=chartBounds]') .node() .getBBox(); // Transform our chart's container to fit where the user placed the wiget container.attr('transform', 'translate(' + bBox.x + ',' + bBox.y + ')') .selectAll('*') .remove(); // Set some sample data to use with out widget. var sampleData = [ ['Tweets', '@tiffanituft', 600], ['Tweets', '@rowandarby', 100], ['Followers', '@tiffanituft', 10000], ['Followers', '@rowandarby', 7000], ['Following', '@tiffanituft', 20], ['Following', '@rowandarby', 74] ]; // Set the data subscription name to what user specified. var dataName = container.node().parentNode.id; var sampleDataObj = {}; sampleDataObj[dataName] = { defaultValue: sampleData, columnNames: ['Category', 'Names', 'Value'] }; //Initialize widget and set parameters. var widget = AutoWidgets.baseWidget(container.chart('MultiMetricComparisonBarChart')) .c('height', bBox.height) .c('width', bBox.width) .sampleData(sampleDataObj); // Used for sample data check. widget._sampleData = sampleData; widget._notifier.showMessage(true); // Pass the dataname to widget object so it knows which data to call // on render. widget.dataName(dataName); // Return wiget so to keep the methods chainable. return widget; });