Creación de una infografía interactiva con Vue.js

  • SmashingConf Friburgo 2024
  • Clase magistral de CSS moderno avanzado, con Manuel Matuzović
  • Índice
    1. Overview Of Tour De France Data
    2. Preparación de SVG
    3. Vue Component Overview
    4. GreenSock Animation
      1. Animating Stages/Spokes Inside The Wheel
      2. ADDING INTERACTIVITY
    5. Final Project
      1. VUEX
      2. Mixins
    6. Conclusion

    ¿Alguna vez ha tenido un requisito en el que tenía que diseñar y crear una experiencia web interactiva pero el sistema de cuadrícula se quedó corto? Además, ¿los elementos de diseño se convirtieron en formas inusuales que simplemente no encajarían en los diseños web habituales? En este artículo, vamos a crear una infografía interactiva utilizando Vue.js, SVG y GreenSock utilizando datos dinámicos y un diseño inusual.

    Este artículo presenta un enfoque moderno para crear una infografía interactiva. Seguro que puedes tener una infografía sencilla con toda la información disponible por adelantado, sin ninguna interacción del usuario. Pero pensar en crear una experiencia interactiva cambia el panorama tecnológico que elegimos. Por lo tanto, primero entendamos por qué Vue.js. Y verá por qué GSAP (GreenSock Animation Platform) y SVG (Scalable Vector Graphics) se convierten en opciones obvias.

    Vue.js proporciona formas prácticas de crear interfaces de usuario dinámicas basadas en componentes donde puede manipular y administrar elementos DOM de maneras poderosas. En este caso, será SVG. Puede actualizar y administrar fácilmente diferentes elementos SVG, dinámicamente, utilizando solo un pequeño subconjunto de funciones disponibles en Vue.js; algunas de las funciones básicas que se ajustan a los requisitos aquí son enlace de datos, representación de listas, enlace dinámico de clases para nombrar un pocos. Esto también le permite agrupar elementos SVG relevantes y componerlos.

    Vue.js funciona bien con bibliotecas externas sin perder su gloria, ese es GSAP aquí. Hay muchos otros beneficios de usar Vue.js, uno de los cuales es que Vue.js le permite aislar plantillas, scripts y estilos relacionados para cada componente. De esta manera, Vue.js promueve una estructura de aplicación modular.

    Lectura recomendada : Reemplazo de jQuery con Vue.js: no es necesario ningún paso de compilación

    Vue.js also comes packaged with powerful lifecycle hooks that let you tap into the different stages of application to modify application behavior. Setting up and maintaining Vue.js applications doesn’t require a big commitment, meaning you can take phased-approach to scale your project as you go.

    The infographic is very light-weight in a visual sense, as the main aim of this article is to learn how to think in terms of data, visual elements, and of course, Vue.js — the framework that makes all the interactivity possible. In addition, we’ll use GreenSock, a library for animating SVG elements. Before we dive in, take a look at the demo.

    We’ll start with:

    1. The overview of the data for infographic;
    2. SVG image preparation;
    3. An overview of Vue components in context of the SVG artwork;
    4. Code samples and diagrams of key interactivity.

    The infographic that we’re going to build is about Tour De France, the annual bicycle racing event held in France.

    Tour De France  —  Interactive bicycle listing game stages (rear-wheel) and participating teams (front-wheel). (Large preview)

    Overview Of Tour De France Data

    In infographic design, data drives the design of your infographic. Therefore, while planning your infographic design, it’s always a good idea to have all data, information, and statistics available for the given subject matter.

    During Tour De France of 2017, I learned everything about this biggest cycling event that I could in 21 days of the game in July, and I familiarized myself with the subject.

    Basic entities of the race that I decided to go for in my design are,

    • Stages,
    • Teams,
    • Routes,
    • Winners,
    • Length and classifications of each routes.

    This next part of the process depends on your thinking style, so you can be creative here.

    I created two sets of data, one for stages and other for teams. These two datasets have multiple rows of data (but within limit)  —  which matched with two wheels of the bicycle with multiple spokes in each. And that defined the key element of the design, The Bicycle Art that you saw at the beginning  —  where each spoke will be interactive responsible to drive what information is revealed on screen.

    I mentioned within limits above, because what we’re aiming for in this instance is not a full-blown data-visualization in context of big data but rather an infographic with high-level data.

    Por lo tanto, dedica tiempo de calidad a los datos y busca similitudes, diferencias, jerarquías o tendencias que puedan ayudarte a transmitir una historia visual. Y no te olvides de la increíble combinación de SVG y Vue.js mientras lo haces, ya que te ayudará a lograr el equilibrio adecuado entre información (datos), interactividad (Vue.js) y elementos de diseño (SVG Artwork). ) de infografía.

    Aquí está el fragmento de un objeto de datos de escenario:

    {    "ID": 1,    "NAME": "STAGE 01",    "DISTANCE": "14",    "ROUTE": "KMDÜSSELDORF / DÜSSELDORF",    "WINNER": "THOMAS G.",    "UCI_CODE": "SKY",    "TYPE": "Individual Time Trial",    "DATE": "Saturday July 1st",    "KEY_MOMENT": " Geraint Thomas takes his first win at 32"}

    Y el fragmento de objeto de datos del equipo como se muestra a continuación:

    {    "ID": 1,    "UCI_CODE": "SKY",    "NAME": " TEAM SKY",    "COUNTRY": "Great Britain",    "STAGE_VICTORIES": 1,    "RIDERS": 8}

    Esta infografía funciona con una lógica muy simple.

    UCI_CODE ( Union Cycliste Internationale ) es la clave de conexión entre la etapa y el objeto del equipo. Cuando se hace clic en una etapa, primero activaremos esa etapa, pero también usaremos UCI_CODEla tecla para activar el equipo ganador correspondiente.

    Preparación de SVG

    Teniendo listo un par de conjuntos de datos y un concepto aproximado del arte de la bicicleta, aquí está el CodePen SVG estático de la infografía que se me ocurrió.

    Vea el SVG Pen Static Bicycle de Krutie( @krutie ) en CodePen .

    Hemos creado solo un radio para cada rueda, eso se debe a que crearemos dinámicamente el resto de los radios usando una cantidad de registros que se encuentran en el conjunto de datos y los animaremos usando la biblioteca GreenSock.

    El flujo de trabajo para crear este código SVG también es muy sencillo. Cree su obra de arte infográfica en Adobe Illustrator y guárdela como SVG. Asegúrese de nombrar cada groupuno de ellos layermientras trabaja en Illustrator, porque necesitará esos identificadores para separar las partes del código SVG que eventualmente completarán `

    SUSCRÍBETE A NUESTRO BOLETÍN 
    No te pierdas de nuestro contenido ni de ninguna de nuestras guías para que puedas avanzar en los juegos que más te gustan.

    Deja un comentario

    Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

    Subir

    Este sitio web utiliza cookies para mejorar tu experiencia mientras navegas por él. Este sitio web utiliza cookies para mejorar tu experiencia de usuario. Al continuar navegando, aceptas su uso. Mas informacion