簡體   English   中英

如何通過DiagrammeR在美人魚(甘特)中獲得超過4種顏色?

[英]How can I have more than 4 section colours in mermaid (Gantt) via DiagrammeR?

我必須每天生成一個甘特圖。 我的想法是使用R的DiagrammeR包中包含的美人魚api。

我的數據總是具有相同的結構,因此,我創建了一個非常原始的解析器,它包含在可重現的示例中。

我面臨的問題是,在4個部分后,樣式從零開始:

rect.section.section0
rect.section.section1
rect.section.section2
rect.section.section3
rect.section.section0

我可以從.css更改rect.section.sectionx顏色,但我無法添加新的顏色。

有沒有辦法改變/個性化該部分的顏色/樣式?

我的R重復的例子:

library(DiagrammeR)
library(htmltools)

fromdftogantt<-function(df,Title="Proba",filename="proba.html"){
  txt<-paste("gantt","dateFormat  YYYY-MM-DD",paste("title",Title),"",sep="\n")
  for(i in unique(df$section)){
    txt<-paste(txt,paste("section",i),sep="\n")
    for(j in which(df$section==i)){

      txt<-paste(txt,paste0(df$name[j],":",df$status[j],",",
                            df$fecini[j],",",
                            df$fecfin[j]),sep="\n")
    }
    txt<-paste0(txt,"\n")
  }
  m<-mermaid(txt)
  m$x$config = list(ganttConfig = list(
    axisFormatter = list(list(
      "%m-%Y" 
      ,htmlwidgets::JS(
        'function(d){ return d.getDate() == 1 }' 
      )
    ))
  ))
  save_html(as.tags(m),file=filename)
}

df<-data.frame(section=letters[1:6],name=paste("Name",1:6),
               status=rep("active",6),
               fecini=as.Date(c("2015-02-03","2015-03-05","2015-04-07",
                                "2015-02-03","2015-03-05","2015-04-07")),
               fecfin=as.Date(c("2015-06-01","2015-04-30","2015-12-31",
                                "2015-06-01","2015-04-30","2015-12-31")),
               stringsAsFactors = FALSE)

fromdftogantt(df,Title="Proba",filename="proba.html")

您根本不需要更改.js文件。 mermaid支持numberSectionStyles配置參數。 在保存HTML之前,只需將以下行添加到R函數:

m$x$config$ganttConfig$numberSectionStyles = 6

您仍然需要調整.css文件,以便在與現有模板相同的模板之后添加其他部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM