-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin: Colored ribbon #537
base: master
Are you sure you want to change the base?
Conversation
* | ||
* `palette`: Colors Array. Default: ["transparent", "#ef2929", "#8ae234"] | ||
* | ||
* `height`: Value (0-1) representing the height of the ribbon: 1 - full height, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's interesting that the x-values of the ribbons are tied to the data whereas the y-values are not (the ribbon doesn't move with y-panning and y-zooming). Why did you choose to do it this way?
Seems like a useful plugin, thanks! I have a few questions about the API, though. |
+1 on being useful. I use this type of functionality a lot, accomplished via the callbacks. Looks cool. |
@danielkrizian Please explain some of the usecases for this plugin. Especially:
|
Rename `height` and `position` parameter names into `top` and `bottom` correspondingly.
The idea behind ribbon (inspired by it's use in financial applications, see charts in The Economist magazine) is to analyze the relationship of different states (their start, end and duration) in connection to other time series. For example, employment rate during recessions (the latter state visualized as red in the red/none ribbon along x axis). Another example, long/short/no investment position in a stock (represented by green/red/no ribbon) in relation to its stock price. In that light, different colors of ribbon mark different states of a discrete/categorical variable over time, hence over the x-axis. The above realization that ribbon just encodes/maps a categorical variable over time into a set of colors helps answer the second question:
As @pshevtsov pointed out, the advantage of the distinction is that the visualization can be completely data-driven. In other words, it helps to separate the data from the visualization choices/functions. Let's take the very common scenario where the analyst has a data table, where one of the columns is a categorical variable taking values over time: To summarize, lines represent (most often) continuous variables. Ribbons represent categorical variables. Both types of objects are time series. Note: One could theoretically have multiple ribbons on a single chart, drawn at different y-positions (as y-position doesn't matter from the data point of view), but let's keep it simple at this point and stick to a single ribbon. |
}; | ||
|
||
ribbon.prototype.activate = function(g) { | ||
if (this.ribbonData_ !== null || this.ribbonDataParser_ !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want to throw
if this isn't the case? Does it always represent misconfiguration?
Overall this looks good. One other use case that might be nice to hit is where you want to just highlight a particular range of dates, e.g. http://dygraphs.com/tests/highlighted-region.html. For that case, it's easier to just specify start & stop values, rather than 0/1 for every x-value in the chart. Not something that needs to be addressed in this PR, anyway. All of the charts in |
* Plugin options: | ||
* | ||
* `data`: Array of numeric values (0-1) corresponding to the position | ||
* in the pallete interval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
palette
(sp)
Vector encoding for each x position (in this case using binary 0/1, but could be an integer domain enumeration) is arguably more general use case than start & stop values. The first can denote multiple regions and multiple colors in a single vector. The latter is a special case for single region and single color. Again, visualization is often data driven, so that one column of the the |
I'd like to merge this, but it really does need some high-level documentation, either in |
Ok, the existing feature called shaded regions (example here http://rstudio.github.io/dygraphs/gallery-shaded-regions.html) specifies
Above can be clunky to write if you have hundreds of regions in the graph. Enter the ribbon. Instead of supplying the The example ribbon graph should showcase hundreds of different colors, to distinguish itself clearly from "highlighted region" (or "shaded region") feature. |
</head> | ||
<body> | ||
<h1>Colored Ribbon demo</h1> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pshevtsov , following can be included in the <div>
of the ribbon.html
to document the use, in addition to the source code of the examples:
Description:
Ribbon is a horizontal band of colors that runs through the chart. It can useful to visualize categorical variables (http://en.wikipedia.org/wiki/Categorical_variable) that change over time (along the x-axis). For example multiple states of economy like "bust","recession", "recovery", "boom" can be encoded as [0, 1, 2, 3] respectively (or normalized as [0, 0.33, 0.66, 1]) and assigned colors ["red","orange","green","purple"].
Arguments:
data
:
Array of numeric values in the range from 0 to 1. Ribbon data
array must be of same length as number of rows of Dygraph raw data
table. Each of the values (0-1) scales to a position in the palette
array scale (see palette
argument below). For example, if palette is defined as ["transparent", "#ef2929", "#8ae234"], then 0 is the leftmost position ("#ef2929") on the palette
scale, 1 is the rightmost position ("#8ae234") and 0.5 is the middle position ("#ef2929")
parser
:
Function (function (data, dygraph)
) returning the array of numeric values. Function arguments: raw data, dygraph instance. Provide it if the ribbon data
, i.e. encodings are part of the dygraph raw data
table rather than supplied separately through ribbon data
argument. See example 2.
options
:
Object with the following properties:
palette
:
array of hexadecimal color codes. Default: ["transparent", "#ef2929", "#8ae234"]. Pick colors from e.g. http://www.w3schools.com/tags/ref_colorpicker.asptop
:
vertical position of the top edge of the ribbon relative to chart height. Value in the range from 0 (bottom edge of the chart) to 1 (top edge of the chart). E.g. 0.5 places the top edge of the ribbon at the 50% height of the chart.bottom
:
vertical position of the bottom edge of the ribbon relative to chart height. Seetop
.
what is the status of this PR? |
Color regions that comprise the ribbon can be different for each date. User supplies an array of numeric values and color palette (gradient), where each numeric value encodes a position in the palette interval.