/*! * bespoke-vis v1.0.0 * * Copyright 2019, Flávio * This content is released under the MIT license * */ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g=(g.bespoke||(g.bespoke = {}));g=(g.plugins||(g.plugins = {}));g.math = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i { const currentSlideIndex = e.index; const visualizationsOnCurrentSlide = visualizationsAndMetadata.filter( vm => vm.slideIndex === currentSlideIndex ); visualizationsOnCurrentSlide.forEach(vm => setTimeout( () => vm.vis.fit({ animation: { duration: 2000, easingFunction: 'easeOutQuad' } }), 200 ) ); }); }; const renderVisElement = function(type, content, targetEl) { const supportedTypes = ['timeline', 'network', 'lines', 'bars']; try { if (supportedTypes.indexOf(type.toLowerCase()) === -1) { throw new Error( 'A non-supported type of visualization was asked from bespoke-vis: ' + type ); } content = JSON.parse(content); const items = content.items || [], groups = content.groups || [], options = content.options || {}; const capitalizedType = type.charAt(0).toUpperCase() + type.slice(1); const element = new vis[capitalizedType](targetEl); element.setOptions(options); if (Array.isArray(groups) && groups.length > 0) { element.setGroups(groups); } element.setItems(items); return new Promise(resolve => { resolve({ type, el: targetEl, vis: element }); }); } catch (err) { console.log( 'Visjs error trying to parse: "' + content + '". Description: ', err ); return Promise.reject(err); } }; module.exports = function() { return function(deck) { const visElements = deck.parent.querySelectorAll('[data-vis]'); if (visElements.length > 0) { require('vis/dist/vis.min.css'); } Array.from(visElements).forEach(el => { const slideIndex = deck.slides.indexOf(el.closest('.bespoke-slide')); const type = el.dataset.vis; let contentReady = Promise.resolve(el.innerHTML); const elStyle = getComputedStyle(el); el.style.minWidth = elStyle.width; el.style.minHeight = elStyle.height; el.innerHTML = ''; if (el.dataset.visUrl) { contentReady = fetch(el.dataset.visUrl).then(r => r.text()); } contentReady .then(content => renderVisElement(type, content, el)) .then(({ type, el, vis }) => registerVisualization(type, el, vis, deck, slideIndex) ); }); }; }; },{"fs":3,"vis":4,"vis/dist/vis.min.css":5}],2:[function(require,module,exports){ 'use strict'; // For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field. var styleElementsInsertedAtTop = []; var insertStyleElement = function(styleElement, options) { var head = document.head || document.getElementsByTagName('head')[0]; var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop[styleElementsInsertedAtTop.length - 1]; options = options || {}; options.insertAt = options.insertAt || 'bottom'; if (options.insertAt === 'top') { if (!lastStyleElementInsertedAtTop) { head.insertBefore(styleElement, head.firstChild); } else if (lastStyleElementInsertedAtTop.nextSibling) { head.insertBefore(styleElement, lastStyleElementInsertedAtTop.nextSibling); } else { head.appendChild(styleElement); } styleElementsInsertedAtTop.push(styleElement); } else if (options.insertAt === 'bottom') { head.appendChild(styleElement); } else { throw new Error('Invalid value for parameter \'insertAt\'. Must be \'top\' or \'bottom\'.'); } }; module.exports = { // Create a tag with optional data attributes createLink: function(href, attributes) { var head = document.head || document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.href = href; link.rel = 'stylesheet'; for (var key in attributes) { if ( ! attributes.hasOwnProperty(key)) { continue; } var value = attributes[key]; link.setAttribute('data-' + key, value); } head.appendChild(link); }, // Create a