@domoinc/legend-connector v0.1.0
How to add the legend to a widget using the legend-connector
Widget.jsAt top of the code, add
var Legend = require('@domoinc/legend'); var legendConnector = require('@domoinc/legend-connector');After the
_Chart.mergeConfig, add_Chart.mergeConfig(legendConnector.getLegendConfigs(daTheme2));At the end of the
transform, addlegendConnector.initializeLegend(_Chart, Legend, _Chart._colorScale); setLegendTriggers(); legendConnector.drawLegend(_Chart, validData, _Chart.a('Series'));The triggers may need modifications to ensure the right data is being passed. The object that the legend returns is
{series: name}function setLegendTriggers() { if (_Chart.c('showLegend').value) { _Chart.on('dispatch:mouseover', function(obj) { _Chart._legend.trigger('external:mouseover', obj); }); _Chart.on('dispatch:mouseout', function() { _Chart._legend.trigger('external:mouseout'); }); _Chart._legend.on('dispatch:mouseover', function(obj) { _Chart.trigger('external:mouseover', obj.series); }); _Chart._legend.on('dispatch:mouseout', function() { _Chart.trigger('external:mouseout'); }); } }DomoWidget.jsAt the top of the code, add
var legendConnector; if (typeof require !== 'undefined') { legendConnector = require('@domoinc/legend-connector'); } else { legendConnector = window.LegendConnector; }After
bboxis defined and before thecontaineris removed, addvar legendPosition = legendConnector.getLegendPosition(container); //gets the client rect for the legend chartboundsAfter the
dataNameis set and beforereturn widget, addlegendConnector.setLegendPosition(widget, legendPosition); //update value for legend position, sets a default if undefined widget.prepareForArtboard = legendConnector.prepareForArtboard(widget, widget.a('Series')); legendConnector.pullFromArtboard(AutoWidgets, widget, widget.a('Series')); //update legend configs changed on artboardCreateWidget.jsAt the top of the code, add
var legendConnector; if (typeof require !== 'undefined') { legendConnector = require('@domoinc/legend-connector'); } else { legendConnector = window.LegendConnector; }Before
chart.draw(data)and afterchartis initialized, add//set default legend position legendConnector.setLegendPosition(chart);auto.htmlTo allow the legend connector to work locally, before the
src/DomoWidget.jsand after thedist/bundle.jsscript tags, add<script type="text/javascript" src="node_modules/@domoinc/legend-connector/dist/bundle.js"></script>index.htmlTo allow the legend connector to work locally, before the
src/DomoWidget.jsand after thedist/bundle.jsscript tags, add<script type="text/javascript" src="node_modules/@domoinc/legend-connector/dist/bundle.js"></script>webpack.config.jsIn the externals object, add
'@domoinc/legend': { root: 'Legend', commonjs: '@domoinc/legend', commonjs2: '@domoinc/legend', amd: 'legend' }, '@domoinc/legend-connector': { root: 'LegendConnector', commonjs: '@domoinc/legend-connector', commonjs2: '@domoinc/legend-connector', amd: 'legend-connector' }package.jsonRun these commands to get the dependencies and
package.jsonupdated:npm install @domoinc/legend -S npm install @domoinc/legend-connector -S"@domoinc/legend": "^6.0.11", "@domoinc/legend-connector": "0.0.27",
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago