| Conditions | 4 |
| Paths | 6 |
| Total Lines | 82 |
| Code Lines | 66 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** global: google */ |
||
| 4 | const generateClusterCanvas = function(options) { |
||
| 5 | let canvas = options.canvas || document.createElement("canvas"), |
||
| 6 | anchorX = 27, |
||
| 7 | anchorY = 53, |
||
| 8 | radius = anchorX - 9, |
||
| 9 | color1, |
||
| 10 | font = options.font || "fontello", |
||
| 11 | fontsize = options.fontsize || 14, |
||
| 12 | context = canvas.getContext("2d"); |
||
| 13 | |||
| 14 | canvas.width = anchorX * 2; |
||
| 15 | canvas.height = anchorY + 1; |
||
| 16 | |||
| 17 | context.clearRect(0, 0, canvas.width, canvas.height); |
||
| 18 | context.moveTo(anchorX, anchorY); |
||
| 19 | |||
| 20 | let labelvalue = parseInt(options.label, 10); |
||
| 21 | if (labelvalue < 10) { |
||
| 22 | color1 = "orange"; |
||
| 23 | fontsize = 14; |
||
| 24 | } else if (labelvalue < 30) { |
||
| 25 | color1 = "red"; |
||
| 26 | fontsize = 15; |
||
| 27 | } else { |
||
| 28 | color1 = "purple"; |
||
| 29 | fontsize = 16; |
||
| 30 | } |
||
| 31 | if (labelvalue > 99) { |
||
| 32 | radius = radius + 3; |
||
| 33 | context.setLineDash([5, 5]); |
||
| 34 | context.beginPath(); |
||
| 35 | context.arc( |
||
| 36 | anchorX, |
||
| 37 | 2 + 0.5 * anchorY, |
||
| 38 | radius + 7, |
||
| 39 | 0, |
||
| 40 | 2 * Math.PI, |
||
| 41 | false |
||
| 42 | ); |
||
| 43 | context.fillStyle = "transparent"; |
||
| 44 | context.strokeStyle = color1; |
||
| 45 | context.lineWidth = 2; |
||
| 46 | context.fill(); |
||
| 47 | context.stroke(); |
||
| 48 | } |
||
| 49 | |||
| 50 | context.setLineDash([5, 5]); |
||
| 51 | context.beginPath(); |
||
| 52 | context.arc(anchorX, 2 + 0.5 * anchorY, radius + 2, 0, 2 * Math.PI, false); |
||
| 53 | context.fillStyle = "transparent"; |
||
| 54 | context.strokeStyle = color1; |
||
| 55 | context.lineWidth = 2; |
||
| 56 | context.fill(); |
||
| 57 | context.stroke(); |
||
| 58 | |||
| 59 | // Círculo blanco |
||
| 60 | context.setLineDash([5, 0]); |
||
| 61 | context.beginPath(); |
||
| 62 | context.arc(anchorX, 2 + 0.5 * anchorY, radius - 3, 0, 2 * Math.PI, false); |
||
| 63 | context.fillStyle = "white"; |
||
| 64 | context.strokeStyle = color1; |
||
| 65 | context.lineWidth = 4; |
||
| 66 | context.fill(); |
||
| 67 | context.stroke(); |
||
| 68 | |||
| 69 | context.beginPath(); |
||
| 70 | |||
| 71 | context.font = "normal normal normal " + fontsize + "px " + font; |
||
| 72 | console.log("context font", context.font); |
||
|
|
|||
| 73 | context.fillStyle = "#333"; |
||
| 74 | context.textBaseline = "top"; |
||
| 75 | |||
| 76 | let textWidth = context.measureText(options.label), |
||
| 77 | text_x = options.label, |
||
| 78 | label_x = Math.floor(canvas.width / 2 - textWidth.width / 2), |
||
| 79 | label_y = 1 + Math.floor(canvas.height / 2 - fontsize / 2); |
||
| 80 | |||
| 81 | // centre the text. |
||
| 82 | context.fillText(text_x, label_x, label_y); |
||
| 83 | |||
| 84 | return canvas; |
||
| 85 | }; |
||
| 86 | function createClusterIcon(theoptions) { |
||
| 109 |