mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@types/chartjs-plugin-colorschemes] Create type definitions (#44149)
This commit is contained in:
parent
e2b8378a90
commit
0dc3b3ce6f
@ -0,0 +1,54 @@
|
||||
import * as Chart from 'chart.js';
|
||||
import { ColorSchemesOptions } from 'chartjs-plugin-colorschemes';
|
||||
|
||||
// https://github.com/nagix/chartjs-plugin-colorschemes/blob/master/src/plugins/plugin.colorschemes.js#L12
|
||||
const defaults: ColorSchemesOptions = {
|
||||
scheme: 'brewer.Paired12',
|
||||
fillAlpha: 0.5,
|
||||
reverse: false,
|
||||
override: false,
|
||||
};
|
||||
|
||||
// Supports global defaults
|
||||
Chart.defaults.global.plugins = {
|
||||
colorschemes: defaults,
|
||||
};
|
||||
|
||||
const ctx = new CanvasRenderingContext2D();
|
||||
const chartData = {};
|
||||
|
||||
// Supports chart options
|
||||
// https://github.com/nagix/chartjs-plugin-colorschemes#usage
|
||||
let chart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: chartData,
|
||||
options: {
|
||||
plugins: {
|
||||
colorschemes: defaults,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// Supports custom function
|
||||
// https://github.com/nagix/chartjs-plugin-colorschemes#custom-function
|
||||
const customColorFunction = (schemeColors: string[]) => {
|
||||
const myColors = ['#ff0000', '#00ff00', '#0000ff']; // define/generate own colors
|
||||
|
||||
// extend the color scheme with own colors
|
||||
Array.prototype.push.apply(schemeColors, myColors);
|
||||
|
||||
return schemeColors; // optional: this is not needed if the array is modified in place
|
||||
};
|
||||
|
||||
chart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: chartData,
|
||||
options: {
|
||||
plugins: {
|
||||
colorschemes: {
|
||||
scheme: 'brewer.Paired12',
|
||||
custom: customColorFunction,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
25
types/chartjs-plugin-colorschemes/index.d.ts
vendored
Normal file
25
types/chartjs-plugin-colorschemes/index.d.ts
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Type definitions for chartjs-plugin-colorschemes 0.4
|
||||
// Project: https://nagix.github.io/chartjs-plugin-colorschemes
|
||||
// Definitions by: Dan Manastireanu <https://github.com/danmana>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import * as Chart from 'chart.js';
|
||||
|
||||
declare module 'chart.js' {
|
||||
interface ChartPluginsOptions {
|
||||
colorschemes?: ColorSchemesOptions;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ColorSchemesOptions {
|
||||
scheme: string | string[];
|
||||
fillAlpha?: number;
|
||||
reverse?: boolean;
|
||||
override?: boolean;
|
||||
custom?: (schemeColors: string[]) => string[] | void;
|
||||
}
|
||||
|
||||
declare const ColorSchemesPlugin: Chart.PluginServiceGlobalRegistration & Chart.PluginServiceRegistrationOptions;
|
||||
|
||||
export default ColorSchemesPlugin;
|
||||
24
types/chartjs-plugin-colorschemes/tsconfig.json
Normal file
24
types/chartjs-plugin-colorschemes/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"chartjs-plugin-colorschemes-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/chartjs-plugin-colorschemes/tslint.json
Normal file
1
types/chartjs-plugin-colorschemes/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user