dat = "2014-08-29 03:59:52 27273 Brown
2014-08-29 03:59:53 27276 Green
2014-08-29 03:59:55 27276 Brown
2014-08-29 03:59:57 27303 Red
2014-08-29 03:59:58 27303 Green
2014-08-29 03:59:59 27303 Brown
2014-08-29 04:00:04 27317 Brown
2014-08-29 04:00:07 27331 Blue
2014-08-29 04:00:07 27334 Blue
2014-08-29 04:00:08 27331 Red
2014-08-29 04:00:08 27334 Cyan";
inputdata = ImportString[dat];
DateListPlot
ClearAll[dateListBars];
dateListBars[inpdata_, leftpadding_, rightpadding_,
opts : OptionsPattern[]] :=
Module[{datasets, dates, firstdate, lastdate,
labels, colors, gdt, dlPltF, options,
data = {#3, DateList[#1 <> " " <> #2], ToExpression@#4} & @@@
inpdata},
gdt = GatherBy[data, First];
{labels, colors} = Transpose[{#[[1, 1]], #[[All, 3]]} & /@ gdt];
datasets = {#[[1, 1]], AbsoluteTime /@ #[[All, 2]], #[[All, 3]]} & /@
gdt;
dates = DeleteDuplicates@data[[All, 2]];
{firstdate, lastdate} = DateList /@ ({leftpadding, rightpadding} +
Through[{Min, Max}[AbsoluteTime /@ dates]]);
dlPltF := DateListPlot[Thread[{{firstdate, lastdate}, #2[[1]]}],
Joined -> True, Mesh -> {#[[2]]},
MeshShading -> {White, Sequence @@ #[[3]], White},
BaseStyle -> Directive[Thickness[.075], CapForm["Butt"]],
Frame -> True, MeshStyle -> Opacity[0]] &;
options = {PlotRange -> All,
GridLines -> {AbsoluteTime /@ dates, None},
Method -> {"GridLinesInFront" -> True},
FrameTicks -> {{Thread[{Range[Length@datasets], labels}], None},
{{AbsoluteTime@#, Rotate[DateString[#,
{"Hour", ":", "Minute", ":", "Second"}], Pi/2]} & /@
{firstdate, Sequence @@ dates, lastdate}, None}},
PlotRangePadding -> {{.5, .5}, {.5, .5}}};
Show[MapIndexed[dlPltF, datasets], Sequence @@ options, opts]]
dateListBars[inputdata, -1, 5, ImageSize -> 600, LabelStyle -> 16] /. Cyan -> White
BarChart
Data preparation:
data = {#3, DateList[#1 <> " " <> #2], ToExpression@#4} & @@@ ImportString[dat];
{labels, colors} = Transpose[{#[[1, 1]], #[[All, 3]]} & /@ GatherBy[data, First]];
datasets = {#[[1,1]], AbsoluteTime /@ #[[All, 2]], #[[All, 3]]} & /@ GatherBy[data, First];
dates = DeleteDuplicates@data[[All, 2]];
{leftpadding, rightpadding} = {-1, 5};
{firstdate, lastdate} = DateList /@ ({leftpadding, rightpadding} +
Through[{Min, Max}[AbsoluteTime /@ dates]]);
bcheights =
DateDifference[DateList[#1], DateList[#2], "Second"][[1]] & @@@
Partition[#, 2,
1] & /@ (Append[Prepend[#, AbsoluteTime[firstdate]],
AbsoluteTime[lastdate]] & /@ datasets[[All, 2]] );
bccolors = Prepend[#, White] & /@ colors;
bcdata = Thread[Style[#, #2]] & @@@ Transpose[{bcheights, bccolors}];
Handling date ticks:
bcticks = Union[Flatten[Accumulate@# & /@ bcheights]];
bcticks = Thread[{bcticks, Rotate[DateString[
DatePlus[firstdate, {#, "Second"}],
{"Hour", ":", "Minute", ":", "Second"}], Pi/2] & /@
Union[Flatten[Accumulate@# & /@ bcheights]]}];
and the options
bcoptions = {ChartLayout -> "Stacked", BarOrigin -> Left,
ChartLabels -> {Placed[labels, Axis], None},
ChartBaseStyle -> Directive[Opacity[1], EdgeForm[]],
LabelStyle -> 16,
Frame -> {{False, True}, {True, True}},
FrameTicks -> {{None, None}, {bcticks, None}},
GridLines -> {bcticks[[All, 1]], None},
Method -> {"GridLinesInFront" -> True}, ImageSize -> 600};
BarChart[bcdata, bcoptions] /. Cyan -> White
BulletGauge
bgaugedata =
Transpose[{Accumulate /@ bcheights, Prepend[#, White] & /@ colors,
labels}];
Panel[Column[
Reverse[BulletGauge[0, foo, Append[Prepend[#1 + 5, 0], 25],
ScaleRangeStyle -> Thread[{#2, White}], GaugeMarkers -> None,
GaugeLabels ->
Placed[Style[#3, "Subsubsection"], {2, Bottom}],
ImageSize -> 600, Axes -> False, Frame -> False,
TicksStyle -> Opacity[0], ReferenceMarkerStyle -> Opacity[0],
AspectRatio -> 1/10] & @@ # & /@ bgaugedata],
Spacings -> -2]] /. Cyan -> White
TODO: Date ticks ...