define([ "dojo/_base/declare", "dojo/dom", "dojo/dom-construct", "dijit/_WidgetBase", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", "chartjs/Chart.bundle", "dojo/text!./templates/vuConcurrencyChartWidget.html", "app/performanceTest/common/dateTimeFormat" ], function( declare, dom, domConstruct, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Chart, template ) { return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { templateString: template, baseClass: "vuConcurrencyChartWidget", vuConcurrencyChart: null, vuConcurrencyChartData: null, actionName: undefined, height: 200, constructor: function( actionName, height ) { this.actionName = actionName; this.height = height; this.vuConcurrencyChartData = { datasets: [ // Data defined here ] }; }, postCreate: function() { // Make sure any parent widget's postCreate functions get called. this.inherited(arguments); // Create a canvas element to draw the chart, and insert it into the dom var canvas = domConstruct.create("canvas"); domConstruct.place(canvas, this.chartNode); this.vuConcurrencyChart = new Chart(canvas, { type: "line", data: this.vuConcurrencyChartData, options: { maintainAspectRatio: false } }); // There seems to be a bug in the Chart.options.maintainAspectRatio attribute where the height // is set to zero if the container is hidden: https://github.com/apertureless/vue-chartjs/issues/235. // Workaround is to set the height after creating the chart. canvas.height = this.height; if (this.actionName !== undefined) { this.subscribe(this.actionName, "onGotData"); } }, onGotData: function(data) { if (this.vuConcurrencyChart !== null) { // Update the vuConcurrencyChartData object this.vuConcurrencyChart.update(); } } }); });