Giter Site home page Giter Site logo

React UI Improvements about divisor HOT 1 OPEN

brio50 avatar brio50 commented on May 30, 2024
React UI Improvements

from divisor.

Comments (1)

brio50 avatar brio50 commented on May 30, 2024

math.js is the way to perform calculations, it can parse the expression for validity and then evaluate it. There are problems though:

  1. on mobile keyboards for iphone, only a decimal is available in the numeric keypad.

  2. validateMeasurement will have to return a validity flag, along with the validated measurement value. The onChange*

    import { parse, evaluate } from 'mathjs';
    
    ...
    
    // TODO: mathematical expressions (only allow +, -, *, / symbols) keyed on = as input?
    function validateMeasurement(event) {
    
    var valid = true; // output 1
    var value = event.target.value; // output 2
    
    function parseValue(value) {
      
      ...
      
      // do math if string contains math operations
      if (value.match(/\d+\+$/)) {      // e.g.  2+
        valid = false;
        value = value;
        console.log("plus");
        return { valid, value };
      }
    
      try {
          parse(value);
          valid = true;
          value = evaluate(value);
          return { valid, value };
      }
      catch (ex) {
          console.log("Not a mathematical expression.");
      }
    
    const onChangeMM = (event) => {
    
    let {valid, value} = validateMeasurement(event)
    
    if (!valid) {
      setMM({
        ...millimeters,
        input: value,
        output: "",
        error: ""
      });
      return;
    }
    
  3. once we detect a mathematical expression is being input, we have to provide a calculate button to let the user tell us when they're done formatting the equation. A good example expression would be adding three measurements : 1 + 1.5 + 3+(5/8)

from divisor.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.