nodetiles/nodetiles-core

View on GitHub
lib/renderer.js

Summary

Maintainability
F
5 days
Test Coverage

File renderer.js has 259 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var Canvas = require('canvas');
var UTFGrid = require('./utfgrid');
var fs = require('fs');
var path = require('path');
var __ = require('lodash');
Severity: Minor
Found in lib/renderer.js - About 2 hrs to fix

    Function deepEqual has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    var deepEqual = function(a, b) {
      try {
      var aKeys = Object.keys(a),
          bKeys = Object.keys(b);
      }
    Severity: Minor
    Found in lib/renderer.js - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function selectorIsMatch has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    var selectorIsMatch = function(selector, feature, source) {
      var matches = true;
      for (var key in selector) {
        if (key === "source") {
          matches = matches && selector[key] === source;
    Severity: Minor
    Found in lib/renderer.js - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function imageRenderer has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    var imageRenderer = function (ctx, scale, layers, styles) {
      // background first
      styles.forEach(function(style) {
        if (selectorIsMatch(style.selector)) {
          if (style.properties["background-color"]) {
    Severity: Minor
    Found in lib/renderer.js - About 1 hr to fix

      Function imageRenderer has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      var imageRenderer = function (ctx, scale, layers, styles) {
        // background first
        styles.forEach(function(style) {
          if (selectorIsMatch(style.selector)) {
            if (style.properties["background-color"]) {
      Severity: Minor
      Found in lib/renderer.js - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function deepEqual has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      var deepEqual = function(a, b) {
        try {
        var aKeys = Object.keys(a),
            bKeys = Object.keys(b);
        }
      Severity: Minor
      Found in lib/renderer.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if (selectorIsMatch(style.selector, feature, source)) {
                  style = style.properties;
                  
                  ctx.fillStyle = style.fillStyle || style['background-color'] || '';
                  ctx.strokeStyle = style.strokeStyle || style['line-color'] || '';
        Severity: Critical
        Found in lib/renderer.js - About 1 hr to fix

          Function renderGrid has 10 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          var renderGrid = exports.renderGrid = function(minX, minY, maxX, maxY, width, height, layers, styles, featureImage, callback) {
          Severity: Major
          Found in lib/renderer.js - About 1 hr to fix

            Function gridRenderer has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            var gridRenderer = function (ctx, scale, layers, styles) {
              var intColor = 1; // color zero is black/empty; so start with 1
              colorIndex = ['']; // make room for black/empty
              
              
            Severity: Minor
            Found in lib/renderer.js - About 1 hr to fix

              Function renderGrid has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              var renderGrid = exports.renderGrid = function(minX, minY, maxX, maxY, width, height, layers, styles, featureImage, callback) {
                var canvas = new Canvas(width, width),
                    ctx = canvas.getContext('2d'),
                    // we're using the same ratio for width and height, so the actual maxY may not match specified maxY...
                    pxPtRatio = width / (maxX - minX),
              Severity: Minor
              Found in lib/renderer.js - About 1 hr to fix

                Function renderImage has 9 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                var renderImage = exports.renderImage = function(minX, minY, maxX, maxY, width, height, layers, styles, callback) {
                Severity: Major
                Found in lib/renderer.js - About 1 hr to fix

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    if (featureImage) {
                      callback(undefined, canvas);
                    }
                    else {
                      var pixels = ctx.getImageData(0, 0, gridSize, gridSize).data; // array of all pixels
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 1 day to fix
                  lib/cartoRenderer.js on lines 85..108

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 222.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      'LineString': function(l) {
                          var start = l[0];
                          if (transform) {
                            start = transform(start);
                          }
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 4 hrs to fix
                  lib/cartoRenderer.js on lines 124..136

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 124.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      'Point': function(p, scale) {
                          if (transform) {
                            p = transform(p);
                            this.arc(p[0], p[1], 8, 0, Math.PI * 2, true);
                          }
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 3 hrs to fix
                  lib/cartoRenderer.js on lines 143..151

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 102.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    transform = function(p) {
                      var point = [];
                      point[0] = (p[0] - minX) * pxPtRatio;
                      point[1] = ((p[1] - minY) * -pxPtRatio) + height;
                      return point;
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 2 hrs to fix
                  lib/renderer.js on lines 27..32

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 75.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Similar blocks of code found in 2 locations. Consider refactoring.
                  Open

                    transform = function(p) {
                      var point = [];
                      point[0] = (p[0] - minX) * pxPtRatio;
                      point[1] = ((p[1] - minY) * -pxPtRatio) + height;
                      return point;
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 2 hrs to fix
                  lib/renderer.js on lines 62..67

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 75.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                      'MultiPoint': function(p, scale) {
                          // Can't use forEach here because we need to pass scale along
                          for (var i = 0, len = p.length; i < len; i++) {
                            renderPath.Point.call(this, p[i], scale);
                          }
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 1 hr to fix
                  lib/cartoRenderer.js on lines 137..142

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 67.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                  function d2h(d, digits) {
                    d = d.toString(16); 
                    while (d.length < digits) {
                          d = '0' + d;
                      }
                  Severity: Major
                  Found in lib/renderer.js and 1 other location - About 1 hr to fix
                  lib/cartoRenderer.js on lines 1020..1027

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 56.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  There are no issues that match your filters.

                  Category
                  Status