mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
R add ride color to metrics()
.. so you can pass to plot functions e.g. scatter plot with the color of each dot controlled by the GC config
This commit is contained in:
@@ -282,9 +282,9 @@ RTool::dfForDateRange(bool all, DateRange range)
|
||||
SEXP names; // column names
|
||||
SEXP rownames; // row names (numeric)
|
||||
|
||||
// +2 is for date and datetime
|
||||
PROTECT(ans=Rf_allocList(metrics+meta+2));
|
||||
PROTECT(names = Rf_allocVector(STRSXP, metrics+meta+2));
|
||||
// +3 is for date and datetime and color
|
||||
PROTECT(ans=Rf_allocList(metrics+meta+3));
|
||||
PROTECT(names = Rf_allocVector(STRSXP, metrics+meta+3));
|
||||
|
||||
// we have to give a name to each row
|
||||
PROTECT(rownames = Rf_allocVector(STRSXP, rides));
|
||||
@@ -416,6 +416,30 @@ RTool::dfForDateRange(bool all, DateRange range)
|
||||
UNPROTECT(1);
|
||||
}
|
||||
|
||||
// add Color
|
||||
SEXP color;
|
||||
PROTECT(color=Rf_allocVector(STRSXP, rides));
|
||||
|
||||
int index=0;
|
||||
foreach(RideItem *item, rtool->context->athlete->rideCache->rides()) {
|
||||
if (all || range.pass(item->dateTime.date())) {
|
||||
|
||||
// apply item color, remembering that 1,1,1 means use default (reverse in this case)
|
||||
if (item->color == QColor(1,1,1,1))
|
||||
SET_STRING_ELT(color, index++, Rf_mkChar(GCColor::invertColor(GColor(CPLOTBACKGROUND)).name().toLatin1().constData()));
|
||||
else
|
||||
SET_STRING_ELT(color, index++, Rf_mkChar(item->color.name().toLatin1().constData()));
|
||||
}
|
||||
}
|
||||
|
||||
// add to the list and name it
|
||||
SETCAR(nextS, color);
|
||||
nextS = CDR(nextS);
|
||||
SET_STRING_ELT(names, next, Rf_mkChar("color"));
|
||||
next++;
|
||||
|
||||
UNPROTECT(1);
|
||||
|
||||
// turn the list into a data frame + set column names
|
||||
Rf_setAttrib(ans, R_ClassSymbol, Rf_mkString("data.frame"));
|
||||
Rf_setAttrib(ans, R_RowNamesSymbol, rownames);
|
||||
|
||||
Reference in New Issue
Block a user