Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/api/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ export default class Solver {
if (equation.includes(variable) === false) return [];

// Trouve les solutions de l'équation
var rawSolutions = nerdamer.solveEquations(equation + ' = ' + y, variable);
while (equation.startsWith(')')) equation = equation.slice(1);

try {
var rawSolutions = nerdamer.solveEquations(equation + ' = ' + y, variable);
} catch {
return [];
}

// Transforme les solutions en array
const solutionsArray = this.stringToArray(rawSolutions.toString());
Expand Down Expand Up @@ -141,6 +147,8 @@ export default class Solver {
if (variableValue.toString() === '0') return NaN;
}

if (x === undefined) return NaN;

return this.toInteger(x.toString());
}
}
118 changes: 66 additions & 52 deletions src/components/Designer.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { afterUpdate, createEventDispatcher, onDestroy, onMount } from 'svelte';
import { createEventDispatcher, onMount } from 'svelte';
import MathsExt from '../extensions/mathsExt';
import Choix from '../models/choix';
import SaisieFonction from './SaisieFormule.svelte';
import SaisieFormule from './saisie/SaisieFormule.svelte';
import TableauDeSigne from './tds/Tableau.svelte';
//@ts-ignore
import DomToImage from 'dom-to-image';
Expand All @@ -26,6 +26,9 @@
// Taille du tableau
let scale: number = 1;

// Utile pour cacher certaines icones
export let isInfoShown: boolean = false;

/**
* Trigger lorsque la taille de la fenêtre change
* Permet de montrer la zone de configuration après être passé sur une fenêtre plus
Expand Down Expand Up @@ -71,7 +74,11 @@
*/
const functionChanged = (e: CustomEvent<any>) => {
// Remplace la formule par la nouvelle
choix = Choix.Tableau;
formula = e.detail;
setTimeout(() => {
choix = Choix.Variation;
}, 100);
};

/**
Expand Down Expand Up @@ -107,7 +114,9 @@

// Désigne la formule utilisé dans le tableau (tout sauf le tableau de variation),
// Si on veut étudier des variations, on dérive la formule de base
$: formuleTableau = choix === Choix.Tableau ? formula : MathsExt.Deriver(formula, variableName);
$: formuleTableau =
choix === Choix.Tableau ? formula : MathsExt.Deriver(formula, variableName)[0];
$: deriverTex = choix === Choix.Tableau ? formula : MathsExt.Deriver(formula, variableName)[1];

/**
* Télécharge le tableau en format image
Expand Down Expand Up @@ -154,7 +163,7 @@
<form class="px-3 flex flex-col w-full">
<fieldset id="group" class="w-full">
<div class="w-full">
<div>
<div class="mt-3">
<input
type="radio"
id="variations"
Expand Down Expand Up @@ -190,7 +199,7 @@
</div>

<div class="md:max-w-[270px]">
<SaisieFonction
<SaisieFormule
on:handleFunctionNameChanged={functionNameChanged}
on:handleVariableNameChanged={variableNameChanged}
on:handleFunctionChanged={functionChanged}
Expand All @@ -213,10 +222,10 @@
{#if choix === Choix.Variation}
<div class="opacity-70 mt-3 md:max-w-[280px]">
<p class="italic -mb-3 cursor-default">Dérivée de f(x)</p>
<SaisieFonction
<SaisieFormule
{variableName}
functionName={functionName + "'"}
formula={formuleTableau}
formula={deriverTex}
isDisabled={true}
/>
</div>
Expand All @@ -225,7 +234,7 @@
</fieldset>
</form>

<label class="mx-5 mt-0 md:mt-3 mb-1 md:mb-2" for="scale"> Taille du tableau </label>
<label class="mx-5 mt-3 mb-1 md:mb-2" for="scale"> Taille du tableau </label>

<input type="range" class="mx-5" bind:value={scale} min="1" max="3" step="0.05" id="scale" />

Expand Down Expand Up @@ -257,31 +266,33 @@

<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- Bouton pour toggle la visibilité de la configuration -->
<div
class="absolute right-1 mt-1 visible md:hidden cursor-pointer opacity-60 z-50 flex flex-col items-center justify-center"
on:mousedown={() => {
toggleConfigVisibility = !toggleConfigVisibility;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="black"
class="w-8 h-8"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d={toggleConfigVisibility
? 'M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z'
: 'M10.5 6h9.75M10.5 6a1.5 1.5 0 11-3 0m3 0a1.5 1.5 0 10-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-9.75 0h9.75'}
/>
</svg>
<p class="-mt-1 text-sm">{toggleConfigVisibility ? 'hide' : 'show'}</p>
</div>

{#if !isInfoShown}
<div
class="absolute right-1 mt-1 visible md:hidden cursor-pointer opacity-60 z-50 flex flex-col items-center justify-center"
on:mousedown={() => {
toggleConfigVisibility = !toggleConfigVisibility;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="black"
class="w-8 h-8"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d={toggleConfigVisibility
? 'M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z'
: 'M10.5 6h9.75M10.5 6a1.5 1.5 0 11-3 0m3 0a1.5 1.5 0 10-3 0M3.75 6H7.5m3 12h9.75m-9.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-3.75 0H7.5m9-6h3.75m-3.75 0a1.5 1.5 0 01-3 0m3 0a1.5 1.5 0 00-3 0m-9.75 0h9.75'}
/>
</svg>
<p class="-mt-1 text-sm">{toggleConfigVisibility ? 'hide' : 'show'}</p>
</div>
{/if}
<div
class="pt-5 w-full h-full overflow-y-auto overflow-x-hidden mb-5 flex flex-col justify-center items-center relative"
>
Expand All @@ -306,7 +317,7 @@

{#if toggleConfigVisibility === false}
<div class="w-8/12 absolute -top-1.5 self-center">
<SaisieFonction
<SaisieFormule
on:handleFunctionNameChanged={functionNameChanged}
on:handleVariableNameChanged={variableNameChanged}
on:handleFunctionChanged={functionChanged}
Expand All @@ -316,24 +327,27 @@
/>
</div>
{/if}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="darkblue"
class={'w-8 h-8 absolute top-1.5 mt-1 left-2 md:left-auto md:right-2 opacity-50 cursor-pointer z-50 '}
on:click={() => {
dispatch('showInfo');
}}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
/>
</svg>

{#if !isInfoShown}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="darkblue"
class={'w-8 h-8 absolute top-1.5 mt-1 left-2 md:left-auto md:right-2 opacity-50 cursor-pointer z-50 '}
on:click={() => {
dispatch('showInfo');
}}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
/>
</svg>
{/if}
</div>
</div>
2 changes: 1 addition & 1 deletion src/components/SaisieFormule.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export let isDisabled: boolean = false;
</script>

<div class="w-full mt-3 flex flex-row items-center rounded-lg bg-white overflow-auto">
<div class="mt-3 flex flex-row items-center rounded-lg bg-white">
<SaisieFonction
{functionName}
{variableName}
Expand Down
13 changes: 9 additions & 4 deletions src/components/SaisieMath.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* mis par défaut
*/
onMount(() => {
dispatch(eventName, value.trim());
dispatch(eventName, value);
});

/**
Expand Down Expand Up @@ -91,7 +91,7 @@

{#if isEditing}
<textarea
class={`bg-transparent text-xs md:text-xs lg:text-lg mt-7 outline-none placeholder:text-opacity-50 resize-none ${classes} ${classesInput} ${
class={`bg-transparent text-xl mt-7 outline-none placeholder:text-opacity-50 resize-none ${classes} ${classesInput} ${
!isFormulaValid ? 'text-red-500' : ''
}`}
spellcheck="false"
Expand Down Expand Up @@ -127,8 +127,13 @@
/>
{:else}
<div
class={`pb-2 pt-2.5 select-none text-xs md:text-xs lg:text-lg ${classes} ` +
(isDisabled ? 'cursor-default ' : 'cursor-text hover:font-bold hover:text-blue-700 ')}
class={` pb-2 pt-2.5 select-none text-xs md:text-xs lg:text-lg ${classes} ` +
(isDisabled ? 'cursor-default ' : 'cursor-text hover:font-bold hover:text-blue-700 ') +
(value.length > 10 && value.length < 15
? 'lg:text-lg '
: value.length > 15
? 'lg:text-xs '
: '')}
on:mousedown={() => {
if (!isDisabled) {
isEditing = true;
Expand Down
Loading