Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use regression.js in a browser #106

Open
alitaker opened this issue Apr 9, 2020 · 3 comments
Open

How to use regression.js in a browser #106

alitaker opened this issue Apr 9, 2020 · 3 comments

Comments

@alitaker
Copy link

alitaker commented Apr 9, 2020

Hi, the readme states that regression.js works in a browser too, but I can't seem to use it when importing with:
import {regression} from 'regression';
Either I get
ReferenceError: regression is not defined
when using it
or
TypeError: global is undefined
or
TypeError: a is undefined
when using the minified version.

Can anybody provide a strip down HTML example without using node.js or package managers?

Thank you

@Miguel446
Copy link

Miguel446 commented Apr 9, 2020

Hi, I found this example and that worked for me https://jsfiddle.net/nagubal/cpxwLf2t/
the relevant part is this one:

const getRegression = (data, degre) => {
degre = degre || 2;
let dataRegression = [];
data.forEach((element, index) => dataRegression.push([index + 1, element]));

let resultRegression = [];
regression('polynomial', dataRegression, degre).points.forEach((element) =>
resultRegression.push(Math.ceil(element[1] * 100) / 100)
);
return resultRegression;
};

Apparently the module usage has been changed but the documentation was not updated yet

@alitaker
Copy link
Author

@Miguel446 that example is using regression.js version 1.3.0 from here:
https://cdnjs.cloudflare.com/ajax/libs/regression/1.3.0/regression.min.js

I found an exampe with 1.4.0 at the following link:
https://bl.ocks.org/daluu/5bb59ef3f3fed3de227535da367649ba
It's working for me and now I'm using that version.

Anyway, I'd like to be able to use current and future versions, so if anyone has a clue on using the latest version in an HTML, please post it here.

After googling a bit I found that there should be a specific build for browsers or a workaround config, as for this example of Vue.js:
https://vuejsdevelopers.com/2019/02/04/vue-es-module-browser-build/

@Miguel446
Copy link

Miguel446 commented Apr 10, 2020

Great article about modules and also the latest regression.js cdn version is 1.4.0 and the npm version is 2.0.1, so unfortunately the developer stopped supporting web browsers some time ago

But if you really need the latest version, I found this article about how to use a npm module on html, I’m not sure if it will work but it’s worth giving it a shot

https://medium.com/jeremy-keeshin/hello-world-for-javascript-with-npm-modules-in-the-browser-6020f82d1072

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants