├── LICENSE
├── README.md
├── bg-desktop.webp
├── graficos
├── common.js
├── informacoesGlobais.js
├── quantidadeUsuarios.js
└── scripts.js
├── index.html
└── style.css
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Rafael Assis Santos
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ciencia de dados criando graficos dinamicos com JavaScript
2 | @rasinformática
3 |
4 |
5 | https://www.youtube.com/watch?v=ZNNDuNZhkkc&t=11s
6 |
--------------------------------------------------------------------------------
/bg-desktop.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/professor-rafael/Ciencia-de-dados-criando-graficos-dinamicos-com-JavaScript/84db615c722ee6a3981263630571e3df06d8f079/bg-desktop.webp
--------------------------------------------------------------------------------
/graficos/common.js:
--------------------------------------------------------------------------------
1 | const getCSS = (variavel) => {
2 | const bodyStyles = getComputedStyle(document.body)
3 | return bodyStyles.getPropertyValue(variavel)
4 | }
5 |
6 | const tickConfig = {
7 | family: getCSS('--font'),
8 | size: 16,
9 | color: getCSS('--primary-color')
10 | }
11 |
12 | export {getCSS, tickConfig}
13 |
--------------------------------------------------------------------------------
/graficos/informacoesGlobais.js:
--------------------------------------------------------------------------------
1 | const url = 'https://raw.githubusercontent.com/guilhermeonrails/api/main/dados-globais.json'
2 |
3 | async function vizualizarInformacoesGlobais() {
4 | const res = await fetch(url)
5 | const dados = await res.json()
6 | const pessoasConectadas = (dados.total_pessoas_conectadas / 1e9)
7 | const pessoasNoMundo = (dados.total_pessoas_mundo / 1e9)
8 | const horas = parseInt(dados.tempo_medio)
9 | const minutos = Math.round((dados.tempo_medio - horas) * 100)
10 | const porcentagemConectada = ((pessoasConectadas / pessoasNoMundo ) * 100).toFixed(2)
11 |
12 | const paragrafo = document.createElement('p')
13 | paragrafo.classList.add('graficos-container__texto')
14 | paragrafo.innerHTML = `Você sabia que o mundo tem ${pessoasNoMundo} bilhões de pessoas e que aproximadamente ${pessoasConectadas} bilhões estão conectadas em alguma rede social e passam em média ${horas} horas e ${minutos} minutos conectadas.
Isso significa que aproximadamente ${porcentagemConectada}% de pessoas estão conectadas em alguma rede social.`
15 |
16 | const container = document.getElementById('graficos-container')
17 | container.appendChild(paragrafo)
18 | }
19 |
20 | vizualizarInformacoesGlobais()
21 |
--------------------------------------------------------------------------------
/graficos/quantidadeUsuarios.js:
--------------------------------------------------------------------------------
1 | import { getCSS, tickConfig } from "./common.js"
2 |
3 | async function quantidadeUsuariosPorRede() {
4 | const url = 'https://raw.githubusercontent.com/guilhermeonrails/api/main/numero-usuarios.json'
5 | const res = await fetch(url)
6 | const dados = await res.json()
7 | const nomeDasRedes = Object.keys(dados)
8 | const quantidadeDeUsuarios = Object.values(dados)
9 |
10 | const data = [
11 | {
12 | x: nomeDasRedes,
13 | y: quantidadeDeUsuarios,
14 | type: 'bar',
15 | marker: {
16 | color: getCSS('--primary-color')
17 | }
18 | }
19 | ]
20 |
21 | const laytout = {
22 | plot_bgcolor: getCSS('--bg-color'),
23 | paper_bgcolor: getCSS('--bg-color'),
24 | title: {
25 | text: 'Redes sociais com mais usuários',
26 | x: 0,
27 | font: {
28 | color: getCSS('--primary-color'),
29 | size: 30,
30 | font: getCSS('--font')
31 | }
32 | },
33 | xaxis: {
34 | tickfont: tickConfig,
35 | title: {
36 | text: 'Nome das redes',
37 | font: {
38 | color: getCSS('--secondary-color')
39 | }
40 | }
41 | },
42 | yaxis: {
43 | tickfont: tickConfig,
44 | title: {
45 | text: 'Bilhões de usuários ativos',
46 | font: {
47 | color: getCSS('--secondary-color')
48 | }
49 | }
50 | }
51 | }
52 |
53 | const grafico = document.createElement('div')
54 | grafico.className = 'grafico'
55 | document.getElementById('graficos-container').appendChild(grafico)
56 | Plotly.newPlot(grafico, data, laytout)
57 | }
58 |
59 | quantidadeUsuariosPorRede()
--------------------------------------------------------------------------------
/graficos/scripts.js:
--------------------------------------------------------------------------------
1 |
2 | const selecaoVoz = document.querySelector("#selecao-voz");
3 | const entradaTexto = document.querySelector("#entrada-de-texto");
4 | const botaoOuvir = document.querySelector("#ouvir-btn");
5 | const botoaBaixarTexto = document.querySelector("#baixar-texto-btn");
6 | const uplaodArquivo = document.querySelector("#upload-arquivo");
7 |
8 |
9 | const fala = new SpeechSynthesisUtterance();
10 |
11 | let vozesDisponiveis = [];
12 |
13 |
14 | const atualizarValores = () => {
15 | vozesDisponiveis = window.speechSynthesis.getVoices();
16 |
17 | fala.voice = vozesDisponiveis[0];
18 |
19 | console.log(vozesDisponiveis);
20 |
21 | vozesDisponiveis.forEach((voz, index) => {
22 | const opcao = document.createElement("option");
23 | opcao.value = index;
24 | opcao.textContent = voz.name;
25 | selecaoVoz.appendChild(opcao);
26 | });
27 | };
28 |
29 | window.speechSynthesis.onvoiceschanged = atualizarValores;
30 |
31 |
32 | selecaoVoz.addEventListener("change", () => {
33 | fala.voice = vozesDisponiveis[selecaoVoz.value];
34 | });
35 |
36 | botaoOuvir.addEventListener("click", () => {
37 | fala.text = entradaTexto.value;
38 |
39 | window.speechSynthesis.speak(fala);
40 | });
41 |
42 |
43 | botoaBaixarTexto.addEventListener("click", () => {
44 | const texto = entradaTexto.value;
45 |
46 | const blob = new Blob([texto], { type: "text/plain" });
47 |
48 | const url = URL.createObjectURL(blob);
49 |
50 | const a = document.createElement("a");
51 |
52 | a.href = url;
53 |
54 | a.download = "texto.txt";
55 |
56 | a.click();
57 |
58 | URL.revokeObjectURL(url);
59 | });
60 |
61 |
62 | uplaodArquivo.addEventListener("change", (event) => {
63 | const arquivo = event.target.files[0];
64 |
65 | if (arquivo) {
66 | const leitor = new FileReader();
67 |
68 | leitor.onload = (e) => {
69 | entradaTexto.value = e.target.result;
70 | };
71 |
72 | leitor.readAsText(arquivo);
73 | }
74 | });
75 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Digite um texto ou envie algum arquivo para ser lido:
35 |Selecione a voz:
48 | 49 |Clique para ouvir:
52 | 53 |Obtenha um arquivo do conteúdo:
56 | 57 |