applied Docs 781 to torquejs docs

This commit is contained in:
csobier 2016-05-26 11:27:52 -04:00
parent d196b617b8
commit 2628bcb9ff
5 changed files with 32 additions and 30 deletions

View File

@ -6,3 +6,5 @@ Torque.js is an efficient and stylish rendering method to animate your data. Tor
* [Getting Started with Torque.js](getting_started.md) * [Getting Started with Torque.js](getting_started.md)
* [Torque API Methods](torque_api.md) * [Torque API Methods](torque_api.md)
* [Advanced Interaction Methods](torque_interaction_methods.md)
* [Torque Time Slider](torque_time_slider.md)

View File

@ -1,6 +1,6 @@
# Getting Started # Getting Started
Although the most straightforward way to use Torque is through either the CartoDB Editor, or by passing the layer's viz.json to [CartoDB.js](http://docs.cartodb.com/cartodb-platform/cartodb-js/getting-started/), many use cases work best with the standalone [Torque.js](https://github.com/CartoDB/torque/tree/master/dist). Assuming you have a public dataset with a `date` column, it is really simple to create an animated map with the library. First, you need to have a Leaflet map prepared in an HTML page: Although the most straightforward way to use Torque is through either the Carto Editor, or by passing the layer's viz.json to [Carto.js](http://docs.carto.com/carto-engine/carto-js/getting-started/), many use cases work best with the standalone [Torque.js](https://github.com/CartoDB/torque/tree/master/dist). Assuming you have a public dataset with a `date` column, it is really simple to create an animated map with the library. First, you need to have a Leaflet map prepared in an HTML page:
```html ```html
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
@ -15,7 +15,7 @@ Although the most straightforward way to use Torque is through either the CartoD
}); });
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', { L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
attribution: 'CartoDB' attribution: 'Carto'
}).addTo(map); }).addTo(map);
</script> </script>
</body> </body>
@ -28,7 +28,7 @@ This HTML file automatically generates the Torque.js library, which includes any
var CARTOCSS = [ var CARTOCSS = [
'Map {', 'Map {',
'-torque-time-attribute: "date";', '-torque-time-attribute: "date";',
'-torque-aggregation-function: "count(cartodb_id)";', '-torque-aggregation-function: "count(carto_id)";',
'-torque-frame-count: 760;', '-torque-frame-count: 760;',
'-torque-animation-duration: 15;', '-torque-animation-duration: 15;',
'-torque-resolution: 2', '-torque-resolution: 2',
@ -51,7 +51,7 @@ This HTML file automatically generates the Torque.js library, which includes any
</script> </script>
``` ```
You can use any kind of tile source outside CartoDB, by specifying the location of a [valid TileJSON](https://github.com/mapbox/tilejson-spec) file: You can use any kind of tile source outside Carto, by specifying the location of a [valid TileJSON](https://github.com/mapbox/tilejson-spec) file:
```javascript ```javascript
var torqueLayer = new L.TorqueLayer({ var torqueLayer = new L.TorqueLayer({
@ -71,7 +71,7 @@ Optionally, it is also possible to use a custom SQL query for your visualization
}); });
``` ```
Like in a video player, you can use animation control methods such as `play`, `stop` and `pause` at any point. Torque's animator fires a `change:time` event each time the animation "ticks" to the next frame, and there are a number of properties and methods that can be run during playback, which are detailed in the [API documentation](/cartodb-platform/torque/torqueapi/). At any point, for example, the styling of the layer's markers can be changed using the `layer.setCartoCSS('##style##')`. Like in a video player, you can use animation control methods such as `play`, `stop` and `pause` at any point. Torque's animator fires a `change:time` event each time the animation "ticks" to the next frame, and there are a number of properties and methods that can be run during playback, which are detailed in the [API documentation](/carto-engine/torque/torqueapi/). At any point, for example, the styling of the layer's markers can be changed using the `layer.setCartoCSS('##style##')`.
## Usage Examples ## Usage Examples
The best way to start learning about the library is by taking a look at some of the examples below: The best way to start learning about the library is by taking a look at some of the examples below:
@ -85,9 +85,9 @@ The best way to start learning about the library is by taking a look at some of
The following links contain examples, and other public information, about using Torque maps. The following links contain examples, and other public information, about using Torque maps.
- Torque [CartoCSS Reference page](https://github.com/cartodb/torque-reference), useful for building parsers, tests, compilers, and syntax highlighting/checking - Torque [CartoCSS Reference page](https://github.com/cartodb/torque-reference), useful for building parsers, tests, compilers, and syntax highlighting/checking
- CartoDB repository of [examples](https://github.com/CartoDB/torque/tree/master/examples) - Carto repository of [examples](https://github.com/CartoDB/torque/tree/master/examples)
- A CartoDB [time example](http://cartodb.github.com/torque/) of a Torque map and data - A Carto [time example](http://cartodb.github.com/torque/) of a Torque map and data
- CartoDB wiki page describing [how spatial aggregration works](https://github.com/CartoDB/torque/wiki/How-spatial-aggregation-works) - Carto wiki page describing [how spatial aggregration works](https://github.com/CartoDB/torque/wiki/How-spatial-aggregation-works)
- The [Guardian's Data Blog](http://www.guardian.co.uk/news/datablog/interactive/2012/oct/01/first-world-war-royal-navy-ships-mapped) about Royal Navy ships in WWI using a Torque map - The [Guardian's Data Blog](http://www.guardian.co.uk/news/datablog/interactive/2012/oct/01/first-world-war-royal-navy-ships-mapped) about Royal Navy ships in WWI using a Torque map
- An example of how to create a [simple Torque visualization](https://github.com/CartoDB/torque#getting-started) and the [source code](https://github.com/CartoDB/torque/blob/master/examples/navy_leaflet.html) used to create the example - An example of how to create a [simple Torque visualization](https://github.com/CartoDB/torque#getting-started) and the [source code](https://github.com/CartoDB/torque/blob/master/examples/navy_leaflet.html) used to create the example
- An example of how to use CartoDB.js to [add a Torque layer from a named map with auth_tokens enabled](https://gist.github.com/chriswhong/a4d1e6305ecaf2ad507a) - An example of how to use Carto.js to [add a Torque layer from a named map with auth_tokens enabled](https://gist.github.com/chriswhong/a4d1e6305ecaf2ad507a)

View File

@ -28,12 +28,12 @@ attribution | Attribution to be added in the bottom right of the map
maxZoom | Maximum zoom for the layer. maxZoom | Maximum zoom for the layer.
tileSize | Size, in pixels of the tiles tileSize | Size, in pixels of the tiles
##### Using a CartoDB table directly ##### Using a Carto table directly
Name | Description Name | Description
--- | --- --- | ---
user | A string object, your CartoDB [account name](/cartodb-editor/your-account/#account). Default value is ```null``` user | A string object, your Carto [account name](/carto-editor/your-account/#account). Default value is ```null```
table | A string object, the CartoDB table name where data is found (also known as a dataset.) Default value is ```null``` table | A string object, the Carto table name where data is found (also known as a dataset.) Default value is ```null```
##### Using a custom SQL query ##### Using a custom SQL query
@ -41,7 +41,7 @@ Name | Description
--- | --- --- | ---
query | A string object, the SQL query to be performed to fetch the data. Default value is ```null```.<br/><br/>You must use this param or table, but not at the same time query | A string object, the SQL query to be performed to fetch the data. Default value is ```null```.<br/><br/>You must use this param or table, but not at the same time
**Tip:** For a Torque category layer that is created dynamically with `cartodb.createLayer`, the SQL query must explicitly include how to build the torque_category column. You must include both the `sql` and `table_name` parameters. See this [createLayer with torque category layer](https://gist.github.com/danicarrion/dcaf6f00a71aa55134b4) example. **Tip:** For a Torque category layer that is created dynamically with `carto.createLayer`, the SQL query must explicitly include how to build the torque_category column. You must include both the `sql` and `table_name` parameters. See this [createLayer with torque category layer](https://gist.github.com/danicarrion/dcaf6f00a71aa55134b4) example.
##### Providing a TileJSON file ##### Providing a TileJSON file
@ -62,7 +62,7 @@ Method | Options | Returns | Description |
`getTime()` | | current animation time (Date) | gets the real animation time `getTime()` | | current animation time (Date) | gets the real animation time
`isRunning()` | | `true`/`false` | describes whether the Torque layer is playing or is stopped `isRunning()` | | `true`/`false` | describes whether the Torque layer is playing or is stopped
**Note:** Torque.js interprets the beginning and ending date/time from your "Time Column" as one block, then divides that up into [Steps](/cartodb-platform/cartocss/properties-for-torque/#torque-frame-count-number), depending on the number you set. It does not necessarily draw one frame for each row. **Note:** Torque.js interprets the beginning and ending date/time from your "Time Column" as one block, then divides that up into [Steps](/carto-engine/cartocss/properties-for-torque/#torque-frame-count-number), depending on the number you set. It does not necessarily draw one frame for each row.
#### Layer Control Methods #### Layer Control Methods
@ -75,9 +75,9 @@ Method | Options | Returns | Description |
Method | Options | Returns | Description Method | Options | Returns | Description
---|---|---|---| ---|---|---|---|
`setCartoCSS(cartocss)` | `cartocss string` | `this` | style the map rendering using client-side CartoCSS (not available with [Named maps](/cartodb-platform/maps-api/named-maps/)) `setCartoCSS(cartocss)` | `cartocss string` | `this` | style the map rendering using client-side CartoCSS (not available with [Named maps](/carto-engine/maps-api/named-maps/))
Torque supports a limited subset of CartoCSS rules defined in the [torque-reference](https://github.com/cartodb/torque-reference). To see the full list of supported rules, read the [Torque CartoCSS documentation](/cartodb-platform/cartocss/properties-for-torque/). `value` and `zoom` variables can be used. `value` is the value of aggregation. `zoom` is the current zoom being rendered. Torque supports a limited subset of CartoCSS rules defined in the [torque-reference](https://github.com/carto/torque-reference). To see the full list of supported rules, read the [Torque CartoCSS documentation](/carto-engine/cartocss/properties-for-torque/). `value` and `zoom` variables can be used. `value` is the value of aggregation. `zoom` is the current zoom being rendered.
TorqueLayer currently expects `marker` styling. TorqueLayer currently expects `marker` styling.
@ -88,7 +88,7 @@ This is how a minimal example of a stylesheet for a Torque visualisation would l
```css ```css
Map { Map {
-torque-time-attribute: "date"; -torque-time-attribute: "date";
-torque-aggregation-function: "count(cartodb_id)"; -torque-aggregation-function: "count(carto_id)";
-torque-frame-count: 760; -torque-frame-count: 760;
-torque-animation-duration: 15; -torque-animation-duration: 15;
-torque-resolution: 2; -torque-resolution: 2;

View File

@ -29,7 +29,7 @@ This layer source object is used for Torque maps. Note that it does not allow su
Used to create an animated torque layer with customized settings. Used to create an animated torque layer with customized settings.
```javascript ```javascript
// initialize a torque layer that uses the CartoDB account details and SQL API to pull in data // initialize a torque layer that uses the Carto account details and SQL API to pull in data
var torqueLayer = new L.TorqueLayer({ var torqueLayer = new L.TorqueLayer({
user : 'viz2', user : 'viz2',
table : 'ow', table : 'ow',
@ -120,7 +120,7 @@ var map = new L.Map('map', {
zoom: 3 zoom: 3
}); });
L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', { L.tileLayer('http://{s}.api.cartocdn.com/base-dark/{z}/{x}/{y}.png', {
attribution: 'CartoDB' attribution: 'Carto'
}).addTo(map); }).addTo(map);
var torqueLayer = new L.TorqueLayer({ var torqueLayer = new L.TorqueLayer({
user : 'viz2', user : 'viz2',

View File

@ -1,25 +1,25 @@
# Torque Time Slider # Torque Time Slider
You can use the `time_slider` option to show an animated time slider with Torque layers. This option is enabled by default when creating visualizations with [cartodb.createVis](http://docs.cartodb.com/cartodb-platform/cartodb-js/api-methods/#cartodbcreatevis) and [createLayer](http://docs.cartodb.com/cartodb-platform/cartodb-js/api-methods/#cartodbcreatelayermap-layersource--options--callback). Both require a map_id DOM object. You can use the `time_slider` option to show an animated time slider with Torque layers. This option is enabled by default when creating visualizations with [carto.createVis](http://docs.carto.com/carto-engine/carto-js/api-methods/#cartocreatevis) and [createLayer](http://docs.carto.com/carto-engine/carto-js/api-methods/#cartocreatelayermap-layersource--options--callback). Both require a map_id DOM object.
**Enable / Disable the Torque Time Slider** **Enable / Disable the Torque Time Slider**
Description | The Torque time slider is enabled by default, for your visualization or layer. Description | The Torque time slider is enabled by default, for your visualization or layer.
Sample Torque.js Code | `{ time_slider: true });` Sample Torque.js Code | `{ time_slider: true });`
Default Value | `true`, enabled by default. Default Value | `true`, enabled by default.
Available Values | See [boolean](http://docs.cartodb.com/cartodb-platform/cartocss/properties/#boolean). Available Values | See [boolean](http://docs.carto.com/carto-engine/cartocss/properties/#boolean).
Related Examples | To disable the time slider option, use `time_slider: false`. See [No Torque Time Slider - Example Code](http://bl.ocks.org/michellechandra/081ca7160a8c782266d2).<br/><br/>For a code example about how to use the `time_slider` option to modify a Torque map, see [Torque with a Custom Time Slider](http://bl.ocks.org/csobier/cebdd47242d7ca98ec5e). Related Examples | To disable the time slider option, use `time_slider: false`. See [No Torque Time Slider - Example Code](http://bl.ocks.org/michellechandra/081ca7160a8c782266d2).<br/><br/>For a code example about how to use the `time_slider` option to modify a Torque map, see [Torque with a Custom Time Slider](http://bl.ocks.org/csobier/cebdd47242d7ca98ec5e).
**Note:** The `time_slider` option is specific for Torque.js only. All the other CartoDB.js options are also supported for Torque.js. For the complete list of arguments, options, and returns, see [CartoDB.js API Methods](http://docs.cartodb.com/cartodb-platform/cartodb-js/api-methods/#api-methods). **Note:** The `time_slider` option is specific for Torque.js only. All the other Carto.js options are also supported for Torque.js. For the complete list of arguments, options, and returns, see [Carto.js API Methods](http://docs.carto.com/carto-engine/carto-js/api-methods/#api-methods).
## Customize Animation for your Time Slider ## Customize Animation for your Time Slider
You can customize the animation of your Torque time slider by editing the `-torque-frame-count` and `-torque-animation-duration` CartoCSS properties. (Optionally, you can create a [CartoDB.js](http://docs.cartodb.com/cartodb-platform/cartodb-js/api-methods/#api-methods) map to create a custom time slider). This section also describes how time interval data is aggregated, and describes the formula used to calculate time buckets. You can customize the animation of your Torque time slider by editing the `-torque-frame-count` and `-torque-animation-duration` CartoCSS properties. (Optionally, you can create a [Carto.js](http://docs.carto.com/carto-engine/carto-js/api-methods/#api-methods) map to create a custom time slider). This section also describes how time interval data is aggregated, and describes the formula used to calculate time buckets.
- [`-torque-frame-count`](http://docs.cartodb.com/cartodb-platform/cartocss/properties-for-torque/#torque-frame-count-number) specifies the number of animation steps/frames in your torque animation. You can change the time slider timestamp by adjusting the number of steps.<br /><br />**Tip:** This is the _Steps_ option from the [Torque wizard](/cartodb-editor/maps/#torque) of the CartDB Editor. - [`-torque-frame-count`](http://docs.carto.com/carto-engine/cartocss/properties-for-torque/#torque-frame-count-number) specifies the number of animation steps/frames in your torque animation. You can change the time slider timestamp by adjusting the number of steps.<br /><br />**Tip:** This is the _Steps_ option from the [Torque wizard](/carto-editor/maps/#torque) of the Carto Editor.
- [`-torque-animation-duration`](http://docs.cartodb.com/cartodb-platform/cartocss/properties-for-torque/#torque-animation-duration-number) specifies the length of time for your animation, in seconds. You can adjust the duration of the animation as needed.<br /><br />**Tip:** This is the _Duration (secs)_ option from the [Torque wizard](/cartodb-editor/maps/#torque) of the CartoDB Editor. - [`-torque-animation-duration`](http://docs.carto.com/carto-engine/cartocss/properties-for-torque/#torque-animation-duration-number) specifies the length of time for your animation, in seconds. You can adjust the duration of the animation as needed.<br /><br />**Tip:** This is the _Duration (secs)_ option from the [Torque wizard](/carto-editor/maps/#torque) of the Carto Editor.
### Aggregating Time Interval Data ### Aggregating Time Interval Data
@ -29,12 +29,12 @@ Before customizing the time slider, you should understand how Torque time interv
- Reads the last date/time stamp to from your dataset - Reads the last date/time stamp to from your dataset
- Aggregates the time period based on the first and last date/time stamp (including seconds) - Aggregates the time period based on the first and last date/time stamp (including seconds)
- Once the time interval is defined, it breaks the time period up in smaller "buckets" - Once the time interval is defined, it breaks the time period up in smaller "buckets"
- The number of buckets is based on the number of [Steps](http://docs.cartodb.com/cartodb-platform/cartocss/properties-for-torque/#torque-frame-count-number) you select for your Torque map - The number of buckets is based on the number of [Steps](http://docs.carto.com/carto-engine/cartocss/properties-for-torque/#torque-frame-count-number) you select for your Torque map
- Each bucket, or step, is one animation frame - Each bucket, or step, is one animation frame
Thus, the start and end time for each bucket depends on the number of divided steps (not a specific start time or end time that you entered). Thus, the start and end time for each bucket depends on the number of divided steps (not a specific start time or end time that you entered).
**Note:** If you are creating Torque maps with the CartoDB Editor, the date format of the Torque time slider is automatically calculated by CartoDB and cannot be edited. See [Calculating the Time Slider in the CartoDB Editor](#calculating-the-time-slider-in-the-cartodb-editor) for more details. **Note:** If you are creating Torque maps with the Carto Editor, the date format of the Torque time slider is automatically calculated by Carto and cannot be edited. See [Calculating the Time Slider in the Carto Editor](#calculating-the-time-slider-in-the-carto-editor) for more details.
### Formula for Calculating Time Buckets ### Formula for Calculating Time Buckets
@ -48,11 +48,11 @@ Where:
- `times.start` = the earliest time in your date/time column - `times.start` = the earliest time in your date/time column
- `times.end` = the latest time in your date/time column - `times.end` = the latest time in your date/time column
The Torque time slider displays these buckets of time, animating the entire sequence of your dataset, and divides the time according to the number of specified steps. You can alter the [duration](http://docs.cartodb.com/cartodb-platform/cartocss/properties-for-torque/#torque-animation-duration-number) of the animation, and adjust the time slider timestamp with the number of [Steps](http://docs.cartodb.com/cartodb-platform/cartocss/properties-for-torque/#torque-frame-count-number). The Torque time slider displays these buckets of time, animating the entire sequence of your dataset, and divides the time according to the number of specified steps. You can alter the [duration](http://docs.carto.com/carto-engine/cartocss/properties-for-torque/#torque-animation-duration-number) of the animation, and adjust the time slider timestamp with the number of [Steps](http://docs.carto.com/carto-engine/cartocss/properties-for-torque/#torque-frame-count-number).
#### Calculating the Time Slider in the CartoDB Editor #### Calculating the Time Slider in the Carto Editor
When creating Torque maps with the CartoDB Editor, the date format of the Torque time slider is automatically calculated by CartoDB, depending on the range of time in your dataset. It cannot be edited. If your data contains the following range of time, the time slider displays as described: When creating Torque maps with the Carto Editor, the date format of the Torque time slider is automatically calculated by Carto, depending on the range of time in your dataset. It cannot be edited. If your data contains the following range of time, the time slider displays as described:
- Time range is _less than one day_, the time slider displays the _time_ - Time range is _less than one day_, the time slider displays the _time_
- Time range is _less than three days_, the time slider displays the _day and time_ - Time range is _less than three days_, the time slider displays the _day and time_