Skip to content

Instantly share code, notes, and snippets.

@obenjiro
Last active September 28, 2015 13:29
Show Gist options
  • Select an option

  • Save obenjiro/366f0e6dc3c46730877e to your computer and use it in GitHub Desktop.

Select an option

Save obenjiro/366f0e6dc3c46730877e to your computer and use it in GitHub Desktop.
d3 template gist
/**
* Шаблонная функция для работы с D3
*/
function act(scenario) {
// устанавливаем сцену
var stage = d3.select('body');
// выбераем актеров
var actors = stage.selectAll('div');
// раздаем роли актерам
var awroles = actors.data(scenario, function(d){ return d });
awroles
/* действия актеров которые уже на сцене */
/* .style({ color: 'blue' }) */
;
awroles.enter()
/* действия актеров которые выходят на сцену */
/* .append('div').text(String) */
;
awroles.exit()
/* действия актеров которые уходят со сцены */
/* .style({ color: 'red' }) */
;
}
// current state of DOM -> act #1
act([1,2,3])
// act #1 -> act #2
act([2,4]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment