GanttSeries.js
10.1 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/**
* (c) 2016 Highsoft AS
* Authors: Lars A. V. Cabrera
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import 'CurrentDateIndicator.js';
import 'GridAxis.js';
import '../modules/static-scale.src.js';
import 'TreeGrid.js';
import 'Pathfinder.js';
import '../modules/xrange.src.js';
var dateFormat = H.dateFormat,
isObject = H.isObject,
isNumber = H.isNumber,
merge = H.merge,
pick = H.pick,
seriesType = H.seriesType,
seriesTypes = H.seriesTypes,
stop = H.stop,
Series = H.Series,
parent = seriesTypes.xrange;
/**
* A `gantt` series. If the [type](#series.gantt.type) option is not specified,
* it is inherited from [chart.type](#chart.type).
*
* @type {Object}
* @extends {plotOptions.xrange}
* @product gantt
* @optionparent plotOptions.gantt
*/
seriesType('gantt', 'xrange', {
// options - default options merged with parent
grouping: false,
dataLabels: {
enabled: true,
formatter: function () {
var point = this,
amount = point.point.partialFill;
if (isObject(amount)) {
amount = amount.amount;
}
if (isNumber(amount) && amount > 0) {
return (amount * 100) + '%';
}
}
},
tooltip: {
headerFormat: '<span style="color:{point.color};text-align:right">' +
'{series.name}' +
'</span><br/>',
pointFormat: null,
pointFormatter: function () {
var point = this,
series = point.series,
tooltip = series.chart.tooltip,
xAxis = series.xAxis,
options = xAxis.options,
formats = options.dateTimeLabelFormats,
startOfWeek = xAxis.options.startOfWeek,
ttOptions = series.tooltipOptions,
format = ttOptions.xDateFormat,
range = point.end ? point.end - point.start : 0,
start,
end,
milestone = point.options.milestone,
dateRowStart = '<span style="font-size: 0.8em">',
dateRowEnd = '</span><br/>',
retVal = '<b>' + (point.name || point.category) + '</b>';
if (ttOptions.pointFormat) {
return point.tooltipFormatter(ttOptions.pointFormat);
}
if (!format) {
format = H.splat(
tooltip.getDateFormat(
range,
point.start,
startOfWeek,
formats
)
)[0];
}
start = dateFormat(format, point.start);
end = dateFormat(format, point.end);
retVal += '<br/>';
if (!milestone) {
retVal += dateRowStart + 'Start: ' + start + dateRowEnd;
retVal += dateRowStart + 'End: ' + end + dateRowEnd;
} else {
retVal += dateRowStart + 'Date ' + start + dateRowEnd;
}
return retVal;
}
},
pathfinder: {
type: 'simpleConnect',
animation: {
reversed: true // Dependencies go from child to parent
},
startMarker: {
enabled: true,
symbol: 'arrow-filled',
radius: 4,
fill: '#fa0',
align: 'left'
},
endMarker: {
enabled: false, // Only show arrow on the dependent task
align: 'right'
}
}
}, {
// props - series member overrides
// Keyboard navigation, don't use nearest vertical mode
keyboardMoveVertical: false,
// Handle milestones, as they have no x2
translatePoint: function (point) {
var series = this,
shapeArgs,
size;
parent.prototype.translatePoint.call(series, point);
if (point.options.milestone) {
shapeArgs = point.shapeArgs;
size = shapeArgs.height;
point.shapeArgs = {
x: shapeArgs.x - (size / 2),
y: shapeArgs.y,
width: size,
height: size
};
}
},
/**
* Draws a single point in the series.
*
* This override draws the point as a diamond if point.options.milestone is
* true, and uses the original drawPoint() if it is false or not set.
*
* @param {Object} point an instance of Point in the series
* @param {string} verb 'animate' (animates changes) or 'attr' (sets
* options)
* @returns {void}
*/
drawPoint: function (point, verb) {
var series = this,
seriesOpts = series.options,
renderer = series.chart.renderer,
shapeArgs = point.shapeArgs,
plotY = point.plotY,
graphic = point.graphic,
state = point.selected && 'select',
cutOff = seriesOpts.stacking && !seriesOpts.borderRadius,
diamondShape;
if (point.options.milestone) {
if (isNumber(plotY) && point.y !== null) {
diamondShape = renderer.symbols.diamond(
shapeArgs.x,
shapeArgs.y,
shapeArgs.width,
shapeArgs.height
);
if (graphic) {
stop(graphic);
graphic[verb]({
d: diamondShape
});
} else {
point.graphic = graphic = renderer.path(diamondShape)
.addClass(point.getClassName(), true)
.add(point.group || series.group);
}
} else if (graphic) {
point.graphic = graphic.destroy(); // #1269
}
} else {
parent.prototype.drawPoint.call(series, point, verb);
}
},
setData: Series.prototype.setData,
setGanttPointAliases: function (options) {
// Add a value to options if the value exists
function addIfExists(prop, val) {
if (val !== undefined) {
options[prop] = val;
}
}
addIfExists('x', pick(options.start, options.x));
addIfExists('x2', pick(options.end, options.x2));
addIfExists(
'partialFill', pick(options.completed, options.partialFill)
);
addIfExists('connect', pick(options.dependency, options.connect));
}
}, merge(parent.prototype.pointClass.prototype, {
// pointProps - point member overrides. We inherit from parent as well.
/**
* Applies the options containing the x and y data and possible some extra
* properties. This is called on point init or from point.update.
*
* @param {Object} options the point options
* @param {number} x the x value
* @return {Object} the Point instance
*/
applyOptions: function (options, x) {
var point = this,
series = point.series,
retVal = merge(options);
series.setGanttPointAliases(retVal);
retVal = parent.prototype.pointClass.prototype.applyOptions
.call(point, retVal, x);
return retVal;
}
}));
/**
* Data for a Gantt series.
*
* @type {Object}
* @extends {series.xrange.data}
* @excluding connect,x,x2,partialFill
* @product gantt
* @apioption series.gantt.data
*/
/**
* Whether the grid node belonging to this point should start as collapsed. Used
* in axes of type treegrid.
*
* @type {Boolean}
* @default false
* @product gantt
* @sample {gantt} gantt/treegrid-axis/collapsed/ Start as collapsed
* @apioption series.gantt.data.collapsed
*/
/**
* The start time of a task.
*
* @type {number}
* @product gantt
* @apioption series.gantt.data.start
*/
/**
* The end time of a task.
*
* @type {number}
* @product gantt
* @apioption series.gantt.data.end
*/
/**
* The Y value of a task.
*
* @type {number}
* @product gantt
* @apioption series.gantt.data.y
*/
/**
* The name of a task. If a `treegrid` y-axis is used (default in Gantt charts),
* this will be picked up automatically, and used to calculate the y-value.
*
* @type {string}
* @product gantt
* @apioption series.gantt.data.name
*/
/**
* Progress indicator, how much of the task completed. If it is a number, the
* `fill` will be applied automatically.
*
* @type {object|number}
* @default undefined
* @extends {series.xrange.data.partialFill}
* @product gantt
* @sample {gantt} gantt/demo/progress-indicator Progress indicator
* @apioption series.gantt.data.completed
*/
/**
* The amount of the progress indicator, ranging from 0 (not started) to 1
* (finished).
*
* @type {number}
* @default 0
* @apioption series.gantt.data.completed.amount
*/
/**
* The fill of the progress indicator. Defaults to a darkened variety of the
* main color.
*
* @type {Highcharts.ColorString}
* @default undefined
* @apioption series.gantt.data.completed.fill
*/
/**
* The ID of the point (task) that this point depends on in Gantt charts.
* Aliases [connect](series.xrange.data#connect). Can also be an object,
* specifying further connecting [options](series.gantt.pathfinder) between the
* points.
*
* @type {string|object}
* @extends {series.xrange.data.connect}
* @since 6.2.0
* @sample gantt/demo/project-management
* Dependencies
* @product gantt
* @apioption series.gantt.data.dependency
*/
/**
* Whether this point is a milestone. If so, only the `start` option is handled,
* while `end` is ignored.
*
* @type {boolean}
* @since 6.2.0
* @sample gantt/gantt/milestones
* Milestones
* @product gantt
* @apioption series.gantt.data.milestone
*/
/**
* The ID of the parent point (task) of this point in Gantt charts.
*
* @type {string}
* @since 6.2.0
* @sample gantt/demo/subtasks
* Gantt chart with subtasks
* @product gantt
* @apioption series.gantt.data.parent
*/
/**
* A `gantt` series.
*
* @type {Object}
* @extends {plotOptions.gantt}
* @product gantt
* @apioption series.gantt
*/