nagix / chartjs-plugin-colorschemes

Predefined color schemes for Chart.js
MIT License
271 stars 59 forks source link

[REQUEST] Modularize #6

Closed CelticParser closed 5 years ago

CelticParser commented 5 years ago

Modularizing the color schema(s) will greatly reduce the user payload.

i.e: Instead of:

import 'chartjs-plugin-colorschemes';  // This loads everything at 50K!

Use:

import { OfficeAspect6 } from 'chartjs-plugin-colorschemes';  // Only loads what's needed = 75 bytes!!
nagix commented 5 years ago

Color schemes are modularized by e1336da. Once a new npm package (v0.4.0) is released, you will be able to import the plugin core and a particular color scheme only as ES6 modules like this:

// import the plugin core
import 'chartjs-plugin-colorschemes/src/plugins/plugin.colorschemes';

// import a particular color scheme
import { Aspect6 } from 'chartjs-plugin-colorschemes/src/colorschemes/colorschemes.office';

// ...
    options: {
        plugins: {
            colorschemes: {
                scheme: Aspect6
            }
        }
    }
//...

Tree-shaking will work, so the size will greatly be reduced.

It will also support the original import statement.

// import the plugin core and all the color schemes
import 'chartjs-plugin-colorschemes';

// ...
    options: {
        plugins: {
            colorschemes: {
                scheme: 'office.Aspect6'
            }
        }
    }
//...
nagix commented 5 years ago

Closing as v0.4.0 was released.