/app/scripts/components/Slider.js

https://gitlab.com/Webxity/vizabi-prototypes · JavaScript · 91 lines · 73 code · 15 blank · 3 comment · 11 complexity · e27aa1ebfecd7fafb9820250d0a8d4e5 MD5 · raw file

  1. (function() {
  2. 'use strict';
  3. /**
  4. * Chroniton ( component used for slider )
  5. */
  6. VizabiPrototype.prototype.Slider = function(sOptions) {
  7. var sliderID = this.sliderID;
  8. var dataset = this.dataset;
  9. if (sOptions.data) {
  10. dataset = sOptions.data;
  11. }
  12. var currentChart = this.currentChart;
  13. var options = this.options;
  14. var optionLoop = options.state.time.loop;
  15. var optionValue = options.state.time.value;
  16. var optionPlayable = options.state.time.playable;
  17. var styleProps = 'float:left;' +
  18. 'margin-top: 20px;' +
  19. 'padding: 11px 12px;' +
  20. 'border: 1px solid;' +
  21. 'border-radius: 25px;' +
  22. 'font-size: 16px;' +
  23. 'text-align: center;' +
  24. 'padding-left: 17px;'+
  25. 'background-color: #607889;'+
  26. 'width: 45px;' +
  27. 'height: 45px;';
  28. var button = d3.select(sliderID)
  29. .append('button')
  30. .attr('style', styleProps)
  31. .classed('fa fa-play text-success', true);
  32. if(optionPlayable == false)
  33. d3.select('div#slider button').classed('vzb-invisible', true);
  34. else
  35. d3.select('div#slider button').classed('vzb-invisible', false);
  36. var playPause = function() {
  37. if (c.playing()) {
  38. button.classed('fa-play', false);
  39. button.classed('fa-pause', true);
  40. } else {
  41. button.classed('fa-play', true);
  42. button.classed('fa-pause', false);
  43. }
  44. };
  45. button.on('click', function () {
  46. c.playPause();
  47. playPause();
  48. });
  49. var c = chroniton()
  50. .domain([options.state.time.start, options.state.time.end])
  51. .setInitialValue(optionValue)
  52. .width(this.screenSize.width).loop(optionLoop);
  53. d3.select(sliderID)
  54. .append('span')
  55. .attr('style', 'float:left;width:80%;margin-top:15px;')
  56. .attr('class', 'theme-example')
  57. .call(c);
  58. c.on('change', function (d) {
  59. if (typeof sOptions.transform === 'function') {
  60. sOptions.transform.call(currentChart, d, dataset);
  61. }
  62. playPause();
  63. });
  64. c.playbackRate(1);
  65. if(this.screenSize.width < 350)
  66. c.playbackRate(1);
  67. else if(this.screenSize.width < 580)
  68. c.playbackRate(1.5);
  69. else if(this.screenSize.width < 900)
  70. c.playbackRate(2);
  71. else
  72. c.playbackRate(2);
  73. c.hideLabel();
  74. return c;
  75. };
  76. })();