forked from antononcube/MathematicaForPrediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitHubDataObjects.m
588 lines (453 loc) · 24.4 KB
/
GitHubDataObjects.m
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
(*
GitHubDataObjects Mathematica package
Copyright (C) 2015 Anton Antonov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by Anton Antonov,
antononcube @ gmail.com,
Windermere, Florida, USA.
*)
(*
Mathematica is (C) Copyright 1988-2015 Wolfram Research, Inc.
Protected by copyright law and international treaties.
Unauthorized reproduction or distribution subject to severe civil
and criminal penalties.
Mathematica is a registered trademark of Wolfram Research, Inc.
*)
(* :Title: GitHubDataObjects *)
(* :Author: Anton Antonov *)
(* :Date: 2015-10-15 *)
(* :Package Version: 0.1 *)
(* :Mathematica Version: 10.2 *)
(* :Copyright: (c) 2015 Anton Antonov *)
(* :Keywords: GitHub, commit, plot, design patterns, Template Method, Strategy, Decorator, Composite, GoF *)
(* :Discussion:
This package provides object-oriented implementation of visualization and query tasks of commits data from GiHub.
The implementation uses the design patterns Template Method, Strategy, Decorator, and Composite described in the
book:
[GoF-94] Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides,
Design Patterns: Elements of Reusable Object-Oriented Software, Addison-Wesley, 1994.
The implementation is a modified and extended version of the functions in the package "GitHubPlots.m".
(Which is also provided in this MathematicaForPrediction GitHub project.)
The most significant feature of this package is the method "Plot3D" for a collection of GitHub projects.
Here is an example how to use it:
ghs = Map[MakeGitHubDataObject["hadley", #] &, {"plyr", "dplyr", "adv-r", "ggplot2", "devtools", "rvest"}]
ghComposite = GitHubDataComposite[Unique[], ghs]
Through[ghComposite["GetChildren"[]]@"Project"[]]
ghComposite["Plot3D"["ProjectPlanes" -> True, BoxRatios -> {1, 2, 2}]]
ghComposite["Plot3D"[
"ProjectPlanes" -> False,
"GlobalTimeOrder" -> False,
"SubsetQueryFunction" -> (StringMatchQ[#committer, ___ ~~ "Hadley" | "hadley" ~~ ___] &),
"SubsetLines" -> True,
"SubsetPlotStyle" -> {PointSize[0.02], Lighter[Purple], Arrowheads[10^-7.7, Appearance -> "Flat"]},
PlotLabel -> "Hadley Wickham",
BoxRatios -> {1, 2, 2}]]
Descriptions of the options follow.
1. "ProjectPlanes" -> True|False
Should planes for the projects be drawn on the 3D plot.
2. "GlobalTimeOrder" -> True|False
Should the points be ordered globally in time or for each project separately.
If False the points of each project are given Z coordinate corresponding to their commit order.
If True the points of all projects are ordered according to their times and their Z coordinates are
derived from that global order.
3. "SubsetQueryFunction" -> selectFunc
Allows for selection of points that adhere to a predicate. The function selectFunc is used in the Dataset's
corresponding to the projects and from the obtained rows the subset of points is derived.
4. "SubsetLines" -> True | False
Should line segments (arrows) be drawn between the subset points.
5. "SubsetPlotStyle" -> subPloStyle
Graphics3D directive for the color, size, etc. of the points and lines corresponding to the specified subset.
6. Other Graphics3D options passed to Graphics3D.
The implementation description with design patterns:
- Template Method is used for the general flow of the data obtaining, parsing, and plotting.
- Strategy is used for the different types of plots based on DateListPlot, BarChart, and Graphics3D.
- Decorator is used to endow the DateListPlot based plots with lines of the commit dependencies.
- Decorator is used to give color to the ticks and points in the plots.
- For a collection of GitHub projects Composite is used to obtain plots with uniform ranges, and
to make a 3D plot of the data of all projects highlighting a subset of the data points.
The functions are not put into a real Mathematica package because the implementations were made for didactic purposes.
TODO:
1. Implement standard functions based on the classes/objects implemented here.
2. Refactor the code to be able to work with other types time logs data.
This file was created using Mathematica Plugin for IntelliJ IDEA.
Anton Antonov
2015-10-15
*)
(**********************************************************)
(* Creation *)
(**********************************************************)
(*Clear[GitHubData]*)
MakeGitHubDataObject[user_String, project_String] :=
Block[{objID = Unique[]},
GitHubData[{objID, user, project}];
GitHubData[{objID, user, project}]["CommitData"] = {};
GitHubData[{objID, user, project}]["PlotFunction"] = GHDDateListPlot;
GitHubData[{objID, user, project}]
];
(**********************************************************)
(* Data download *)
(**********************************************************)
GitHubData[{objID_, user_String, project_String}]["GetData"[]] :=
Block[{obj = GitHubData[{objID, user, project}], url, data},
If[Length[obj["CommitData"]] == 0,
url = StringTemplate["https://api.github.com/repos/`1`/`2`/commits"];
data = Import[url[user, project], "JSON"];
obj["CommitData"] = data;
];
obj["CommitData"]
];
(**********************************************************)
(* Parsing *)
(**********************************************************)
Clear[ParseGitRecord]
ParseGitRecord[recRules_] :=
Block[{sha, message, committer, date, parentSha, htmlURL},
(*Print["ParseGitRecord called."];*)
sha = "sha" /. recRules;
message = StringReplace["message" /. ("commit" /. recRules), Whitespace -> " "];
committer = "name" /. ("committer" /. ("commit" /. recRules));
date = "date" /. ("committer" /. ("commit" /. recRules));
parentSha = "sha" /. ("parents" /. recRules);
htmlURL = "html_url" /. recRules;
Thread[{"sha", "message", "committer", "date", "parentSha", "htmlURL"} -> {sha, message, committer, date, parentSha, htmlURL}]
];
GitHubData[{objID_, user_String, project_String}]["ParseData"[]] :=
Block[{obj = GitHubData[{objID, user, project}], commitRecs, graphRules, unknown, unknownDate},
(*Similarly to the previous implementation code.*)
If[Length[obj["CommitRecords"]] == 0 || !ListQ[obj["CommitRecords"]],
Evaluate[obj]["CommitRecords"] = SortBy[ParseGitRecord /@ obj["GetData"[]], "date" /. # &];
(*A shortcut.*)
commitRecs = GitHubData[{objID, user, project}]["CommitRecords"];
(*Make a commits graph rules*)
graphRules =
Flatten@Map[Thread, ("parentSha" -> "sha") /. commitRecs];
(*Find the unknown parents and add empty records for them.*)
unknown =
Complement[Union[Flatten[List @@@ graphRules]],
"sha" /. commitRecs];
(*Offset the commit dates of the unknown commits to be one day behind.*)
unknownDate =
DateString[Min[Map[AbsoluteTime[DateList[#]] &, "date" /. commitRecs]] - 24*3600];
(*Add records for the unknown commits.*)
commitRecs =
Join[commitRecs,
Map[{"sha" -> #, "message" -> "none", "committer" -> "unknown", "date" -> unknownDate, "parentSha" -> "none"} &, unknown]];
commitRecs = SortBy[commitRecs, DateList["date" /. #] &];
(*Assign and return result.*)
obj["CommitRecords"] = commitRecs;
];
obj["CommitRecords"]
];
(**********************************************************)
(* Template Method for "Plot" *)
(**********************************************************)
GitHubDataHEAD = GitHubData;
GitHubData[{objID_, user_String, project_String}]["TickLabels"[]] :=
Block[{ obj = GitHubDataHEAD[{objID, user, project}], commitRecs, tickLabels },
commitRecs = obj["ParseData"[]];
tickLabels = {"message", Style["committer", GrayLevel[0.7]], Style["date", GrayLevel[0.8]]} /. commitRecs;
tickLabels[[All, 1]] = StringReplace[#, WhitespaceCharacter -> " "] & /@ tickLabels[[All, 1]];
tickLabels
];
GitHubData[{objID_, user_String, project_String}]["DatePoints"[]] :=
Block[{ obj = GitHubDataHEAD[{objID, user, project}], commitRecs },
commitRecs = obj["ParseData"[]];
MapThread[{AbsoluteTime[DateList[#1]], #2} &, {"date" /. commitRecs, Range[Length[commitRecs]]}]
];
GitHubData[{objID_, user_String, project_String}]["Plot"[opts___]] :=
Block[{obj = GitHubDataHEAD[{objID, user, project}], commitRecs, tickLabels, datePoints},
commitRecs = obj["ParseData"[]];
tickLabels = obj["TickLabels"[]];
datePoints = obj["DatePoints"[]];
obj["PlotFunction"][datePoints, tickLabels, opts]
];
(**********************************************************)
(* Plot strategies *)
(**********************************************************)
GHDDateListPlot[datePoints_, tickLabels_, opts : OptionsPattern[]] :=
DateListPlot[
MapThread[Tooltip[#1, #2] &, {datePoints, tickLabels}],
opts,
Joined -> False, PlotStyle -> {PointSize[0.03]},
PlotRange -> All, AspectRatio -> 2, ImageSize -> {Automatic, 800},
GridLines -> {None, Automatic},
FrameTicks -> {{Automatic, Table[{i, Style[tickLabels[[i]], FontSize -> 14]}, {i, 1, Length[tickLabels]}] },
{Automatic, Automatic}},
FrameLabel -> {{"commit order", None}, {1, 1} "date"}];
GHDBarChart[datePoints_, tickLabels_, opts : OptionsPattern[]] :=
Block[{distancesFromNow =
Map[DateDifference[DateList[#], Date[]] &, datePoints[[All, 1]]]},
BarChart[distancesFromNow,
opts,
BarOrigin -> Right, BarSpacing -> 0.5,
ChartElementFunction -> "GradientScaleRectangle", Frame -> True,
GridLines -> Automatic, Method -> {"GridLinesInFront" -> True},
PlotRangePadding -> {{None, 0.5}, {None, 0.3}},
FrameLabel -> {{"commit order", None}, {1, 1} "number of days"},
FrameTicks -> {{Automatic,
Table[{i, Style[tickLabels[[i]], FontSize -> 14]}, {i, 1,
Length[tickLabels]}]}, {Automatic, Automatic}},
AspectRatio -> 3, ImageSize -> {Automatic, 700}]
];
GHDGraphics3D[datePoints_, tickLabels_, opts : OptionsPattern[]] :=
Block[{
distancesFromNow = Map[DateDifference[DateList[#], Date[]] &, datePoints[[All, 1]]],
committers = Union[tickLabels[[All, 2]]],
committersAssoc},
committersAssoc = AssociationThread[committers, Range[Length[committers]]];
Graphics3D[
{Pink, PointSize[0.03],
Point[MapThread[{#1,
committersAssoc[#2], #3} &, {distancesFromNow[[All, 1]], tickLabels[[All, 2]], datePoints[[All, 2]]}]],
GrayLevel[0.5],
Line[
MapThread[{#1, committersAssoc[#2], #3} &, {distancesFromNow[[All, 1]], tickLabels[[All, 2]], datePoints[[All, 2]]}]]},
opts,
BoxRatios -> {1, 1, 4},
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
Axes -> True,
AxesLabel -> {"number of days ago", "committer", "commit order"},
Ticks -> {Automatic,
Table[{i, committers[[i]]}, {i, 1, Length[committers]}],
Table[{i, Style[tickLabels[[i, 1]], FontSize -> 14]}, {i, 1, Length[tickLabels]}]}]
];
(**********************************************************)
(* Other methods *)
(**********************************************************)
GitHubData[{objID_, user_String, project_String}]["Dataset"[]] :=
Dataset[ Association /@ GitHubData[{objID, user, project}]["CommitRecords"] ];
GitHubData[{objID_, user_String, project_String}]["DatasetExtended"[]] :=
Block[{datePoints,extendedRules},
datePoints = GitHubData[{objID, user, project}]["DatePoints"[]];
extendedRules = Thread[{ GitHubData[{objID,user,project}]["ParseData"[]], Thread["datePoint"->datePoints], "project"->project } ];
Dataset[ Association /@ extendedRules ]
];
GitHubData[{objID_, user_String, project_String}]["ReferenceGraph"[]] :=
Block[{graphRules, commitsGraph},
graphRules =
Flatten@Map[
Thread, ("parentSha" -> "sha") /.
GitHubData[{objID, user, project}]["ParseData"[]]];
commitsGraph = Graph[DirectedEdge @@@ graphRules];
commitsGraph
];
GitHubData[{objID_, user_String, project_String}]["User"[]] := user;
GitHubData[{objID_, user_String, project_String}]["Project"[]] := project;
(**********************************************************)
(* GitHubDataDecorators *)
(**********************************************************)
Clear[GitHubDataComponent, GitHubDataDecorator, GitHubDataColorFunctionDecorator]
GitHubDataComponentHEAD = GitHubDataComponent;
GitHubDataComponent[{objID_, user_String, project_String}]["Plot"[opts___]] := Print["Error"];
GitHubDataDecorator[{objID_, user_String, project_String}, component_][s_] :=
Block[{GitHubDataComponentHEAD = GitHubDataDecorator},
(*Print["Decorator abstract component call. Head[component]=",Head[component]];*)
(*Use GitHubDataComponent[{objID,user,project},component][s] in the concrete decorators.*)
component[s]
];
GitHubDataDecorator[{objID_, user_String, project_String}, component_]["Plot"[opts___]] :=
component["Plot"[opts]];
GitHubDataColorFunctionDecorator[{objID_, user_String, project_String}, component_][s_] :=
Block[{GitHubDataComponentHEAD = GitHubDataColorFunctionDecorator},
GitHubDataDecorator[{objID, user, project}, component][s]
];
GitHubDataColorFunctionDecorator[{objID_, user_String, project_String}, component_]["Plot"[opts___]] :=
Block[{obj = GitHubDataDecorator[{objID, user, project}, component], gr, commitRecs, datePoints, colorFunc, pSize},
gr = obj["Plot"[DeleteCases[{opts},(PointSize->_)|("DecoratorColorFunction"->_)]]];
(*get option values*)
colorFunc = OptionValue[Join[{opts}, {"DecoratorColorFunction" -> (Blend[{Black, Red}, #] &)}], "DecoratorColorFunction"];
pSize = OptionValue[Join[{opts}, {PointSize->0.015}], PointSize];
(*decorate the tick labels*)
gr = gr /. { GrayLevel[x_] :> colorFunc[x] };
(*decorate the graphics*)
If[ obj["PlotFunction"] === GHDDateListPlot,
commitRecs = obj["ParseData"[]];
datePoints = obj["DatePoints"[]];
gr = Show[{gr,
Graphics[{colorFunc[0.2], Line[datePoints], colorFunc[1], PointSize[pSize],
Point[datePoints]}]}]
];
gr
];
(**********************************************************)
(* GitHubDataMessageHyperlinks *)
(**********************************************************)
GitHubDataMessageHyperlinks[{objID_, user_String, project_String}][s_] :=
Block[{GitHubDataHEAD = GitHubDataMessageHyperlinks},
GitHubData[{objID, user, project}][s]
];
GitHubDataMessageHyperlinks[{objID_, user_String, project_String}]["TickLabels"[]] :=
Block[{tickLabels},
tickLabels =
GitHubData[{objID, user, project}]["TickLabels"[]];
tickLabels[[All, 1]] =
MapThread[
Function[{mess, url},
Button[Mouseover[Style[mess, "Text"],
Style[mess, "HyperlinkActive"]],
NotebookLocate[{URL[url], None}],
Appearance -> None]], {tickLabels[[All, 1]],
"htmlURL" /. commitRecs}];
tickLabels
];
(**********************************************************)
(* GitHubDataCommitPathsDecorator *)
(**********************************************************)
GitHubDataCommitPathsDecorator[{objID_, user_String, project_String}, component_][s_] :=
Block[{GitHubDataComponentHEAD = GitHubDataCommitPathsDecorator},
GitHubDataDecorator[{objID, user, project}, component][s]
];
GitHubDataCommitPathsDecorator[{objID_, user_String, project_String}, component_]["Plot"[opts___]] :=
Block[{obj = GitHubDataDecorator[{objID, user, project}, component],
gr, commitRecs, graphRules, commitsGraph, roots, leaves, paths,
shaInds, pathsByInds, datePoints, pointSize = 0.03},
(*Base plot*)
gr = obj["Plot"[opts]];
(*If the right function is used decorate it*)
If[ obj["PlotFunction"] === GHDDateListPlot,
(*Make a commits graph*)
commitRecs = obj["ParseData"[]];
graphRules = Flatten@Map[Thread, ("parentSha" -> "sha") /. commitRecs];
commitsGraph = Graph[DirectedEdge @@@ graphRules];
(*Find paths*)
roots = Select[graphRules, #[[1]] == "none" &][[All, 2]];
leaves = Complement[graphRules[[All, 2]], graphRules[[All, 1]]];
paths =
Flatten[Outer[FindPath[commitsGraph, #1, #2, Length[commitRecs], All] &, roots, leaves], 2];
paths = SortBy[paths, -Length[#] &];
shaInds =
AssociationThread["sha" /. commitRecs, Range[Length[commitRecs]]];
pathsByInds = Map[shaInds /@ # &, paths];
(*Combine the base plot and with the paths plot*)
datePoints = obj["DatePoints"[]];
gr =
Show[gr,
Graphics[{Opacity[0.5], Thickness[0.01],
MapThread[{ColorData["TemperatureMap"][#2],
Mouseover[
Line[datePoints[[#1]]], {Red, PointSize[pointSize*1.18],
Point[datePoints[[#1]]]}]} &, {pathsByInds,
RandomSample[Range[0, 1, 1/(Length[pathsByInds] - 1)]]}],
Opacity[1], LightBlue, PointSize[pointSize*0.66],
MapThread[
Tooltip[Point[#1],
Row[{#2, " ",
DateDifference[#1[[1]],
Date[], {"Month", "Day", "Hour", "Minute"}], " ago"}]] &, {datePoints, "sha" /. commitRecs}]}
]
]
];
gr
];
(**********************************************************)
(* GitHubDataComposite *)
(**********************************************************)
ClearAll[GitHubDataCompositeComponent,GitHubDataComposite]
(*The Component*)
GitHubDataCompositeComponentHEAD = GitHubDataCompositeComponent;
GitHubDataCompositeComponent[objID_, children_]["AddChild"[newChild_]] :=
GitHubDataCompositeHEAD[objID,Append[children,newChild]];
GitHubDataCompositeComponent[objID_, children_]["GetChild"[childIndex_]] :=
children[[childIndex]];
GitHubDataCompositeComponent[objID_, children_]["GetChildren"[]] := children;
(*GitHubDataCompositeComponent[objID_, children_]["Plot"[___]] :=*)
(*Print["Error: GitHubDataCompositeComponent is an abstract class."];*)
GitHubDataCompositeComponent[objID_, children_][s_] :=
Print["Error: GitHubDataCompositeComponent is an abstract class."];
(*The Composite*)
GitHubDataComposite[objID_, children_]["AddChild"[newChild_]] :=
Block[{GitHubDataCompositeComponentHEAD = GitHubDataComposite},
GitHubDataCompositeComponent[objID, children]["AddChild"[newChild]]
];
GitHubDataComposite[objID_, children_]["GetChild"[childIndex_]] :=
Block[{GitHubDataCompositeComponentHEAD = GitHubDataComposite},
GitHubDataCompositeComponent[objID, children]["GetChild"[childIndex]]
];
GitHubDataComposite[objID_, children_]["GetChildren"[]] :=
Block[{GitHubDataCompositeComponentHEAD = GitHubDataComposite},
GitHubDataCompositeComponent[objID, children]["GetChildren"[]]
];
(*GitHubDataComposite[objID_, children_][s_] := Map[#[s]&,children];*)
GitHubDataComposite[objID_, children_]["Plot"[opts___]] :=
Block[{ plots, ranges, glRange },
plots = Map[ #["Plot"[opts]]&, children ];
(*Instead of relying on the PlotRange specifications in the plots we can use these ...*)
(*allDatePoints = Map[ #["DatePoints"[]]&, children ];*)
(*dateRange = { Min[Flatten[allDatePoints[[All,All,1]]]], Max[Flatten[allDatePoints[[All,All,1]]]] };*)
ranges = Cases[plots, (PlotRange -> x_) :> x, Infinity];
glRange = {{Min[ranges[[All, 1]]], Max[ranges[[All, 1]]]}, {Min[ranges[[All, 2]]], Max[ranges[[All, 2]]]}};
plots /. (PlotRange -> x_) -> (PlotRange -> glRange)
];
GitHubDataComposite[objID_, children_]["Plot3D"[opts___]] :=
Block[{colorFunc,pSize,projectPlanesQ,subsetQueryFunc,subsetLinesQ,optsRest,subsetPlotStyle,globalTimeOrderQ,
ghsDatePoints,projects,projectToCoordRules,ghsDate3DPoints,projectColors,
grPrism,projectPlanes,ghsExtDs,crossQueryPoints, dateRange, t},
(*get option values*)
colorFunc = OptionValue[Join[{opts}, {ColorFunction -> ColorData["SouthwestColors","ColorFunction"]}], ColorFunction];
pSize = OptionValue[Join[{opts}, {PointSize->0.015}], PointSize];
projectPlanesQ = OptionValue[Join[{opts}, {"ProjectPlanes"->True}], "ProjectPlanes"];
subsetQueryFunc = OptionValue[Join[{opts}, {"SubsetQueryFunction"->None}], "SubsetQueryFunction"];
subsetLinesQ = OptionValue[Join[{opts}, {"SubsetLines"->False}], "SubsetLines"];
subsetPlotStyle = OptionValue[Join[{opts}, {"SubsetPlotStyle"->{}}], "SubsetPlotStyle"];
globalTimeOrderQ = OptionValue[Join[{opts}, {"GlobalTimeOrder"->True}], "GlobalTimeOrder"];
optsRest = Select[ {opts}, MemberQ[ Options[Graphics3D][[All,1]], #[[1]] ]& ];
ghsDatePoints = Map[ #["DatePoints"[]]&, children ];
projects = Map[ #["Project"[]]&, children ];
projectToCoordRules = Thread[projects -> Range[Length[projects]]];
ghsDate3DPoints = MapThread[Function[{dps,p}, Riffle[#, p]& /@ dps], {ghsDatePoints,projects/.projectToCoordRules}];
If[ globalTimeOrderQ,
t = SortBy[ Flatten[ghsDate3DPoints,1], #[[1]]& ];
t = Dispatch[ MapIndexed[ #1->Append[ #1[[1;;2]],#2[[1]] ]&, t ] ];
ghsDate3DPoints = ghsDate3DPoints /. t;
];
projectColors = colorFunc/@Rescale[Range[Length[children]]/Length[children]];
If[ TrueQ[projectPlanesQ],
projectPlanes = Map[InfinitePlane[Through[{First, Last, Mean}[#]]] &, ghsDate3DPoints],
projectPlanes = {}
];
If[ TrueQ[ subsetQueryFunc =!= None ],
ghsExtDs = Map[#["DatasetExtended"[]] &, children];
crossQueryPoints =
Flatten[Map[Flatten /@ Values[Normal[#]] &,
Map[#[Select[ subsetQueryFunc ], {"datePoint", "project"}] /. projectToCoordRules &, ghsExtDs]], 1];
crossQueryPoints = crossQueryPoints[[All, {1, 3, 2}]];
If[ globalTimeOrderQ, crossQueryPoints = crossQueryPoints /. t ];
];
dateRange = {Min[Flatten[ghsDate3DPoints[[All,All,1]]]],Max[Flatten[ghsDate3DPoints[[All,All,1]]]]};
grPrism =
Graphics3D[{
Lighting->"Neutral", Opacity[0.07], projectPlanes,
Lighting-> Automatic, Opacity[0.9],
MapThread[ Function[{dps,col},{col,Line[dps]}], { ghsDate3DPoints, projectColors}],
PointSize[pSize],
MapThread[Function[{dps,col},{col,Point[dps]}],{ ghsDate3DPoints, projectColors}],
If[ TrueQ[ subsetQueryFunc === None ], {},
{ PointSize[pSize*1.1], Red, Arrowheads[ 10^-Log[9,Abs[Subtract@@dateRange]] ],
Sequence @@ subsetPlotStyle,
Point[crossQueryPoints],
If[ TrueQ[subsetLinesQ],
Arrow /@ Partition[SortBy[crossQueryPoints, #[[3]] &], 2, 1]
, {} ]
}
] },
optsRest,
BoxRatios -> {1, 1, 2},
Axes -> True,
AxesLabel -> {None, None, "commit order"},
AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}},
Ticks -> {Function[{xmin, xmax}, {#, DateString[#]} & /@ FindDivisions[{xmin, xmax}, 10]],
Table[{i, projects[[i]]}, {i, 1, Length[projects]}], Automatic},
FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
PlotRange->{ dateRange, {0,Length[projects]+1},All}
];
grPrism
];