0.3.2 • Published 3 years ago

cojasclib v0.3.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

COJASCLIB

COmmon JAvascript Standard for Charting LIBraries

Note: This package is in active development and therefore should not be used until further notice

Introduction

With the increasing number of javascript libraries for data visualization, and the benefits and flaws of each of them, programmers are often obliged to use several libraries for the same project. These heterogeneity adds unnecessary complexity to the code and can lead to problems. We developped this package as an intent to define a standard for data visualization with a system of pluggable adaptors for external libraries.

Quick start:

npm install cojasclib --save

let Cojasclib = require('cojasclib')

let chart = new Cojasclib.Chart(graphOptions)
let serie = new Cojasclib.Serie({ name: 'serie name', options: serieOptions)

serie.setDataPoint({ x: '', y: '', label: '', options: {} })

chart.setSerie(serie)
chart.render("chartjs", renderingOptions).then(res => {
  this.renderChart(res[0], res[1]);
)

chart Object

setSerie(): Adds serie to final chart object. can be done several time for multi-series

Note: Sort can be set at chartSerie or at chartObject at rendering

  • renderingOptions:
    • sort: true is sorted, false not
    • order: defaults to numeric sort
      • 'array': sort according to the array
      • 'date': date sorted
      • 'alpha': alpha sorted
      • typeof function: The function is passed directly to the lodash function "orderBy"
    • direction: 'ASC' or 'DESC'. Defaults to 'ASC'
    • noConsolidation: true, skips consolidation (only for multiple series). Consolidation populates with empty values the points that are set in one serie and not in another
    • missingPointOptions: In case of consolidation, the options that are used for the created points
    • sortOrdinates: if true, sorts by ordinate (y values)
    • yLabels: Array of labels that defines the order they have to appear. For example: "fruits", "Vegetables", "Meat"
    • labelFunction: String modifier function applied to x Labels before displaying. Ex: labelFunction: label => { return label.split("-")[1]; }
    • lengthXMax: INTEGER Max Number of character for splitting x labels, splitting is done on spaces

chart serie object:

  • name: name of the serie. Appears as serie legend
  • opts:
    • sort: true is sorted, false not
    • order: defaults to numeric sort
      • 'array': sort according to the array
      • 'date': date sorted
      • 'alpha': alpha sorted
      • typeof function: The function is passed directly to the lodash function "orderBy"
    • direction: 'ASC' or 'DESC'. Defaults to 'ASC'
    • fillNullDateValues: if a date are missing in the serie, replaces it with the point {label: date, x: date, y: 0}
    • dateFormat: defines the output of the label if it is moment object. see Moment formatting
    • cumulative: adds each value of serie to previous one
    • grouped: if 2 points have the same label, they are cumulated.
    • limitedPoints: Allow to limit the number of points and define a point with "name" as label and the sum of remaining points y as value
  options {
      ...
    limitedPoints = {
        max: x,
        name: 'Others',
    }
    ...
  }
  ;

Data point

  • x: the absciss value
  • label: the x label (defaults to x)
  • y: the ordinate value (defaults to label)
  • z: the z coordinate for a 3d point (defaults to none)
  • options:
    • color: Set this to change a single point color (color: "#C7E84D")

Available plugins

  • chartist
  • chartjs
  • chartcsv

Plugin Development

The idea is that the same settings will work with any Library

TODO

Common Options:

OptionTypeDescription
defaultFontColorstringDefines font color for all graph text
legendDisplayBoolWether legend should be displayed
xDisplayBoolIf xaxis legends, ticks and labels should be displayed
yDisplayBoolIf yaxis legends, ticks and labels should be displayed
xDisplayGridBoolIf xaxis grid should be displayed
yDisplayGridBoolIf yaxis grid should be displayed

TODO

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.9

3 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.0

5 years ago