Skip to content

Commit

Permalink
v1.0.6. markmap added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Zhao committed Jul 5, 2017
1 parent 00d1386 commit 780b7e9
Show file tree
Hide file tree
Showing 39 changed files with 11,734 additions and 56 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Package: mindr
Version: 1.0.5
Date: 2017-07-03
Version: 1.0.6
Date: 2017-07-05
Title: Convert Files Between Markdown or Rmarkdown Files and Mindmaps
Author: Peng Zhao
Maintainer: Peng Zhao <pzhao@pzhao.net>
Depends: R (>= 3.0.0)
Imports:
Imports: htmlwidgets
Suggests:
Description: Convert Markdown ('.md') or Rmarkdown ('.Rmd') files into FreeMind mindmap ('.mm') files, and vice versa. FreeMind mindmap ('.mm') files can be opened by or imported to common mindmap software such as 'FreeMind' (<http://freemind.sourceforge.net/wiki/index.php/Main_Page>) and 'XMind' (<http://www.xmind.net>).
License: GPL
Expand Down
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Generated by roxygen2: do not edit by hand

export(markmap)
export(markmapOption)
export(markmapOutput)
export(md2mm)
export(mm2md)
export(outline)
export(renderMarkmap)
import(htmlwidgets)
176 changes: 162 additions & 14 deletions R/foo.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#'
#' @return a mindmap file, which can be viewed by common mindmap software, such as 'FreeMind' (<http://freemind.sourceforge.net/wiki/index.php/Main_Page>) and 'XMind' (<http://www.xmind.net>).
#' @export
#' @examples md2mm()
#' @examples
#' folder <- system.file('examples/md', package = 'mindr')
#' md2mm(folder = folder)
#' md2mm(folder = folder, remove_curly_bracket = TRUE)
md2mm <- function(title = 'my title',
folder = 'mm',
remove_curly_bracket = FALSE,
Expand All @@ -28,10 +31,11 @@ md2mm <- function(title = 'my title',
}
mm[length(ncc) + 2] <- paste0('<node TEXT="', mmtext[length(ncc)], '">', paste0(rep('</node>', ncc[length(ncc)]), collapse = ''))
mm[length(ncc) + 3] <- '</node></map>'
if (backup & file.exists(paste0(savefilename, '.mm'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
}
writeLines(text = mm, paste0(savefilename, '.mm'), useBytes = TRUE)
savefilename <- paste0(savefilename, ifelse(backup & file.exists(paste0(savefilename, '.mm')), paste0('-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S')), ''), '.mm')
# if (backup & file.exists(paste0(savefilename, '.mm'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
# savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
# }
writeLines(text = mm, savefilename, useBytes = TRUE)
} else {print(paste('The directory', folder, 'does not exist!'))}
}

Expand All @@ -45,7 +49,8 @@ md2mm <- function(title = 'my title',
#' @return a vector of strings showing outline of a markdown document or book.
#' @export
#' @examples
#' mm2md()
#' folder <- system.file('examples/mm', package = 'mindr')
#' mm2md(folder = folder)
mm2md <- function(folder = 'mm',
savefile = TRUE,
savefilename = 'mindr',
Expand All @@ -64,11 +69,12 @@ mm2md <- function(folder = 'mm',
md <- paste(sapply(node_level - 1, function(x) paste0(rep('#', x), collapse = '')), headers)
md[1] <- paste('Title:', md[1])
if (savefile) {
if (backup & file.exists(paste0(savefilename, '.md'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
}
savefilename <- paste0(savefilename, ifelse(backup & file.exists(paste0(savefilename, '.md')), paste0('-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S')), ''), '.md')
# if (backup & file.exists(paste0(savefilename, '.md'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
# savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
# }
# if (backup & file.exists(savefilename)) file.copy(savefilename, to = paste0(savefilename, 'backup'))
writeLines(text = md, paste0(savefilename, '.md'), useBytes = TRUE)
writeLines(text = md, savefilename, useBytes = TRUE)
}
return(md)
} else {print(paste('The directory', folder, 'does not exist!'))}
Expand All @@ -85,7 +91,9 @@ mm2md <- function(folder = 'mm',
#' @return a vector of strings showing outline of a markdown document or book.
#' @export
#' @examples
#' outline()
#' folder <- system.file('examples/md', package = 'mindr')
#' outline(folder = folder)
#' outline(folder = folder, remove_curly_bracket = TRUE)
outline <- function(folder = 'mm',
remove_curly_bracket = FALSE,
savefile = TRUE,
Expand All @@ -102,13 +110,153 @@ outline <- function(folder = 'mm',
header <- md[headerloc]
if (remove_curly_bracket) header <- gsub(pattern = '\\{.*\\}', '', header)
if (savefile) {
if (backup & file.exists(paste0(savefilename, '.md'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
}
savefilename <- paste0(savefilename, ifelse(backup & file.exists(paste0(savefilename, '.md')), paste0('-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S')), ''), '.md')
# if (backup & file.exists(paste0(savefilename, '.md'))){ #file.copy(savefilename, to = paste0(savefilename, 'backup'))
# savefilename <- paste0(savefilename, '-', format(Sys.time(), '%Y-%m-%d-%H-%M-%S'))
# }
# if (backup & file.exists(savefilename)) file.copy(savefilename, to = paste0(savefilename, 'backup'))
writeLines(text = header, savefilename, useBytes = TRUE)
}
return(header)
} else {print(paste('The directory', folder, 'does not exist!'))}
}

####################################################

#' Create a markmap widget
#'
#' This function creates a markmap widget using htmlwidgets.
#' The widget can be rendered on HTML pages generated from
#' R Markdown,Shiny,or other applications.
#' @param path the path of markdown file
#' @param width the width of the markmap
#' @param height the height of the markmap
#' @param options the markmap options
#' @import htmlwidgets
#' @return A HTML widget object rendered from a given document.
#' @examples
#' folder <- system.file('examples/md', package = 'mindr')
#' markmap(folder = folder)
#' markmap(folder = folder, remove_curly_bracket = TRUE)
#' @export
markmap <- function(folder = 'mm',
remove_curly_bracket = FALSE,
width = NULL, height = NULL, elementId = NULL, options = markmapOption()) {
if (dir.exists(folder)) {
header <- outline(folder, remove_curly_bracket, savefile = FALSE)
data <-paste(header, collapse = '\n')
# forward options using x
x = list(
data = data,
options = options
)


# create widget
htmlwidgets::createWidget(
name = 'markmap',
x,
width = width,
height = height,
sizingPolicy = htmlwidgets::sizingPolicy(
defaultWidth = '100%',
defaultHeight = 400,
padding = 0,
browser.fill = TRUE
),
package = 'mindr',
elementId = elementId
)
} else {print(paste('The directory', folder, 'does not exist!'))}

}
#' Options for markmap creation
#' @param preset the name of built-in theme for markmap. If present, any other parameters will be ignored.
#' @param nodeHeight the height of nodes in the markmap.
#' @param nodeWidth the width of nodes in the markmap.
#' @param spacingVertical space of vertical.
#' @param spacingHorizontal space of horizontal.
#' @param duration duration time for animation.
#' @param layout layout mode of makrmap. Currently, only 'tree' is accepted.
#' @param color color of markmap. A character color value ,either 'gray' or
#' a categorical colors including 'category10','category20','category20b' and 'category20c'.
#' @param linkShape link shape of markmap. A character value, either 'diagonal' or 'bracket'.
#' @param renderer rendered shaped of markmap. A character value ,either 'basic' or 'boxed'.
#' @param ... other options.
#' @describeIn theme Options for markmap creation
#' @details Currently,markmap have 'default' and 'colorful' themes.
#' 'colorful' themes have three different parameters from default themes:
#' {nodeHeight: 10, renderer: 'basic',color: 'category20'}
#' @seealso \url{https://github.com/dundalek/markmap/blob/master/view.mindmap.js} for details.
#' @examples
#' md<-system.file('examples/test.md',package = 'Rmarkmap')
#' markmap(md,options = markmapOption(preset = 'colorful')) # 'colorful' theme
#'
#' # more options for self-defined markmap
#' markmap(md,options = markmapOption(color='category20b',linkShape='bracket'))
#'
#' markmap(md,options = markmapOption(color='category20b',linkShape='diagonal',renderer = 'basic'))
#' @export
markmapOption <- function(preset=NULL,nodeHeight=20,
nodeWidth=180,
spacingVertical=10,
spacingHorizontal=120,
duration=750,
layout='tree',
color='gray',#
linkShape='diagonal',
renderer='boxed',...){
filterNULL<-function (x) {
if (length(x) == 0 || !is.list(x))
return(x)
x[!unlist(lapply(x, is.null))]
}
if(!is.null(preset)&&(preset=='default'|preset=='colorful')){
filterNULL(list(preset=preset,autoFit=TRUE))
}else{
if (is.null(layout)||(layout!='tree')){
warning('Currenly, only tree layout is supported. Changing to tree layout...')
layout = 'tree'
}
filterNULL(list(nodeHeight=nodeHeight,
nodeWidth=nodeWidth,
spacingVertical=spacingVertical,
spacingHorizontal=spacingHorizontal,
duration=duration,
layout='tree',
color=color,
linkShape=linkShape,
renderer=renderer,
autoFit=TRUE,
...))
}

}
#'
#'
#' Shiny bindings for markmap
#'
#' Output and render functions for using markmap within Shiny
#' applications and interactive Rmd documents.
#'
#' @param outputId output variable to read from
#' @param width,height Must be a valid CSS unit (like \code{'100\%'},
#' \code{'400px'}, \code{'auto'}) or a number, which will be coerced to a
#' string and have \code{'px'} appended.
#' @param expr An expression that generates a markmap
#' @param env The environment in which to evaluate \code{expr}.
#' @param quoted Is \code{expr} a quoted expression (with \code{quote()})? This
#' is useful if you want to save an expression in a variable.
#' #'
#' @rdname markmap-shiny
#'
#' @export
markmapOutput <- function(outputId, width = '100%', height = '400px'){
htmlwidgets::shinyWidgetOutput(outputId, 'markmap', width, height, package = 'mindr')
}
#' @rdname markmap-shiny
#' @export
renderMarkmap <- function(expr, env = parent.frame(), quoted = FALSE) {
if (!quoted) { expr <- substitute(expr) } # force quoted
htmlwidgets::shinyRenderWidget(expr, markmapOutput, env, quoted = TRUE)
}
13 changes: 13 additions & 0 deletions inst/examples/md/bookdownplus1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Introduction {#introduction}
## What is 'bookdown' {#what_is__bookdown_}
## What is 'bookdownplus' {#what_is__bookdownplus_}
## Why 'bookdownplus' {#why__bookdownplus_}
## Giants' Shoulders {#giants__shoulders}
# Quick Start {#quick_start}
## Preparation {#preparation}
## Installation of 'bookdownplus' {#installation_of__bookdownplus_}
## How to use {#how_to_use}
## More output formats
## More templates
## A magic trick
## Recommendations
34 changes: 34 additions & 0 deletions inst/examples/md/bookdownplus2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Basic {#basic}
## Markdown Syntax {#markdown_syntax}
### What is Markdown {#what_is_markdown}
### Basic syntax {#basic_syntax}
### Chapters {#chapters}
### Figures and tables {#figures_and_tables}
### References {#references}
### Theorems, lemma, definitions, etc. {#theorems__lemma__definitions__etc_}
### Export Word document {#export_word_document}
### Equations numbering {#equations_numbering}
## R, RStudio and bookdown {#r__rstudio_and_bookdown}
## LaTeX and Pandoc {#latex_and_pandoc}
## Workflow {#workflow}
# Simple {#simple}
# Lifestyle {#lifestyle}
## Journal {#journal}
## Poem book {#poem_book}
## Music {#music}
# Office {#office}
## Mail {#mail}
### Arguments for mail content
### Mail themes
## Calendar {#calendar}
# Academic {#academic}
## Articles {#articles}
## Thesis {#thesis}
## Poster {#poster}
## Chemistry {#chemistry}
# Advanced {#advanced}
## Chinese {#chinese}
## Mind Map {#mind_map}
## Create Your Own Templates {#customize}
# FAQ {#faq}
# Bibliography {-}
50 changes: 50 additions & 0 deletions inst/examples/mm/bookdownplus.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<map version="1.0.1">
<node TEXT="my title">
<node TEXT="Introduction ">
<node TEXT="What is 'bookdown' "></node>
<node TEXT="What is 'bookdownplus' "></node>
<node TEXT="Why 'bookdownplus' "></node>
<node TEXT="Giants' Shoulders "></node></node>
<node TEXT="Quick Start ">
<node TEXT="Preparation "></node>
<node TEXT="Installation of 'bookdownplus' "></node>
<node TEXT="How to use "></node>
<node TEXT="More output formats"></node>
<node TEXT="More templates"></node>
<node TEXT="A magic trick"></node>
<node TEXT="Recommendations"></node></node>
<node TEXT="Basic ">
<node TEXT="Markdown Syntax ">
<node TEXT="What is Markdown "></node>
<node TEXT="Basic syntax "></node>
<node TEXT="Chapters "></node>
<node TEXT="Figures and tables "></node>
<node TEXT="References "></node>
<node TEXT="Theorems, lemma, definitions, etc. "></node>
<node TEXT="Export Word document "></node>
<node TEXT="Equations numbering "></node></node>
<node TEXT="R, RStudio and bookdown "></node>
<node TEXT="LaTeX and Pandoc "></node>
<node TEXT="Workflow "></node></node>
<node TEXT="Simple "></node>
<node TEXT="Lifestyle ">
<node TEXT="Journal "></node>
<node TEXT="Poem book "></node>
<node TEXT="Music "></node></node>
<node TEXT="Office ">
<node TEXT="Mail ">
<node TEXT="Arguments for mail content"></node>
<node TEXT="Mail themes"></node></node>
<node TEXT="Calendar "></node></node>
<node TEXT="Academic ">
<node TEXT="Articles "></node>
<node TEXT="Thesis "></node>
<node TEXT="Poster "></node>
<node TEXT="Chemistry "></node></node>
<node TEXT="Advanced ">
<node TEXT="Chinese "></node>
<node TEXT="Mind Map "></node>
<node TEXT="Create Your Own Templates "></node></node>
<node TEXT="FAQ "></node>
<node TEXT="Bibliography "></node>
</node></map>
2 changes: 2 additions & 0 deletions inst/htmlwidgets/lib/d3/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
d3.js -diff merge=ours
d3.min.js -diff merge=ours
6 changes: 6 additions & 0 deletions inst/htmlwidgets/lib/d3/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
examples/
test/
lib/
.DS_Store
_site
d3.zip
4 changes: 4 additions & 0 deletions inst/htmlwidgets/lib/d3/.spmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
lib
src
test
13 changes: 13 additions & 0 deletions inst/htmlwidgets/lib/d3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Data-Driven Documents

<a href="https://d3js.org"><img src="https://d3js.org/logo.svg" align="left" hspace="10" vspace="6"></a>

**D3.js** is a JavaScript library for manipulating documents based on data. **D3** helps you bring data to life using HTML, SVG, and CSS. **D3** emphasizes web standards and combines powerful visualization components with a data-driven approach to DOM manipulation, giving you the full capabilities of modern browsers without tying yourself to a proprietary framework.

Want to learn more? [See the wiki.](https://github.com/mbostock/d3/wiki)

For examples, [see the gallery](https://github.com/mbostock/d3/wiki/Gallery) and [mbostock’s bl.ocks](http://bl.ocks.org/mbostock).

## Good News, Everyone!

The next major release of D3, 4.0, is coming! See the [4.0 development branch](https://github.com/mbostock/d3/tree/4) and read the [new API reference](https://github.com/mbostock/d3/blob/4/README.md) to get ready.
5 changes: 5 additions & 0 deletions inst/htmlwidgets/lib/d3/d3.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions inst/htmlwidgets/lib/markmap-0.3.3/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "markmap",
"homepage": "https://github.com/dundalek/markmap",
"version": "0.3.3",
"_release": "0.3.3",
"_resolution": {
"type": "version",
"tag": "v0.3.3",
"commit": "2a4fd2cfdd1663a017a058167d6be9902b2d8727"
},
"_source": "https://github.com/dundalek/markmap.git",
"_target": "^0.3.3",
"_originalSource": "dundalek/markmap",
"_direct": true
}
2 changes: 2 additions & 0 deletions inst/htmlwidgets/lib/markmap-0.3.3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tmp
Loading

0 comments on commit 780b7e9

Please sign in to comment.