chartjs/Chart.js

View on GitHub

Showing 242 of 247 total issues

File helpers.canvas.ts has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type {
Chart,
Point,
FontSpec,
CanvasFontSpec,
Severity: Minor
Found in src/helpers/helpers.canvas.ts - About 5 hrs to fix

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

    function createAttachObserver(chart, type, listener) {
    const canvas = chart.canvas;
    const observer = new MutationObserver(entries => {
    let trigger = false;
    for (const entry of entries) {
    Severity: Major
    Found in src/platform/platform.dom.js and 1 other location - About 5 hrs to fix
    src/platform/platform.dom.js on lines 145..159

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

    function createDetachObserver(chart, type, listener) {
    const canvas = chart.canvas;
    const observer = new MutationObserver(entries => {
    let trigger = false;
    for (const entry of entries) {
    Severity: Major
    Found in src/platform/platform.dom.js and 1 other location - About 5 hrs to fix
    src/platform/platform.dom.js on lines 129..143

    File scale.time.js has 385 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import adapters from '../core/core.adapters.js';
    import {callback as call, isFinite, isNullOrUndef, mergeIf, valueOrDefault} from '../helpers/helpers.core.js';
    import {toRadians, isNumber, _limitValue} from '../helpers/helpers.math.js';
    import Scale from '../core/core.scale.js';
    import {_arrayUnique, _filterBetween, _lookup} from '../helpers/helpers.collection.js';
    Severity: Minor
    Found in src/scales/scale.time.js - About 5 hrs to fix

      Function drawPointLegend has 119 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function drawPointLegend(
      ctx: CanvasRenderingContext2D,
      options: DrawPointOptions,
      x: number,
      y: number,
      Severity: Major
      Found in src/helpers/helpers.canvas.ts - About 4 hrs to fix

        Function _draw has 118 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        _draw() {
        const {options: opts, columnSizes, lineWidths, ctx} = this;
        const {align, labels: labelOpts} = opts;
        const defaultColor = defaults.color;
        const rtlHelper = getRtlAdapter(opts.rtl, this.left, this.width);
        Severity: Major
        Found in src/plugins/plugin.legend.js - About 4 hrs to fix

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

          if (isObject(position)) {
          const positionAxisID = Object.keys(position)[0];
          const value = position[positionAxisID];
          titleX = scales[positionAxisID].getPixelForValue(value) - width + offset;
          } else if (position === 'center') {
          Severity: Major
          Found in src/core/core.scale.js and 1 other location - About 4 hrs to fix
          src/core/core.scale.js on lines 142..150

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

          if (isObject(position)) {
          const positionAxisID = Object.keys(position)[0];
          const value = position[positionAxisID];
          titleY = scales[positionAxisID].getPixelForValue(value) + height - offset;
          } else if (position === 'center') {
          Severity: Major
          Found in src/core/core.scale.js and 1 other location - About 4 hrs to fix
          src/core/core.scale.js on lines 153..161

          Function _computeGridLineItems has 113 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          _computeGridLineItems(chartArea) {
          const axis = this.axis;
          const chart = this.chart;
          const options = this.options;
          const {grid, position, border} = options;
          Severity: Major
          Found in src/core/core.scale.js - About 4 hrs to fix

            File helpers.config.ts has 344 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            /* eslint-disable @typescript-eslint/no-use-before-define */
            import type {AnyObject} from '../types/basic.js';
            import type {ChartMeta} from '../types/index.js';
            import type {
            ResolverObjectKey,
            Severity: Minor
            Found in src/helpers/helpers.config.ts - About 4 hrs to fix

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

              getTitle(context, options) {
              const {callbacks} = options;
               
              const beforeTitle = invokeCallbackWithFallback(callbacks, 'beforeTitle', this, context);
              const title = invokeCallbackWithFallback(callbacks, 'title', this, context);
              Severity: Major
              Found in src/plugins/plugin.tooltip.js and 1 other location - About 4 hrs to fix
              src/plugins/plugin.tooltip.js on lines 582..595

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

              getFooter(tooltipItems, options) {
              const {callbacks} = options;
               
              const beforeFooter = invokeCallbackWithFallback(callbacks, 'beforeFooter', this, tooltipItems);
              const footer = invokeCallbackWithFallback(callbacks, 'footer', this, tooltipItems);
              Severity: Major
              Found in src/plugins/plugin.tooltip.js and 1 other location - About 4 hrs to fix
              src/plugins/plugin.tooltip.js on lines 533..546

              Function _getYAxisLabelAlignment has a Cognitive Complexity of 29 (exceeds 7 allowed). Consider refactoring.
              Open

              _getYAxisLabelAlignment(tl) {
              const {position, ticks: {crossAlign, mirror, padding}} = this.options;
              const labelSizes = this._getLabelSizes();
              const tickAndPadding = tl + padding;
              const widest = labelSizes.widest.width;
              Severity: Minor
              Found in src/core/core.scale.js - About 3 hrs to fix

              effects has 31 functions (exceeds 20 allowed). Consider refactoring.
              Open

              const effects = {
              linear: (t: number) => t,
               
              easeInQuad: (t: number) => t * t,
               
               
              Severity: Minor
              Found in src/helpers/helpers.easing.ts - About 3 hrs to fix

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

                if (yAlign === 'top') {
                y1 = ptY;
                y2 = y1 - caretSize;
                 
                // Top draws left -> right, thus x1 is on the left
                Severity: Major
                Found in src/plugins/plugin.tooltip.js and 1 other location - About 3 hrs to fix
                src/plugins/plugin.tooltip.js on lines 710..724

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

                if (xAlign === 'left') {
                x1 = ptX;
                x2 = x1 - caretSize;
                 
                // Left draws bottom -> top, this y1 is on the bottom
                Severity: Major
                Found in src/plugins/plugin.tooltip.js and 1 other location - About 3 hrs to fix
                src/plugins/plugin.tooltip.js on lines 736..750

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

                if (reverse) {
                if (val >= table[lo].pos && val <= table[hi].pos) {
                ({lo, hi} = _lookupByKey(table, 'pos', val));
                }
                ({pos: prevSource, time: prevTarget} = table[lo]);
                Severity: Major
                Found in src/scales/scale.timeseries.js and 1 other location - About 3 hrs to fix
                src/scales/scale.timeseries.js on lines 22..28

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

                } else {
                if (val >= table[lo].time && val <= table[hi].time) {
                ({lo, hi} = _lookupByKey(table, 'time', val));
                }
                ({time: prevSource, pos: prevTarget} = table[lo]);
                Severity: Major
                Found in src/scales/scale.timeseries.js and 1 other location - About 3 hrs to fix
                src/scales/scale.timeseries.js on lines 16..22

                Function generateTicks has 86 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function generateTicks(generationOptions, dataRange) {
                const ticks = [];
                // To get a "nice" value for the tick spacing, we will use the appropriately named
                // "nice number" algorithm. See https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
                // for details.
                Severity: Major
                Found in src/scales/scale.linearbase.js - About 3 hrs to fix

                  File core.config.js has 310 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  import defaults, {overrides, descriptors} from './core.defaults.js';
                  import {mergeIf, resolveObjectKey, isArray, isFunction, valueOrDefault, isObject} from '../helpers/helpers.core.js';
                  import {_attachContext, _createResolver, _descriptors} from '../helpers/helpers.config.js';
                   
                  export function getIndexAxis(type, options) {
                  Severity: Minor
                  Found in src/core/core.config.js - About 3 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language