@carbon/charts-vue 0.53.3 → 0.53.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/charts-vue.umd.js CHANGED
@@ -450,6 +450,7 @@ var events_Toolbar;
450
450
  (function (Toolbar) {
451
451
  Toolbar["SHOW_OVERFLOW_MENU"] = "show-toolbar-overflow-menu";
452
452
  Toolbar["HIDE_OVERFLOW_MENU"] = "hide-toolbar-overflow-menu";
453
+ Toolbar["BUTTON_CLICK"] = "toolbar-button-click";
453
454
  })(events_Toolbar || (events_Toolbar = {}));
454
455
  /**
455
456
  * enum of all events related to the zoom-bar
@@ -893,6 +894,7 @@ var ToolbarControlTypes;
893
894
  ToolbarControlTypes["RESET_ZOOM"] = "Reset zoom";
894
895
  ToolbarControlTypes["MAKE_FULLSCREEN"] = "Make fullscreen";
895
896
  ToolbarControlTypes["SHOW_AS_DATATABLE"] = "Show as data-table";
897
+ ToolbarControlTypes["CUSTOM"] = "Custom";
896
898
  })(ToolbarControlTypes || (ToolbarControlTypes = {}));
897
899
  /**
898
900
  * enum of title orientations for _vertical axes_
@@ -38644,23 +38646,26 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38644
38646
  var self_1 = this;
38645
38647
  var allToolbarControls = enteringToolbarControls
38646
38648
  .merge(toolbarControls)
38647
- .classed('disabled', function (d) {
38648
- return d.shouldBeDisabled ? d.shouldBeDisabled() : false;
38649
- })
38650
- .attr('aria-disabled', function (d) {
38651
- return d.shouldBeDisabled ? d.shouldBeDisabled() : false;
38652
- })
38649
+ .classed('disabled', function (d) { return d.shouldBeDisabled(); })
38650
+ .attr('aria-disabled', function (d) { return d.shouldBeDisabled(); })
38653
38651
  .attr('aria-label', function (d) { return d.title; })
38654
- .html(function (d) { return "\n\t\t\t<button\n\t\t\t\tclass=\"bx--overflow-menu__trigger\"\n\t\t\t\taria-haspopup=\"true\" aria-expanded=\"false\" id=\"" + _this.services.domUtils.generateElementIDString("control-" + d.id) + "\" aria-label=\"" + d.title + "\">\n\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\" style=\"will-change: transform; width: " + (d.iconWidth !== undefined ? d.iconWidth : '20px') + "; height: " + (d.iconWidth !== undefined ? d.iconHeight : '20px') + "\" xmlns=\"http://www.w3.org/2000/svg\" class=\"bx--overflow-menu__icon\" viewBox=\"0 0 32 32\" aria-hidden=\"true\">\n\t\t\t\t\t" + d.iconSVGContent + "\n\t\t\t\t</svg>\n\t\t\t</button>"; })
38652
+ .html(function (d) { return "\n\t\t\t<button\n\t\t\t\tclass=\"bx--overflow-menu__trigger\"\n\t\t\t\taria-haspopup=\"true\" aria-expanded=\"false\" id=\"" + _this.services.domUtils.generateElementIDString("control-" + d.id) + "\" aria-label=\"" + d.title + "\">\n\t\t\t\t<svg focusable=\"false\" preserveAspectRatio=\"xMidYMid meet\" style=\"will-change: transform; width: " + (d.iconSVG.width !== undefined ? d.iconSVG.width : '20px') + "; height: " + (d.iconSVG.height !== undefined
38653
+ ? d.iconSVG.height
38654
+ : '20px') + "\" xmlns=\"http://www.w3.org/2000/svg\" class=\"bx--overflow-menu__icon\" viewBox=\"0 0 32 32\" aria-hidden=\"true\">\n\t\t\t\t\t" + d.iconSVG.content + "\n\t\t\t\t</svg>\n\t\t\t</button>"; })
38655
38655
  .each(function (d, index) {
38656
+ var _this = this;
38656
38657
  src_select(this)
38657
38658
  .select('button')
38658
- .on('click', !d.shouldBeDisabled() ? d.clickFunction : null)
38659
+ .on('click', function (event) {
38660
+ if (!d.shouldBeDisabled()) {
38661
+ self_1.triggerFunctionAndEvent(d, event, _this);
38662
+ }
38663
+ })
38659
38664
  .on('keydown', function (event) {
38660
38665
  if ((event.key && event.key === 'Enter') ||
38661
38666
  event.key === ' ') {
38662
38667
  event.preventDefault();
38663
- d.clickFunction();
38668
+ self_1.triggerFunctionAndEvent(d, event, _this);
38664
38669
  }
38665
38670
  else if (event.key && event.key === 'ArrowLeft') {
38666
38671
  self_1.focusOnPreviousEnabledToolbarItem(index);
@@ -38814,15 +38819,13 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38814
38819
  var element = src_select("#" + _this.services.domUtils.generateElementIDString("control-" + menuItem.id));
38815
38820
  if (element !== null) {
38816
38821
  element.on('click', function () {
38817
- // call the specified function
38818
- menuItem.clickFunction();
38822
+ self_2.triggerFunctionAndEvent(menuItem, event, element.node());
38819
38823
  // hide overflow menu
38820
38824
  self_2.updateOverflowMenu(false);
38821
38825
  });
38822
38826
  element.on('keydown', function (keyEvent) {
38823
38827
  if (keyEvent && keyEvent.key === 'Enter') {
38824
- // call the specified function
38825
- menuItem.clickFunction();
38828
+ self_2.triggerFunctionAndEvent(menuItem, event, element.node());
38826
38829
  }
38827
38830
  else if (keyEvent && keyEvent.key === 'ArrowUp') {
38828
38831
  // focus on previous menu item
@@ -38849,35 +38852,75 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38849
38852
  event.stopImmediatePropagation();
38850
38853
  }
38851
38854
  };
38855
+ // Calls passed function && dispatches event
38856
+ Toolbar.prototype.triggerFunctionAndEvent = function (control, event, element) {
38857
+ // Call custom function only if it exists
38858
+ if (typeof control.clickFunction === 'function') {
38859
+ control.clickFunction(event);
38860
+ }
38861
+ // Dispatch selection event
38862
+ this.services.events.dispatchEvent(Events.Toolbar.BUTTON_CLICK, {
38863
+ control: control,
38864
+ event: event,
38865
+ element: element,
38866
+ });
38867
+ };
38852
38868
  Toolbar.prototype.getControlConfigs = function () {
38853
38869
  var _this = this;
38854
- var numberOfIcons = tools_Tools.getProperty(this.getOptions(), 'toolbar', 'numberOfIcons');
38870
+ var numberOfIcons = tools_Tools.getProperty(this.getOptions(), 'toolbar', 'numberOfIcons') -
38871
+ 1;
38855
38872
  var controls = tools_Tools.getProperty(this.getOptions(), 'toolbar', 'controls');
38856
- var controlList = [];
38857
38873
  var overflowSpecificControls = [];
38874
+ var buttonList = [];
38875
+ var overflowList = [];
38858
38876
  controls.forEach(function (control) {
38859
- var controlConfig = _this.getControlConfigByType(control.type);
38877
+ var controlConfig = null;
38878
+ // check if button is custom or default control
38879
+ if (control.type === ToolbarControlTypes.CUSTOM) {
38880
+ // add generic id if missing
38881
+ if (tools_Tools.getProperty(control, 'id') === null) {
38882
+ // add id directly to the data passed so that id isn't reassigned on rerender
38883
+ control.id = "toolbar-button-" + Toolbar.buttonID++;
38884
+ }
38885
+ // define function if missing
38886
+ if (tools_Tools.getProperty(control, 'shouldBeDisabled') === null) {
38887
+ control.shouldBeDisabled = function () { return false; };
38888
+ }
38889
+ controlConfig = control;
38890
+ }
38891
+ else {
38892
+ controlConfig = _this.getControlConfigByType(control.type);
38893
+ }
38860
38894
  // add to list if config is valid
38861
38895
  if (controlConfig) {
38862
38896
  controlConfig.text = control.text ? control.text : control.type;
38863
38897
  if (controlConfig.id.indexOf('toolbar-export') !== -1) {
38864
38898
  overflowSpecificControls.push(controlConfig);
38865
38899
  }
38900
+ else if (buttonList.length < numberOfIcons) {
38901
+ // check if icon exists else assign to the overflow list
38902
+ if (tools_Tools.getProperty(controlConfig, 'iconSVG', 'content') === null) {
38903
+ overflowList.push(controlConfig);
38904
+ }
38905
+ else {
38906
+ buttonList.push(controlConfig);
38907
+ }
38908
+ }
38866
38909
  else {
38867
- controlList.push(controlConfig);
38910
+ overflowList.push(controlConfig);
38868
38911
  }
38869
38912
  }
38870
38913
  });
38871
- if (controlList.length <= numberOfIcons &&
38872
- overflowSpecificControls.length === 0) {
38914
+ // Ensures the `export` controls are always at the bottom
38915
+ overflowList.push.apply(overflowList, overflowSpecificControls);
38916
+ if (!overflowList.length) {
38873
38917
  return {
38874
- buttonList: controlList,
38918
+ buttonList: buttonList,
38875
38919
  };
38876
38920
  }
38877
38921
  return {
38878
- // leave one button for overflow button
38879
- buttonList: controlList.splice(0, numberOfIcons - 1),
38880
- overflowMenuItemList: controlList.concat(overflowSpecificControls),
38922
+ buttonList: buttonList,
38923
+ overflowMenuItemList: overflowList,
38881
38924
  };
38882
38925
  };
38883
38926
  Toolbar.prototype.getToolbarButtonItems = function () {
@@ -38906,7 +38949,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38906
38949
  id: 'toolbar-overflow-menu',
38907
38950
  title: 'More options',
38908
38951
  shouldBeDisabled: function () { return false; },
38909
- iconSVGContent: "<circle cx=\"16\" cy=\"8\" r=\"2\"></circle>\n\t\t\t\t\t\t\t <circle cx=\"16\" cy=\"16\" r=\"2\"></circle>\n\t\t\t\t\t\t\t <circle cx=\"16\" cy=\"24\" r=\"2\"></circle>",
38952
+ iconSVG: {
38953
+ content: "<circle cx=\"16\" cy=\"8\" r=\"2\"></circle>\n\t\t\t\t<circle cx=\"16\" cy=\"16\" r=\"2\"></circle>\n\t\t\t\t<circle cx=\"16\" cy=\"24\" r=\"2\"></circle>",
38954
+ },
38910
38955
  clickFunction: function (event) { return _this.toggleOverflowMenu(event); },
38911
38956
  };
38912
38957
  };
@@ -38926,7 +38971,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38926
38971
  shouldBeDisabled: function () {
38927
38972
  return _this.services.zoom.isMinZoomDomain();
38928
38973
  },
38929
- iconSVGContent: this.getControlIconByType(controlType),
38974
+ iconSVG: {
38975
+ content: this.getControlIconByType(controlType),
38976
+ },
38930
38977
  clickFunction: function () { return _this.services.zoom.zoomIn(); },
38931
38978
  };
38932
38979
  }
@@ -38939,7 +38986,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38939
38986
  shouldBeDisabled: function () {
38940
38987
  return _this.services.zoom.isMaxZoomDomain();
38941
38988
  },
38942
- iconSVGContent: this.getControlIconByType(controlType),
38989
+ iconSVG: {
38990
+ content: this.getControlIconByType(controlType),
38991
+ },
38943
38992
  clickFunction: function () { return _this.services.zoom.zoomOut(); },
38944
38993
  };
38945
38994
  }
@@ -38952,7 +39001,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38952
39001
  shouldBeDisabled: function () {
38953
39002
  return _this.services.zoom.isMaxZoomDomain();
38954
39003
  },
38955
- iconSVGContent: this.getControlIconByType(controlType),
39004
+ iconSVG: {
39005
+ content: this.getControlIconByType(controlType),
39006
+ },
38956
39007
  clickFunction: function () {
38957
39008
  return _this.services.zoom.resetZoomDomain();
38958
39009
  },
@@ -38962,10 +39013,12 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38962
39013
  case ToolbarControlTypes.MAKE_FULLSCREEN:
38963
39014
  controlConfig = {
38964
39015
  id: 'toolbar-makefullscreen',
39016
+ iconSVG: {
39017
+ content: this.getControlIconByType(controlType),
39018
+ width: '15px',
39019
+ height: '15px',
39020
+ },
38965
39021
  title: 'Make fullscreen',
38966
- iconSVGContent: this.getControlIconByType(controlType),
38967
- iconWidth: '15px',
38968
- iconHight: '15px',
38969
39022
  shouldBeDisabled: function () { return false; },
38970
39023
  clickFunction: function () {
38971
39024
  _this.services.domUtils.toggleFullscreen();
@@ -38975,8 +39028,10 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38975
39028
  case ToolbarControlTypes.SHOW_AS_DATATABLE:
38976
39029
  controlConfig = {
38977
39030
  id: 'toolbar-showasdatatable',
39031
+ iconSVG: {
39032
+ content: this.getControlIconByType(controlType),
39033
+ },
38978
39034
  title: 'Show as table',
38979
- iconSVGContent: this.getControlIconByType(controlType),
38980
39035
  shouldBeDisabled: function () { return displayData.length === 0; },
38981
39036
  clickFunction: function () {
38982
39037
  return _this.services.events.dispatchEvent(Events.Modal.SHOW);
@@ -38988,7 +39043,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38988
39043
  id: 'toolbar-export-CSV',
38989
39044
  title: 'Export as CSV',
38990
39045
  shouldBeDisabled: function () { return false; },
38991
- iconSVGContent: this.getControlIconByType(controlType),
39046
+ iconSVG: {
39047
+ content: this.getControlIconByType(controlType),
39048
+ },
38992
39049
  clickFunction: function () { return _this.model.exportToCSV(); },
38993
39050
  };
38994
39051
  break;
@@ -38997,7 +39054,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
38997
39054
  id: 'toolbar-export-PNG',
38998
39055
  title: 'Export as PNG',
38999
39056
  shouldBeDisabled: function () { return false; },
39000
- iconSVGContent: this.getControlIconByType(controlType),
39057
+ iconSVG: {
39058
+ content: this.getControlIconByType(controlType),
39059
+ },
39001
39060
  clickFunction: function () { return _this.services.domUtils.exportToPNG(); },
39002
39061
  };
39003
39062
  break;
@@ -39006,7 +39065,9 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
39006
39065
  id: 'toolbar-export-JPG',
39007
39066
  title: 'Export as JPG',
39008
39067
  shouldBeDisabled: function () { return false; },
39009
- iconSVGContent: this.getControlIconByType(controlType),
39068
+ iconSVG: {
39069
+ content: this.getControlIconByType(controlType),
39070
+ },
39010
39071
  clickFunction: function () { return _this.services.domUtils.exportToJPG(); },
39011
39072
  };
39012
39073
  break;
@@ -39039,6 +39100,7 @@ var toolbar_Toolbar = /** @class */ (function (_super) {
39039
39100
  throw Error('Not supported toolbar control type: ' + controlType);
39040
39101
  }
39041
39102
  };
39103
+ Toolbar.buttonID = 0;
39042
39104
  return Toolbar;
39043
39105
  }(component_Component));
39044
39106