Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/controllers/controller.histogram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import BarController from './controller.bar.js';

/**
* @typedef { import('../types.js').ChartMeta } ChartMeta
* @typedef { import('../types.js').Point } Point
*/

export default class HistogramController extends BarController {

static id = 'histogram';

/**
* @type {any}
*/
static defaults = {
datasetElementType: false,
dataElementType: 'bar',

// Bars fill the entire category width with no gaps between them,
// which is the expected appearance for a histogram.
barPercentage: 1,
categoryPercentage: 1,

grouped: false,

animations: {
numbers: {
type: 'number',
properties: ['x', 'y', 'base', 'width', 'height']
}
}
};

/**
* @type {any}
*/
static overrides = {
scales: {
// A linear index axis is required so bars are positioned and sized
// according to their numeric x values rather than by category index.
_index_: {
type: 'linear',
offset: false,
grid: {
offset: false
}
},
_value_: {
type: 'linear',
beginAtZero: true,
}
}
};

}
1 change: 1 addition & 0 deletions src/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {default as BarController} from './controller.bar.js';
export {default as BubbleController} from './controller.bubble.js';
export {default as HistogramController} from './controller.histogram.js';
export {default as DoughnutController} from './controller.doughnut.js';
export {default as LineController} from './controller.line.js';
export {default as PolarAreaController} from './controller.polarArea.js';
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
BarController,
BubbleController,
DoughnutController,
HistogramController,
LineController,
PieController,
PolarAreaController,
Expand Down
17 changes: 17 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ export declare const BarController: ChartComponent & {
new (chart: Chart, datasetIndex: number): BarController;
};

export type HistogramControllerDatasetOptions = BarControllerDatasetOptions;
export type HistogramControllerChartOptions = BarControllerChartOptions;

export type HistogramController = BarController
export declare const HistogramController: ChartComponent & {
prototype: HistogramController;
new (chart: Chart, datasetIndex: number): HistogramController;
};

export interface BubbleControllerDatasetOptions
extends ControllerDatasetOptions,
ScriptableAndArrayOptions<PointOptions, ScriptableContext<'bubble'>>,
Expand Down Expand Up @@ -3716,6 +3725,14 @@ export interface ChartTypeRegistry {
parsedDataType: BarParsedData,
scales: keyof CartesianScaleTypeRegistry;
};
histogram: {
chartOptions: HistogramControllerChartOptions;
datasetOptions: HistogramControllerDatasetOptions;
defaultDataPoint: ScatterDataPoint | number | null;
metaExtensions: {};
parsedDataType: BarParsedData;
scales: keyof CartesianScaleTypeRegistry;
};
line: {
chartOptions: LineControllerChartOptions;
datasetOptions: LineControllerDatasetOptions & FillerControllerDatasetOptions;
Expand Down