mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
File structure for extensibility
This commit is contained in:
parent
cf88ec8333
commit
e1237feb97
43
Chart.min.js
vendored
43
Chart.min.js
vendored
File diff suppressed because one or more lines are too long
30
gulpfile.js
30
gulpfile.js
@ -23,30 +23,17 @@ var srcDir = './src/';
|
||||
|
||||
gulp.task('build', function() {
|
||||
|
||||
// Default to all of the chart types, with Chart.Core first
|
||||
var srcFiles = [
|
||||
FileName('Core'),
|
||||
FileName('Core.**'),
|
||||
FileName('Scale'),
|
||||
FileName('Scale.**'),
|
||||
FileName('Animation'),
|
||||
FileName('Tooltip'),
|
||||
'./src/core/core.js',
|
||||
'./src/core/**',
|
||||
'./src/scales/**',
|
||||
'./src/elements/**',
|
||||
'./src/charts/**',
|
||||
'./src/**',
|
||||
'./node_modules/color/dist/color.min.js'
|
||||
],
|
||||
isCustom = !!(util.env.types),
|
||||
outputDir = (isCustom) ? 'custom' : '.';
|
||||
if (isCustom) {
|
||||
util.env.types.split(',').forEach(function(type) {
|
||||
return srcFiles.push(FileName(type));
|
||||
});
|
||||
} else {
|
||||
// Seems gulp-concat remove duplicates - nice!
|
||||
// So we can use this to sort out dependency order - aka include Core first!
|
||||
srcFiles.push(srcDir + '*');
|
||||
srcFiles.push(srcDir + '*');
|
||||
srcFiles.push(srcDir + '*');
|
||||
srcFiles.push(srcDir + '*');
|
||||
}
|
||||
srcFiles.push('./node_modules/color/dist/color.min.js');
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(concat('Chart.js'))
|
||||
@ -58,9 +45,6 @@ gulp.task('build', function() {
|
||||
.pipe(concat('Chart.min.js'))
|
||||
.pipe(gulp.dest(outputDir));
|
||||
|
||||
function FileName(moduleName) {
|
||||
return srcDir + 'Chart.' + moduleName + '.js';
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
scales: {
|
||||
xAxes: [{
|
||||
scaleType: "dataset", // scatter should not use a dataset axis
|
||||
type: "category", // scatter should not use a dataset axis
|
||||
display: true,
|
||||
position: "bottom",
|
||||
id: "x-axis-1", // need an ID so datasets can reference the scale
|
||||
@ -43,7 +43,7 @@
|
||||
},
|
||||
}],
|
||||
yAxes: [{
|
||||
scaleType: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
||||
type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
|
||||
display: true,
|
||||
position: "left",
|
||||
id: "y-axis-1",
|
||||
@ -398,7 +398,7 @@
|
||||
this.scales = {};
|
||||
|
||||
// Build the x axis. The line chart only supports a single x axis
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].scaleType);
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(this.options.scales.xAxes[0].type);
|
||||
var xScale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: this.options.scales.xAxes[0],
|
||||
@ -413,7 +413,7 @@
|
||||
|
||||
// Build up all the y scales
|
||||
helpers.each(this.options.scales.yAxes, function(yAxisOptions) {
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.scaleType);
|
||||
var ScaleClass = Chart.scales.getScaleConstructor(yAxisOptions.type);
|
||||
var scale = new ScaleClass({
|
||||
ctx: this.chart.ctx,
|
||||
options: yAxisOptions,
|
||||
@ -11,8 +11,8 @@
|
||||
Chart.scaleService = {
|
||||
// The interesting function
|
||||
fitScalesForChart: function(chartInstance, width, height) {
|
||||
var xPadding = 5;
|
||||
var yPadding = 5;
|
||||
var xPadding = width > 30 ? 5 : 2;
|
||||
var yPadding = height > 30 ? 5 : 2;
|
||||
|
||||
if (chartInstance) {
|
||||
var leftScales = helpers.where(chartInstance.scales, function(scaleInstance) {
|
||||
@ -294,11 +294,11 @@
|
||||
constructors: {},
|
||||
// Use a registration function so that we can move to an ES6 map when we no longer need to support
|
||||
// old browsers
|
||||
registerScaleType: function(scaleType, scaleConstructor) {
|
||||
this.constructors[scaleType] = scaleConstructor;
|
||||
registerScaleType: function(type, scaleConstructor) {
|
||||
this.constructors[type] = scaleConstructor;
|
||||
},
|
||||
getScaleConstructor: function(scaleType) {
|
||||
return this.constructors.hasOwnProperty(scaleType) ? this.constructors[scaleType] : undefined;
|
||||
getScaleConstructor: function(type) {
|
||||
return this.constructors.hasOwnProperty(type) ? this.constructors[type] : undefined;
|
||||
}
|
||||
};
|
||||
|
||||
@ -207,7 +207,7 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
Chart.scales.registerScaleType("dataset", DatasetScale);
|
||||
Chart.scales.registerScaleType("category", DatasetScale);
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user