manipular los ejes x e y
This commit is contained in:
parent
491b41efa7
commit
06aff490dc
@ -1,4 +1,5 @@
|
|||||||
import React, { useEffect } from 'react';
|
|
||||||
|
import React, { useRef, useEffect } from 'react';
|
||||||
import { Chart, registerables } from 'chart.js';
|
import { Chart, registerables } from 'chart.js';
|
||||||
import zoomPlugin from 'chartjs-plugin-zoom';
|
import zoomPlugin from 'chartjs-plugin-zoom';
|
||||||
|
|
||||||
@ -6,17 +7,17 @@ import zoomPlugin from 'chartjs-plugin-zoom';
|
|||||||
Chart.register(...registerables, zoomPlugin);
|
Chart.register(...registerables, zoomPlugin);
|
||||||
|
|
||||||
const Tablero = ({ labels, dataPoints }) => {
|
const Tablero = ({ labels, dataPoints }) => {
|
||||||
|
const canvasRef = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Verifica si el canvas está disponible
|
// Asegúrate de que el código solo se ejecute en el cliente
|
||||||
const canvas = document.getElementById("myChart");
|
const canvas = canvasRef.current;
|
||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
console.error("Canvas element not found");
|
console.error("Canvas element not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
// Verifica si el contexto es válido
|
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
console.error("Failed to get canvas context");
|
console.error("Failed to get canvas context");
|
||||||
return;
|
return;
|
||||||
@ -46,11 +47,11 @@ const Tablero = ({ labels, dataPoints }) => {
|
|||||||
},
|
},
|
||||||
zoom: {
|
zoom: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'x', // Habilita el zoom en el eje X
|
mode: 'x',
|
||||||
},
|
},
|
||||||
pan: {
|
pan: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'x', // Habilita el desplazamiento en el eje X
|
mode: 'x',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
y: {
|
y: {
|
||||||
@ -60,11 +61,11 @@ const Tablero = ({ labels, dataPoints }) => {
|
|||||||
},
|
},
|
||||||
zoom: {
|
zoom: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'y', // Habilita el zoom en el eje Y
|
mode: 'y',
|
||||||
},
|
},
|
||||||
pan: {
|
pan: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'y', // Habilita el desplazamiento en el eje Y
|
mode: 'y',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -72,14 +73,14 @@ const Tablero = ({ labels, dataPoints }) => {
|
|||||||
zoom: {
|
zoom: {
|
||||||
pan: {
|
pan: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'xy', // Permite el desplazamiento en ambos ejes
|
mode: 'xy',
|
||||||
},
|
},
|
||||||
zoom: {
|
zoom: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'xy', // Permite el zoom en ambos ejes
|
mode: 'xy',
|
||||||
speed: 0.1, // Velocidad de zoom
|
speed: 0.1,
|
||||||
sensitivity: 3, // Sensibilidad del zoom
|
sensitivity: 3,
|
||||||
threshold: 2, // Umbral de activación del zoom
|
threshold: 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ const Tablero = ({ labels, dataPoints }) => {
|
|||||||
return () => myChart.destroy();
|
return () => myChart.destroy();
|
||||||
}, [labels, dataPoints]);
|
}, [labels, dataPoints]);
|
||||||
|
|
||||||
return <canvas id="myChart" width="400" height="175"></canvas>;
|
return <canvas ref={canvasRef} width="400" height="175"></canvas>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Tablero;
|
export default Tablero;
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import Tablero from './funciones';
|
|
||||||
import { evaluate } from 'mathjs';
|
import { evaluate } from 'mathjs';
|
||||||
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
|
// Importa el componente Tablero dinámicamente sin renderizado del lado del servidor
|
||||||
|
const Tablero = dynamic(() => import('./funciones'), { ssr: false });
|
||||||
|
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const [expression, setExpression] = useState('');
|
const [expression, setExpression] = useState('');
|
||||||
|
22
package-lock.json
generated
22
package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chart.js": "^4.4.4",
|
"chart.js": "^4.4.4",
|
||||||
|
"chartjs-plugin-zoom": "^2.0.1",
|
||||||
"mathjs": "^13.1.1",
|
"mathjs": "^13.1.1",
|
||||||
"next": "14.2.11",
|
"next": "14.2.11",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
@ -1217,6 +1218,18 @@
|
|||||||
"pnpm": ">=8"
|
"pnpm": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/chartjs-plugin-zoom": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/chartjs-plugin-zoom/-/chartjs-plugin-zoom-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-ogOmLu6e+Q7E1XWOCOz9YwybMslz9qNfGV2a+qjfmqJYpsw5ZMoRHZBUyW+NGhkpQ5PwwPA/+rikHpBZb7PZuA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"hammerjs": "^2.0.8"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"chart.js": ">=3.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/chokidar": {
|
"node_modules/chokidar": {
|
||||||
"version": "3.6.0",
|
"version": "3.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||||
@ -2642,6 +2655,15 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/hammerjs": {
|
||||||
|
"version": "2.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/hammerjs/-/hammerjs-2.0.8.tgz",
|
||||||
|
"integrity": "sha512-tSQXBXS/MWQOn/RKckawJ61vvsDpCom87JgxiYdGwHdOa0ht0vzUWDlfioofFCRU0L+6NGDt6XzbgoJvZkMeRQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/has-bigints": {
|
"node_modules/has-bigints": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz",
|
||||||
|
Loading…
Reference in New Issue
Block a user