GanttChart.js
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* (c) 2016 Highsoft AS
* Authors: Lars A. V. Cabrera
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import 'GanttSeries.js';
var each = H.each,
map = H.map,
merge = H.merge,
splat = H.splat,
Chart = H.Chart;
/**
* The GanttChart class.
* @class Highcharts.ganttChart
* @memberOf Highcharts
* @param {String|HTMLDOMElement} renderTo The DOM element to render to, or
* its id.
* @param {ChartOptions} options The chart options structure.
* @param {Function} callback Function to run when the chart has
* loaded.
*/
H.ganttChart = function (renderTo, options, callback) {
var hasRenderToArg = typeof renderTo === 'string' || renderTo.nodeName,
seriesOptions = options.series,
defaultOptions = H.getOptions(),
defaultLinkedTo;
options = arguments[hasRenderToArg ? 1 : 0];
// If user hasn't defined axes as array, make it into an array and add a
// second axis by default.
if (!H.isArray(options.xAxis)) {
options.xAxis = [options.xAxis || {}, {}];
}
// apply X axis options to both single and multi x axes
options.xAxis = map(options.xAxis, function (xAxisOptions, i) {
if (i === 1) { // Second xAxis
defaultLinkedTo = 0;
}
return merge(
defaultOptions.xAxis,
{ // defaults
grid: {
enabled: true
},
opposite: true,
linkedTo: defaultLinkedTo
},
xAxisOptions, // user options
{ // forced options
type: 'datetime'
}
);
});
// apply Y axis options to both single and multi y axes
options.yAxis = map(splat(options.yAxis || {}), function (yAxisOptions) {
return merge(
defaultOptions.yAxis, // #3802
{ // defaults
grid: {
enabled: true
},
staticScale: 50,
reversed: true,
// Set default type treegrid, but only if 'categories' is
// undefined
type: yAxisOptions.categories ? yAxisOptions.type : 'treegrid'
},
yAxisOptions // user options
);
});
options.series = null;
options = merge(
{
chart: {
type: 'gantt'
},
title: {
text: null
},
legend: {
enabled: false
}
},
options // user's options
);
options.series = seriesOptions;
each(options.series, function (series) {
each(series.data, function (point) {
H.seriesTypes.gantt.prototype.setGanttPointAliases(point);
});
});
return hasRenderToArg ?
new Chart(renderTo, options, callback) :
new Chart(options, options);
};