mxNetworks2.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * Copyright (c) 2006-2025, JGraph Holdings Ltd
  3. */
  4. //**********************************************************************************************************************************************************
  5. //Icon with background and long shadow
  6. //**********************************************************************************************************************************************************
  7. /**
  8. * Extends mxShape.
  9. */
  10. function mxShapeNetworks2Icon(bounds, fill, stroke, strokewidth)
  11. {
  12. mxShape.call(this);
  13. this.bounds = bounds;
  14. this.fill = fill;
  15. this.stroke = stroke;
  16. this.strokewidth = (strokewidth != null) ? strokewidth : 1;
  17. this.prevNetwork2BgColor = "9DA6A8";
  18. };
  19. /**
  20. * Extends mxShape.
  21. */
  22. mxUtils.extend(mxShapeNetworks2Icon, mxShape);
  23. mxShapeNetworks2Icon.prototype.customProperties = [
  24. {name: 'network2IconShadow', dispName: 'Long Shadow', type: 'bool', defVal: true, primary: true},
  25. {name: 'network2bgFillColor', dispName: 'Background Color', type: 'color', defVal: "#9DA6A8", primary: true},
  26. ];
  27. mxShapeNetworks2Icon.prototype.cst = {
  28. SHAPE_ICON : 'mxgraph.networks2.icon'
  29. };
  30. /**
  31. * Function: paintVertexShape
  32. *
  33. * Paints the vertex shape.
  34. */
  35. mxShapeNetworks2Icon.prototype.paintVertexShape = function(c, x, y, w, h)
  36. {
  37. var isShadow = mxUtils.getValue(this.style, 'network2IconShadow', false);
  38. var bgColor = mxUtils.getColorValue(this.style, 'network2bgFillColor', 'none');
  39. c.translate(x, y);
  40. if (bgColor != 'none')
  41. {
  42. this.background(c, 0, 0, w, h);
  43. }
  44. c.setShadow(false);
  45. if (isShadow && bgColor != 'none')
  46. {
  47. this.longShadow(c, 0, 0, w, h);
  48. }
  49. if (bgColor != 'none')
  50. {
  51. c.translate(w / 7, h / 7);
  52. this.foreground(c, 0, 0, w / 1.4, h / 1.4);
  53. c.translate(-w / 7, -h / 7);
  54. }
  55. else
  56. {
  57. this.foreground(c, 0, 0, w, h);
  58. }
  59. this.prevNetwork2BgColor = bgColor;
  60. };
  61. mxShapeNetworks2Icon.prototype.background = function(c, x, y, w, h)
  62. {
  63. var gradientColor = mxUtils.getColorValue(this.style, 'gradientColor', 'none');
  64. var gradientDir = mxUtils.getValue(this.style, 'gradientDirection', 'south');
  65. var fillColor = mxUtils.getColorValue(this.style, 'fillColor', '#ffffff');
  66. var fillColor = mxUtils.getColorValue(this.style, 'fillColor', '#ffffff');
  67. var bgColor = mxUtils.getColorValue(this.style, 'network2bgFillColor', 'none');
  68. if (gradientColor == 'none')
  69. {
  70. c.setFillColor(bgColor);
  71. }
  72. else
  73. {
  74. c.setGradient(bgColor, gradientColor, 0, 0, w, h, gradientDir);
  75. }
  76. c.roundrect(x, y, w, h, w * 0.03571, h * 0.03571);
  77. c.fill();
  78. c.setFillColor(fillColor);
  79. };
  80. mxShapeNetworks2Icon.prototype.foreground = function(c, x, y, w, h)
  81. {
  82. var stencilName = mxUtils.getValue(this.style, 'network2Icon', null);
  83. var stencil = null;
  84. if (stencilName != null)
  85. {
  86. stencil = mxStencilRegistry.getStencil(stencilName);
  87. }
  88. var bgColor = mxUtils.getColorValue(this.style, 'network2bgFillColor', 'none');
  89. if (bgColor != 'none')
  90. {
  91. var stencilW = mxUtils.getValue(this.style, 'network2IconW', 1);
  92. var stencilH = mxUtils.getValue(this.style, 'network2IconH', 1);
  93. var xOff = mxUtils.getValue(this.style, 'network2IconXOffset', 0);
  94. var yOff = mxUtils.getValue(this.style, 'network2IconYOffset', 0);
  95. if (stencil != null)
  96. {
  97. stencil.drawShape(c, this, x + w * 0.5 * (1 - stencilW) + xOff * w, y + h * 0.5 * (1 - stencilH) + yOff * h, w * stencilW, h * stencilH);
  98. }
  99. }
  100. else if (stencil != null)
  101. {
  102. stencil.drawShape(c, this, x, y, w, h);
  103. }
  104. };
  105. mxShapeNetworks2Icon.prototype.longShadow = function(c, x, y, w, h)
  106. {
  107. var stencilName = mxUtils.getValue(this.style, 'network2Icon', null) + "_shadow";
  108. var stencil = null;
  109. c.setFillColor('#000000');
  110. c.setStrokeColor('none');
  111. if (stencilName != null)
  112. {
  113. stencil = mxStencilRegistry.getStencil(stencilName);
  114. }
  115. if (stencil != null)
  116. {
  117. stencil.drawShape(c, this, x, y, w, h);
  118. }
  119. };
  120. mxShapeNetworks2Icon.prototype.styleChanged = function(key, value, state)
  121. {
  122. if (key == 'network2bgFillColor' && state.style[key] != value && value == 'none')
  123. {
  124. var graph = state.view.graph;
  125. var geometry = graph.getCellGeometry(state.cell);
  126. var stencilW = mxUtils.getValue(this.style, 'network2IconW', 1);
  127. var stencilH = mxUtils.getValue(this.style, 'network2IconH', 1);
  128. if (geometry != null)
  129. {
  130. geometry = geometry.clone();
  131. var w = geometry.width;
  132. var h = geometry.height;
  133. geometry.width = geometry.width * stencilW / 1.4;
  134. geometry.height = geometry.height * stencilH / 1.4;
  135. geometry.x = geometry.x + (w - geometry.width) * 0.5;
  136. geometry.y = geometry.y + (h - geometry.height) * 0.5;
  137. graph.model.setGeometry(state.cell, geometry);
  138. }
  139. }
  140. else if (key == 'network2bgFillColor' && state.style[key] != value && value != 'none' && this.prevNetwork2BgColor == 'none')
  141. {
  142. var graph = state.view.graph;
  143. var geometry = graph.getCellGeometry(state.cell);
  144. var stencilW = mxUtils.getValue(this.style, 'network2IconW', 1);
  145. var stencilH = mxUtils.getValue(this.style, 'network2IconH', 1);
  146. if (geometry != null)
  147. {
  148. geometry = geometry.clone();
  149. var w = geometry.width;
  150. var h = geometry.height;
  151. geometry.width = geometry.width * 1.4 / stencilW;
  152. geometry.height = geometry.height * 1.4 / stencilH;
  153. geometry.x = geometry.x + (w - geometry.width) * 0.5;
  154. geometry.y = geometry.y + (h - geometry.height) * 0.5;
  155. graph.model.setGeometry(state.cell, geometry);
  156. }
  157. }
  158. }
  159. mxCellRenderer.registerShape(mxShapeNetworks2Icon.prototype.cst.SHAPE_ICON, mxShapeNetworks2Icon);