@domoinc/multiline-chart
Version:
MultiLineChart - Domo Widget
57 lines (44 loc) • 1.75 kB
JavaScript
/*----------------------------------------------------------------------------------
Chart Auto Widget File
© 2011 - 2015 DOMO, INC.
----------------------------------------------------------------------------------*/
// Add your chart to our the registry with your chart's unique name.
AutoWidgets.register('DomoDomoTooltipDomo', 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 widget
container.attr('transform', 'translate(' + bBox.x + ', ' + bBox.y + ')')
.selectAll('*')
.remove();
// Set some sample data to use with out widget.
var sampleData = [
['A', 10, 20, 30],
['B', 20, 30, 40],
['C', 40, 20, 10]
];
// Set the data subscription name to what user specified.
var dataName = container.node().parentNode.id;
// Create the data subscription with sample data.
// You can create as many of these as your chart needs.
var sampleDataObj = {};
sampleDataObj[dataName] = {
columnNames: ['Name', 'Series1', 'Series2', 'Series3'],
defaultValue: sampleData
};
//Initialize widget and set parameters.
var widget = AutoWidgets.baseWidget(container.chart('DomoTooltip'))
.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 widget so to keep the methods chainable.
return widget;
});