Skip to content

Commit

Permalink
0.7 release prep
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Mar 13, 2015
1 parent 1a1f9e2 commit df5821f
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: streamgraph
Type: Package
Title: streamgraph is an htmlwidget for building streamgraph visualizations
Version: 0.5.1
Date: 2015-02-15
Version: 0.7
Date: 2015-03-12
Author: Bob Rudis (@hrbrmstr)
Maintainer: Bob Rudis <[email protected]>
Description: A streamgraph (or "stream graph") is a type of stacked area graph
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.0.9000): do not edit by hand
# Generated by roxygen2 (4.1.0): do not edit by hand

export("%>%")
export(renderStreamgraph)
Expand Down
34 changes: 29 additions & 5 deletions R/streamgraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,25 @@ sg_legend <- function(sg, show=FALSE, label="") {

#' Add a vertical marker (with optional label) to streamgraph
#'
#' @export
sg_add_marker <- function(sg, x, stroke_width=0.5, stroke="#7f7f7f", space=5,
y=0, label="", color="#7f7f7f", size=12) {
#' This is useful for marking/labeling notable events along the streams.
#'
#' @param x horizontal position
#' @param label text for the annotation
#' @param stroke_width line width
#' @param stroke line color
#' @param space space (in points) from the marker to place the label
#' @param y vertical position
#' @param color color of the label
#' @param size font size#' @export
#' @param anchor how to justify the label (one of \code{start} [left],
#' \code{middle} [center] or \code{end} [right])
sg_add_marker <- function(sg, x, label="", stroke_width=0.5, stroke="#7f7f7f", space=5,
y=0, color="#7f7f7f", size=12, anchor="start") {

if (inherits(x, "Date")) { x <- format(x, "%Y-%m-%d") }

mark <- data.frame(x=x, y=y, label=label, color=color, stroke_width=stroke_width, stroke=stroke,
space=space, size=size, stringsAsFactors=FALSE)
space=space, size=size, anchor=anchor, stringsAsFactors=FALSE)

if (is.null(sg$x$markers)) {
sg$x$markers <- mark
Expand All @@ -446,8 +459,19 @@ sg_add_marker <- function(sg, x, stroke_width=0.5, stroke="#7f7f7f", space=5,

#' Add text annotation to streamgraph
#'
#' Use this function to place text at any point on a streamgraph. This
#' is especially useful for non-interactive streamgraphs (i.e. to label
#' a particular stream).
#'
#' @param label text for the annotation
#' @param x horizontal position
#' @param y vertical position
#' @param color color of the label
#' @param size font size
#' @export
sg_annotate <- function(sg, label, x, y, color="black", size="12") {
sg_annotate <- function(sg, label, x, y, color="black", size=12) {

if (inherits(x, "Date")) { x <- format(x, "%Y-%m-%d") }

ann <- data.frame(label=label, x=x, y=y, color=color, size=size, stringsAsFactors=FALSE)

Expand Down
26 changes: 24 additions & 2 deletions inst/htmlwidgets/streamgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ HTMLWidgets.widget({
if (params.annotations != null) {

var ann = HTMLWidgets.dataframeToD3(params.annotations) ;

ann.forEach(function(d) {
if (params.x_scale == "date") {
d.x = format.parse(d.x);
} else {
d.x = +d.x;
}
});

svg.selectAll(".annotation")
.data(ann)
.enter().append("text")
Expand All @@ -279,6 +288,15 @@ HTMLWidgets.widget({
if (params.markers != null) {

var mrk = HTMLWidgets.dataframeToD3(params.markers) ;

mrk.forEach(function(d) {
if (params.x_scale == "date") {
d.x = format.parse(d.x);
} else {
d.x = +d.x;
}
});

dbg3 = mrk ;
svg.selectAll(".marker")
.data(mrk)
Expand All @@ -294,11 +312,15 @@ HTMLWidgets.widget({
svg.selectAll(".markerlab")
.data(mrk)
.enter().append("text")
.attr("x", function(d) { return(x(d.x)+d.space) ; })
.attr("x", function(d) {
if (d.anchor=="end") { d.space = -d.space; }
if (d.anchor=="middle") { d.space = 0; }
return(x(d.x)+d.space) ;
})
.attr("y", function(d) { return(y(d.y)) ; })
.attr("fill", function(d) { return(d.color) ; })
.style("font-size", function(d) { return(d.size+"px") ; })
//.style("text-anchor", function(d) { return(d.align) ; })
.style("text-anchor", function(d) { return(d.anchor) ; })
.text(function(d) { return(d.label) ;})

}
Expand Down
2 changes: 1 addition & 1 deletion man/renderStreamgraph.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{renderStreamgraph}
\alias{renderStreamgraph}
Expand Down
28 changes: 24 additions & 4 deletions man/sg_add_marker.Rd
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_add_marker}
\alias{sg_add_marker}
\title{Add a vertical marker (with optional label) to streamgraph}
\usage{
sg_add_marker(sg, x, stroke_width = 0.5, stroke = "#7f7f7f", space = 5,
y = 0, label = "", color = "#7f7f7f", size = 12)
sg_add_marker(sg, x, label = "", stroke_width = 0.5, stroke = "#7f7f7f",
space = 5, y = 0, color = "#7f7f7f", size = 12, anchor = "start")
}
\arguments{
\item{x}{horizontal position}

\item{label}{text for the annotation}

\item{stroke_width}{line width}

\item{stroke}{line color}

\item{space}{space (in points) from the marker to place the label}

\item{y}{vertical position}

\item{color}{color of the label}

\item{size}{font size#'}

\item{anchor}{how to justify the label (one of \code{start} [left],
\code{middle} [center] or \code{end} [right])}
}
\description{
Add a vertical marker (with optional label) to streamgraph
This is useful for marking/labeling notable events along the streams.
}

19 changes: 16 additions & 3 deletions man/sg_annotate.Rd
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_annotate}
\alias{sg_annotate}
\title{Add text annotation to streamgraph}
\usage{
sg_annotate(sg, label, x, y, color = "black", size = "12")
sg_annotate(sg, label, x, y, color = "black", size = 12)
}
\arguments{
\item{label}{text for the annotation}

\item{x}{horizontal position}

\item{y}{vertical position}

\item{color}{color of the label}

\item{size}{font size}
}
\description{
Add text annotation to streamgraph
Use this function to place text at any point on a streamgraph. This
is especially useful for non-interactive streamgraphs (i.e. to label
a particular stream).
}

2 changes: 1 addition & 1 deletion man/sg_axis_x.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_axis_x}
\alias{sg_axis_x}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_axis_y.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_axis_y}
\alias{sg_axis_y}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_colors.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_colors}
\alias{sg_colors}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_fill_brewer.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_fill_brewer}
\alias{sg_fill_brewer}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_fill_manual.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_fill_manual}
\alias{sg_fill_manual}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_fill_tableau.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_fill_tableau}
\alias{sg_fill_tableau}
Expand Down
2 changes: 1 addition & 1 deletion man/sg_legend.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{sg_legend}
\alias{sg_legend}
Expand Down
2 changes: 1 addition & 1 deletion man/streamgraph-exports.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph-package.R
\name{streamgraph-exports}
\alias{\%>\%}
Expand Down
2 changes: 1 addition & 1 deletion man/streamgraph-package.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph-package.R
\docType{package}
\name{streamgraph-package}
Expand Down
2 changes: 1 addition & 1 deletion man/streamgraph.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{streamgraph}
\alias{streamgraph}
Expand Down
2 changes: 1 addition & 1 deletion man/streamgraphOutput.Rd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/streamgraph.R
\name{streamgraphOutput}
\alias{streamgraphOutput}
Expand Down

0 comments on commit df5821f

Please sign in to comment.