item.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * DevExtreme (viz/funnel/item.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var states = ["normal", "hover", "selection", "selection"];
  11. var isDefined = require("../../core/utils/type").isDefined;
  12. function parseStyles(color, style, baseStyle) {
  13. var border = style.border;
  14. var baseBorder = baseStyle.border;
  15. var borderVisible = isDefined(border.visible) ? border.visible : baseBorder.visible;
  16. var borderWidth = isDefined(border.width) ? border.width : baseBorder.width;
  17. return {
  18. fill: color,
  19. hatching: style.hatching,
  20. stroke: border.color || baseBorder.color,
  21. "stroke-width": borderVisible ? borderWidth : 0
  22. }
  23. }
  24. function Item(widget, options) {
  25. var that = this;
  26. var data = options.data;
  27. that.code = 0;
  28. that.widget = widget;
  29. that.figure = options.figure;
  30. that.argument = data.argument;
  31. that.value = data.value;
  32. that.data = data.dataItem;
  33. that.percent = options.percent;
  34. that.id = options.id;
  35. that.color = options.color;
  36. that.states = {
  37. normal: parseStyles(options.color, options.itemOptions, options.itemOptions),
  38. hover: parseStyles(options.color, options.itemOptions.hoverStyle, options.itemOptions),
  39. selection: parseStyles(options.color, options.itemOptions.selectionStyle, options.itemOptions)
  40. }
  41. }
  42. Item.prototype = {
  43. getState: function() {
  44. return states[this.code]
  45. },
  46. getNormalStyle: function() {
  47. return this.states.normal
  48. },
  49. setHover: function() {
  50. this.hover(true)
  51. },
  52. hover: function(state) {
  53. if (!this.widget._getOption("hoverEnabled", true) || state === this.isHovered()) {
  54. return
  55. }
  56. this.widget._suspend();
  57. state && this.widget.clearHover();
  58. this.setState(1, state);
  59. this.widget._eventTrigger("hoverChanged", {
  60. item: this
  61. });
  62. this.widget._resume()
  63. },
  64. setState: function(code, state) {
  65. if (state) {
  66. this.code |= code
  67. } else {
  68. this.code &= ~code
  69. }
  70. this.widget._applyTilesAppearance()
  71. },
  72. select: function(state) {
  73. var mode = this.widget._getOption("selectionMode", true);
  74. if ("none" === mode || state === this.isSelected()) {
  75. return
  76. }
  77. this.widget._suspend();
  78. if (state && "multiple" !== mode) {
  79. this.widget.clearSelection()
  80. }
  81. this.setState(2, state);
  82. this.widget._eventTrigger("selectionChanged", {
  83. item: this
  84. });
  85. this.widget._resume()
  86. },
  87. showTooltip: function(coords) {
  88. this.widget._showTooltip(this.id, coords)
  89. },
  90. getColor: function() {
  91. return this.color
  92. },
  93. isHovered: function() {
  94. return !!(1 & this.code)
  95. },
  96. isSelected: function() {
  97. return !!(2 & this.code)
  98. }
  99. };
  100. module.exports = Item;