pathnode.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. define(function(require, exports, module) {
  2. var Group = require('graphic/group');
  3. var Rect = require('graphic/rect');
  4. var Text = require('graphic/text');
  5. var TextSpan = require('graphic/textspan');
  6. var colors = require('../pathdiagram/colors');
  7. return require('core/class').createClass({
  8. base: Group,
  9. constructor: function(x, y, width, height, data, bold) {
  10. this.callBase();
  11. this.data = data;
  12. this.rect = new Rect(width, height, x, y, 5);
  13. this.text = new Text().pipe(function() {
  14. this.setSize(14);
  15. this.setX(x + width / 2);
  16. this.setY(y + height / 2 + 6);
  17. this.setTextAnchor('middle');
  18. this.addSpan(new TextSpan(data.word + ' | ').fill(colors.get('text')));
  19. this.addSpan(new TextSpan(data.uv).fill(colors.get('text-uv')));
  20. });
  21. this.addShape(this.rect);
  22. this.addShape(this.text);
  23. this.unselect();
  24. this.setStyle('cursor', 'pointer');
  25. this.bold = bold;
  26. },
  27. unselect: function() {
  28. this.rect.fill(colors.get('node-fill'));
  29. this.rect.stroke(colors.get('node-stroke'));
  30. },
  31. select: function() {
  32. this.rect.fill(colors.get('node-fill-active'));
  33. this.rect.stroke(colors.get('node-stroke-active'), this.bold ? 3 : 1);
  34. }
  35. });
  36. });