Introduction

This article provides a sample of drawing a Label in HTML.
First, we download the file in the following attachment:
  1. Kinectic_beta.js
This file is then added to the project, then use the following procedure.
Step 1
Open Visual Studio 2010 and click "File" -> "New" -> "Website...". A window is opened. In this window, give the name of your application as "Label" and then click "Ok".
Step 2
Add the "kinetic_beta.js" file. The project will have then been created; a new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the js file and HTML files.
solution.jpg
Coding
Label.html
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <style type="text/css">
  5. #container {
  6. height: 361px;
  7. }
  8. </style>
  9. <title></title>
  10. </head>
  11. <body>
  12. <h3> Label in HTML5 </h3>
  13. <div id="container"></div>
  14. <script src="Kinetic_beta.js" type="text/javascript"></script>
  15. <script>
  16. var stage = new Kinetic.Stage({
  17. container: 'container',
  18. width: 478,
  19. height: 800
  20. });
  21. var layer = new Kinetic.Layer();
  22. var tooltip = new Kinetic.Label({
  23. x: 170,
  24. y: 75,
  25. opacity: 0.75,
  26. listening: false,
  27. text: {
  28. text: 'Tooltip pointing down',
  29. fontFamily: 'Calibri',
  30. fontSize: 18,
  31. padding: 5,
  32. fill: 'Black'
  33. },
  34. rect: {
  35. fill: '#CCCCFF',
  36. pointerDirection: 'down',
  37. pointerWidth: 10,
  38. pointerHeight: 10,
  39. lineJoin: 'round',
  40. shadowColor: 'black',
  41. shadowBlur: 10,
  42. shadowOffset: 10,
  43. shadowOpacity: 0.5
  44. }
  45. });
  46. var labelLeft = new Kinetic.Label({
  47. x: 195,
  48. y: 130,
  49. opacity: 0.75,
  50. listening: false,
  51. text: {
  52. text: 'Label pointing left',
  53. fontFamily: 'Calibri',
  54. fontSize: 18,
  55. padding: 5,
  56. fill: 'white'
  57. },
  58. rect: {
  59. fill: 'green',
  60. pointerDirection: 'left',
  61. pointerWidth: 20,
  62. pointerHeight: 28,
  63. lineJoin: 'round',
  64. }
  65. });
  66. var simpleLabel = new Kinetic.Label({
  67. x: 350,
  68. y: 50,
  69. opacity: 0.75,
  70. text: {
  71. text: 'Simple label',
  72. fontFamily: 'Calibri',
  73. fontSize: 18,
  74. padding: 5,
  75. fill: 'black'
  76. },
  77. rect: {
  78. fill: '#0099CC',
  79. }
  80. });
  81. // add the shape to the layer
  82. layer.add(tooltip).add(labelLeft).add(simpleLabel);
  83. // add the layer to the stage
  84. stage.add(layer);
  85. </script>
  86. </body>
  87. </html>
Output
output.jpg
For more information, download the attached sample application.